diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 3341a799f6e2..8137b16035d9 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -694,6 +694,8 @@ MipsOptionsInputSection::MipsOptionsInputSection(elf::ObjectFile *F, error(getName(this) + ": unsupported non-zero ri_gp_value"); break; } + if (!O->size) + fatal(getName(this) + ": zero option descriptor size"); D = D.slice(O->size); } } diff --git a/lld/test/ELF/invalid/Inputs/mips-invalid-options-descriptor.elf b/lld/test/ELF/invalid/Inputs/mips-invalid-options-descriptor.elf new file mode 100644 index 000000000000..85feeebc6198 Binary files /dev/null and b/lld/test/ELF/invalid/Inputs/mips-invalid-options-descriptor.elf differ diff --git a/lld/test/ELF/invalid/mips-invalid-options-descriptor.s b/lld/test/ELF/invalid/mips-invalid-options-descriptor.s new file mode 100644 index 000000000000..2fd5bf5a513e --- /dev/null +++ b/lld/test/ELF/invalid/mips-invalid-options-descriptor.s @@ -0,0 +1,5 @@ +## mips-invalid-options-descriptor.elf has option descriptor in +## .MIPS.options with size of zero. +# RUN: not ld.lld %p/Inputs/mips-invalid-options-descriptor.elf -o %t2 2>&1 | \ +# RUN: FileCheck %s +# CHECK: zero option descriptor size