[lld] d001ab8 - [ELF] Don't fall back to .text for e_entry

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 20 09:35:16 PDT 2021


Author: Fangrui Song
Date: 2021-09-20T09:35:12-07:00
New Revision: d001ab82e410d0c6ccf14be9f507c8aca53abc67

URL: https://github.com/llvm/llvm-project/commit/d001ab82e410d0c6ccf14be9f507c8aca53abc67
DIFF: https://github.com/llvm/llvm-project/commit/d001ab82e410d0c6ccf14be9f507c8aca53abc67.diff

LOG: [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

Added: 
    

Modified: 
    lld/ELF/Writer.cpp
    lld/docs/ReleaseNotes.rst
    lld/test/ELF/basic-ppc.s
    lld/test/ELF/basic-ppc64.s
    lld/test/ELF/entry.s

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index 0069822d1217..a9b0854fad92 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -2833,8 +2833,7 @@ template <class ELFT> void Writer<ELFT>::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 68d6f6a0dd58..1ab3f9971fbf 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 <https://reviews.llvm.org/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 <https://reviews.llvm.org/D110014>`_)
 
 Breaking changes
 ----------------

diff  --git a/lld/test/ELF/basic-ppc.s b/lld/test/ELF/basic-ppc.s
index b67841e691a2..e0021062a955 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 a768436f222c..4032ceca614f 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 4f6ad1546ef9..d1a2434a190f 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


        


More information about the llvm-commits mailing list