<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Wed, Sep 9, 2015 at 7:34 AM, Michael J. Spencer via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Author: mspencer<br>
Date: Tue Sep 8 17:34:57 2015<br>
New Revision: 247089<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=247089&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=247089&view=rev</a><br>
Log:<br>
[lld][elf2] Fix hard coded entry address.<br>
<br>
Modified:<br>
lld/trunk/ELF/SymbolTable.cpp<br>
lld/trunk/ELF/SymbolTable.h<br>
lld/trunk/ELF/Writer.cpp<br>
lld/trunk/test/elf2/basic.s<br>
lld/trunk/test/elf2/basic32.s<br>
lld/trunk/test/elf2/basic32be.s<br>
lld/trunk/test/elf2/basic64be.s<br>
<br>
Modified: lld/trunk/ELF/SymbolTable.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=247089&r1=247088&r2=247089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=247089&r1=247088&r2=247089&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/SymbolTable.cpp (original)<br>
+++ lld/trunk/ELF/SymbolTable.cpp Tue Sep 8 17:34:57 2015<br>
@@ -17,7 +17,7 @@ using namespace llvm::object;<br>
using namespace lld;<br>
using namespace lld::elf2;<br>
<br>
-SymbolTable::SymbolTable() {<br>
+SymbolTable::SymbolTable() : EntrySym(nullptr) {<br>
}<br>
<br>
void SymbolTable::addFile(std::unique_ptr<InputFile> File) {<br>
@@ -33,8 +33,10 @@ void SymbolTable::addFile(std::unique_pt<br>
}<br>
<br>
template <class ELFT> void SymbolTable::init() {<br>
- resolve<ELFT>(new (Alloc)<br>
- Undefined<ELFT>("_start", Undefined<ELFT>::Synthetic));<br>
+ if (EntrySym)<br>
+ return;<br></blockquote><div><br></div><div>How can this guarded condition happen?</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+ EntrySym = new (Alloc) Undefined<ELFT>("_start", Undefined<ELFT>::Synthetic);<br>
+ resolve<ELFT>(EntrySym);<br>
}<br>
<br>
template <class ELFT> void SymbolTable::addELFFile(ELFFileBase *File) {<br>
<br>
Modified: lld/trunk/ELF/SymbolTable.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=247089&r1=247088&r2=247089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.h?rev=247089&r1=247088&r2=247089&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/SymbolTable.h (original)<br>
+++ lld/trunk/ELF/SymbolTable.h Tue Sep 8 17:34:57 2015<br>
@@ -54,6 +54,10 @@ public:<br>
return SharedFiles;<br>
}<br>
<br>
+ SymbolBody *getEntrySym() const {<br>
+ return EntrySym;<br>
+ }<br></blockquote><div><br></div><div>You may want to return EntrySym->getReplacement() instead of requiring all calling sides to do that.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
+<br>
private:<br>
Symbol *insert(SymbolBody *New);<br>
template <class ELFT> void addELFFile(ELFFileBase *File);<br>
@@ -73,6 +77,8 @@ private:<br>
std::vector<std::unique_ptr<ObjectFileBase>> ObjectFiles;<br>
<br>
std::vector<std::unique_ptr<SharedFileBase>> SharedFiles;<br>
+<br>
+ SymbolBody *EntrySym;<br></blockquote><div><br></div><div>Use C++11 member initialization -- SymbolBody *EntrySym = nullptr;</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
};<br>
<br>
} // namespace elf2<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247089&r1=247088&r2=247089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247089&r1=247088&r2=247089&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Tue Sep 8 17:34:57 2015<br>
@@ -577,7 +577,8 @@ template <class ELFT> void Writer<ELFT>:<br>
auto &FirstObj = cast<ObjectFile<ELFT>>(*Symtab.getFirstELF());<br>
EHdr->e_machine = FirstObj.getEMachine();<br>
EHdr->e_version = EV_CURRENT;<br>
- EHdr->e_entry = 0x401000;<br>
+ EHdr->e_entry = getSymVA(<br>
+ cast<DefinedRegular<ELFT>>(Symtab.getEntrySym()->getReplacement()));<br>
EHdr->e_phoff = sizeof(Elf_Ehdr);<br>
EHdr->e_shoff = SectionHeaderOff;<br>
EHdr->e_ehsize = sizeof(Elf_Ehdr);<br>
<br>
Modified: lld/trunk/test/elf2/basic.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic.s?rev=247089&r1=247088&r2=247089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic.s?rev=247089&r1=247088&r2=247089&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/basic.s (original)<br>
+++ lld/trunk/test/elf2/basic.s Tue Sep 8 17:34:57 2015<br>
@@ -1,6 +1,7 @@<br>
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t<br>
# RUN: lld -flavor gnu2 %t -o %t2<br>
-# RUN: llvm-readobj -file-headers -sections -program-headers %t2 | FileCheck %s<br>
+# RUN: llvm-readobj -file-headers -sections -program-headers -symbols %t2 \<br>
+# RUN: | FileCheck %s<br>
# REQUIRES: x86<br>
<br>
# exits with return code 42 on linux<br>
@@ -23,7 +24,7 @@ _start:<br>
# CHECK-NEXT: Type: Executable (0x2)<br>
# CHECK-NEXT: Machine: EM_X86_64 (0x3E)<br>
# CHECK-NEXT: Version: 1<br>
-# CHECK-NEXT: Entry: 0x401000<br>
+# CHECK-NEXT: Entry: [[ENTRY:0x[0-9A-F]+]]<br>
# CHECK-NEXT: ProgramHeaderOffset: 0x40<br>
# CHECK-NEXT: SectionHeaderOffset: 0x1070<br>
# CHECK-NEXT: Flags [ (0x0)<br>
@@ -127,6 +128,26 @@ _start:<br>
# CHECK-NEXT: EntrySize: 0<br>
# CHECK-NEXT: }<br>
# CHECK-NEXT: ]<br>
+# CHECK-NEXT: Symbols [<br>
+# CHECK-NEXT: Symbol {<br>
+# CHECK-NEXT: Name: (0)<br>
+# CHECK-NEXT: Value: 0x0<br>
+# CHECK-NEXT: Size: 0<br>
+# CHECK-NEXT: Binding: Local (0x0)<br>
+# CHECK-NEXT: Type: None (0x0)<br>
+# CHECK-NEXT: Other: 0<br>
+# CHECK-NEXT: Section: Undefined (0x0)<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: Symbol {<br>
+# CHECK-NEXT: Name: _start (7)<br>
+# CHECK-NEXT: Value: [[ENTRY]]<br>
+# CHECK-NEXT: Size: 0<br>
+# CHECK-NEXT: Binding: Global (0x1)<br>
+# CHECK-NEXT: Type: None (0x0)<br>
+# CHECK-NEXT: Other: 0<br>
+# CHECK-NEXT: Section: .text (0x1)<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: ]<br>
# CHECK-NEXT: ProgramHeaders [<br>
# CHECK-NEXT: ProgramHeader {<br>
# CHECK-NEXT: Type: PT_LOAD (0x1)<br>
<br>
Modified: lld/trunk/test/elf2/basic32.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32.s?rev=247089&r1=247088&r2=247089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32.s?rev=247089&r1=247088&r2=247089&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/basic32.s (original)<br>
+++ lld/trunk/test/elf2/basic32.s Tue Sep 8 17:34:57 2015<br>
@@ -23,7 +23,7 @@ _start:<br>
# CHECK-NEXT: Type: Executable (0x2)<br>
# CHECK-NEXT: Machine: EM_386 (0x3)<br>
# CHECK-NEXT: Version: 1<br>
-# CHECK-NEXT: Entry: 0x401000<br>
+# CHECK-NEXT: Entry: 0x1000<br>
# CHECK-NEXT: ProgramHeaderOffset: 0x34<br>
# CHECK-NEXT: SectionHeaderOffset: 0x1058<br>
# CHECK-NEXT: Flags [ (0x0)<br>
<br>
Modified: lld/trunk/test/elf2/basic32be.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32be.s?rev=247089&r1=247088&r2=247089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32be.s?rev=247089&r1=247088&r2=247089&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/basic32be.s (original)<br>
+++ lld/trunk/test/elf2/basic32be.s Tue Sep 8 17:34:57 2015<br>
@@ -23,7 +23,7 @@ _start:<br>
# CHECK-NEXT: Type: Executable (0x2)<br>
# CHECK-NEXT: Machine: EM_PPC (0x14)<br>
# CHECK-NEXT: Version: 1<br>
-# CHECK-NEXT: Entry: 0x401000<br>
+# CHECK-NEXT: Entry: 0x1000<br>
# CHECK-NEXT: ProgramHeaderOffset: 0x34<br>
# CHECK-NEXT: SectionHeaderOffset: 0x1058<br>
# CHECK-NEXT: Flags [ (0x0)<br>
<br>
Modified: lld/trunk/test/elf2/basic64be.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic64be.s?rev=247089&r1=247088&r2=247089&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic64be.s?rev=247089&r1=247088&r2=247089&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/basic64be.s (original)<br>
+++ lld/trunk/test/elf2/basic64be.s Tue Sep 8 17:34:57 2015<br>
@@ -28,7 +28,7 @@ _start:<br>
# CHECK-NEXT: Type: Executable (0x2)<br>
# CHECK-NEXT: Machine: EM_PPC64 (0x15)<br>
# CHECK-NEXT: Version: 1<br>
-# CHECK-NEXT: Entry: 0x401000<br>
+# CHECK-NEXT: Entry: 0x100C<br>
# CHECK-NEXT: ProgramHeaderOffset: 0x40<br>
# CHECK-NEXT: SectionHeaderOffset: 0x1088<br>
# CHECK-NEXT: Flags [ (0x0)<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>