This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Give automatically generated __start_* and __stop_* symbols default visibility.
ClosedPublic

Authored by grimar on Aug 16 2016, 6:10 AM.

Details

Summary

This patch is opposite to D19024, which made this symbols to be hidden by default.

Unfortunately as was pointed by Sean Silva,
looks that FreeBSD loader wants to see start_set_modmetadata_set/stop_set_modmetadata_set in the dynamic symbol table.
They were not placed there because had hidden visibility.

Patch makes them to have default visibility again.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 68164.Aug 16 2016, 6:10 AM
grimar retitled this revision from to [ELF] - Give automatically generated __start_* and __stop_* symbols default visibility..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, silvas, davide and 2 others.
grimar added a subscriber: pcc.Aug 16 2016, 6:15 AM

The argument for making them hidden in D19024 is pretty reasonable. But I think it is also reasonable to be compatible if real code relies on this behavior.

Considering how difficult it can be to debug the type of issues that occur due to our incompatible behavior (e.g. kernel does not boot), it is not a good experience for a user of LLD.

ruiu added inline comments.Aug 17 2016, 1:03 PM
ELF/SymbolTable.cpp
425 ↗(On Diff #68164)

I'm not the type of person who wants to eliminate all constants, but 3? It's too magical.

grimar added inline comments.Aug 18 2016, 12:04 AM
ELF/SymbolTable.cpp
425 ↗(On Diff #68164)

Actually it is used in many places in lld. I count 4 more places in this file (SymbolTable.cpp) and also once in Symbols.h:

uint8_t getVisibility() const { return StOther & 0x3; }

I suggest to leave it for now and fix once for all places if you want it.

ruiu added inline comments.Aug 18 2016, 1:35 PM
ELF/SymbolTable.cpp
425 ↗(On Diff #68164)

The use of 0x3 in getVisibility is fine because it is obvious that it is extracting visibility bits. It actually hides the use of 0x3 and wraps it with a better name (getVisibility). But in this context there's no information as to what you are doing.

grimar added inline comments.Aug 19 2016, 1:15 AM
ELF/SymbolTable.cpp
425 ↗(On Diff #68164)

What about adding comment then ?

bool WasInserted;
std::tie(S, WasInserted) =
    insert(N, STT_NOTYPE, StOther & 0x3 /*Visibility*/, /*CanOmitFromDynSym*/ false,

Or do you prefer static method for that ?

static unsigned getVisibility(unsigned O) { 
  return O & 0x3;
}

...

  std::tie(S, WasInserted) =
      insert(N, STT_NOTYPE, getVisibility(StOther), /*CanOmitFromDynSym*/ false,
ruiu added inline comments.Aug 19 2016, 7:53 AM
ELF/SymbolTable.cpp
425 ↗(On Diff #68164)

A quick google search showed me that there's macros to get the value, ELF32_ST_VISIBILITY and ELF64_ST_VISIBILITY. Unfortunately they are as confusing as the mask because of ELF32/ELF64 prefixes (although what they do is the same.) So I'd go with a comment.

grimar added inline comments.Aug 19 2016, 7:55 AM
ELF/SymbolTable.cpp
425 ↗(On Diff #68164)

Yes, that is why I did not use them + also do not sure if we were using macroses in lld before.

ruiu accepted this revision.Aug 19 2016, 8:13 AM
ruiu edited edge metadata.

LGTM with a comment. Thanks!

This revision is now accepted and ready to land.Aug 19 2016, 8:13 AM
This revision was automatically updated to reflect the committed changes.