diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -259,6 +259,7 @@ make(mbref, withLOption ? path::filename(path) : path)); return; case file_magic::bitcode: + case file_magic::elf_executable: // handled the same way as an ET_REL case file_magic::elf_relocatable: if (inLib) files.push_back(make(mbref, "", 0)); diff --git a/lld/test/ELF/executable.s b/lld/test/ELF/executable.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/executable.s @@ -0,0 +1,20 @@ +# REQUIRES: x86 +## Test an ET_EXEC can be linked like a relocatable object. + +# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o +# RUN: ld.lld %t.o -o %t.exe + +# RUN: ld.lld %t.exe -o %t +# RUN: cmp %t.exe %t + +## This demonstrates a use case that a linker script can +## uses the section contents to create another output. +## seabios has such a use case. + +# RUN: echo 'SECTIONS { .foo : {*(.text)}}' > %t.script +# RUN: ld.lld -T %t.script %t.exe %t.exe -o %t2 +# RUN: llvm-readelf -x .foo %t2 | FileCheck %s + +# CHECK: 0x00000000 90cccccc 90 + +nop diff --git a/lld/test/ELF/invalid/core.test b/lld/test/ELF/invalid/core.test new file mode 100644 --- /dev/null +++ b/lld/test/ELF/invalid/core.test @@ -0,0 +1,12 @@ +## Reject core files. +# RUN: yaml2obj %s -o %t +# RUN: not ld.lld %t -o /dev/null 2>&1 | FileCheck %s + +# CHECK: unknown file type + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_CORE + Machine: EM_X86_64 diff --git a/lld/test/ELF/invalid/executable.s b/lld/test/ELF/invalid/executable.s deleted file mode 100644 --- a/lld/test/ELF/invalid/executable.s +++ /dev/null @@ -1,9 +0,0 @@ -# REQUIRES: x86 -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o -# RUN: ld.lld -o %t1.exe %t.o -# RUN: not ld.lld -o /dev/null %t1.exe 2>&1 | FileCheck %s -# CHECK: unknown file type - -.global _start -_start: - ret