llvm-project/llvm/test/CodeGen/Mips/micromips-gcc-except-table.ll
Fangrui Song 4c89277095 [Mips][MC] AttemptToFoldSymbolOffsetDifference: revert isMicroMips special case
D52985/D57677 added a .gcc_except_table workaround, but the new behavior
doesn't match GNU assembler.
```
void foo();
int bar() {
  foo();
  try { throw 1; }
  catch (int) { return 1; }
  return 0;
}

clang --target=mipsel-linux-gnu -mmicromips -S a.cc
mipsel-linux-gnu-gcc -mmicromips -c a.s -o gnu.o

.uleb128 ($cst_end0)-($cst_begin0)     // bit 0 is not forced to 1
.uleb128 ($func_begin0)-($func_begin0) // bit 0 is not forced to 1
```

I have inspected `.gcc_except_table` output by `mipsel-linux-gnu-gcc -mmicromips -c a.cc`.
The `.uleb128` values are not forced to set the least significant bit.

In addition, D57677's adjustment (even->odd) to CodeGen/Mips/micromips-b-range.ll is wrong.
PC-relative `.long func - .` values will differ from GNU assembler as well.

The original intention of D52985 seems unclear to me. I think whatever
goal it wants to achieve should be moved to an upper layer.

This isMicroMips special case has caused problems to fix MCAssembler::relaxLEB to use evaluateAsAbsolute instead of evaluateKnownAbsolute,
which is needed to proper support R_RISCV_SET_ULEB128/R_RISCV_SUB_ULEB128.

Differential Revision: https://reviews.llvm.org/D157655
2023-08-16 23:11:59 -07:00

37 lines
1.1 KiB
LLVM

; RUN: llc -mtriple=mips-linux-gnu -mcpu=mips32r2 -mattr=+micromips -O3 -filetype=obj < %s | llvm-objdump -s -j .gcc_except_table - | FileCheck %s
; CHECK: Contents of section .gcc_except_table:
; CHECK-NEXT: 0000 ff9b1501 0c001000 00100e1e 011e1800
; CHECK-NEXT: 0010 00010000 00000000
@_ZTIi = external constant ptr
define dso_local i32 @main() local_unnamed_addr norecurse personality ptr @__gxx_personality_v0 {
entry:
%exception.i = tail call ptr @__cxa_allocate_exception(i32 4) nounwind
store i32 5, ptr %exception.i, align 16
invoke void @__cxa_throw(ptr %exception.i, ptr @_ZTIi, ptr null) noreturn
to label %.noexc unwind label %return
.noexc:
unreachable
return:
%0 = landingpad { ptr, i32 }
catch ptr null
%1 = extractvalue { ptr, i32 } %0, 0
%2 = tail call ptr @__cxa_begin_catch(ptr %1) nounwind
tail call void @__cxa_end_catch()
ret i32 0
}
declare i32 @__gxx_personality_v0(...)
declare ptr @__cxa_begin_catch(ptr) local_unnamed_addr
declare void @__cxa_end_catch() local_unnamed_addr
declare ptr @__cxa_allocate_exception(i32) local_unnamed_addr
declare void @__cxa_throw(ptr, ptr, ptr) local_unnamed_addr