This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - Give a symbol version extracted from name a priority over version set by script.
ClosedPublic

Authored by grimar on Jul 10 2017, 9:14 AM.

Details

Summary

This fixes PR33712.

Imagine following script and code:

VER1 { global: foo; local: *; };
VER2 { global: foo; };
.global bar
bar:
.symver bar, foo@VER1

.global zed
zed:
.symver zed, foo@@VER2

We add foo@@VER2 as foo to symbol table, because have to resolve references to
foo for default symbols.
Later we are trying to assign symbol versions from script. For that we are searching for 'foo'
again. Here it is placed under VER1 and VER2 at the same time, we find it twice and trying to
set version again both times, hence LLD shows a warning.
Though sample code is correct: we have 2 different versions of foo.

Probably easiest way is to give .symver a priority over version script and do not reassign versions.
Looks bfd and gold do the same here.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar created this revision.Jul 10 2017, 9:14 AM
ruiu added inline comments.Jul 10 2017, 10:36 AM
ELF/SymbolTable.cpp
234 ↗(On Diff #105866)

Got is in general not a good name in the linker as it could mean Global Offset Table.

ELF/Symbols.h
366–370 ↗(On Diff #105866)

Do you really need this? You could just call parseSymbolVersion after processing version scripts, no?

grimar updated this revision to Diff 105984.Jul 11 2017, 3:02 AM
  • Addressed review comments.
ELF/Symbols.h
366–370 ↗(On Diff #105866)

I can drop this flag with a cost of one more lookup of '@' (updated the diff to demonstrate).

Without that it will not work so simple becaue of next:
When we have symbol foo@@VER2 we drop version and add it as foo to SymbolTable.
One of steps proccessing version scripts is a call of assignExactVersion and it do:

std::vector<SymbolBody *> Syms = findByVersion(Ver);

For this call Ver.Name is foo for VER1 and VER2. Hence it will try to assign version to the same
symbol twice and will report warning.

ruiu added inline comments.Jul 11 2017, 10:54 AM
ELF/SymbolTable.cpp
705 ↗(On Diff #105984)

Can you replace this with

if (Sym->VersionId != Config->DefaultSymbolVersion)

to remove Symbol::InVersionScript?

756 ↗(On Diff #105984)

Indentation

grimar updated this revision to Diff 106171.Jul 12 2017, 4:22 AM
  • Rebased.
  • Fixed identation.
ruiu accepted this revision.Jul 12 2017, 6:40 AM

LGTM

ELF/SymbolTable.cpp
698–699 ↗(On Diff #106171)

// Skip symbols containing version info because symbol versions specified by symbol names take precedence over version scripts. See parseSymbolVersion().

This revision is now accepted and ready to land.Jul 12 2017, 6:40 AM
This revision was automatically updated to reflect the committed changes.