[PATCH] D65891: [llvm-objcopy] Allow 'protected' visibility to be set when using add-symbol

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 8 03:01:05 PDT 2019


MaskRay added a comment.

It makes sense from the perspective of completeness but STV_PROTECTED is problematic and can hardly find a justified use case.

People use STV_PROTECTED when they want to avoid GOT/PLT costs in PIC code. However,

A protected STT_OBJECT prevents you from doing copy relocation. ld.bfd silently accepts this, which can cause ODR violations.
A protected STT_FUNC prevents you from making a canonical PLT (-fno-pic code in executable references an external function). If the linker fails to stop you, you'll get pointer equality problems. (It can be argued this case can be fixed by letting the compiler go through GOT when the address of a protected function is taken, but then the GOT indirection will likely break people's expectation. A symbol lookup change is also required on ld.so side.)

I think lld and gold reject both cases. So at the best, a protected symbol can be seen as a promise of the toolchain that the symbol will not be interposed.

Actually, in a DSO, a STV_PROTECTED use case can be easily replaced with the hidden+alias idiom:

  __attribute__((visibility("hidden"))) void internal() {} // internal use
  __attribute__((alias("internal"))) void external(); // external API

The reservation of STV_INTERNAL was requested by SGI when gABI was formulated. All other parties appear to treat STV_INTERNAL the same as STV_HIDDEN.


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

https://reviews.llvm.org/D65891





More information about the llvm-commits mailing list