Skip to content

Commit 0b95d37

Browse files
committed
[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 llvm-svn: 313086
1 parent 7c5b45d commit 0b95d37

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lld/ELF/Symbols.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ static uint64_t getSymVA(const SymbolBody &Body, int64_t &Addend) {
103103
if (!Config->DefineCommon)
104104
return 0;
105105
auto DC = cast<DefinedCommon>(Body);
106+
if (!DC.Live)
107+
return 0;
106108
return DC.Section->getParent()->Addr + DC.Section->OutSecOff;
107109
}
108110
case SymbolBody::SharedKind: {

lld/test/ELF/common-gc3.s

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# REQUIRES: x86
2+
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
3+
# RUN: ld.lld %t.o -o %t1 --gc-sections
4+
# RUN: llvm-objdump -s %t1 | FileCheck %s
5+
6+
# CHECK: Contents of section .noalloc:
7+
# 0000 00000000 00000000 ........
8+
9+
.section .text._start,"ax",@progbits
10+
.globl _start
11+
_start:
12+
retq
13+
14+
.type unused,@object
15+
.comm unused,4,4
16+
17+
.section .noalloc,"",@progbits
18+
.quad unused

0 commit comments

Comments
 (0)