<div dir="ltr">Could the frontend just generate a description of the variable witohut a location instead?</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Feb 27, 2018 at 11:14 PM Lei Liu via Phabricator via llvm-commits <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">lliu0 created this revision.<br>
Herald added subscribers: llvm-commits, JDevlieghere, kristof.beyls, javed.absar, rengolin.<br>
<br>
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.<br>
<br>
<br>
Repository:<br>
  rL LLVM<br>
<br>
<a href="https://reviews.llvm.org/D43860" rel="noreferrer" target="_blank">https://reviews.llvm.org/D43860</a><br>
<br>
Files:<br>
  include/llvm/CodeGen/TargetLoweringObjectFile.h<br>
  lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
  lib/Target/AArch64/AArch64TargetObjectFile.cpp<br>
  test/DebugInfo/AArch64/tls-at-location.ll<br>
<br>
<br>
Index: test/DebugInfo/AArch64/tls-at-location.ll<br>
===================================================================<br>
--- /dev/null<br>
+++ test/DebugInfo/AArch64/tls-at-location.ll<br>
@@ -0,0 +1,42 @@<br>
+; RUN: llc -filetype=obj -o - %s | llvm-dwarfdump -v - | FileCheck %s<br>
+;<br>
+; CHECK: .debug_info contents:<br>
+; CHECK: DW_TAG_variable<br>
+; CHECK-NOT: DW_AT_location<br>
+<br>
+; ModuleID = 'tls-at-location.c'<br>
+source_filename = "tls-at-location.c"<br>
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"<br>
+target triple = "arm64"<br>
+<br>
+@var = thread_local global i32 0, align 4, !dbg !0<br>
+<br>
+; Function Attrs: noinline nounwind optnone<br>
+define i32 @foo() #0 !dbg !11 {<br>
+entry:<br>
+  %0 = load i32, i32* @var, align 4, !dbg !14<br>
+  ret i32 %0, !dbg !15<br>
+}<br>
+<br>
+attributes #0 = { noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="generic" "target-features"="+neon" "unsafe-fp-math"="false" "use-soft-float"="false" }<br>
+<br>
+!<a href="http://llvm.dbg.cu" rel="noreferrer" target="_blank">llvm.dbg.cu</a> = !{!2}<br>
+!llvm.module.flags = !{!7, !8, !9}<br>
+!llvm.ident = !{!10}<br>
+<br>
+!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())<br>
+!1 = distinct !DIGlobalVariable(name: "var", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)<br>
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (<a href="https://github.com/llvm-mirror/clang.git" rel="noreferrer" target="_blank">https://github.com/llvm-mirror/clang.git</a> 43eac1f9d7d2c985831b485d9ccc807416d1cf29) (<a href="https://github.com/llvm-mirror/llvm.git" rel="noreferrer" target="_blank">https://github.com/llvm-mirror/llvm.git</a> d53cdbf4cc5414ea540174a036202c555ce8fc4b)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)<br>
+!3 = !DIFile(filename: "tls-at-location.c", directory: "/home/lliu0/llvm/tls-at-location/DebugInfo/AArch64")<br>
+!4 = !{}<br>
+!5 = !{!0}<br>
+!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)<br>
+!7 = !{i32 2, !"Dwarf Version", i32 4}<br>
+!8 = !{i32 2, !"Debug Info Version", i32 3}<br>
+!9 = !{i32 1, !"wchar_size", i32 4}<br>
+!10 = !{!"clang version 7.0.0 (<a href="https://github.com/llvm-mirror/clang.git" rel="noreferrer" target="_blank">https://github.com/llvm-mirror/clang.git</a> 43eac1f9d7d2c985831b485d9ccc807416d1cf29) (<a href="https://github.com/llvm-mirror/llvm.git" rel="noreferrer" target="_blank">https://github.com/llvm-mirror/llvm.git</a> d53cdbf4cc5414ea540174a036202c555ce8fc4b)"}<br>
+!11 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 3, type: !12, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: false, unit: !2, variables: !4)<br>
+!12 = !DISubroutineType(types: !13)<br>
+!13 = !{!6}<br>
+!14 = !DILocation(line: 4, column: 10, scope: !11)<br>
+!15 = !DILocation(line: 4, column: 3, scope: !11)<br>
Index: lib/Target/AArch64/AArch64TargetObjectFile.cpp<br>
===================================================================<br>
--- lib/Target/AArch64/AArch64TargetObjectFile.cpp<br>
+++ lib/Target/AArch64/AArch64TargetObjectFile.cpp<br>
@@ -22,6 +22,9 @@<br>
                                              const TargetMachine &TM) {<br>
   TargetLoweringObjectFileELF::Initialize(Ctx, TM);<br>
   InitializeELF(TM.Options.UseInitArray);<br>
+  // AARCH64 ELF ABI does not define static relocation type for TLS offset<br>
+  // within a module.  Do not generate AT_location for TLS variables.<br>
+  SupportDebugThreadLocalLocation = false;<br>
 }<br>
<br>
 AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()<br>
Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
===================================================================<br>
--- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
+++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp<br>
@@ -186,6 +186,10 @@<br>
     if (!Global && (!Expr || !Expr->isConstant()))<br>
       continue;<br>
<br>
+    if (Global && Global->isThreadLocal() &&<br>
+        !Asm->getObjFileLowering().supportDebugThreadLocalLocation())<br>
+      continue;<br>
+<br>
     if (!Loc) {<br>
       addToAccelTable = true;<br>
       Loc = new (DIEValueAllocator) DIELoc;<br>
Index: include/llvm/CodeGen/TargetLoweringObjectFile.h<br>
===================================================================<br>
--- include/llvm/CodeGen/TargetLoweringObjectFile.h<br>
+++ include/llvm/CodeGen/TargetLoweringObjectFile.h<br>
@@ -45,6 +45,7 @@<br>
 protected:<br>
   bool SupportIndirectSymViaGOTPCRel = false;<br>
   bool SupportGOTPCRelWithOffset = true;<br>
+  bool SupportDebugThreadLocalLocation = true;<br>
<br>
   /// This section contains the static constructor pointer list.<br>
   MCSection *StaticCtorSection = nullptr;<br>
@@ -171,6 +172,11 @@<br>
     return SupportGOTPCRelWithOffset;<br>
   }<br>
<br>
+  /// \brief Target supports TLS offset relocation in debug section?<br>
+  bool supportDebugThreadLocalLocation() const {<br>
+    return SupportDebugThreadLocalLocation;<br>
+  }<br>
+<br>
   /// \brief Get the target specific PC relative GOT entry relocation<br>
   virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,<br>
                                                   const MCValue &MV,<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div>