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

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 2 13:43:16 PDT 2020


phosek added a comment.
Herald added a reviewer: MaskRay.

In D55682#1336709 <https://reviews.llvm.org/D55682#1336709>, @MaskRay wrote:

> Does that mean there is a visibility mismatch between source code and linker-defined symbol? e.g.
>
>   //extern char __start_f __attribute__((visibility("hidden")));
>   extern char __start_f; // Fuchsia wants to write code like this, but its visibility is set to hidden due to -z hidden-start-stop-symbols
>  
>   __attribute__((section("f"))) char *foo() {
>     return &__start_f;
>   }
>
>
> Please correct me but if my understanding is correct, I think the explicit visibility attribute in source code would be clearer.




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

> Thank you for the explanation. Your explanation makes sense to me. Being said that, I don't think I'd add a new option to the linker for Fuchsia, as I guess that the situation in which you want to iterate over start/end symbols is not too frequent. Also if you iterate over a known list of start/end symbols, you can define the symbols as hidden ones using __attribute__, so there's already an easy workaround that works on many ELF linkers.


The reason why is preferred over using explicit annotations in the source is because it matches the compiler behavior. We compile all our code with `-fvisibility=hidden` and we use explicit visibility annotations on symbols that should be exported. This is a standard way for controlling your ABI which is not specific to Fuchsia and is used by many other projects including LLVM. In that model, any symbol that does not have an explicit annotation is hidden. However, with `__start`/`__stop` symbols generated by lld, it's the opposite: they're exported by default and you need to use explicit annotation to make them hidden. That's confusing for developers and what we're trying to address. We would actually like to set `-z hidden-start-stop-symbols` in the Clang driver whenever `-fvisibility=hidden` is set to ensure that the compiler and linker use the same rules when it comes to symbol visibility.


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