[PATCH] D50742: [ELF] mergeSections: remove non-alive MergeInputSection

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 15 11:02:42 PDT 2018


MaskRay updated this revision to Diff 160855.
MaskRay added a comment.

Add test


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D50742

Files:
  ELF/SyntheticSections.cpp
  test/ELF/x86-64-reloc-error2.s


Index: test/ELF/x86-64-reloc-error2.s
===================================================================
--- test/ELF/x86-64-reloc-error2.s
+++ test/ELF/x86-64-reloc-error2.s
@@ -1,14 +1,25 @@
 # REQUIRES: x86
 # RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: not ld.lld %t.o -o /dev/null 2>&1 | FileCheck %s
+# RUN: not ld.lld --entry=func -Ttext=0x80000000 --gc-sections %t.o -o /dev/null 2>&1 | FileCheck %s
 
 ## Check we are able to find a function symbol that encloses
 ## a given location when reporting error messages.
-# CHECK: {{.*}}.o:(function func): relocation R_X86_64_32S out of range: -281474974609408 is not in [-2147483648, 2147483647]
+# CHECK: {{.*}}.o:(function func): relocation R_X86_64_32S out of range: 2147487744 is not in [-2147483648, 2147483647]
+
+# This section will be garbage collected.
+# It is here to check no MergeInputSection (which is not a subclass of InputSection)
+# is in InputSections after mergeSections is called.
+# If this section is kept, cast<InputSection>(D) in getErrPlace will cause an assertion failure.
+.section .rodata.str1.1,"aMS", at progbits,1
+.asciz "b"
+
+.section .rodata.str2.1,"aMS", at progbits,1
+foo:
+.asciz "a"
 
 .section .text.func, "ax", %progbits
 .globl func
 .type func, at function
-.size func, 0x10
 func:
- movq func - 0x1000000000000, %rdx
+  movq $foo, %rdx
+.size func, .-func
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -2929,8 +2929,10 @@
 
     // We do not want to handle sections that are not alive, so just remove
     // them instead of trying to merge.
-    if (!MS->Live)
+    if (!MS->Live) {
+      S = nullptr;
       continue;
+    }
 
     StringRef OutsecName = getOutputSectionName(MS);
     uint32_t Alignment = std::max<uint32_t>(MS->Alignment, MS->Entsize);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50742.160855.patch
Type: text/x-patch
Size: 1895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180815/2d43ab9a/attachment.bin>


More information about the llvm-commits mailing list