diff options
| -rw-r--r-- | lld/ELF/Writer.cpp | 14 | ||||
| -rw-r--r-- | lld/test/ELF/ehdr_start.s | 11 |
2 files changed, 19 insertions, 6 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 9ffe6e984af..6a3b27717a3 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -901,16 +901,18 @@ template <class ELFT> void Writer<ELFT>::addReservedSymbols() { if (!InX::DynSymTab) Symtab<ELFT>::X->addIgnored("__tls_get_addr"); - // __dso_handle symbol is passed to cxa_finalize as a marker to identify - // each DSO. The address of the symbol doesn't matter as long as they are - // different in different DSOs, so we chose the start address of the DSO. - addOptionalRegular<ELFT>("__dso_handle", Out::ElfHeader, 0, STV_HIDDEN); - // __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); + // __executable_start is not documented, but the expectation of at + // least the android libc is that it points to the elf header too. + // __dso_handle symbol is passed to cxa_finalize as a marker to identify + // each DSO. The address of the symbol doesn't matter as long as they are + // different in different DSOs, so we chose the start address of the DSO. + for (const char *Name : + {"__ehdr_start", "__executable_start", "__dso_handle"}) + addOptionalRegular<ELFT>(Name, Out::ElfHeader, 0, STV_HIDDEN); // If linker script do layout we do not need to create any standart symbols. if (Script->Opt.HasSections) diff --git a/lld/test/ELF/ehdr_start.s b/lld/test/ELF/ehdr_start.s index 32bcf4b8475..94e0fedcfc5 100644 --- a/lld/test/ELF/ehdr_start.s +++ b/lld/test/ELF/ehdr_start.s @@ -13,10 +13,21 @@ # CHECK-NEXT: ] # CHECK-NEXT: Section: .text (0x1) +# CHECK: Name: __executable_start +# CHECK-NEXT: Value: 0x200000 +# CHECK-NEXT: Size: 0 +# CHECK-NEXT: Binding: Local +# CHECK-NEXT: Type: None +# CHECK-NEXT: Other [ +# CHECK-NEXT: STV_HIDDEN +# CHECK-NEXT: ] +# CHECK-NEXT: Section: .text + .text .global _start, __ehdr_start _start: .quad __ehdr_start + .quad __executable_start # RUN: ld.lld -r %t.o -o %t.r # RUN: llvm-readobj -symbols %t.r | FileCheck %s --check-prefix=RELOCATABLE |

