[PATCH] D23925: [ELF] Default to entry address 0x0 in case start symbol is not defined and entry point is not specified in command line
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 26 08:33:25 PDT 2016
evgeny777 created this revision.
evgeny777 added a reviewer: ruiu.
evgeny777 added subscribers: grimar, ikudrin, llvm-commits.
evgeny777 set the repository for this revision to rL LLVM.
evgeny777 added a project: lld.
The default behavior of GNU linkers is to set entry address to 0x0 when there is no start symbol (_start) and entry point is not passed to linker in command line arguments. Unfortunately lld reports undefined symbol error in this case (undefined symbol _start) and fails to link the program. An alternative is to always pass -Wl,-e,0 (or "-e 0"), which is not very convenient.
Repository:
rL LLVM
https://reviews.llvm.org/D23925
Files:
ELF/Config.h
ELF/Driver.cpp
ELF/Writer.cpp
test/ELF/entry.s
test/ELF/reproduce-windows.s
test/ELF/undef-start.s
Index: test/ELF/undef-start.s
===================================================================
--- test/ELF/undef-start.s
+++ test/ELF/undef-start.s
@@ -1,4 +1,3 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: not ld.lld %t -o %t2 2>&1 | FileCheck %s
-# CHECK: undefined symbol: _start
+# RUN: ld.lld %t -o %t2 2>&1
# REQUIRES: x86
Index: test/ELF/reproduce-windows.s
===================================================================
--- test/ELF/reproduce-windows.s
+++ test/ELF/reproduce-windows.s
@@ -5,7 +5,7 @@
# RUN: mkdir -p %t.dir/build
# RUN: llvm-mc %s -o %t.dir/build/foo.o -filetype=obj -triple=x86_64-pc-linux
# RUN: cd %t.dir
-# RUN: not ld.lld build/foo.o --reproduce repro
+# RUN: ld.lld build/foo.o --reproduce repro
# RUN: cpio -t < repro.cpio | FileCheck %s
# CHECK: repro/response.txt
Index: test/ELF/entry.s
===================================================================
--- test/ELF/entry.s
+++ test/ELF/entry.s
@@ -1,5 +1,6 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1
-# RUN: not ld.lld %t1 -o %t2
+# RUN: ld.lld %t1 -o %t2
+# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=NOENTRY %s
# RUN: ld.lld %t1 -o %t2 -e entry
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=SYM %s
# RUN: ld.lld %t1 -shared -o %t2 -e entry
@@ -11,6 +12,7 @@
# RUN: ld.lld %t1 -o %t2 -e 0777
# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s
+# NOENTRY: Entry: 0x0
# SYM: Entry: 0x11000
# DSO: Entry: 0x1000
# DEC: Entry: 0x1000
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -740,8 +740,11 @@
// We only report undefined symbols in regular objects. This means that we
// will accept an undefined reference in bitcode if it can be optimized out.
- if (S->IsUsedInRegularObj && Body->isUndefined() && !S->isWeak())
+ if (S->IsUsedInRegularObj && Body->isUndefined() && !S->isWeak()) {
+ if (S == Config->EntrySym && Config->ForcedEntry)
+ continue;
reportUndefined<ELFT>(Body);
+ }
if (!includeInSymtab<ELFT>(*Body))
continue;
Index: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -551,8 +551,10 @@
// Add entry symbol. Note that AMDGPU binaries have no entry points.
if (Config->Entry.empty() && !Config->Shared && !Config->Relocatable &&
- Config->EMachine != EM_AMDGPU)
+ Config->EMachine != EM_AMDGPU) {
Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";
+ Config->ForcedEntry = true;
+ }
// Default output filename is "a.out" by the Unix tradition.
if (Config->OutputFile.empty())
Index: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -115,6 +115,7 @@
bool ZNow;
bool ZOrigin;
bool ZRelro;
+ bool ForcedEntry = false;
UnresolvedPolicy UnresolvedSymbols;
BuildIdKind BuildId = BuildIdKind::None;
ELFKind EKind = ELFNoneKind;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23925.69378.patch
Type: text/x-patch
Size: 3124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160826/63559029/attachment.bin>
More information about the llvm-commits
mailing list