[PATCH] D24789: Accept sh_entsize = 0.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 20 17:25:51 PDT 2016
ruiu created this revision.
ruiu added a reviewer: grimar.
ruiu added a subscriber: llvm-commits.
This surfaced again with Rust. As per bug 30435, rustc creates a
mergeable section with a sh_entsize. It bit us before, too.
So I think we should relax the input check rather than being too picky.
https://reviews.llvm.org/D24789
Files:
ELF/InputFiles.cpp
test/ELF/invalid-elf.test
test/ELF/merge-invalid-size.s
Index: test/ELF/merge-invalid-size.s
===================================================================
--- test/ELF/merge-invalid-size.s
+++ 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", 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
Index: test/ELF/invalid-elf.test
===================================================================
--- test/ELF/invalid-elf.test
+++ 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: ELF/InputFiles.cpp
===================================================================
--- ELF/InputFiles.cpp
+++ 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24789.72000.patch
Type: text/x-patch
Size: 2497 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160921/5dcaac02/attachment.bin>
More information about the llvm-commits
mailing list