-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[ELF] Merge exportDynamic into versionId #71272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,9 @@ struct SymbolAux { | |
|
||
LLVM_LIBRARY_VISIBILITY extern SmallVector<SymbolAux, 0> symAux; | ||
|
||
// A versionId value similar to VER_NDX_LOCAL, but the binding is not changed. | ||
constexpr uint16_t nonExported = uint16_t(-1); | ||
|
||
// The base class for real symbol classes. | ||
class Symbol { | ||
public: | ||
|
@@ -129,17 +132,6 @@ class Symbol { | |
// which are referenced by relocations when -r or --emit-relocs is given. | ||
uint8_t used : 1; | ||
|
||
// Used by a Defined symbol with protected or default visibility, to record | ||
// whether it is required to be exported into .dynsym. This is set when any of | ||
// the following conditions hold: | ||
// | ||
// - If there is an interposable symbol from a DSO. Note: We also do this for | ||
// STV_PROTECTED symbols which can't be interposed (to match BFD behavior). | ||
// - If -shared or --export-dynamic is specified, any symbol in an object | ||
// file/bitcode sets this property, unless suppressed by LTO | ||
// canBeOmittedFromSymbolTable(). | ||
uint8_t exportDynamic : 1; | ||
|
||
// True if the symbol is in the --dynamic-list file. A Defined symbol with | ||
// protected or default visibility with this property is required to be | ||
// exported into .dynsym. | ||
|
@@ -254,7 +246,7 @@ class Symbol { | |
Symbol(Kind k, InputFile *file, StringRef name, uint8_t binding, | ||
uint8_t stOther, uint8_t type) | ||
: file(file), nameData(name.data()), nameSize(name.size()), type(type), | ||
binding(binding), stOther(stOther), symbolKind(k), exportDynamic(false), | ||
binding(binding), stOther(stOther), symbolKind(k), | ||
archSpecificBit(false) {} | ||
|
||
void overwrite(Symbol &sym, Kind k) const { | ||
|
@@ -316,9 +308,25 @@ class Symbol { | |
// This field is a index to the symbol's version definition. | ||
uint16_t verdefIndex; | ||
|
||
// Version definition index. | ||
uint16_t versionId; | ||
// Used by a Defined symbol with protected or default visibility, to record | ||
// the verdef index and whether the symbol is exported into .dynsym. | ||
// * -1 (initial): not exported, binding unchanged | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it work saying -1u as the field is uint16_t? I guess this means that we'll not be able to support a program with 65535 symbol versions. Probably not likely to encounter that in practice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The most significant bit is for VERSYM_HIDDEN 0x8000, so the largest version index is 0x7fff. This changes means that we cannot use 0x7fff as the version index. In practice, version indexes don't even reach 256... |
||
// * 0: VER_NDX_LOCAL, not exported, binding changed to STB_LOCAL | ||
// * 1: VER_NDX_GLOBAL, exported, binding unchanged | ||
// * others: verdef index, exported, binding unchanged | ||
// | ||
// -1 transits to 1 if any of the following conditions hold: | ||
// * If there is an interposable symbol from a DSO. Note: We also do this for | ||
// STV_PROTECTED symbols which can't be interposed (to match BFD behavior). | ||
// * If -shared or --export-dynamic is specified, any symbol in an object | ||
// file/bitcode sets this property, unless suppressed by LTO | ||
// canBeOmittedFromSymbolTable(). | ||
uint16_t versionId = nonExported; | ||
|
||
void exportIfNonExported() { | ||
if (versionId == nonExported) | ||
versionId = llvm::ELF::VER_NDX_GLOBAL; | ||
} | ||
void setFlags(uint16_t bits) { | ||
flags.fetch_or(bits, std::memory_order_relaxed); | ||
} | ||
|
@@ -353,7 +361,7 @@ class Defined : public Symbol { | |
uint8_t type, uint64_t value, uint64_t size, SectionBase *section) | ||
: Symbol(DefinedKind, file, name, binding, stOther, type), value(value), | ||
size(size), section(section) { | ||
exportDynamic = config->exportDynamic; | ||
versionId = config->defaultVersionId; | ||
} | ||
void overwrite(Symbol &sym) const { | ||
Symbol::overwrite(sym, DefinedKind); | ||
|
@@ -398,7 +406,7 @@ class CommonSymbol : public Symbol { | |
uint8_t stOther, uint8_t type, uint64_t alignment, uint64_t size) | ||
: Symbol(CommonKind, file, name, binding, stOther, type), | ||
alignment(alignment), size(size) { | ||
exportDynamic = config->exportDynamic; | ||
versionId = config->defaultVersionId; | ||
} | ||
void overwrite(Symbol &sym) const { | ||
Symbol::overwrite(sym, CommonKind); | ||
|
@@ -442,7 +450,7 @@ class SharedSymbol : public Symbol { | |
uint32_t alignment) | ||
: Symbol(SharedKind, &file, name, binding, stOther, type), value(value), | ||
size(size), alignment(alignment) { | ||
exportDynamic = true; | ||
versionId = llvm::ELF::VER_NDX_GLOBAL; | ||
dsoProtected = visibility() == llvm::ELF::STV_PROTECTED; | ||
// GNU ifunc is a mechanism to allow user-supplied functions to | ||
// resolve PLT slot values at load-time. This is contrary to the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this would be easier to read with parens, the operator precedence is not necessarily obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen some people use
(a && b) ? c : d
, but this isn't a majority.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case we should keep to the more common style. I think I just found it slightly harder to parse since I initially viewed this diff on mobile.