[PATCH] D54624: [LLD][ELF] Error if _GLOBAL_OFFSET_TABLE_ is defined in input objects
Peter Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 29 03:21:11 PST 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL347854: [LLD][ELF] Error if _GLOBAL_OFFSET_TABLE_ is defined in input objects (authored by psmith, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D54624?vs=175677&id=175844#toc
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D54624/new/
https://reviews.llvm.org/D54624
Files:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/global-offset-table-position-redef-err.s
Index: lld/trunk/test/ELF/global-offset-table-position-redef-err.s
===================================================================
--- lld/trunk/test/ELF/global-offset-table-position-redef-err.s
+++ lld/trunk/test/ELF/global-offset-table-position-redef-err.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
+
+# On some targets the location of the _GLOBAL_OFFSET_TABLE_ symbol table can
+# matter for the correctness of some relocations. Follow the example of ld.gold
+# and give a multiple definition error if input objects attempt to redefine it.
+
+# CHECK: ld.lld: error: {{.*o}} cannot redefine linker defined symbol '_GLOBAL_OFFSET_TABLE_'
+
+.data
+.global _GLOBAL_OFFSET_TABLE_
+_GLOBAL_OFFSET_TABLE_:
+.word 0
Index: lld/trunk/ELF/Writer.cpp
===================================================================
--- lld/trunk/ELF/Writer.cpp
+++ lld/trunk/ELF/Writer.cpp
@@ -212,9 +212,20 @@
// _GLOBAL_OFFSET_TABLE_ and _SDA_BASE_ from the 32-bit ABI. It is used to
// represent the TOC base which is offset by 0x8000 bytes from the start of
// the .got section.
- ElfSym::GlobalOffsetTable = addOptionalRegular(
- (Config->EMachine == EM_PPC64) ? ".TOC." : "_GLOBAL_OFFSET_TABLE_",
- Out::ElfHeader, Target->GotBaseSymOff);
+ // We do not allow _GLOBAL_OFFSET_TABLE_ to be defined by input objects as the
+ // correctness of some relocations depends on its value.
+ StringRef GotTableSymName =
+ (Config->EMachine == EM_PPC64) ? ".TOC." : "_GLOBAL_OFFSET_TABLE_";
+ if (Symbol *S = Symtab->find(GotTableSymName)) {
+ if (S->isDefined())
+ error(toString(S->File) + " cannot redefine linker defined symbol '" +
+ GotTableSymName + "'");
+ else
+ ElfSym::GlobalOffsetTable = Symtab->addDefined(
+ GotTableSymName, STV_HIDDEN, STT_NOTYPE, Target->GotBaseSymOff,
+ /*Size=*/0, STB_GLOBAL, Out::ElfHeader,
+ /*File=*/nullptr);
+ }
// __ehdr_start is the location of ELF file headers. Note that we define
// this symbol unconditionally even when using a linker script, which
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54624.175844.patch
Type: text/x-patch
Size: 2185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181129/d44296cd/attachment.bin>
More information about the llvm-commits
mailing list