Merge visibility from all symbols with the same name.
The ELF spec says:
... if any reference to or definition of a name is a symbol with a
non-default visibility attribute, the visibility attribute must be
propagated to the resolving symbol in the linked object. If different
visibility attributes are specified for distinct references to or
definitions of a symbol, the most constraining visibility attribute
must be propagated to the resolving symbol in the linked object. The
attributes, ordered from least to most constraining, are:
STV_PROTECTED, STV_HIDDEN and STV_INTERNAL.
llvm-svn: 246603
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 9108384..3145efc 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -304,7 +304,7 @@
SymbolBody *Body = Sym->Body;
const Elf_Sym &InputSym = cast<ELFSymbolBody<ELFT>>(Body)->Sym;
- uint8_t V = InputSym.getVisibility();
+ uint8_t V = Body->getMostConstrainingVisibility();
if (V != STV_DEFAULT && V != STV_PROTECTED)
continue;
@@ -331,7 +331,8 @@
uint8_t Binding = InputSym.getBinding();
ESym->setBindingAndType(Binding, Type);
ESym->st_size = InputSym.st_size;
- ESym->st_other = InputSym.st_other;
+ uint8_t Other = InputSym.st_other;
+ ESym->st_other = (Other & ~0x3) | Body->getMostConstrainingVisibility();
if (InputSym.isAbsolute()) {
ESym->st_shndx = SHN_ABS;
ESym->st_value = InputSym.st_value;
@@ -454,8 +455,7 @@
SymbolBody *Body = P.second->Body;
if (auto *C = dyn_cast<DefinedCommon<ELFT>>(Body))
CommonSymbols.push_back(C);
- auto *E = cast<ELFSymbolBody<ELFT>>(Body);
- uint8_t V = E->Sym.getVisibility();
+ uint8_t V = Body->getMostConstrainingVisibility();
if (V != STV_DEFAULT && V != STV_PROTECTED)
continue;
NumVisible++;