Skip to content

Commit c0fc253

Browse files
committed
Change the --retain-symbols-file implementation.
It now uses the same infrastructure as symbol versions. This fixes us creating a dynamic relocation without a corresponding dynamic symbol. This also means that unlike gold and bfd we keep a STB_LOCAL in the static symbol table. It seems an odd feature to offer precise control over what is in a symbol table that is not used by the dynamic linker. We can bring this back if needed, but it would probably be better to just have --discard option that tells the linker to keep in the static symbol table only what is in the dynamic one. Should fix the eog build. llvm-svn: 293093
1 parent 65144c8 commit c0fc253

File tree

5 files changed

+36
-15
lines changed

5 files changed

+36
-15
lines changed

lld/ELF/Config.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ enum ELFKind {
3434
// For --build-id.
3535
enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
3636

37-
// For --discard-{all,locals,none} and --retain-symbols-file.
38-
enum class DiscardPolicy { Default, All, Locals, RetainFile, None };
37+
// For --discard-{all,locals,none}.
38+
enum class DiscardPolicy { Default, All, Locals, None };
3939

4040
// For --strip-{all,debug}.
4141
enum class StripPolicy { None, All, Debug };
@@ -84,7 +84,6 @@ struct Configuration {
8484
llvm::StringRef OutputFile;
8585
llvm::StringRef SoName;
8686
llvm::StringRef Sysroot;
87-
llvm::StringSet<> RetainSymbolsFile;
8887
std::string RPath;
8988
std::vector<VersionDefinition> VersionDefinitions;
9089
std::vector<llvm::StringRef> AuxiliaryList;

lld/ELF/Driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,11 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
614614
// If --retain-symbol-file is used, we'll retail only the symbols listed in
615615
// the file and discard all others.
616616
if (auto *Arg = Args.getLastArg(OPT_retain_symbols_file)) {
617-
Config->Discard = DiscardPolicy::RetainFile;
617+
Config->DefaultSymbolVersion = VER_NDX_LOCAL;
618618
if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
619619
for (StringRef S : getLines(*Buffer))
620-
Config->RetainSymbolsFile.insert(S);
620+
Config->VersionScriptGlobals.push_back(
621+
{S, /*IsExternCpp*/ false, /*HasWildcard*/ false});
621622
}
622623

623624
for (auto *Arg : Args.filtered(OPT_export_dynamic_symbol))

lld/ELF/Writer.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,6 @@ template <class ELFT> static bool includeInSymtab(const SymbolBody &B) {
425425
if (!B.isLocal() && !B.symbol()->IsUsedInRegularObj)
426426
return false;
427427

428-
// If --retain-symbols-file is given, we'll keep only symbols listed in that
429-
// file.
430-
if (Config->Discard == DiscardPolicy::RetainFile &&
431-
!Config->RetainSymbolsFile.count(B.getName()))
432-
return false;
433-
434428
if (auto *D = dyn_cast<DefinedRegular<ELFT>>(&B)) {
435429
// Always include absolute symbols.
436430
if (!D->Section)

lld/test/ELF/retain-symbols-file.s

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
# RUN: echo "bar" > %t_retain.txt
44
# RUN: echo "foo" >> %t_retain.txt
55
# RUN: ld.lld -shared --retain-symbols-file=%t_retain.txt %t -o %t2
6-
# RUN: llvm-readobj -t %t2 | FileCheck %s
6+
# RUN: llvm-readobj --dyn-symbols %t2 | FileCheck %s
77

88
## Check separate form.
99
# RUN: ld.lld -shared --retain-symbols-file %t_retain.txt %t -o %t2
10-
# RUN: llvm-readobj -t %t2 | FileCheck %s
10+
# RUN: llvm-readobj --dyn-symbols %t2 | FileCheck %s
1111

12-
# CHECK: Symbols [
12+
# CHECK: DynamicSymbols [
1313
# CHECK-NEXT: Symbol {
14-
# CHECK-NEXT: Name: (0)
14+
# CHECK-NEXT: Name: @
1515
# CHECK-NEXT: Value:
1616
# CHECK-NEXT: Size:
1717
# CHECK-NEXT: Binding:
@@ -37,6 +37,15 @@
3737
# CHECK-NEXT: Other:
3838
# CHECK-NEXT: Section: .text
3939
# CHECK-NEXT: }
40+
# CHECK-NEXT: Symbol {
41+
# CHECK-NEXT: Name: und
42+
# CHECK-NEXT: Value:
43+
# CHECK-NEXT: Size:
44+
# CHECK-NEXT: Binding: Global
45+
# CHECK-NEXT: Type:
46+
# CHECK-NEXT: Other:
47+
# CHECK-NEXT: Section: Undefined
48+
# CHECK-NEXT: }
4049
# CHECK-NEXT: ]
4150

4251
.text

lld/test/ELF/retain-und.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
3+
# RUN: echo > %t.retain
4+
# RUN: echo "{ local: *; }; " > %t.script
5+
# RUN: ld.lld -shared --version-script %t.script %t.o -o %t1.so
6+
# RUN: ld.lld -shared --retain-symbols-file %t.retain %t.o -o %t2.so
7+
# RUN: llvm-readobj -r %t1.so | FileCheck %s
8+
# RUN: llvm-readobj -r %t2.so | FileCheck %s
9+
10+
# CHECK: Relocations [
11+
# CHECK-NEXT: Section ({{.*}}) .rela.dyn {
12+
# CHECK-NEXT: 0x{{.*}} R_X86_64_64 foo 0x0
13+
# CHECK-NEXT: }
14+
# CHECK-NEXT: ]
15+
16+
.data
17+
.quad foo
18+
.weak foo

0 commit comments

Comments
 (0)