On Wednesday, August 5, 2015, Rafael Espindola <<a href="mailto:rafael.espindola@gmail.com">rafael.espindola@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Wed Aug 5 10:08:40 2015<br>
New Revision: 244050<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=244050&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=244050&view=rev</a><br>
Log:<br>
Add bare minimum to get a working i386 linux program.<br>
<br>
Added:<br>
lld/trunk/test/elf2/basic32.s<br>
Modified:<br>
lld/trunk/ELF/Driver.cpp<br>
lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=244050&r1=244049&r2=244050&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=244050&r1=244049&r2=244050&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Driver.cpp (original)<br>
+++ lld/trunk/ELF/Driver.cpp Wed Aug 5 10:08:40 2015<br>
@@ -114,6 +114,27 @@ void LinkerDriver::link(ArrayRef<const c<br>
Symtab.reportRemainingUndefines();<br>
<br>
// Write the result.<br>
- Writer<object::ELF64LE> Out(&Symtab);<br>
- Out.write(Config->OutputFile);<br>
+ ObjectFileBase &FirstObj = *Symtab.ObjectFiles[0];<br>
+ switch (FirstObj.kind()) {<br>
+ case InputFile::Object32LEKind: {<br>
+ Writer<object::ELF32LE> Out(&Symtab);<br>
+ Out.write(Config->OutputFile);<br>
+ return;<br>
+ }<br>
+ case InputFile::Object32BEKind: {<br>
+ Writer<object::ELF32BE> Out(&Symtab);<br>
+ Out.write(Config->OutputFile);<br>
+ return;<br>
+ }<br>
+ case InputFile::Object64LEKind: {<br>
+ Writer<object::ELF64LE> Out(&Symtab);<br>
+ Out.write(Config->OutputFile);<br>
+ return;<br>
+ }<br>
+ case InputFile::Object64BEKind: {<br>
+ Writer<object::ELF64BE> Out(&Symtab);<br>
+ Out.write(Config->OutputFile);<br>
+ return;<br>
+ }<br>
+ }<br>
}<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=244050&r1=244049&r2=244050&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=244050&r1=244049&r2=244050&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Wed Aug 5 10:08:40 2015<br>
@@ -119,13 +119,16 @@ template <class ELFT> void Writer<ELFT>:<br>
EHdr->e_ident[EI_MAG1] = 0x45;<br>
EHdr->e_ident[EI_MAG2] = 0x4C;<br>
EHdr->e_ident[EI_MAG3] = 0x46;<br>
- EHdr->e_ident[EI_CLASS] = ELFCLASS64;<br>
- EHdr->e_ident[EI_DATA] = ELFDATA2LSB;<br>
+ EHdr->e_ident[EI_CLASS] = ELFT::Is64Bits ? ELFCLASS64 : ELFCLASS32;<br>
+ EHdr->e_ident[EI_DATA] = ELFT::TargetEndianness == llvm::support::little<br>
+ ? ELFDATA2LSB<br>
+ : ELFDATA2MSB;<br>
EHdr->e_ident[EI_VERSION] = EV_CURRENT;<br>
EHdr->e_ident[EI_OSABI] = ELFOSABI_NONE;<br>
<br>
EHdr->e_type = ET_EXEC;<br>
- EHdr->e_machine = EM_X86_64;<br>
+ auto &FirstObj = cast<ObjectFile<ELFT>>(*Symtab->ObjectFiles[0]);<br>
+ EHdr->e_machine = FirstObj.getObj()->getHeader()->e_machine;</blockquote><div><br></div><div>Is the intent to behave more like link rather than ld? link bases the target machine based on the first input file if /machine is not specified. ld uses the emulation IIRC.<span></span></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
EHdr->e_version = EV_CURRENT;<br>
EHdr->e_entry = 0x401000;<br>
EHdr->e_phoff = sizeof(Elf_Ehdr_Impl<ELFT>);<br>
<br>
Added: lld/trunk/test/elf2/basic32.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32.s?rev=244050&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32.s?rev=244050&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/elf2/basic32.s (added)<br>
+++ lld/trunk/test/elf2/basic32.s Wed Aug 5 10:08:40 2015<br>
@@ -0,0 +1,116 @@<br>
+# RUN: llvm-mc -filetype=obj -triple=i686-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>
+# REQUIRES: x86<br>
+<br>
+# exits with return code 42 on linux<br>
+.globl _start;<br>
+_start:<br>
+ mov $1, %eax<br>
+ mov $42, %ebx<br>
+ int $0x80<br>
+<br>
+# CHECK: ElfHeader {<br>
+# CHECK-NEXT: Ident {<br>
+# CHECK-NEXT: Magic: (7F 45 4C 46)<br>
+# CHECK-NEXT: Class: 32-bit (0x1)<br>
+# CHECK-NEXT: DataEncoding: LittleEndian (0x1)<br>
+# CHECK-NEXT: FileVersion: 1<br>
+# CHECK-NEXT: OS/ABI: SystemV (0x0)<br>
+# CHECK-NEXT: ABIVersion: 0<br>
+# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)<br>
+# CHECK-NEXT: }<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: ProgramHeaderOffset: 0x34<br>
+# CHECK-NEXT: SectionHeaderOffset: 0x1010<br>
+# CHECK-NEXT: Flags [ (0x0)<br>
+# CHECK-NEXT: ]<br>
+# CHECK-NEXT: HeaderSize: 52<br>
+# CHECK-NEXT: ProgramHeaderEntrySize: 32<br>
+# CHECK-NEXT: ProgramHeaderCount: 1<br>
+# CHECK-NEXT: SectionHeaderEntrySize: 40<br>
+# CHECK-NEXT: SectionHeaderCount: 4<br>
+# CHECK-NEXT: StringTableSectionIndex: 0<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: Sections [<br>
+# CHECK-NEXT: Section {<br>
+# CHECK-NEXT: Index: 0<br>
+# CHECK-NEXT: Name: (0)<br>
+# CHECK-NEXT: Type: SHT_NULL (0x0)<br>
+# CHECK-NEXT: Flags [ (0x0)<br>
+# CHECK-NEXT: ]<br>
+# CHECK-NEXT: Address: 0x0<br>
+# CHECK-NEXT: Offset: 0x0<br>
+# CHECK-NEXT: Size: 0<br>
+# CHECK-NEXT: Link: 0<br>
+# CHECK-NEXT: Info: 0<br>
+# CHECK-NEXT: AddressAlignment: 0<br>
+# CHECK-NEXT: EntrySize: 0<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: Section {<br>
+# CHECK-NEXT: Index: 1<br>
+# CHECK-NEXT: Name: (0)<br>
+# CHECK-NEXT: Type: SHT_PROGBITS (0x1)<br>
+# CHECK-NEXT: Flags [ (0x6)<br>
+# CHECK-NEXT: SHF_ALLOC (0x2)<br>
+# CHECK-NEXT: SHF_EXECINSTR (0x4)<br>
+# CHECK-NEXT: ]<br>
+# CHECK-NEXT: Address: 0x1000<br>
+# CHECK-NEXT: Offset: 0x1000<br>
+# CHECK-NEXT: Size: 12<br>
+# CHECK-NEXT: Link: 0<br>
+# CHECK-NEXT: Info: 0<br>
+# CHECK-NEXT: AddressAlignment: 0<br>
+# CHECK-NEXT: EntrySize: 0<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: Section {<br>
+# CHECK-NEXT: Index: 2<br>
+# CHECK-NEXT: Name: (0)<br>
+# CHECK-NEXT: Type: SHT_PROGBITS (0x1)<br>
+# CHECK-NEXT: Flags [ (0x3)<br>
+# CHECK-NEXT: SHF_ALLOC (0x2)<br>
+# CHECK-NEXT: SHF_WRITE (0x1)<br>
+# CHECK-NEXT: ]<br>
+# CHECK-NEXT: Address: 0x2000<br>
+# CHECK-NEXT: Offset: 0x0<br>
+# CHECK-NEXT: Size: 0<br>
+# CHECK-NEXT: Link: 0<br>
+# CHECK-NEXT: Info: 0<br>
+# CHECK-NEXT: AddressAlignment: 0<br>
+# CHECK-NEXT: EntrySize: 0<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: Section {<br>
+# CHECK-NEXT: Index: 3<br>
+# CHECK-NEXT: Name: (0)<br>
+# CHECK-NEXT: Type: SHT_NOBITS (0x8)<br>
+# CHECK-NEXT: Flags [ (0x3)<br>
+# CHECK-NEXT: SHF_ALLOC (0x2)<br>
+# CHECK-NEXT: SHF_WRITE (0x1)<br>
+# CHECK-NEXT: ]<br>
+# CHECK-NEXT: Address: 0x2000<br>
+# CHECK-NEXT: Offset: 0x0<br>
+# CHECK-NEXT: Size: 0<br>
+# CHECK-NEXT: Link: 0<br>
+# CHECK-NEXT: Info: 0<br>
+# CHECK-NEXT: AddressAlignment: 0<br>
+# CHECK-NEXT: EntrySize: 0<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: ]<br>
+# CHECK-NEXT: ProgramHeaders [<br>
+# CHECK-NEXT: ProgramHeader {<br>
+# CHECK-NEXT: Type: PT_LOAD (0x1)<br>
+# CHECK-NEXT: Offset: 0x0<br>
+# CHECK-NEXT: VirtualAddress: 0x400000<br>
+# CHECK-NEXT: PhysicalAddress: 0x400000<br>
+# CHECK-NEXT: FileSize: 4272<br>
+# CHECK-NEXT: MemSize: 4272<br>
+# CHECK-NEXT: Flags [ (0x5)<br>
+# CHECK-NEXT: PF_R (0x4)<br>
+# CHECK-NEXT: PF_X (0x1)<br>
+# CHECK-NEXT: ]<br>
+# CHECK-NEXT: Alignment: 16384<br>
+# CHECK-NEXT: }<br>
+# CHECK-NEXT: ]<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'llvm-commits@lists.llvm.org')">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote><br><br>-- <br>Saleem Abdulrasool<br>compnerd (at) compnerd (dot) org<br>