[PATCH] D43860: [AArch64] DWARF: do not generate AT_location for thread local

Liu, Lei via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 5 18:51:29 PST 2018


The problem is really a limitation of AArch64 ELF ABI.  I don't think
frontend should change its behavior based on such low level target information.

Thanks,
Lei

On 2018年03月06日 02:43, David Blaikie wrote:
> Could the frontend just generate a description of the variable witohut a location instead?
> 
> On Tue, Feb 27, 2018 at 11:14 PM Lei Liu via Phabricator via llvm-commits <llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>> wrote:
> 
>     lliu0 created this revision.
>     Herald added subscribers: llvm-commits, JDevlieghere, kristof.beyls, javed.absar, rengolin.
> 
>     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.
> 
> 
>     Repository:
>       rL LLVM
> 
>     https://reviews.llvm.org/D43860
> 
>     Files:
>       include/llvm/CodeGen/TargetLoweringObjectFile.h
>       lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>       lib/Target/AArch64/AArch64TargetObjectFile.cpp
>       test/DebugInfo/AArch64/tls-at-location.ll
> 
> 
>     Index: test/DebugInfo/AArch64/tls-at-location.ll
>     ===================================================================
>     --- /dev/null
>     +++ test/DebugInfo/AArch64/tls-at-location.ll
>     @@ -0,0 +1,42 @@
>     +; RUN: llc -filetype=obj -o - %s | llvm-dwarfdump -v - | FileCheck %s
>     +;
>     +; CHECK: .debug_info contents:
>     +; CHECK: DW_TAG_variable
>     +; CHECK-NOT: DW_AT_location
>     +
>     +; ModuleID = 'tls-at-location.c'
>     +source_filename = "tls-at-location.c"
>     +target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
>     +target triple = "arm64"
>     +
>     + at var = thread_local global i32 0, align 4, !dbg !0
>     +
>     +; Function Attrs: noinline nounwind optnone
>     +define i32 @foo() #0 !dbg !11 {
>     +entry:
>     +  %0 = load i32, i32* @var, align 4, !dbg !14
>     +  ret i32 %0, !dbg !15
>     +}
>     +
>     +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" }
>     +
>     +!llvm.dbg.cu <http://llvm.dbg.cu> = !{!2}
>     +!llvm.module.flags = !{!7, !8, !9}
>     +!llvm.ident = !{!10}
>     +
>     +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
>     +!1 = distinct !DIGlobalVariable(name: "var", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
>     +!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)
>     +!3 = !DIFile(filename: "tls-at-location.c", directory: "/home/lliu0/llvm/tls-at-location/DebugInfo/AArch64")
>     +!4 = !{}
>     +!5 = !{!0}
>     +!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
>     +!7 = !{i32 2, !"Dwarf Version", i32 4}
>     +!8 = !{i32 2, !"Debug Info Version", i32 3}
>     +!9 = !{i32 1, !"wchar_size", i32 4}
>     +!10 = !{!"clang version 7.0.0 (https://github.com/llvm-mirror/clang.git 43eac1f9d7d2c985831b485d9ccc807416d1cf29) (https://github.com/llvm-mirror/llvm.git d53cdbf4cc5414ea540174a036202c555ce8fc4b)"}
>     +!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)
>     +!12 = !DISubroutineType(types: !13)
>     +!13 = !{!6}
>     +!14 = !DILocation(line: 4, column: 10, scope: !11)
>     +!15 = !DILocation(line: 4, column: 3, scope: !11)
>     Index: lib/Target/AArch64/AArch64TargetObjectFile.cpp
>     ===================================================================
>     --- lib/Target/AArch64/AArch64TargetObjectFile.cpp
>     +++ lib/Target/AArch64/AArch64TargetObjectFile.cpp
>     @@ -22,6 +22,9 @@
>                                                   const TargetMachine &TM) {
>        TargetLoweringObjectFileELF::Initialize(Ctx, TM);
>        InitializeELF(TM.Options.UseInitArray);
>     +  // AARCH64 ELF ABI does not define static relocation type for TLS offset
>     +  // within a module.  Do not generate AT_location for TLS variables.
>     +  SupportDebugThreadLocalLocation = false;
>      }
> 
>      AArch64_MachoTargetObjectFile::AArch64_MachoTargetObjectFile()
>     Index: lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>     ===================================================================
>     --- lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>     +++ lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
>     @@ -186,6 +186,10 @@
>          if (!Global && (!Expr || !Expr->isConstant()))
>            continue;
> 
>     +    if (Global && Global->isThreadLocal() &&
>     +        !Asm->getObjFileLowering().supportDebugThreadLocalLocation())
>     +      continue;
>     +
>          if (!Loc) {
>            addToAccelTable = true;
>            Loc = new (DIEValueAllocator) DIELoc;
>     Index: include/llvm/CodeGen/TargetLoweringObjectFile.h
>     ===================================================================
>     --- include/llvm/CodeGen/TargetLoweringObjectFile.h
>     +++ include/llvm/CodeGen/TargetLoweringObjectFile.h
>     @@ -45,6 +45,7 @@
>      protected:
>        bool SupportIndirectSymViaGOTPCRel = false;
>        bool SupportGOTPCRelWithOffset = true;
>     +  bool SupportDebugThreadLocalLocation = true;
> 
>        /// This section contains the static constructor pointer list.
>        MCSection *StaticCtorSection = nullptr;
>     @@ -171,6 +172,11 @@
>          return SupportGOTPCRelWithOffset;
>        }
> 
>     +  /// \brief Target supports TLS offset relocation in debug section?
>     +  bool supportDebugThreadLocalLocation() const {
>     +    return SupportDebugThreadLocalLocation;
>     +  }
>     +
>        /// \brief Get the target specific PC relative GOT entry relocation
>        virtual const MCExpr *getIndirectSymViaGOTPCRel(const MCSymbol *Sym,
>                                                        const MCValue &MV,
> 
> 
>     _______________________________________________
>     llvm-commits mailing list
>     llvm-commits at lists.llvm.org <mailto:llvm-commits at lists.llvm.org>
>     http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 



More information about the llvm-commits mailing list