[PATCH] D30224: [ELF] Insert linkerscript symbols directly into symbol table
Petr Hosek via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 21 14:44:30 PST 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL295780: [ELF] Insert linkerscript symbols directly into symbol table (authored by phosek).
Changed prior to commit:
https://reviews.llvm.org/D30224?vs=89281&id=89286#toc
Repository:
rL LLVM
https://reviews.llvm.org/D30224
Files:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/SymbolTable.h
lld/trunk/test/ELF/linkerscript/Inputs/lazy-symbols.s
lld/trunk/test/ELF/linkerscript/lazy-symbols.s
Index: lld/trunk/test/ELF/linkerscript/lazy-symbols.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/lazy-symbols.s
+++ lld/trunk/test/ELF/linkerscript/lazy-symbols.s
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/lazy-symbols.s -o %t1
+# RUN: llvm-ar rcs %tar %t1
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2
+# RUN: echo "foo = 1;" > %t.script
+# RUN: ld.lld %t2 %tar --script %t.script -o %tout
+# RUN: llvm-readobj -symbols %tout | FileCheck %s
+
+# This test is to ensure a linker script can define a symbol which have the same
+# name as a lazy symbol.
+
+# CHECK: Name: foo
+# CHECK-NEXT: Value: 0x1
Index: lld/trunk/test/ELF/linkerscript/Inputs/lazy-symbols.s
===================================================================
--- lld/trunk/test/ELF/linkerscript/Inputs/lazy-symbols.s
+++ lld/trunk/test/ELF/linkerscript/Inputs/lazy-symbols.s
@@ -0,0 +1,2 @@
+.globl foo
+foo:
Index: lld/trunk/ELF/LinkerScript.cpp
===================================================================
--- lld/trunk/ELF/LinkerScript.cpp
+++ lld/trunk/ELF/LinkerScript.cpp
@@ -57,27 +57,27 @@
ScriptConfiguration *elf::ScriptConfig;
template <class ELFT> static SymbolBody *addRegular(SymbolAssignment *Cmd) {
+ Symbol *Sym;
uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
- Symbol *Sym = Symtab<ELFT>::X->addUndefined(
- Cmd->Name, /*IsLocal=*/false, STB_GLOBAL, Visibility,
- /*Type*/ 0,
- /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
-
+ std::tie(Sym, std::ignore) = Symtab<ELFT>::X->insert(
+ Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false,
+ /*File*/ nullptr);
+ Sym->Binding = STB_GLOBAL;
replaceBody<DefinedRegular<ELFT>>(Sym, Cmd->Name, /*IsLocal=*/false,
Visibility, STT_NOTYPE, 0, 0, nullptr,
nullptr);
return Sym->body();
}
template <class ELFT> static SymbolBody *addSynthetic(SymbolAssignment *Cmd) {
+ Symbol *Sym;
uint8_t Visibility = Cmd->Hidden ? STV_HIDDEN : STV_DEFAULT;
const OutputSectionBase *Sec =
ScriptConfig->HasSections ? nullptr : Cmd->Expression.Section();
- Symbol *Sym = Symtab<ELFT>::X->addUndefined(
- Cmd->Name, /*IsLocal=*/false, STB_GLOBAL, Visibility,
- /*Type*/ 0,
- /*CanOmitFromDynSym*/ false, /*File*/ nullptr);
-
+ std::tie(Sym, std::ignore) = Symtab<ELFT>::X->insert(
+ Cmd->Name, /*Type*/ 0, Visibility, /*CanOmitFromDynSym*/ false,
+ /*File*/ nullptr);
+ Sym->Binding = STB_GLOBAL;
replaceBody<DefinedSynthetic>(Sym, Cmd->Name, 0, Sec);
return Sym->body();
}
Index: lld/trunk/ELF/SymbolTable.h
===================================================================
--- lld/trunk/ELF/SymbolTable.h
+++ lld/trunk/ELF/SymbolTable.h
@@ -77,6 +77,11 @@
uint8_t Binding, uint8_t StOther, uint8_t Type,
InputFile *File);
+ std::pair<Symbol *, bool> insert(StringRef Name);
+ std::pair<Symbol *, bool> insert(StringRef Name, uint8_t Type,
+ uint8_t Visibility, bool CanOmitFromDynSym,
+ InputFile *File);
+
void scanUndefinedFlags();
void scanShlibUndefined();
void scanVersionScript();
@@ -90,11 +95,6 @@
std::vector<InputSectionBase<ELFT> *> Sections;
private:
- std::pair<Symbol *, bool> insert(StringRef Name);
- std::pair<Symbol *, bool> insert(StringRef Name, uint8_t Type,
- uint8_t Visibility, bool CanOmitFromDynSym,
- InputFile *File);
-
std::vector<SymbolBody *> findByVersion(SymbolVersion Ver);
std::vector<SymbolBody *> findAllByVersion(SymbolVersion Ver);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D30224.89286.patch
Type: text/x-patch
Size: 3839 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170221/985c4e4f/attachment.bin>
More information about the llvm-commits
mailing list