[lld] bd288eb - [ELF] Make -t work with --format=binary

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 16 00:41:28 PDT 2023


Author: Fangrui Song
Date: 2023-09-16T00:41:23-07:00
New Revision: bd288ebf5f08c941831b19e536d5d1156b47abf7

URL: https://github.com/llvm/llvm-project/commit/bd288ebf5f08c941831b19e536d5d1156b47abf7
DIFF: https://github.com/llvm/llvm-project/commit/bd288ebf5f08c941831b19e536d5d1156b47abf7.diff

LOG: [ELF] Make -t work with --format=binary

This is natural and matches GNU ld.

Added: 
    

Modified: 
    lld/ELF/InputFiles.cpp
    lld/test/ELF/format-binary.test

Removed: 
    


################################################################################
diff  --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp
index d96b47b3585b9fa..fa0731854689b94 100644
--- a/lld/ELF/InputFiles.cpp
+++ b/lld/ELF/InputFiles.cpp
@@ -284,13 +284,6 @@ template <class ELFT> static void doParseFile(InputFile *file) {
   if (!isCompatible(file))
     return;
 
-  // Binary file
-  if (auto *f = dyn_cast<BinaryFile>(file)) {
-    ctx.binaryFiles.push_back(f);
-    f->parse();
-    return;
-  }
-
   // Lazy object file
   if (file->lazy) {
     if (auto *f = dyn_cast<BitcodeFile>(file)) {
@@ -305,22 +298,18 @@ template <class ELFT> static void doParseFile(InputFile *file) {
   if (config->trace)
     message(toString(file));
 
-  // .so file
-  if (auto *f = dyn_cast<SharedFile>(file)) {
+  if (file->kind() == InputFile::ObjKind) {
+    ctx.objectFiles.push_back(cast<ELFFileBase>(file));
+    cast<ObjFile<ELFT>>(file)->parse();
+  } else if (auto *f = dyn_cast<SharedFile>(file)) {
     f->parse<ELFT>();
-    return;
-  }
-
-  // LLVM bitcode file
-  if (auto *f = dyn_cast<BitcodeFile>(file)) {
+  } else if (auto *f = dyn_cast<BitcodeFile>(file)) {
     ctx.bitcodeFiles.push_back(f);
     f->parse();
-    return;
+  } else {
+    ctx.binaryFiles.push_back(cast<BinaryFile>(file));
+    cast<BinaryFile>(file)->parse();
   }
-
-  // Regular object file
-  ctx.objectFiles.push_back(cast<ELFFileBase>(file));
-  cast<ObjFile<ELFT>>(file)->parse();
 }
 
 // Add symbols in File to the symbol table.

diff  --git a/lld/test/ELF/format-binary.test b/lld/test/ELF/format-binary.test
index 3c580ebb99ed4dd..21dafac38ca9b40 100644
--- a/lld/test/ELF/format-binary.test
+++ b/lld/test/ELF/format-binary.test
@@ -6,9 +6,11 @@
 
 # RUN: mkdir d
 # RUN: echo -n "Fluffle Puff" > d/t.txt
-# RUN: ld.lld -m elf_x86_64 -r -b binary d/t.txt -o ro
+# RUN: ld.lld -m elf_x86_64 -r -b binary d/t.txt -t -o ro | FileCheck %s --check-prefix=RO-TRACE
 # RUN: llvm-readelf -h -S -s -x .data ro | FileCheck --check-prefix=RO %s
 
+# RO-TRACE: d/t.txt
+
 # RO:      Machine: Advanced Micro Devices X86-64
 # RO:      Name         Type     Address          Off    Size   ES Flg Lk Inf Al
 # RO-NEXT:              NULL     0000000000000000 000000 000000 00      0   0  0


        


More information about the llvm-commits mailing list