[lld] r277568 - Do not handle zero-sized mergeable section as mergeable.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 2 22:28:02 PDT 2016


Author: ruiu
Date: Wed Aug  3 00:28:02 2016
New Revision: 277568

URL: http://llvm.org/viewvc/llvm-project?rev=277568&view=rev
Log:
Do not handle zero-sized mergeable section as mergeable.

Mergeable sections with size zero are useless because they don't
actually contain data, and therefore there's no merit ot merge them.
However, in reality, there are object files in the wild containing
such sections. Currently, LLD can't handle them proerply.

This patch makes LLD to handle such sections as if they are non-
mergeable to fix the issue.

Fixes bug 28822.

Added:
    lld/trunk/test/ELF/merge-string-empty.s
Modified:
    lld/trunk/ELF/InputFiles.cpp
    lld/trunk/test/ELF/relocation-past-merge-end.s
    lld/trunk/test/ELF/writable-merge.s

Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=277568&r1=277567&r2=277568&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Wed Aug  3 00:28:02 2016
@@ -162,6 +162,13 @@ bool elf::ObjectFile<ELFT>::shouldMerge(
   if (Config->Optimize == 0)
     return false;
 
+  // A mergeable section with size 0 is useless because they don't have
+  // any data to merge. A mergeable string section with size 0 can be
+  // argued as invalid because it doesn't end with a null character.
+  // We'll avoid a mess by handling them as if they were non-mergeable.
+  if (Sec.sh_size == 0)
+    return false;
+
   uintX_t Flags = Sec.sh_flags;
   if (!(Flags & SHF_MERGE))
     return false;

Added: lld/trunk/test/ELF/merge-string-empty.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/merge-string-empty.s?rev=277568&view=auto
==============================================================================
--- lld/trunk/test/ELF/merge-string-empty.s (added)
+++ lld/trunk/test/ELF/merge-string-empty.s Wed Aug  3 00:28:02 2016
@@ -0,0 +1,12 @@
+// Ensure that a mergeable string with size 0 does not cause any issue.
+
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: ld.lld %t.o -o %t
+
+.globl _start, s
+.section .rodata.str1.1,"aMS", at progbits,1
+s:
+.text
+_start:
+	.quad s

Modified: lld/trunk/test/ELF/relocation-past-merge-end.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocation-past-merge-end.s?rev=277568&r1=277567&r2=277568&view=diff
==============================================================================
--- lld/trunk/test/ELF/relocation-past-merge-end.s (original)
+++ lld/trunk/test/ELF/relocation-past-merge-end.s Wed Aug  3 00:28:02 2016
@@ -3,6 +3,7 @@
 // RUN: not ld.lld %t.o -o %t.so -shared 2>&1 | FileCheck %s
 // CHECK: relocation-past-merge-end.s.tmp.o(.foo): entry is past the end of the section
 
-        .data
-        .long .foo + 1
-        .section	.foo,"aM", at progbits,4
+.data
+.long .foo + 10
+.section	.foo,"aM", at progbits,4
+.quad 0

Modified: lld/trunk/test/ELF/writable-merge.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/writable-merge.s?rev=277568&r1=277567&r2=277568&view=diff
==============================================================================
--- lld/trunk/test/ELF/writable-merge.s (original)
+++ lld/trunk/test/ELF/writable-merge.s Wed Aug  3 00:28:02 2016
@@ -4,3 +4,4 @@
 // CHECK: writable SHF_MERGE section is not supported
 
 .section .foo,"awM", at progbits,4
+.quad 0




More information about the llvm-commits mailing list