Index: lld/trunk/ELF/InputFiles.cpp =================================================================== --- lld/trunk/ELF/InputFiles.cpp +++ lld/trunk/ELF/InputFiles.cpp @@ -184,15 +184,23 @@ if (Sec.sh_size == 0) return false; + // Check for sh_entsize. The ELF spec is not clear about the zero + // sh_entsize. It says that "the member [sh_entsize] contains 0 if + // the section does not hold a table of fixed-size entries". We know + // that Rust 1.13 produces a string mergeable section with a zero + // sh_entsize. Here we just accept it rather than being picky about it. + uintX_t EntSize = Sec.sh_entsize; + if (EntSize == 0) + return false; + if (Sec.sh_size % EntSize) + fatal(getFilename(this) + + ": SHF_MERGE section size must be a multiple of sh_entsize"); + uintX_t Flags = Sec.sh_flags; if (!(Flags & SHF_MERGE)) return false; if (Flags & SHF_WRITE) fatal(getFilename(this) + ": writable SHF_MERGE section is not supported"); - uintX_t EntSize = Sec.sh_entsize; - if (!EntSize || Sec.sh_size % EntSize) - fatal(getFilename(this) + - ": SHF_MERGE section size must be a multiple of sh_entsize"); // Don't try to merge if the alignment is larger than the sh_entsize and this // is not SHF_STRINGS. Index: lld/trunk/test/ELF/invalid-elf.test =================================================================== --- lld/trunk/test/ELF/invalid-elf.test +++ lld/trunk/test/ELF/invalid-elf.test @@ -24,10 +24,6 @@ # RUN: FileCheck --check-prefix=INVALID-SECTION-INDEX %s # INVALID-SECTION-INDEX: Invalid section index -# RUN: not ld.lld %p/Inputs/invalid-shentsize-zero.elf -o %t2 2>&1 | \ -# RUN: FileCheck --check-prefix=INVALID-SHENTSIZE-ZERO %s -# INVALID-SHENTSIZE-ZERO: SHF_MERGE section size must be a multiple of sh_entsize - # RUN: not ld.lld %p/Inputs/invalid-multiple-eh-relocs.elf -o %t2 2>&1 | \ # RUN: FileCheck --check-prefix=INVALID-EH-RELOCS %s # INVALID-EH-RELOCS: multiple relocation sections to .eh_frame are not supported Index: lld/trunk/test/ELF/merge-invalid-size.s =================================================================== --- lld/trunk/test/ELF/merge-invalid-size.s +++ lld/trunk/test/ELF/merge-invalid-size.s @@ -3,5 +3,8 @@ // RUN: not ld.lld %t.o -o %t.so 2>&1 | FileCheck %s // CHECK: SHF_MERGE section size must be a multiple of sh_entsize - .section .foo,"aM",@progbits,4 - .short 42 +// Test that we accept a zero sh_entsize. +// RUN: ld.lld %p/Inputs/invalid-shentsize-zero.elf -o %t2 + +.section .foo,"aM",@progbits,4 +.short 42