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

Commit 0046ceb

Browse files
committed
[mips] Handle MipsMCExpr sub-expression for the MEK_DTPREL tag
This is a fix for a regression introduced by the rL348194 commit. In that change new type (MEK_DTPREL) of MipsMCExpr expression was added, but in some places of the code this type of expression considered as unexpected. This change fixes the bug. The MEK_DTPREL type of expression is used for marking TLS DIEExpr only and contains a regular sub-expression. Where we need to handle the expression, we retrieve the sub-expression and handle it in a common way. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@351987 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent c7b61ab commit 0046ceb

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

lib/Target/Mips/MCTargetDesc/MipsMCCodeEmitter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,9 @@ getExprOpValue(const MCExpr *Expr, SmallVectorImpl<MCFixup> &Fixups,
613613
llvm_unreachable("Unhandled fixup kind!");
614614
break;
615615
case MipsMCExpr::MEK_DTPREL:
616-
llvm_unreachable("MEK_DTPREL is used for TLS DIEExpr only");
617-
break;
616+
// MEK_DTPREL is used for marking TLS DIEExpr only
617+
// and contains a regular sub-expression.
618+
return getExprOpValue(MipsExpr->getSubExpr(), Fixups, STI);
618619
case MipsMCExpr::MEK_CALL_HI16:
619620
FixupKind = Mips::fixup_Mips_CALL_HI16;
620621
break;

lib/Target/Mips/MCTargetDesc/MipsMCExpr.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ void MipsMCExpr::printImpl(raw_ostream &OS, const MCAsmInfo *MAI) const {
4343
llvm_unreachable("MEK_None and MEK_Special are invalid");
4444
break;
4545
case MEK_DTPREL:
46-
llvm_unreachable("MEK_DTPREL is used for TLS DIEExpr only");
47-
break;
46+
// MEK_DTPREL is used for marking TLS DIEExpr only
47+
// and contains a regular sub-expression.
48+
getSubExpr()->print(OS, MAI, true);
49+
return;
4850
case MEK_CALL_HI16:
4951
OS << "%call_hi";
5052
break;
@@ -160,7 +162,9 @@ MipsMCExpr::evaluateAsRelocatableImpl(MCValue &Res,
160162
case MEK_Special:
161163
llvm_unreachable("MEK_None and MEK_Special are invalid");
162164
case MEK_DTPREL:
163-
llvm_unreachable("MEK_DTPREL is used for TLS DIEExpr only");
165+
// MEK_DTPREL is used for marking TLS DIEExpr only
166+
// and contains a regular sub-expression.
167+
return getSubExpr()->evaluateAsRelocatable(Res, Layout, Fixup);
164168
case MEK_DTPREL_HI:
165169
case MEK_DTPREL_LO:
166170
case MEK_GOT:
@@ -248,9 +252,6 @@ void MipsMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
248252
case MEK_Special:
249253
llvm_unreachable("MEK_None and MEK_Special are invalid");
250254
break;
251-
case MEK_DTPREL:
252-
llvm_unreachable("MEK_DTPREL is used for TLS DIEExpr only");
253-
break;
254255
case MEK_CALL_HI16:
255256
case MEK_CALL_LO16:
256257
case MEK_GOT:
@@ -273,6 +274,7 @@ void MipsMCExpr::fixELFSymbolsInTLSFixups(MCAssembler &Asm) const {
273274
if (const MipsMCExpr *E = dyn_cast<const MipsMCExpr>(getSubExpr()))
274275
E->fixELFSymbolsInTLSFixups(Asm);
275276
break;
277+
case MEK_DTPREL:
276278
case MEK_DTPREL_HI:
277279
case MEK_DTPREL_LO:
278280
case MEK_TLSLDM:

test/DebugInfo/Mips/dwarfdump-tls.ll

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
; RUN: llc -O0 -march=mips -mcpu=mips32r2 -filetype=obj -o=%t-32.o < %s
1+
; RUN: llc -O0 -march=mips -mcpu=mips32r2 -filetype=obj \
2+
; RUN: -split-dwarf-file=foo.dwo -o=%t-32.o < %s
23
; RUN: llvm-dwarfdump %t-32.o 2>&1 | FileCheck %s
3-
; RUN: llc -O0 -march=mips64 -mcpu=mips64r2 -filetype=obj -o=%t-64.o < %s
4+
; RUN: llc -O0 -march=mips64 -mcpu=mips64r2 -filetype=obj \
5+
; RUN: -split-dwarf-file=foo.dwo -o=%t-64.o < %s
46
; RUN: llvm-dwarfdump %t-64.o 2>&1 | FileCheck %s
57

8+
; RUN: llc -O0 -march=mips -mcpu=mips32r2 -filetype=asm \
9+
; RUN: -split-dwarf-file=foo.dwo < %s | FileCheck -check-prefix=ASM32 %s
10+
; RUN: llc -O0 -march=mips64 -mcpu=mips64r2 -filetype=asm \
11+
; RUN: -split-dwarf-file=foo.dwo < %s | FileCheck -check-prefix=ASM64 %s
12+
613
@x = thread_local global i32 5, align 4, !dbg !0
714

815
; CHECK-NOT: error: failed to compute relocation: R_MIPS_TLS_DTPREL
916

17+
; CHECK: DW_AT_name ("x")
18+
; CHECK-NEXT: DW_AT_type (0x00000025 "int")
19+
; CHECK-NEXT: DW_AT_external (true)
20+
; CHECK-NEXT: DW_AT_decl_file (0x01)
21+
; CHECK-NEXT: DW_AT_decl_line (1)
22+
; CHECK-NEXT: DW_AT_location (DW_OP_GNU_const_index 0x0, DW_OP_GNU_push_tls_address)
23+
24+
; ASM32: .section .debug_addr
25+
; ASM32-NEXT: $addr_table_base0:
26+
; ASM32-NEXT: .4byte x+32768
27+
28+
; ASM64: .section .debug_addr
29+
; ASM64-NEXT: .Laddr_table_base0:
30+
; ASM64-NEXT: .8byte x+32768
31+
1032
!llvm.dbg.cu = !{!2}
1133
!llvm.module.flags = !{!7, !8}
1234

0 commit comments

Comments
 (0)