Background
The AIX linker and XCOFF object file format, while having some visibility styles semantically similar to ELF (eg.e hidden, protected) have some unique distinctions. For the AIX linker, global or weak symbols which have no visibility bits (i.e the field set to zero, similar to ELF STV_DEFAULT) are only exported if specified on an export list provided to the linker (under the default and customary options).
To address usages of visibility in applications which may expect a symbol to be default to being exported in a shared object (such as may be expected by the user with __attribute__((__visibility__(default)))
on ELF targets), XCOFF has an additional visibility type called “exported” which indicates to the linker that the symbol should be explicitly globally exported.
The existing LLVM visibility styles (LLVM Language Reference Manual — LLVM 16.0.0git documentation) do not allow us to model this distinction between symbols with the “default” visibility style, which are rendered for XCOFF by the MC layer as symbols with no visibility type / bits, and ones which should instead have “exported” visibility type.
Proposal
To model this visibility type, the proposal is to add the “exported” visibility style to the existing LLVM IR visibility styles. This visibility would be largely similar to default, and ignored for non-XCOFF targets, but will allow the direct modelling of this visibility in the IR for XCOFF. This seems preferable then alternatives such as attributes, as this visibility style is indeed mutually exclusive with other known visibility styles such as hidden. Making this IR change will frontends such as clang to emit the correct visibility information for AIX targets based on the unique source level attributes and option settings in use.
Draft Implementation
A draft implementation is up on Phabricator as ⚙ D123951 [LLVM][AIX] Implement XCOFF exported visibility. Any feedback here or on the patch is most appreciated.
References
https://www.ibm.com/docs/en/aix/7.3?topic=l-ld-command
https://www.ibm.com/docs/en/aix/7.3?topic=formats-xcoff-object-file-format
https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=extension-types-visibility-attributes