Index: lib/CodeGen/TargetLoweringObjectFileImpl.cpp =================================================================== --- lib/CodeGen/TargetLoweringObjectFileImpl.cpp +++ lib/CodeGen/TargetLoweringObjectFileImpl.cpp @@ -205,6 +205,27 @@ TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_udata8; break; + case Triple::riscv32: + case Triple::riscv64: + assert((CM == CodeModel::Small || CM == CodeModel::Medium) + && "unhandled code model"); + if (isPositionIndependent()) { + PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | + dwarf::DW_EH_PE_sdata4; + LSDAEncoding = dwarf::DW_EH_PE_pcrel | dwarf::DW_EH_PE_sdata4; + TTypeEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_pcrel | + dwarf::DW_EH_PE_sdata4; + } else if (CM == CodeModel::Small) { + PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_udata4; + LSDAEncoding = dwarf::DW_EH_PE_udata4; + TTypeEncoding = dwarf::DW_EH_PE_udata4; + } else { + assert(CM == CodeModel::Medium); + PersonalityEncoding = dwarf::DW_EH_PE_indirect | dwarf::DW_EH_PE_absptr; + LSDAEncoding = dwarf::DW_EH_PE_absptr; + TTypeEncoding = dwarf::DW_EH_PE_absptr; + } + break; case Triple::sparcel: case Triple::sparc: if (isPositionIndependent()) { Index: test/CodeGen/RISCV/exception.ll =================================================================== --- /dev/null +++ test/CodeGen/RISCV/exception.ll @@ -0,0 +1,90 @@ +; RUN: llc -march=riscv32 --code-model=small < %s | FileCheck --check-prefixes=CHECK,SMALL %s +; RUN: llc -march=riscv32 --code-model=medium < %s | FileCheck --check-prefixes=CHECK,MED %s +; RUN: llc -march=riscv32 --code-model=small -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s +; RUN: llc -march=riscv32 --code-model=medium -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s + +; RUN: llc -march=riscv64 --code-model=small < %s | FileCheck --check-prefixes=CHECK,SMALL %s +; RUN: llc -march=riscv64 --code-model=medium < %s | FileCheck --check-prefixes=CHECK,MED %s +; RUN: llc -march=riscv64 --code-model=small -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s +; RUN: llc -march=riscv64 --code-model=medium -relocation-model=pic < %s | FileCheck --check-prefixes=CHECK,PIC %s + +declare i8* @__cxa_allocate_exception(i64) +declare void @__cxa_throw(i8*, i8*, i8*) +declare i32 @__gxx_personality_v0(...) +declare i32 @llvm.eh.typeid.for(i8*) nounwind readnone +declare i8* @__cxa_begin_catch(i8*) +declare void @__cxa_end_catch() + +@_ZTIi = external constant i8* + +; CHECK-LABEL: foo: +; CHECK: .cfi_startproc +; +; # Personality encoding # +; SMALL-NEXT: .cfi_personality 131, DW.ref.__gxx_personality_v0 +; ^-- Personality encoding: DW_EH_PE_indirect | +; DW_EH_PE_udata4 +; MED-NEXT: .cfi_personality 128, DW.ref.__gxx_personality_v0 +; ^-- Personality encoding: DW_EH_PE_indirect | +; DW_EH_PE_absptr +; PIC-NEXT: .cfi_personality 155, DW.ref.__gxx_personality_v0 +; ^-- Personality encoding: DW_EH_PE_indirect | +; DW_EH_PE_pcrel | +; DW_EH_PE_sdata4 +; # LSDA encoding # +; SMALL-NEXT: .cfi_lsda 3, .Lexception0 +; ^-- LSDA encoding: DW_EH_PE_udata4 +; MED-NEXT: .cfi_lsda 0, .Lexception0 +; ^-- LSDA encoding: DW_EH_PE_absptr +; PIC-NEXT: .cfi_lsda 27, .Lexception0 +; ^-- LSDA encoding: DW_EH_PE_pcrel | DW_EH_PE_sdata4 +define signext i32 @foo() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + %exception = tail call i8* @__cxa_allocate_exception(i64 4) + %0 = bitcast i8* %exception to i32* + store i32 5, i32* %0, align 16 + invoke void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) + to label %unreachable unwind label %lpad + +lpad: + %1 = landingpad { i8*, i32 } + catch i8* bitcast (i8** @_ZTIi to i8*) + %2 = extractvalue { i8*, i32 } %1, 1 + %3 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) + %matches = icmp eq i32 %2, %3 + br i1 %matches, label %catch, label %eh.resume + +catch: + %4 = extractvalue { i8*, i32 } %1, 0 + %5 = tail call i8* @__cxa_begin_catch(i8* %4) + %6 = bitcast i8* %5 to i32* + %7 = load i32, i32* %6, align 4 + tail call void @__cxa_end_catch() + ret i32 %7 + +eh.resume: + resume { i8*, i32 } %1 + +unreachable: + unreachable +} + +; CHECK: .section .gcc_except_table,"a",@progbits +; CHECK: GCC_except_table0: +; CHECK-NEXT: .Lexception0: +; CHECK-NEXT: .byte 255 +; ^-- Landing pad base encoding: DW_EH_PE_omit +; +; # Type table encoding # +; SMALL-NEXT: .byte 3 +; ^-- Type table encoding: DW_EH_PE_udata4 +; MED-NEXT: .byte 0 +; ^-- Type table encoding: DW_EH_PE_absptr +; PIC-NEXT: .byte 155 +; ^-- Type table encoding: DW_EH_PE_indirect | +; DW_EH_PE_pcrel | +; DW_EH_PE_sdata4 +; # Call site encoding # +; CHECK: .Lttbaseref0: +; CHECK-NEXT: .byte 1 +; ^-- Call site encoding: DW_EH_PE_uleb128 Index: test/MC/RISCV/eh-frame.s =================================================================== --- /dev/null +++ test/MC/RISCV/eh-frame.s @@ -0,0 +1,32 @@ +# Test the bits of .eh_frame on riscv that are already implemented correctly. + +# RUN: llvm-mc -filetype=obj %s -o %t.o -triple riscv32 +# RUN: llvm-dwarfdump -eh-frame %t.o | FileCheck --check-prefixes=CHECK,RV32 %s + +# RUN: llvm-mc -filetype=obj %s -o %t.o -triple riscv64 +# RUN: llvm-dwarfdump -eh-frame %t.o | FileCheck --check-prefixes=CHECK,RV64 %s + +func: + .cfi_startproc + .cfi_endproc + +# CHECK: 00000000 00000010 ffffffff CIE +# CHECK: Version: 1 +# CHECK: Augmentation: "zR" +# CHECK: Code alignment factor: 1 + +# RV32: Data alignment factor: -4 +# RV64: Data alignment factor: -8 +# ^-- GAS uses -4. Should be okay provided all +# offsets are multiples of 8 + +# CHECK: Return address column: 1 +# CHECK: Augmentation data: 1B +# ^-- FDE encoding: DW_EH_PE_pcrel | +# DW_EH_PE_sdata4 +# CHECK: DW_CFA_def_cfa: reg2 +0 +# +# CHECK: 00000014 00000010 00000018 FDE cie=00000018 pc=00000000...00000000 +# CHECK: DW_CFA_nop: +# CHECK: DW_CFA_nop: +# CHECK: DW_CFA_nop: