[lld] 189b739 - [lld][RISCV] Use an e_flags of 0 if there are only binary input files.

James Clarke via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 21 10:00:00 PST 2019


Author: John Baldwin
Date: 2019-12-21T17:59:37Z
New Revision: 189b7393d545330fae6b84e9a140d34e09eb634e

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

LOG: [lld][RISCV] Use an e_flags of 0 if there are only binary input files.

Summary:
If none of the input files are ELF object files (for example, when
generating an object file from a single binary input file via
"-b binary"), use a fallback value for the ELF header flags instead
of crashing with an assertion failure.

Reviewers: MaskRay, ruiu, espindola

Reviewed By: MaskRay, ruiu

Subscribers: kevans, grimar, emaste, arichardson, asb, rbar, johnrusso, simoncook, sabuasal, niosHD, kito-cheng, shiva0217, zzheng, edward-jones, rogfer01, MartinMosbeck, brucehoult, the_o, rkruppe, PkmX, jocewei, psnobl, benna, Jim, lenary, s.egerton, pzheng, sameer.abuasal, apazos, luismarques, llvm-commits, jrtc27

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D71101

Added: 
    lld/test/ELF/riscv-elf-flags.s

Modified: 
    lld/ELF/Arch/RISCV.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 7b807aa494d9..d4acccf80a3c 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -108,7 +108,10 @@ static uint32_t getEFlags(InputFile *f) {
 }
 
 uint32_t RISCV::calcEFlags() const {
-  assert(!objectFiles.empty());
+  // If there are only binary input files (from -b binary), use a
+  // value of 0 for the ELF header flags.
+  if (objectFiles.empty())
+    return 0;
 
   uint32_t target = getEFlags(objectFiles.front());
 

diff  --git a/lld/test/ELF/riscv-elf-flags.s b/lld/test/ELF/riscv-elf-flags.s
new file mode 100644
index 000000000000..137c89db3488
--- /dev/null
+++ b/lld/test/ELF/riscv-elf-flags.s
@@ -0,0 +1,8 @@
+# REQUIRES: riscv
+
+# RUN: echo -n "BLOB" > %t.binary
+# RUN: ld.lld -m elf64lriscv -b binary %t.binary -o %t.out
+# RUN: llvm-readobj -h %t.out | FileCheck %s
+
+# CHECK:      Flags [
+# CHECK-NEXT: ]


        


More information about the llvm-commits mailing list