Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -911,7 +911,10 @@ // 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("__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. + for (const char *Name : {"__ehdr_start", "__executable_start"}) + addOptionalRegular(Name, Out::ElfHeader, 0, STV_HIDDEN); // If linker script do layout we do not need to create any standart symbols. if (Script->Opt.HasSections) Index: test/ELF/ehdr_start.s =================================================================== --- test/ELF/ehdr_start.s +++ 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