Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -54,6 +54,24 @@ error("Unknown emulation: " + S); } +static StringRef getDefaultInterp() { + switch (Config->EMachine) { + case EM_386: + return "/lib/ld-linux-x86-64.so.2"; + case EM_AARCH64: + return "/lib/ld-linux-aarch64.so.1"; + case EM_PPC: + return "/lib/ld.so.1"; + case EM_PPC64: + return "/lib64/ld64.so.1"; + case EM_X86_64: + return "/lib64/ld-linux-x86-64.so.2"; + } + // No interpreter specified. + // Assumes that it is taken from commandline. + return ""; +} + // Opens and parses a file. Path has to be resolved already. // Newly created memory buffers are owned by this driver. void LinkerDriver::addFile(StringRef Path) { @@ -146,7 +164,6 @@ Config->Shared = Args.hasArg(OPT_shared); Config->Verbose = Args.hasArg(OPT_verbose); - Config->DynamicLinker = getString(Args, OPT_dynamic_linker); Config->Entry = getString(Args, OPT_entry); Config->Fini = getString(Args, OPT_fini, "_fini"); Config->Init = getString(Args, OPT_init, "_init"); @@ -196,6 +213,9 @@ SymbolTable Symtab; Target.reset(createTarget()); + Config->DynamicLinker = + getString(Args, OPT_dynamic_linker, getDefaultInterp()); + if (!Config->Shared) { // Add entry symbol. if (Config->Entry.empty()) Index: test/elf2/dynamic-reloc.s =================================================================== --- test/elf2/dynamic-reloc.s +++ test/elf2/dynamic-reloc.s @@ -6,7 +6,7 @@ // RUN: llvm-readobj -dynamic-table -r --expand-relocs -s %t | FileCheck %s // REQUIRES: x86 -// CHECK: Index: 1 +// CHECK: Index: 2 // CHECK-NEXT: Name: .dynsym // CHECK: Name: .rela.dyn @@ -17,7 +17,7 @@ // CHECK-NEXT: Address: [[RELAADDR:.*]] // CHECK-NEXT: Offset: // CHECK-NEXT: Size: [[RELASIZE:.*]] -// CHECK-NEXT: Link: 1 +// CHECK-NEXT: Link: 2 // CHECK-NEXT: Info: 0 // CHECK-NEXT: AddressAlignment: 8 // CHECK-NEXT: EntrySize: 24 Index: test/elf2/interp.s =================================================================== --- test/elf2/interp.s +++ test/elf2/interp.s @@ -0,0 +1,61 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=i686-unknown-linux %s -o %t86.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t64.o + +# RUN: ld.lld2 -shared %t86.o -o %t.so +# RUN: ld.lld2 %t86.o %t.so -o %t +# RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data -hash-table %t | FileCheck -check-prefix=CHECK_X86 %s + +# RUN: ld.lld2 -shared %t64.o -o %t.so +# RUN: ld.lld2 %t64.o %t.so -o %t +# RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data -hash-table %t | FileCheck -check-prefix=CHECK_X64 %s + +# RUN: ld.lld2 %t64.o %t.so -dynamic-linker /aaa/bbb -o %t +# RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data -hash-table %t | FileCheck -check-prefix=CHECK_AAABBB %s + +# RUN: ld.lld2 %t64.o -o %t +# RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data -hash-table %t | FileCheck -check-prefix=CHECK_NO %s + +# CHECK_X86: Name: .interp +# CHECK_X86-NEXT: Type: SHT_PROGBITS +# CHECK_X86-NEXT: Flags [ +# CHECK_X86-NEXT: SHF_ALLOC +# CHECK_X86-NEXT: ] +# CHECK_X86-NEXT: Address: 0x100D4 +# CHECK_X86-NEXT: Offset: 0xD4 +# CHECK_X86-NEXT: Size: 26 +# CHECK_X86-NEXT: Link: 0 +# CHECK_X86-NEXT: Info: 0 +# CHECK_X86-NEXT: AddressAlignment: 1 +# CHECK_X86-NEXT: EntrySize: 0 +# CHECK_X86-NEXT: SectionData ( +# CHECK_X86-NEXT: 0000: 2F6C6962 2F6C642D 6C696E75 782D7838 |/lib/ld-linux-x8| +# CHECK_X86-NEXT: 0010: 362D3634 2E736F2E 3200 |6-64.so.2.| +# CHECK_X86-NEXT: ) + +# CHECK_X64: Name: .interp +# CHECK_X64-NEXT: Type: SHT_PROGBITS +# CHECK_X64-NEXT: Flags [ +# CHECK_X64-NEXT: SHF_ALLOC +# CHECK_X64-NEXT: ] +# CHECK_X64-NEXT: Address: 0x10158 +# CHECK_X64-NEXT: Offset: 0x158 +# CHECK_X64-NEXT: Size: 28 +# CHECK_X64-NEXT: Link: 0 +# CHECK_X64-NEXT: Info: 0 +# CHECK_X64-NEXT: AddressAlignment: 1 +# CHECK_X64-NEXT: EntrySize: 0 +# CHECK_X64-NEXT: SectionData ( +# CHECK_X64-NEXT: 0000: 2F6C6962 36342F6C 642D6C69 6E75782D |/lib64/ld-linux-| +# CHECK_X64-NEXT: 0010: 7838362D 36342E73 6F2E3200 |x86-64.so.2.| +# CHECK_X64-NEXT: ) + +# CHECK_AAABBB: Name: .interp +# CHECK_AAABBB: SectionData ( +# CHECK_AAABBB-NEXT: 0000: 2F616161 2F626262 00 |/aaa/bbb.| +# CHECK_AAABBB-NEXT: ) + +# CHECK_NO-NOT: Name: .interp + +.global _start +_start: Index: test/elf2/relocation.s =================================================================== --- test/elf2/relocation.s +++ test/elf2/relocation.s @@ -86,7 +86,7 @@ .quad R_X86_64_64 // CHECK: Contents of section .R_X86_64_64: -// CHECK-NEXT: 10158 58010100 00000000 +// CHECK-NEXT: 101ac ac010100 00000000 .section .R_X86_64_GOTPCREL,"a",@progbits .global R_X86_64_GOTPCREL @@ -96,4 +96,4 @@ // 0x120A8 - 0x10160 = 8008 // 8008 = 0x481f0000 in little endian // CHECK: Contents of section .R_X86_64_GOTPCREL -// CHECK-NEXT: 10160 481f0000 +// CHECK-NEXT: 101b4 f41e0000