[PATCH] D110014: [ELF] Don't fall back to .text for e_entry

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


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd001ab82e410: [ELF] Don't fall back to .text for e_entry (authored by MaskRay).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110014/new/

https://reviews.llvm.org/D110014

Files:
  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


Index: lld/test/ELF/entry.s
===================================================================
--- lld/test/ELF/entry.s
+++ 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
Index: lld/test/ELF/basic-ppc64.s
===================================================================
--- lld/test/ELF/basic-ppc64.s
+++ 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)
Index: lld/test/ELF/basic-ppc.s
===================================================================
--- lld/test/ELF/basic-ppc.s
+++ 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)
Index: lld/docs/ReleaseNotes.rst
===================================================================
--- lld/docs/ReleaseNotes.rst
+++ lld/docs/ReleaseNotes.rst
@@ -26,6 +26,9 @@
 
 * ``--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
 ----------------
Index: lld/ELF/Writer.cpp
===================================================================
--- lld/ELF/Writer.cpp
+++ lld/ELF/Writer.cpp
@@ -2833,8 +2833,7 @@
 // 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 @@
     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");


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110014.373623.patch
Type: text/x-patch
Size: 3822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210920/250dceb3/attachment.bin>


More information about the llvm-commits mailing list