[ELF] Consistently prioritize non-* wildcards overs "*" in version scripts
authorFangrui Song <maskray@google.com>
Mon, 5 Aug 2019 14:31:39 +0000 (14:31 +0000)
committerFangrui Song <maskray@google.com>
Mon, 5 Aug 2019 14:31:39 +0000 (14:31 +0000)
commite28a70daf4e685ed4b50619fb30983b4464fae1c
tree4a5bb115f6a58f96669f788bb0de95aac9861eea
parent0039f87fa5c9b621d2e3aee0e79f1bab297cd5ef
[ELF] Consistently prioritize non-* wildcards overs "*" in version scripts

We prioritize non-* wildcards overs VER_NDX_LOCAL/VER_NDX_GLOBAL "*".
This patch generalizes the rule to "*" of other versions and thus fixes PR40176.
I don't feel strongly about this GNU linkers' behavior but the
generalization simplifies code.

Delete `config->defaultSymbolVersion` which was used to special case
VER_NDX_LOCAL/VER_NDX_GLOBAL "*".

In `SymbolTable::scanVersionScript`, custom versions are handled the same
way as VER_NDX_LOCAL/VER_NDX_GLOBAL. So merge
`config->versionScript{Locals,Globals}` into `config->versionDefinitions`.
Overall this seems to simplify the code.

In `SymbolTable::assign{Exact,Wildcard}Versions`,
`sym->verdefIndex == config->defaultSymbolVersion` is changed to
`verdefIndex == UINT32_C(-1)`.
This allows us to give duplicate assignment diagnostics for
`{ global: foo; };` `V1 { global: foo; };`

In test/linkerscript/version-script.s:
  vs_index of an undefined symbol changes from 0 to 1. This doesn't matter (arguably 1 is better because the binding is STB_GLOBAL) because vs_index of an undefined symbol is ignored.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D65716

llvm-svn: 367869
lld/ELF/Config.h
lld/ELF/Driver.cpp
lld/ELF/ScriptParser.cpp
lld/ELF/SymbolTable.cpp
lld/ELF/Symbols.cpp
lld/ELF/SyntheticSections.cpp
lld/ELF/Writer.cpp
lld/test/ELF/linkerscript/version-script.s
lld/test/ELF/version-script-reassign-glob.s [new file with mode: 0644]
lld/test/ELF/version-script-reassign.s