[PATCH] D77368: [ELF] Allow invalid sh_size%sh_entsize!=0 for non-SHF_MERGE sections
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 22:45:47 PDT 2020
MaskRay created this revision.
MaskRay added reviewers: grimar, psmith, ruiu.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
Fixes https://bugs.llvm.org/show_bug.cgi?id=45370
.stab holds a table of 12-byte entries. GNU as incorrectly sets
sh_entsize(.stab) to 20 on 64-bit architectures.
https://sourceware.org/bugzilla/show_bug.cgi?id=25768
We should not emit the confusing error:
"SHF_MERGE section size (...) must be a multiple of sh_entsize (20)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77368
Files:
lld/ELF/InputFiles.cpp
lld/test/ELF/invalid/entsize.yaml
Index: lld/test/ELF/invalid/entsize.yaml
===================================================================
--- /dev/null
+++ lld/test/ELF/invalid/entsize.yaml
@@ -0,0 +1,15 @@
+## Ignore invalid sh_entsize (sh_size%sh_entsize!=0) for non-SHF_MERGE sections.
+# RUN: yaml2obj %s -o %t.o
+# RUN: ld.lld -e 0 --fatal-warnings %t.o -o /dev/null
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_X86_64
+Sections:
+ - Name: .stab
+ Type: SHT_PROGBITS
+ EntSize: 20
+ Size: 24
Index: lld/ELF/InputFiles.cpp
===================================================================
--- lld/ELF/InputFiles.cpp
+++ lld/ELF/InputFiles.cpp
@@ -446,6 +446,10 @@
if (sec.sh_size == 0)
return false;
+ uint64_t flags = sec.sh_flags;
+ if (!(flags & SHF_MERGE))
+ 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
@@ -459,9 +463,6 @@
Twine(sec.sh_size) + ") must be a multiple of sh_entsize (" +
Twine(entSize) + ")");
- uint64_t flags = sec.sh_flags;
- if (!(flags & SHF_MERGE))
- return false;
if (flags & SHF_WRITE)
fatal(toString(this) + ":(" + name +
"): writable SHF_MERGE section is not supported");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77368.254710.patch
Type: text/x-patch
Size: 1399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200403/372fb5d8/attachment-0001.bin>
More information about the llvm-commits
mailing list