Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit eb2c5a9

Browse files
[mips] Fix debug information for __thread variable
This patch fixes debug information for __thread variable on Mips using .dtprelword and .dtpreldword directives. Patch by Aleksandar Beserminji. Differential Revision: http://reviews.llvm.org/D28770 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@292624 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 68c521d commit eb2c5a9

File tree

8 files changed

+65
-1
lines changed

8 files changed

+65
-1
lines changed

include/llvm/CodeGen/AsmPrinter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,12 @@ class AsmPrinter : public MachineFunctionPass {
480480
/// Get the value for DW_AT_APPLE_isa. Zero if no isa encoding specified.
481481
virtual unsigned getISAEncoding() { return 0; }
482482

483+
/// Emit the directive and value for debug thread local expression
484+
///
485+
/// \p Value - The value to emit.
486+
/// \p Size - The size of the integer (in bytes) to emit.
487+
virtual void EmitDebugValue(const MCExpr *Value, unsigned Size) const;
488+
483489
//===------------------------------------------------------------------===//
484490
// Dwarf Lowering Routines
485491
//===------------------------------------------------------------------===//

lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,15 @@ void AsmPrinter::EmitGlobalVariable(const GlobalVariable *GV) {
567567
OutStreamer->AddBlankLine();
568568
}
569569

570+
/// Emit the directive and value for debug thread local expression
571+
///
572+
/// \p Value - The value to emit.
573+
/// \p Size - The size of the integer (in bytes) to emit.
574+
void AsmPrinter::EmitDebugValue(const MCExpr *Value,
575+
unsigned Size) const {
576+
OutStreamer->EmitValue(Value, Size);
577+
}
578+
570579
/// EmitFunctionHeader - This method emits the header for the current
571580
/// function.
572581
void AsmPrinter::EmitFunctionHeader() {

lib/CodeGen/AsmPrinter/DIE.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ void DIEInteger::print(raw_ostream &O) const {
484484
/// EmitValue - Emit expression value.
485485
///
486486
void DIEExpr::EmitValue(const AsmPrinter *AP, dwarf::Form Form) const {
487-
AP->OutStreamer->EmitValue(Expr, SizeOf(AP, Form));
487+
AP->EmitDebugValue(Expr, SizeOf(AP, Form));
488488
}
489489

490490
/// SizeOf - Determine size of expression value in bytes.

lib/Target/Mips/MipsAsmPrinter.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,22 @@ void MipsAsmPrinter::PrintDebugValueComment(const MachineInstr *MI,
10371037
// TODO: implement
10381038
}
10391039

1040+
// Emit .dtprelword or .dtpreldword directive
1041+
// and value for debug thread local expression.
1042+
void MipsAsmPrinter::EmitDebugValue(const MCExpr *Value,
1043+
unsigned Size) const {
1044+
switch (Size) {
1045+
case 4:
1046+
OutStreamer->EmitDTPRel32Value(Value);
1047+
break;
1048+
case 8:
1049+
OutStreamer->EmitDTPRel64Value(Value);
1050+
break;
1051+
default:
1052+
llvm_unreachable("Unexpected size of expression value.");
1053+
}
1054+
}
1055+
10401056
// Align all targets of indirect branches on bundle size. Used only if target
10411057
// is NaCl.
10421058
void MipsAsmPrinter::NaClAlignIndirectJumpTargets(MachineFunction &MF) {

lib/Target/Mips/MipsAsmPrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class LLVM_LIBRARY_VISIBILITY MipsAsmPrinter : public AsmPrinter {
140140
void EmitStartOfAsmFile(Module &M) override;
141141
void EmitEndOfAsmFile(Module &M) override;
142142
void PrintDebugValueComment(const MachineInstr *MI, raw_ostream &OS);
143+
void EmitDebugValue(const MCExpr *Value, unsigned Size) const override;
143144
};
144145
}
145146

lib/Target/Mips/MipsTargetObjectFile.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,11 @@ MCSection *MipsTargetObjectFile::getSectionForConstant(const DataLayout &DL,
148148
// Otherwise, we work the same as ELF.
149149
return TargetLoweringObjectFileELF::getSectionForConstant(DL, Kind, C, Align);
150150
}
151+
152+
const MCExpr *
153+
MipsTargetObjectFile::getDebugThreadLocalSymbol(const MCSymbol *Sym) const {
154+
const MCExpr *Expr =
155+
MCSymbolRefExpr::create(Sym, MCSymbolRefExpr::VK_None, getContext());
156+
return MCBinaryExpr::createAdd(
157+
Expr, MCConstantExpr::create(0x8000, getContext()), getContext());
158+
}

lib/Target/Mips/MipsTargetObjectFile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ class MipsTargetMachine;
4242
MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
4343
const Constant *C,
4444
unsigned &Align) const override;
45+
/// Describe a TLS variable address within debug info.
46+
const MCExpr *getDebugThreadLocalSymbol(const MCSymbol *Sym) const override;
4547
};
4648
} // end namespace llvm
4749

test/DebugInfo/Mips/tls.ll

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc -O0 -march=mips -mcpu=mips32r2 -filetype=asm < %s | FileCheck %s -check-prefix=CHECK-WORD
2+
; RUN: llc -O0 -march=mips64 -mcpu=mips64r2 -filetype=asm < %s | FileCheck %s -check-prefix=CHECK-DWORD
3+
4+
@x = thread_local global i32 5, align 4, !dbg !0
5+
6+
; CHECK-WORD: .dtprelword x+32768
7+
; CHECK-DWORD: .dtpreldword x+32768
8+
9+
!llvm.dbg.cu = !{!2}
10+
!llvm.module.flags = !{!7, !8}
11+
!llvm.ident = !{!9}
12+
13+
!0 = !DIGlobalVariableExpression(var: !1)
14+
!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
15+
!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 4.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
16+
!3 = !DIFile(filename: "tls.c", directory: "/tmp")
17+
!4 = !{}
18+
!5 = !{!0}
19+
!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
20+
!7 = !{i32 2, !"Dwarf Version", i32 4}
21+
!8 = !{i32 2, !"Debug Info Version", i32 3}
22+
!9 = !{!"clang version 4.0.0"}

0 commit comments

Comments
 (0)