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: ]