Skip to content

Commit 3e9ceae

Browse files
authored
[lld] [hexagon] guard allocateAux: only if idx nonzero (#149690)
While building libclang_rt.asan-hexagon.so, lld would assert in lld::elf::hexagonTLSSymbolUpdate(). Fixes #132766
1 parent dd50e8e commit 3e9ceae

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lld/ELF/Relocations.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2553,7 +2553,8 @@ void elf::hexagonTLSSymbolUpdate(Ctx &ctx) {
25532553
for (Relocation &rel : isec->relocs())
25542554
if (rel.sym->type == llvm::ELF::STT_TLS && rel.expr == R_PLT_PC) {
25552555
if (needEntry) {
2556-
sym->allocateAux(ctx);
2556+
if (sym->auxIdx == 0)
2557+
sym->allocateAux(ctx);
25572558
addPltEntry(ctx, *ctx.in.plt, *ctx.in.gotPlt, *ctx.in.relaPlt,
25582559
ctx.target->pltRel, *sym);
25592560
needEntry = false;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# REQUIRES: hexagon
2+
# RUN: rm -rf %t && split-file %s %t && cd %t
3+
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf a.s -o a.o
4+
# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf b.s -o b.o
5+
# RUN: ld.lld -shared a.o b.o -o out.so
6+
# RUN: llvm-readobj -r out.so | FileCheck --check-prefix=RELOC %s
7+
8+
#--- a.s
9+
.globl _start
10+
.type _start, @function
11+
12+
_start:
13+
r2 = add(pc,##_GLOBAL_OFFSET_TABLE_@PCREL)
14+
r0 = add(r2,##tls_var@GDGOT)
15+
call tls_var@GDPLT
16+
jumpr r31
17+
18+
.section .tdata,"awT",@progbits
19+
.globl tls_var
20+
.type tls_var, @object
21+
tls_var:
22+
.word 0x1234
23+
24+
#--- b.s
25+
.globl other_func
26+
.type other_func, @function
27+
28+
other_func:
29+
## Direct call to __tls_get_addr - this creates another path that may
30+
## try to allocate auxiliary data for the same symbol
31+
call __tls_get_addr
32+
jumpr r31
33+
34+
# RELOC: Section ({{.*}}) .rela.plt {
35+
# RELOC: R_HEX_JMP_SLOT __tls_get_addr 0x0
36+
# RELOC: }

0 commit comments

Comments
 (0)