[lld] r282049 - Accept sh_entsize = 0.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 20 20:22:18 PDT 2016
Author: ruiu
Date: Tue Sep 20 22:22:18 2016
New Revision: 282049
URL: http://llvm.org/viewvc/llvm-project?rev=282049&view=rev
Log:
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
Modified:
lld/trunk/ELF/InputFiles.cpp
lld/trunk/test/ELF/invalid-elf.test
lld/trunk/test/ELF/merge-invalid-size.s
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=282049&r1=282048&r2=282049&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Tue Sep 20 22:22:18 2016
@@ -184,15 +184,23 @@ bool elf::ObjectFile<ELFT>::shouldMerge(
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.
Modified: lld/trunk/test/ELF/invalid-elf.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/invalid-elf.test?rev=282049&r1=282048&r2=282049&view=diff
==============================================================================
--- lld/trunk/test/ELF/invalid-elf.test (original)
+++ lld/trunk/test/ELF/invalid-elf.test Tue Sep 20 22:22:18 2016
@@ -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
Modified: lld/trunk/test/ELF/merge-invalid-size.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/merge-invalid-size.s?rev=282049&r1=282048&r2=282049&view=diff
==============================================================================
--- lld/trunk/test/ELF/merge-invalid-size.s (original)
+++ lld/trunk/test/ELF/merge-invalid-size.s Tue Sep 20 22:22:18 2016
@@ -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", at 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", at progbits,4
+.short 42
More information about the llvm-commits
mailing list