Skip to content

Commit 7515784

Browse files
committed
Merging r344516:
------------------------------------------------------------------------ r344516 | abeserminji | 2018-10-15 07:39:12 -0700 (Mon, 15 Oct 2018) | 12 lines [mips][micromips] Fix overlaping FDEs error When compiling static executable for micromips, CFI symbols are incorrectly labeled as MICROMIPS, which cause ".eh_frame_hdr refers to overlapping FDEs." error. This patch does not label CFI symbols as MICROMIPS, and FDEs do not overlap anymore. This patch also exposes another bug, which is fixed here: https://reviews.llvm.org/D52985 Differential Revision: https://reviews.llvm.org/D52987 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@347023 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7d87789 commit 7515784

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

lib/Target/Mips/MCTargetDesc/MipsELFStreamer.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "llvm/MC/MCAssembler.h"
1616
#include "llvm/MC/MCCodeEmitter.h"
1717
#include "llvm/MC/MCContext.h"
18+
#include "llvm/MC/MCDwarf.h"
1819
#include "llvm/MC/MCInst.h"
1920
#include "llvm/MC/MCObjectWriter.h"
2021
#include "llvm/MC/MCSymbolELF.h"
@@ -53,6 +54,22 @@ void MipsELFStreamer::EmitInstruction(const MCInst &Inst,
5354
createPendingLabelRelocs();
5455
}
5556

57+
void MipsELFStreamer::EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) {
58+
Frame.Begin = getContext().createTempSymbol();
59+
MCELFStreamer::EmitLabel(Frame.Begin);
60+
}
61+
62+
MCSymbol *MipsELFStreamer::EmitCFILabel() {
63+
MCSymbol *Label = getContext().createTempSymbol("cfi", true);
64+
MCELFStreamer::EmitLabel(Label);
65+
return Label;
66+
}
67+
68+
void MipsELFStreamer::EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) {
69+
Frame.End = getContext().createTempSymbol();
70+
MCELFStreamer::EmitLabel(Frame.End);
71+
}
72+
5673
void MipsELFStreamer::createPendingLabelRelocs() {
5774
MipsTargetELFStreamer *ELFTargetStreamer =
5875
static_cast<MipsTargetELFStreamer *>(getTargetStreamer());

lib/Target/Mips/MCTargetDesc/MipsELFStreamer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class MCAsmBackend;
2626
class MCCodeEmitter;
2727
class MCContext;
2828
class MCSubtargetInfo;
29+
struct MCDwarfFrameInfo;
2930

3031
class MipsELFStreamer : public MCELFStreamer {
3132
SmallVector<std::unique_ptr<MipsOptionRecord>, 8> MipsOptionRecords;
@@ -60,6 +61,12 @@ class MipsELFStreamer : public MCELFStreamer {
6061
void EmitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override;
6162
void EmitIntValue(uint64_t Value, unsigned Size) override;
6263

64+
// Overriding these functions allows us to avoid recording of these labels
65+
// in EmitLabel and later marking them as microMIPS.
66+
void EmitCFIStartProcImpl(MCDwarfFrameInfo &Frame) override;
67+
void EmitCFIEndProcImpl(MCDwarfFrameInfo &Frame) override;
68+
MCSymbol *EmitCFILabel() override;
69+
6370
/// Emits all the option records stored up until the point it's called.
6471
void EmitMipsOptionRecords();
6572

test/DebugInfo/Mips/eh_frame.ll

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
; RUN: llc -mtriple mips-unknown-linux-gnu -mattr=+micromips -O3 -filetype=obj -o - %s | llvm-readelf -r | FileCheck %s
2+
3+
; CHECK: .rel.eh_frame
4+
; CHECK: DW.ref.__gxx_personality_v0
5+
; CHECK-NEXT: .text
6+
; CHECK-NEXT: .gcc_except_table
7+
8+
@_ZTIi = external constant i8*
9+
10+
define dso_local i32 @main() local_unnamed_addr personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
11+
entry:
12+
%exception.i = tail call i8* @__cxa_allocate_exception(i32 4) nounwind
13+
%0 = bitcast i8* %exception.i to i32*
14+
store i32 5, i32* %0, align 16
15+
invoke void @__cxa_throw(i8* %exception.i, i8* bitcast (i8** @_ZTIi to i8*), i8* null) noreturn
16+
to label %.noexc unwind label %return
17+
18+
.noexc:
19+
unreachable
20+
21+
return:
22+
%1 = landingpad { i8*, i32 }
23+
catch i8* null
24+
%2 = extractvalue { i8*, i32 } %1, 0
25+
%3 = tail call i8* @__cxa_begin_catch(i8* %2) nounwind
26+
tail call void @__cxa_end_catch()
27+
ret i32 0
28+
}
29+
30+
declare i32 @__gxx_personality_v0(...)
31+
32+
declare i8* @__cxa_begin_catch(i8*) local_unnamed_addr
33+
34+
declare void @__cxa_end_catch() local_unnamed_addr
35+
36+
declare i8* @__cxa_allocate_exception(i32) local_unnamed_addr
37+
38+
declare void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr

0 commit comments

Comments
 (0)