[PATCH] D76174: [ELF] Support linking ET_EXEC

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 14 15:34:40 PDT 2020


MaskRay updated this revision to Diff 250391.
MaskRay added a comment.

Rename executable.test to executable.s and switch the role of assembly/linker script


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76174/new/

https://reviews.llvm.org/D76174

Files:
  lld/ELF/Driver.cpp
  lld/test/ELF/executable.s
  lld/test/ELF/invalid/core.test
  lld/test/ELF/invalid/executable.s


Index: lld/test/ELF/invalid/executable.s
===================================================================
--- 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
Index: lld/test/ELF/invalid/core.test
===================================================================
--- /dev/null
+++ 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
Index: lld/test/ELF/executable.s
===================================================================
--- /dev/null
+++ 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
Index: lld/ELF/Driver.cpp
===================================================================
--- lld/ELF/Driver.cpp
+++ lld/ELF/Driver.cpp
@@ -259,6 +259,7 @@
         make<SharedFile>(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<LazyObjFile>(mbref, "", 0));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76174.250391.patch
Type: text/x-patch
Size: 2023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200314/e55216b0/attachment.bin>


More information about the llvm-commits mailing list