From f2ac6882179370bc1eacacad68d077520eec0557 Mon Sep 17 00:00:00 2001 From: Ed Maste Date: Fri, 11 Dec 2015 17:46:46 +0000 Subject: [PATCH] ELF: Allow -e with -shared It is reasonable to specify an entry point for shared objects - for example, for the FreeBSD rtld ld-elf.so.1. Unlike GNU ld we leave the entry address as 0 if -shared is specified without -e. Differential Revision: http://reviews.llvm.org/D15454 llvm-svn: 255349 --- lld/ELF/Driver.cpp | 12 +++++++----- lld/test/ELF/entry.s | 3 +++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 2f1cf9be4df0..f1e1abee2674 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -248,11 +248,6 @@ template void LinkerDriver::link(opt::InputArgList &Args) { if (Config->Entry.empty()) Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start"; - // Set either EntryAddr (if S is a number) or EntrySym (otherwise). - StringRef S = Config->Entry; - if (S.getAsInteger(0, Config->EntryAddr)) - Config->EntrySym = Symtab.addUndefined(S); - // In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol // is magical and is used to produce a R_386_GOTPC relocation. // The R_386_GOTPC relocation value doesn't actually depend on the @@ -268,6 +263,13 @@ template void LinkerDriver::link(opt::InputArgList &Args) { Symtab.addIgnoredSym("_GLOBAL_OFFSET_TABLE_"); } + if (!Config->Entry.empty()) { + // Set either EntryAddr (if S is a number) or EntrySym (otherwise). + StringRef S = Config->Entry; + if (S.getAsInteger(0, Config->EntryAddr)) + Config->EntrySym = Symtab.addUndefined(S); + } + // Define _gp for MIPS. st_value of _gp symbol will be updated by Writer // so that it points to an absolute address which is relative to GOT. // See "Global Data Symbols" in Chapter 6 in the following document: diff --git a/lld/test/ELF/entry.s b/lld/test/ELF/entry.s index c68c00f620cb..c8758ece69eb 100644 --- a/lld/test/ELF/entry.s +++ b/lld/test/ELF/entry.s @@ -2,6 +2,8 @@ # RUN: not ld.lld %t1 -o %t2 # 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 +# RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DSO %s # RUN: ld.lld %t1 -o %t2 -e 4096 # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=DEC %s # RUN: ld.lld %t1 -o %t2 -e 0xcafe @@ -10,6 +12,7 @@ # RUN: llvm-readobj -file-headers %t2 | FileCheck -check-prefix=OCT %s # SYM: Entry: 0x11000 +# DSO: Entry: 0x1000 # DEC: Entry: 0x1000 # HEX: Entry: 0xCAFE # OCT: Entry: 0x1FF