[PATCH] D37718: [ELF] Handle references to garbage collected common symbols

ben via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 11 15:48:51 PDT 2017


bd1976llvm created this revision.
Herald added a subscriber: emaste.

https://reviews.llvm.org/rL312796 meant that references to garbage collected common symbols would cause a segfault.

This change fixes the behaviour for references to stripped common symbols.


https://reviews.llvm.org/D37718

Files:
  ELF/Symbols.cpp
  test/ELF/common-gc3.s


Index: test/ELF/common-gc3.s
===================================================================
--- /dev/null
+++ test/ELF/common-gc3.s
@@ -0,0 +1,18 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t1 --gc-sections
+# RUN: llvm-objdump -s %t1 | FileCheck %s
+
+# CHECK:      Contents of section .noalloc:
+# 0000 00000000 00000000                    ........
+
+	.section	.text._start,"ax", at progbits
+	.globl	_start
+_start:
+	retq
+
+	.type	unused, at object
+	.comm	unused,4,4
+
+	.section	.noalloc,"", at progbits
+	.quad	unused
Index: ELF/Symbols.cpp
===================================================================
--- ELF/Symbols.cpp
+++ ELF/Symbols.cpp
@@ -103,6 +103,8 @@
     if (!Config->DefineCommon)
       return 0;
     auto DC = cast<DefinedCommon>(Body);
+    if (!DC.Live)
+      return 0;
     return DC.Section->getParent()->Addr + DC.Section->OutSecOff +
            DC.Offset;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37718.114719.patch
Type: text/x-patch
Size: 967 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170911/e95fe0fc/attachment.bin>


More information about the llvm-commits mailing list