In IBM compiler xlclang , there is an option -fnovisibility which suppresses visibility. For more details see: https://www.ibm.com/support/knowledgecenter/SSGH3R_16.1.0/com.ibm.xlcpp161.aix.doc/compiler_ref/opt_visibility.html.
We need to add the option -mignore-xcoff-visibility for compatibility with the IBM AIX OS (as the option is enabled by default in AIX). With this option llvm does not emit any visibility attribute to ASM or XCOFF object file.
The option only work on the AIX OS, for other non-AIX OS using the option will report an unsupported options error. For example, the file test.c:
bash-4.2$ test.c __attribute__((visibility ("protected"))) int b; clang -mignore-xcoff-visibility -target powerpc-unknown-linux -S test.c clang-12: error: unsupported option '-mignore-xcoff-visibility' for target 'powerpc-unknown-linux
In AIX OS:
1.1 the option -mignore-xcoff-visibility is enabled by default , if there is not -fvisibility=* and -mignore-xcoff-visibility explicitly in the clang command .
clang -mignore-xcoff-visibility -target powerpc-unknown-aix -S test.c or clang -target powerpc-unknown-aix -S test.c ( the -mignore-xcoff-visibility is enabled by default in AIX OS) Generate as as : .globl b
1.2 if there is -fvisibility=* explicitly but not -mignore-xcoff-visibility explicitly in the clang command. it will generate visibility attributes.
clang -fvisibility=default -target powerpc-unknown-aix -S test.c Generate ASM as : .globl b,protected
1.3 if there are both -fvisibility=* and -mignore-xcoff-visibility explicitly in the clang command. The option "-mignore-xcoff-visibility" wins , it do not emit the visibility attribute.
clang -mignore-xcoff-visibility -fvisibility=default -target powerpc-unknown-aix -S test.c Generate ASM as : .globl b
The option -mignore-xcoff-visibility has no effect on visibility attribute when compile with -emit-llvm option to generated LLVM IR.
We should move this option to where all the other -m options resides.