From d001ab82e410d0c6ccf14be9f507c8aca53abc67 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 20 Sep 2021 09:35:12 -0700 Subject: [PATCH] [ELF] Don't fall back to .text for e_entry We have the rule to simulate (https://sourceware.org/binutils/docs/ld/Entry-Point.html), but the behavior is questionable (https://sourceware.org/pipermail/binutils/2021-September/117929.html). gold doesn't fall back to .text. The behavior is unlikely relied by projects (there is even a warning for executable links), so let's just delete this fallback path. Reviewed By: jhenderson, peter.smith Differential Revision: https://reviews.llvm.org/D110014 --- lld/ELF/Writer.cpp | 11 +---------- lld/docs/ReleaseNotes.rst | 3 +++ lld/test/ELF/basic-ppc.s | 2 +- lld/test/ELF/basic-ppc64.s | 2 +- lld/test/ELF/entry.s | 11 ++++++----- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 0069822..a9b0854f 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -2833,8 +2833,7 @@ template void Writer::checkSections() { // 2. the ENTRY(symbol) command in a linker control script; // 3. the value of the symbol _start, if present; // 4. the number represented by the entry symbol, if it is a number; -// 5. the address of the first byte of the .text section, if present; -// 6. the address 0. +// 5. the address 0. static uint64_t getEntryAddr() { // Case 1, 2 or 3 if (Symbol *b = symtab->find(config->entry)) @@ -2846,14 +2845,6 @@ static uint64_t getEntryAddr() { return addr; // Case 5 - if (OutputSection *sec = findSection(".text")) { - if (config->warnMissingEntry) - warn("cannot find entry symbol " + config->entry + "; defaulting to 0x" + - utohexstr(sec->addr)); - return sec->addr; - } - - // Case 6 if (config->warnMissingEntry) warn("cannot find entry symbol " + config->entry + "; not setting start address"); diff --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst index 68d6f6a..1ab3f99 100644 --- a/lld/docs/ReleaseNotes.rst +++ b/lld/docs/ReleaseNotes.rst @@ -26,6 +26,9 @@ ELF Improvements * ``--export-dynamic-symbol-list`` has been added. (`D107317 `_) +* ``e_entry`` no longer falls back to the address of ``.text`` if the entry symbol does not exist. + Instead, a value of 0 will be written. + (`D110014 `_) Breaking changes ---------------- diff --git a/lld/test/ELF/basic-ppc.s b/lld/test/ELF/basic-ppc.s index b67841e..e002106 100644 --- a/lld/test/ELF/basic-ppc.s +++ b/lld/test/ELF/basic-ppc.s @@ -26,7 +26,7 @@ // CHECK-NEXT: Type: Executable (0x2) // CHECK-NEXT: Machine: EM_PPC (0x14) // CHECK-NEXT: Version: 1 -// CHECK-NEXT: Entry: 0x100100B4 +// CHECK-NEXT: Entry: 0x0 // CHECK-NEXT: ProgramHeaderOffset: 0x34 // CHECK-NEXT: SectionHeaderOffset: 0x104 // CHECK-NEXT: Flags [ (0x0) diff --git a/lld/test/ELF/basic-ppc64.s b/lld/test/ELF/basic-ppc64.s index a768436..4032cec 100644 --- a/lld/test/ELF/basic-ppc64.s +++ b/lld/test/ELF/basic-ppc64.s @@ -33,7 +33,7 @@ // CHECK-NEXT: Type: SharedObject (0x3) // CHECK-NEXT: Machine: EM_PPC64 (0x15) // CHECK-NEXT: Version: 1 -// CHECK-NEXT: Entry: 0x1022C +// CHECK-NEXT: Entry: 0x0 // CHECK-NEXT: ProgramHeaderOffset: 0x40 // CHECK-NEXT: SectionHeaderOffset: 0x330 // CHECK-NEXT: Flags [ (0x2) diff --git a/lld/test/ELF/entry.s b/lld/test/ELF/entry.s index 4f6ad15..d1a2434 100644 --- a/lld/test/ELF/entry.s +++ b/lld/test/ELF/entry.s @@ -2,16 +2,17 @@ # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1 # RUN: ld.lld -e foobar %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN1 %s -# RUN: llvm-readobj --file-headers %t2 | FileCheck -check-prefix=TEXT %s +# RUN: llvm-readobj --file-headers %t2 | FileCheck -check-prefix=NOENTRY %s -# WARN1: warning: cannot find entry symbol foobar; defaulting to 0x201120 -# TEXT: Entry: 0x201120 +# WARN1: warning: cannot find entry symbol foobar; not setting start address # RUN: ld.lld %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN2 %s -# WARN2: warning: cannot find entry symbol _start; defaulting to 0x201120 +# RUN: llvm-readobj --file-headers %t2 | FileCheck -check-prefix=NOENTRY %s +# WARN2: warning: cannot find entry symbol _start; not setting start address # RUN: ld.lld -shared -e foobar %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN3 %s -# WARN3: warning: cannot find entry symbol foobar; defaulting to 0x1238 +# RUN: llvm-readobj --file-headers %t2 | FileCheck -check-prefix=NOENTRY %s +# WARN3: warning: cannot find entry symbol foobar; not setting start address # RUN: ld.lld -shared --fatal-warnings -e entry %t1 -o %t2 # RUN: ld.lld -shared --fatal-warnings %t1 -o %t2 -- 2.7.4