[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
Fri Sep 17 16:40:36 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: grimar, jhenderson, peter.smith.
Herald added subscribers: kbarton, arichardson, nemanjai, emaste.
MaskRay requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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).

The behavior is unlikely relied by projects (there is even a warning for
executable links), so let's just delete this fallback path.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D110014

Files:
  lld/ELF/Writer.cpp
  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
@@ -4,14 +4,14 @@
 # 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
 
-# WARN1: warning: cannot find entry symbol foobar; defaulting to 0x201120
-# TEXT: Entry: 0x201120
+# WARN1: warning: cannot find entry symbol foobar; not setting start address
+# TEXT: Entry: 0x0
 
 # RUN: ld.lld %t1 -o %t2 2>&1 | FileCheck -check-prefix=WARN2 %s
-# WARN2: warning: cannot find entry symbol _start; defaulting to 0x201120
+# 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
+# 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/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.373369.patch
Type: text/x-patch
Size: 3025 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210917/6702a688/attachment.bin>


More information about the llvm-commits mailing list