[lld] r313086 - [ELF] Handle references to garbage collected common symbols

Ben Dunbobbin via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 15:41:45 PDT 2017


Author: bd1976llvm
Date: Tue Sep 12 15:41:45 2017
New Revision: 313086

URL: http://llvm.org/viewvc/llvm-project?rev=313086&view=rev
Log:
[ELF] Handle references to garbage collected common symbols

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.

Differential Revision: https://reviews.llvm.org/D37718

Added:
    lld/trunk/test/ELF/common-gc3.s
Modified:
    lld/trunk/ELF/Symbols.cpp

Modified: lld/trunk/ELF/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.cpp?rev=313086&r1=313085&r2=313086&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.cpp (original)
+++ lld/trunk/ELF/Symbols.cpp Tue Sep 12 15:41:45 2017
@@ -103,6 +103,8 @@ static uint64_t getSymVA(const SymbolBod
     if (!Config->DefineCommon)
       return 0;
     auto DC = cast<DefinedCommon>(Body);
+    if (!DC.Live)
+      return 0;
     return DC.Section->getParent()->Addr + DC.Section->OutSecOff;
   }
   case SymbolBody::SharedKind: {

Added: lld/trunk/test/ELF/common-gc3.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/common-gc3.s?rev=313086&view=auto
==============================================================================
--- lld/trunk/test/ELF/common-gc3.s (added)
+++ lld/trunk/test/ELF/common-gc3.s Tue Sep 12 15:41:45 2017
@@ -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




More information about the llvm-commits mailing list