[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
Fri Apr 3 09:07:50 PDT 2020


MaskRay updated this revision to Diff 254829.
MaskRay edited the summary of this revision.
MaskRay added a comment.

Update description


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77368/new/

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,17 @@
+## Ignore invalid sh_entsize (sh_size%sh_entsize!=0) for non-SHF_MERGE sections.
+## GNU as before 2.35 had such a bug for .stab
+## https://sourceware.org/bugzilla/show_bug.cgi?id=25768
+# 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
@@ -424,6 +424,9 @@
 
 template <class ELFT>
 bool ObjFile<ELFT>::shouldMerge(const Elf_Shdr &sec, StringRef name) {
+  if (!(sec.sh_flags & SHF_MERGE))
+    return false;
+
   // On a regular link we don't merge sections if -O0 (default is -O1). This
   // sometimes makes the linker significantly faster, although the output will
   // be bigger.
@@ -459,10 +462,7 @@
           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)
+  if (sec.sh_flags & SHF_WRITE)
     fatal(toString(this) + ":(" + name +
           "): writable SHF_MERGE section is not supported");
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77368.254829.patch
Type: text/x-patch
Size: 1528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200403/c2cd9d82/attachment.bin>


More information about the llvm-commits mailing list