[PATCH] D55682: [ELF] Support defining __start/__stop symbols as hidden

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 19 11:58:53 PST 2018


phosek added a comment.

In D55682#1331628 <https://reviews.llvm.org/D55682#1331628>, @ruiu wrote:

> Adding a new option is a big deal. Could you elaborate on why you want to make these symbols hidden ones?


The real question is concrete examples of when you'd ever not want them hidden? The normal use for these symbols is always local to the module, and you want to be able to have multiple modules using the same section names.

Consider a static library that is meant to be statically linked into shared objects as a private implementation detail.  Say this library provides macros/templates to its users that emit metadata into a named section, and then library code that iterates over the section.  Each instance of this library inside a given shared object must iterate over its own list, not the list of whichever user of the static library happens to be first in dynamic linking symbol resolution order.

It seems like the only reason these symbols are exported is because when support for generating these symbols has been first implemented in ld.bfd, it didn't even have a concept of visibility. Later, binutils tried to make these symbols hidden, but that broke clients that depend on the old behavior (according to Hyrum's law) which is documented in https://sourceware.org/bugzilla/show_bug.cgi?id=21964

In D55682#1332033 <https://reviews.llvm.org/D55682#1332033>, @pcc wrote:

> I don't think you need to introduce an option for this. You can give the `__start_` and `__stop_` symbols hidden visibility in any object file, and the symbols in the final output file will be hidden because the linker will choose the most restrictive visibility that it sees for the visibility of the symbols in the final output file.


Yes that works, but it has to be done explicitly for each such symbol. We cannot change these symbols to be hidden by default for existing platforms as described above, but we would like to make them hidden by default in Fuchsia since we don't have any legacy code (yet) that would depend on the existing behavior. Introducing new option allows us to set it in the driver like we already do e.g. for `-z rodynamic` <https://github.com/llvm-mirror/clang/blob/master/lib/Driver/ToolChains/Fuchsia.cpp#L50> which is a similar case.


Repository:
  rLLD LLVM Linker

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D55682/new/

https://reviews.llvm.org/D55682





More information about the llvm-commits mailing list