[lld] r279452 - [ELF] Define __ehdr_start symbol
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 22 11:44:05 PDT 2016
Author: phosek
Date: Mon Aug 22 13:44:04 2016
New Revision: 279452
URL: http://llvm.org/viewvc/llvm-project?rev=279452&view=rev
Log:
[ELF] Define __ehdr_start symbol
This symbol can be used by the program to examine its own headers.
Differential Revision: https://reviews.llvm.org/D23750
Added:
lld/trunk/test/ELF/ehdr_start.s
lld/trunk/test/ELF/linkerscript/linkerscript-ehdr_start.s
Modified:
lld/trunk/ELF/Symbols.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=279452&r1=279451&r2=279452&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Mon Aug 22 13:44:04 2016
@@ -366,6 +366,9 @@ public:
// Some linker-generated symbols need to be created as
// DefinedRegular symbols.
template <class ELFT> struct ElfSym {
+ // The content for __ehdr_start symbol.
+ static DefinedRegular<ELFT> *EhdrStart;
+
// The content for _etext and etext symbols.
static DefinedRegular<ELFT> *Etext;
static DefinedRegular<ELFT> *Etext2;
@@ -382,6 +385,7 @@ template <class ELFT> struct ElfSym {
static SymbolBody *MipsGpDisp;
};
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::EhdrStart;
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Etext;
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Etext2;
template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::Edata;
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=279452&r1=279451&r2=279452&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Aug 22 13:44:04 2016
@@ -598,6 +598,8 @@ template <class ELFT> void Writer<ELFT>:
if (ScriptConfig->HasContents)
return;
+ ElfSym<ELFT>::EhdrStart = Symtab<ELFT>::X->addIgnored("__ehdr_start");
+
auto Define = [this](StringRef S, DefinedRegular<ELFT> *&Sym1,
DefinedRegular<ELFT> *&Sym2) {
Sym1 = Symtab<ELFT>::X->addIgnored(S, STV_DEFAULT);
@@ -1180,6 +1182,10 @@ static uint16_t getELFType() {
// to each section. This function fixes some predefined absolute
// symbol values that depend on section address and size.
template <class ELFT> void Writer<ELFT>::fixAbsoluteSymbols() {
+ // __ehdr_start is the location of program headers.
+ if (ElfSym<ELFT>::EhdrStart)
+ ElfSym<ELFT>::EhdrStart->Value = Out<ELFT>::ProgramHeaders->getVA();
+
auto Set = [](DefinedRegular<ELFT> *S1, DefinedRegular<ELFT> *S2, uintX_t V) {
if (S1)
S1->Value = V;
Added: lld/trunk/test/ELF/ehdr_start.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ehdr_start.s?rev=279452&view=auto
==============================================================================
--- lld/trunk/test/ELF/ehdr_start.s (added)
+++ lld/trunk/test/ELF/ehdr_start.s Mon Aug 22 13:44:04 2016
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t
+# RUN: llvm-objdump -t %t | FileCheck %s
+# CHECK: 0000000000010040 *ABS* 00000000 .hidden __ehdr_start
+
+.text
+.global _start, __ehdr_start
+_start:
+ .quad __ehdr_start
Added: lld/trunk/test/ELF/linkerscript/linkerscript-ehdr_start.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/linkerscript/linkerscript-ehdr_start.s?rev=279452&view=auto
==============================================================================
--- lld/trunk/test/ELF/linkerscript/linkerscript-ehdr_start.s (added)
+++ lld/trunk/test/ELF/linkerscript/linkerscript-ehdr_start.s Mon Aug 22 13:44:04 2016
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+
+# 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: undefined symbol: __ehdr_start
+
+.text
+.global _start, __ehdr_start
+_start:
+ .quad __ehdr_start
More information about the llvm-commits
mailing list