Skip to content

Commit 0599806

Browse files
committed
Merging r344591:
------------------------------------------------------------------------ r344591 | abeserminji | 2018-10-16 01:27:28 -0700 (Tue, 16 Oct 2018) | 11 lines [mips][micromips] Fix how values in .gcc_except_table are calculated When a landing pad is calculated in a program that is compiled for micromips, it will point to an even address. Such an error will cause a segmentation fault, as the instructions in micromips are aligned on odd addresses. This patch sets the last bit of the offset where a landing pad is, to 1, which will effectively be an odd address and point to the instruction exactly. Differential Revision: https://reviews.llvm.org/D52985 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_70@347028 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 7515784 commit 0599806

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

include/llvm/MC/MCAsmBackend.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,11 @@ class MCAsmBackend {
165165
return 0;
166166
}
167167

168+
/// Check whether a given symbol has been flagged with MICROMIPS flag.
169+
virtual bool isMicroMips(const MCSymbol *Sym) const {
170+
return false;
171+
}
172+
168173
/// Handles all target related code padding when starting to write a new
169174
/// basic block to an object file.
170175
///

lib/MC/MCExpr.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,11 @@ static void AttemptToFoldSymbolOffsetDifference(
524524
if (Asm->isThumbFunc(&SA))
525525
Addend |= 1;
526526

527+
// If symbol is labeled as micromips, we set low-bit to ensure
528+
// correct offset in .gcc_except_table
529+
if (Asm->getBackend().isMicroMips(&SA))
530+
Addend |= 1;
531+
527532
// Clear the symbol expr pointers to indicate we have folded these
528533
// operands.
529534
A = B = nullptr;

lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "llvm/MC/MCFixupKindInfo.h"
2626
#include "llvm/MC/MCObjectWriter.h"
2727
#include "llvm/MC/MCSubtargetInfo.h"
28+
#include "llvm/MC/MCSymbolELF.h"
2829
#include "llvm/MC/MCTargetOptions.h"
2930
#include "llvm/MC/MCValue.h"
3031
#include "llvm/Support/ErrorHandling.h"
@@ -568,6 +569,14 @@ bool MipsAsmBackend::shouldForceRelocation(const MCAssembler &Asm,
568569
}
569570
}
570571

572+
bool MipsAsmBackend::isMicroMips(const MCSymbol *Sym) const {
573+
if (const auto *ElfSym = dyn_cast<const MCSymbolELF>(Sym)) {
574+
if (ElfSym->getOther() & ELF::STO_MIPS_MICROMIPS)
575+
return true;
576+
}
577+
return false;
578+
}
579+
571580
MCAsmBackend *llvm::createMipsAsmBackend(const Target &T,
572581
const MCSubtargetInfo &STI,
573582
const MCRegisterInfo &MRI,

lib/Target/Mips/MCTargetDesc/MipsAsmBackend.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class MCAssembler;
2525
struct MCFixupKindInfo;
2626
class MCObjectWriter;
2727
class MCRegisterInfo;
28+
class MCSymbolELF;
2829
class Target;
2930

3031
class MipsAsmBackend : public MCAsmBackend {
@@ -90,6 +91,7 @@ class MipsAsmBackend : public MCAsmBackend {
9091
bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup,
9192
const MCValue &Target) override;
9293

94+
bool isMicroMips(const MCSymbol *Sym) const override;
9395
}; // class MipsAsmBackend
9496

9597
} // namespace
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: llc -mtriple=mips-linux-gnu -mcpu=mips32r2 -mattr=+micromips -O3 -filetype=obj < %s | llvm-objdump -s -j .gcc_except_table - | FileCheck %s
2+
3+
; CHECK: Contents of section .gcc_except_table:
4+
; CHECK-NEXT: 0000 ff9b1501 0c011100 00110e1f 011f1800
5+
; CHECK-NEXT: 0010 00010000 00000000
6+
7+
@_ZTIi = external constant i8*
8+
9+
define dso_local i32 @main() local_unnamed_addr norecurse personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
10+
entry:
11+
%exception.i = tail call i8* @__cxa_allocate_exception(i32 4) nounwind
12+
%0 = bitcast i8* %exception.i to i32*
13+
store i32 5, i32* %0, align 16
14+
invoke void @__cxa_throw(i8* %exception.i, i8* bitcast (i8** @_ZTIi to i8*), i8* null) noreturn
15+
to label %.noexc unwind label %return
16+
17+
.noexc:
18+
unreachable
19+
20+
return:
21+
%1 = landingpad { i8*, i32 }
22+
catch i8* null
23+
%2 = extractvalue { i8*, i32 } %1, 0
24+
%3 = tail call i8* @__cxa_begin_catch(i8* %2) nounwind
25+
tail call void @__cxa_end_catch()
26+
ret i32 0
27+
}
28+
29+
declare i32 @__gxx_personality_v0(...)
30+
31+
declare i8* @__cxa_begin_catch(i8*) local_unnamed_addr
32+
33+
declare void @__cxa_end_catch() local_unnamed_addr
34+
35+
declare i8* @__cxa_allocate_exception(i32) local_unnamed_addr
36+
37+
declare void @__cxa_throw(i8*, i8*, i8*) local_unnamed_addr

0 commit comments

Comments
 (0)