Skip to content

Commit

Permalink
[ELF] Drop unnecessary VersionId setting in scanShlibUndefined
Browse files Browse the repository at this point in the history
LLD previously used to handle dynamic lists and version scripts in the
exact same way, even though they have very different semantics for
shared libraries and subtly different semantics for executables. r315114
untangled their semantics for executables (building on previous work to
correct their semantics for shared libraries). With that change, dynamic
lists won't set the default version to VER_NDX_LOCAL, and so resetting
the version to VER_NDX_GLOBAL in scanShlibUndefined is unnecessary.

This was causing an issue because version scripts containing `local: *`
work by setting the default version to VER_NDX_LOCAL, but scanShlibUndefined
would override this default, and therefore symbols which should have
been local would end up in the dynamic symbol table, which differs from
both bfd and gold's behavior. gold silently keeps the symbol hidden in
such a scenario, whereas bfd issues an error. I prefer bfd's behavior
and plan to implement that in LLD in a follow-up (and the test case
added here will be updated accordingly).

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

llvm-svn: 321982
  • Loading branch information
smeenai committed Jan 8, 2018
1 parent 66aea6e commit 3a15fb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
6 changes: 0 additions & 6 deletions lld/ELF/SymbolTable.cpp
Expand Up @@ -598,12 +598,6 @@ template <class ELFT> void SymbolTable::scanShlibUndefined() {
if (!Sym || !Sym->isDefined())
continue;
Sym->ExportDynamic = true;

// If -dynamic-list is given, the default version is set to
// VER_NDX_LOCAL, which prevents a symbol to be exported via .dynsym.
// Set to VER_NDX_GLOBAL so the symbol will be handled as if it were
// specified by -dynamic-list.
Sym->VersionId = VER_NDX_GLOBAL;
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions lld/test/ELF/shlib-undefined-local.s
@@ -0,0 +1,19 @@
# REQUIRES: x86

# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t1.o %S/Inputs/shlib-undefined-ref.s
# RUN: ld.lld -shared -o %t.so %t1.o

# RUN: llvm-mc -filetype=obj -triple=x86_64-linux-gnu -o %t2.o %s
# RUN: echo "{ local: *; };" > %t.script
# RUN: ld.lld -version-script %t.script -o %t %t2.o %t.so
# RUN: llvm-nm -g %t | FileCheck -allow-empty %s

# CHECK-NOT: should_not_be_exported

.globl should_not_be_exported
should_not_be_exported:
ret

.globl _start
_start:
ret

0 comments on commit 3a15fb5

Please sign in to comment.