forked from OSchip/llvm-project
Accept sh_entsize = 0.
This surfaced again with Rust. As per bug 30435, rustc creates a mergeable section with a sh_entsize zero. It bit us before, too. I think we should relax the input check rather than being too picky. Differential Revision: https://reviews.llvm.org/D24789 llvm-svn: 282049
This commit is contained in:
parent
e3cef93727
commit
c75ef85e84
|
@ -184,15 +184,23 @@ bool elf::ObjectFile<ELFT>::shouldMerge(const Elf_Shdr &Sec) {
|
|||
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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue