[lld] r293093 - Change the --retain-symbols-file implementation.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 13:23:06 PST 2017
Author: rafael
Date: Wed Jan 25 15:23:06 2017
New Revision: 293093
URL: http://llvm.org/viewvc/llvm-project?rev=293093&view=rev
Log:
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.
Added:
lld/trunk/test/ELF/retain-und.s
Modified:
lld/trunk/ELF/Config.h
lld/trunk/ELF/Driver.cpp
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/retain-symbols-file.s
Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=293093&r1=293092&r2=293093&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed Jan 25 15:23:06 2017
@@ -34,8 +34,8 @@ enum ELFKind {
// For --build-id.
enum class BuildIdKind { None, Fast, Md5, Sha1, Hexstring, Uuid };
-// For --discard-{all,locals,none} and --retain-symbols-file.
-enum class DiscardPolicy { Default, All, Locals, RetainFile, None };
+// For --discard-{all,locals,none}.
+enum class DiscardPolicy { Default, All, Locals, None };
// For --strip-{all,debug}.
enum class StripPolicy { None, All, Debug };
@@ -84,7 +84,6 @@ struct Configuration {
llvm::StringRef OutputFile;
llvm::StringRef SoName;
llvm::StringRef Sysroot;
- llvm::StringSet<> RetainSymbolsFile;
std::string RPath;
std::vector<VersionDefinition> VersionDefinitions;
std::vector<llvm::StringRef> AuxiliaryList;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=293093&r1=293092&r2=293093&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Jan 25 15:23:06 2017
@@ -614,10 +614,11 @@ void LinkerDriver::readConfigs(opt::Inpu
// If --retain-symbol-file is used, we'll retail only the symbols listed in
// the file and discard all others.
if (auto *Arg = Args.getLastArg(OPT_retain_symbols_file)) {
- Config->Discard = DiscardPolicy::RetainFile;
+ Config->DefaultSymbolVersion = VER_NDX_LOCAL;
if (Optional<MemoryBufferRef> Buffer = readFile(Arg->getValue()))
for (StringRef S : getLines(*Buffer))
- Config->RetainSymbolsFile.insert(S);
+ Config->VersionScriptGlobals.push_back(
+ {S, /*IsExternCpp*/ false, /*HasWildcard*/ false});
}
for (auto *Arg : Args.filtered(OPT_export_dynamic_symbol))
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=293093&r1=293092&r2=293093&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Jan 25 15:23:06 2017
@@ -425,12 +425,6 @@ template <class ELFT> static bool includ
if (!B.isLocal() && !B.symbol()->IsUsedInRegularObj)
return false;
- // If --retain-symbols-file is given, we'll keep only symbols listed in that
- // file.
- if (Config->Discard == DiscardPolicy::RetainFile &&
- !Config->RetainSymbolsFile.count(B.getName()))
- return false;
-
if (auto *D = dyn_cast<DefinedRegular<ELFT>>(&B)) {
// Always include absolute symbols.
if (!D->Section)
Modified: lld/trunk/test/ELF/retain-symbols-file.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/retain-symbols-file.s?rev=293093&r1=293092&r2=293093&view=diff
==============================================================================
--- lld/trunk/test/ELF/retain-symbols-file.s (original)
+++ lld/trunk/test/ELF/retain-symbols-file.s Wed Jan 25 15:23:06 2017
@@ -3,15 +3,15 @@
# RUN: echo "bar" > %t_retain.txt
# RUN: echo "foo" >> %t_retain.txt
# RUN: ld.lld -shared --retain-symbols-file=%t_retain.txt %t -o %t2
-# RUN: llvm-readobj -t %t2 | FileCheck %s
+# RUN: llvm-readobj --dyn-symbols %t2 | FileCheck %s
## Check separate form.
# RUN: ld.lld -shared --retain-symbols-file %t_retain.txt %t -o %t2
-# RUN: llvm-readobj -t %t2 | FileCheck %s
+# RUN: llvm-readobj --dyn-symbols %t2 | FileCheck %s
-# CHECK: Symbols [
+# CHECK: DynamicSymbols [
# CHECK-NEXT: Symbol {
-# CHECK-NEXT: Name: (0)
+# CHECK-NEXT: Name: @
# CHECK-NEXT: Value:
# CHECK-NEXT: Size:
# CHECK-NEXT: Binding:
@@ -37,6 +37,15 @@
# CHECK-NEXT: Other:
# CHECK-NEXT: Section: .text
# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: und
+# CHECK-NEXT: Value:
+# CHECK-NEXT: Size:
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type:
+# CHECK-NEXT: Other:
+# CHECK-NEXT: Section: Undefined
+# CHECK-NEXT: }
# CHECK-NEXT: ]
.text
Added: lld/trunk/test/ELF/retain-und.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/retain-und.s?rev=293093&view=auto
==============================================================================
--- lld/trunk/test/ELF/retain-und.s (added)
+++ lld/trunk/test/ELF/retain-und.s Wed Jan 25 15:23:06 2017
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: echo > %t.retain
+# RUN: echo "{ local: *; }; " > %t.script
+# RUN: ld.lld -shared --version-script %t.script %t.o -o %t1.so
+# RUN: ld.lld -shared --retain-symbols-file %t.retain %t.o -o %t2.so
+# RUN: llvm-readobj -r %t1.so | FileCheck %s
+# RUN: llvm-readobj -r %t2.so | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section ({{.*}}) .rela.dyn {
+# CHECK-NEXT: 0x{{.*}} R_X86_64_64 foo 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+.data
+.quad foo
+.weak foo
More information about the llvm-commits
mailing list