[lld] r302687 - [ELF] Define __ehdr_start unconditionally even when using linker script
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Wed May 10 09:20:34 PDT 2017
Author: phosek
Date: Wed May 10 11:20:33 2017
New Revision: 302687
URL: http://llvm.org/viewvc/llvm-project?rev=302687&view=rev
Log:
[ELF] Define __ehdr_start unconditionally even when using linker script
This behavior differs from the semantics implemented by GNU linkers
which only define this symbol iff ELF headers are in the memory
mapped segment.
Differential Revision: https://reviews.llvm.org/D33019
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/ELF/linkerscript/ehdr_start.s
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=302687&r1=302686&r2=302687&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed May 10 11:20:33 2017
@@ -859,13 +859,16 @@ template <class ELFT> void Writer<ELFT>:
if (!In<ELFT>::DynSymTab)
Symtab<ELFT>::X->addIgnored("__tls_get_addr");
+ // __ehdr_start is the location of ELF file headers. Note that we define
+ // this symbol unconditionally even when using a linker script, which
+ // differs from the behavior implemented by GNU linker which only define
+ // this symbol if ELF headers are in the memory mapped segment.
+ addOptionalRegular<ELFT>("__ehdr_start", Out::ElfHeader, 0, STV_HIDDEN);
+
// If linker script do layout we do not need to create any standart symbols.
if (Script->Opt.HasSections)
return;
- // __ehdr_start is the location of ELF file headers.
- addOptionalRegular<ELFT>("__ehdr_start", Out::ElfHeader, 0, STV_HIDDEN);
-
auto Add = [](StringRef S) {
return addOptionalRegular<ELFT>(S, Out::ElfHeader, 0, STV_DEFAULT);
};
Modified: lld/trunk/test/ELF/linkerscript/ehdr_start.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/ehdr_start.s?rev=302687&r1=302686&r2=302687&view=diff
==============================================================================
--- lld/trunk/test/ELF/linkerscript/ehdr_start.s (original)
+++ lld/trunk/test/ELF/linkerscript/ehdr_start.s Wed May 10 11:20:33 2017
@@ -2,9 +2,17 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: echo "SECTIONS { }" > %t.script
-# RUN: not ld.lld %t.o -script %t.script -o %t 2>&1 | FileCheck %s
-# CHECK: error: undefined symbol: __ehdr_start
-# CHECK: >>> referenced by {{.*}}:(.text+0x0)
+# RUN: ld.lld %t.o -script %t.script -o %t
+# RUN: llvm-readobj -symbols %t | FileCheck %s
+# CHECK: Name: __ehdr_start (1)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other [ (0x2)
+# CHECK-NEXT: STV_HIDDEN (0x2)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Section: .text (0x1)
.text
.global _start, __ehdr_start
More information about the llvm-commits
mailing list