diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -108,7 +108,10 @@ } 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 --- /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: ]