Skip to content

Commit 8e422b8

Browse files
author
Lei Liu
committedAug 1, 2018
[AArch64] DWARF: do not generate AT_location for thread local
AArch64 ELF ABI does not define a static relocation type for TLS offset within a module, which makes it impossible for compiler to generate a valid DW_AT_location content for thread local variables. Currently LLVM generates an invalid R_AARCH64_ABS64 relocation at the DW_AT_location field for a TLS variable. That causes trouble for linker because thread local variable does not have an absolute address at link time. AArch64 GCC solves the problem by not generating DW_AT_location for thread local variables. We should do the same in LLVM. Differential Revision: https://reviews.llvm.org/D43860 llvm-svn: 338655
1 parent 9ff1489 commit 8e422b8

File tree

4 files changed

+50
-0
lines changed

4 files changed

+50
-0
lines changed
 

‎llvm/include/llvm/Target/TargetLoweringObjectFile.h

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
4545
protected:
4646
bool SupportIndirectSymViaGOTPCRel = false;
4747
bool SupportGOTPCRelWithOffset = true;
48+
bool SupportDebugThreadLocalLocation = true;
4849

4950
/// This section contains the static constructor pointer list.
5051
MCSection *StaticCtorSection = nullptr;
@@ -170,6 +171,11 @@ class TargetLoweringObjectFile : public MCObjectFileInfo {
170171
return SupportGOTPCRelWithOffset;
171172
}
172173

174+
/// Target supports TLS offset relocation in debug section?
175+
bool supportDebugThreadLocalLocation() const {
176+
return SupportDebugThreadLocalLocation;
177+
}
178+
173179
/// Get the target specific PC relative GOT entry relocation
174180
virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
175181
const MCValue &MV,

‎llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ DIE *DwarfCompileUnit::getOrCreateGlobalVariableDIE(
186186
if (!Global && (!Expr || !Expr->isConstant()))
187187
continue;
188188

189+
if (Global && Global->isThreadLocal() &&
190+
!Asm->getObjFileLowering().supportDebugThreadLocalLocation())
191+
continue;
192+
189193
if (!Loc) {
190194
addToAccelTable = true;
191195
Loc = new (DIEValueAllocator) DIELoc;

‎llvm/lib/Target/AArch64/AArch64TargetObjectFile.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ void AArch64_ELFTargetObjectFile::Initialize(MCContext &Ctx,
2222
const TargetMachine &TM) {
2323
TargetLoweringObjectFileELF::Initialize(Ctx, TM);
2424
InitializeELF(TM.Options.UseInitArray);
25+
// AARCH64 ELF ABI does not define static relocation type for TLS offset
26+
// within a module. Do not generate AT_location for TLS variables.
27+
SupportDebugThreadLocalLocation = false;
2528
}
2629

2730
AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: llc -filetype=obj -mtriple=aarch64--linux-gnu -o - %s | llvm-dwarfdump -v - | FileCheck %s
2+
;
3+
; CHECK: .debug_info contents:
4+
; CHECK: DW_TAG_variable
5+
; CHECK-NOT: DW_AT_location
6+
7+
@var = thread_local global i32 0, align 4, !dbg !0
8+
9+
; Function Attrs: noinline nounwind optnone
10+
define i32 @foo() #0 !dbg !11 {
11+
entry:
12+
%0 = load i32, i32* @var, align 4, !dbg !14
13+
ret i32 %0, !dbg !15
14+
}
15+
16+
attributes #0 = { noinline nounwind optnone }
17+
18+
!llvm.dbg.cu = !{!2}
19+
!llvm.module.flags = !{!7, !8, !9}
20+
!llvm.ident = !{!10}
21+
22+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
23+
!1 = distinct !DIGlobalVariable(name: "var", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
24+
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (https://github.com/llvm-mirror/clang.git 43eac1f9d7d2c985831b485d9ccc807416d1cf29) (https://github.com/llvm-mirror/llvm.git d53cdbf4cc5414ea540174a036202c555ce8fc4b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
25+
!3 = !DIFile(filename: "tls-at-location.c", directory: "/home/lliu0/llvm/tls-at-location/DebugInfo/AArch64")
26+
!4 = !{}
27+
!5 = !{!0}
28+
!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
29+
!7 = !{i32 2, !"Dwarf Version", i32 4}
30+
!8 = !{i32 2, !"Debug Info Version", i32 3}
31+
!9 = !{i32 1, !"wchar_size", i32 4}
32+
!10 = !{!"clang version 7.0.0 (https://github.com/llvm-mirror/clang.git 43eac1f9d7d2c985831b485d9ccc807416d1cf29) (https://github.com/llvm-mirror/llvm.git d53cdbf4cc5414ea540174a036202c555ce8fc4b)"}
33+
!11 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 3, type: !12, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: false, unit: !2)
34+
!12 = !DISubroutineType(types: !13)
35+
!13 = !{!6}
36+
!14 = !DILocation(line: 4, column: 10, scope: !11)
37+
!15 = !DILocation(line: 4, column: 3, scope: !11)

0 commit comments

Comments
 (0)
Please sign in to comment.