mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-01-26 19:36:28 +00:00
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
This commit is contained in:
parent
65144c852d
commit
c0fc253071
@ -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;
|
||||
|
@ -614,10 +614,11 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
|
||||
// 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))
|
||||
|
@ -425,12 +425,6 @@ template <class ELFT> static bool includeInSymtab(const SymbolBody &B) {
|
||||
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)
|
||||
|
@ -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
|
||||
|
18
lld/test/ELF/retain-und.s
Normal file
18
lld/test/ELF/retain-und.s
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user