Linkage warning in current trunk

Building on OS X 10.7.1 with the standard toolchain, I have seen the
following linker warnings going back a number of versions in trunk
whenever I build an executable linked with LLVM:

    ld: warning: direct access in llvm::fouts() to global weak
symbol llvm::formatted_raw_ostream::~formatted_raw_ostream() means the
weak symbol cannot be overridden at runtime. This was likely caused by
different translation units being compiled with different visibility
settings.
    ld: warning: direct access in llvm::ferrs() to global weak
symbol llvm::formatted_raw_ostream::~formatted_raw_ostream() means the
weak symbol cannot be overridden at runtime. This was likely caused by
different translation units being compiled with different visibility
settings.
    ld: warning: direct access in llvm::fdbgs() to global weak
symbol llvm::formatted_raw_ostream::~formatted_raw_ostream() means the
weak symbol cannot be overridden at runtime. This was likely caused by
different translation units being compiled with different visibility
settings.

My code makes no references to the fouts/ferrs/fdbgs accessors—the
only references are in include/llvm/Support/FormattedStream.h and
lib/Support/FormattedStream.cpp.

This happens with a clean build of both LLVM and my project—I don't
believe it's an outdated header anywhere (at least outside LLVM).

(The only potential oddity: this project uses the OCaml bindings.)

Hi Jonathan,

This is likely caused by the addition of the "-fvisibility-inlines-hidden" flag when building LLVM. There are multiple things that can actually trigger the warnings though.

- If you're doing an incremental build, you may try to "make clean" and do a clean rebuild. It's not unlikely that it fixes the warnings.
- The ld binary that ships with xcode sometimes emits spurious warnings like those you're seeing. It's safe to ignore them.
- The clang binary that ships with xcode has a bug which breaks builds of shared libraries (this should manifest in linker errors though). This is fixed in clang trunk.

In any case you can avoid problems by commenting the line "CXX.Flags += -fvisibility-inlines-hidden" in Makefile.rules and do a rebuild. It will increase the size of the resulting binaries a bit but has no effects on functionality.

Sorry for the inconvenience
- Ben

Digging this up from the ancient past, since it still applies today, with the Xcode 4.5 toolchain on OS X 10.8:

The problem indeed seems to be the `-fvisibility-inlines-hidden` option.

This option is only settable by hacking the actual Makefile.rules (or elsewhere in the build process)—the actual ENABLE_VISIBILITY_INLINES_HIDDEN config variable is inferred from the system and cannot be overridden during configuration.

1. Is this really the right default choice, since it spews a moderate volume of disconcerting warning output all over any build which depends on LLVM?

2. Is it possible to make this an overridable option in the configure process? I'd be glad to make my project's local build of LLVM override this setting with a configure flag, but don't want to be in the business of having it patch the trunk repository. (The users of our system frequently complain about this warning, since they find it worrying and fear that their build is malfunctioning or they have done something wrong.)

Thanks.