Skip to content

Commit 4c89277

Browse files
committed
[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
1 parent 235dad3 commit 4c89277

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

llvm/lib/MC/MCExpr.cpp

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

614-
// If symbol is labeled as micromips, we set low-bit to ensure
615-
// correct offset in .gcc_except_table
616-
if (Asm->getBackend().isMicroMips(&SA))
617-
Addend |= 1;
618-
619614
// Clear the symbol expr pointers to indicate we have folded these
620615
// operands.
621616
A = B = nullptr;

llvm/test/CodeGen/Mips/micromips-b-range.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
; CHECK-NEXT: 1e: fb fd 00 00 sw $ra, 0($sp)
1414
; CHECK-NEXT: 22: 41 a1 00 01 lui $1, 1
1515
; CHECK-NEXT: 26: 40 60 00 02 bal 0x2e <foo+0x2e>
16-
; CHECK-NEXT: 2a: 30 21 04 69 addiu $1, $1, 1129
16+
; CHECK-NEXT: 2a: 30 21 04 68 addiu $1, $1, 1128
1717
; CHECK-NEXT: 2e: 00 3f 09 50 addu $1, $ra, $1
1818
; CHECK-NEXT: 32: ff fd 00 00 lw $ra, 0($sp)
1919
; CHECK-NEXT: 36: 00 01 0f 3c jr $1
@@ -27,7 +27,7 @@
2727
; CHECK-NEXT: 56: fb fd 00 00 sw $ra, 0($sp)
2828
; CHECK-NEXT: 5a: 41 a1 00 01 lui $1, 1
2929
; CHECK-NEXT: 5e: 40 60 00 02 bal 0x66 <foo+0x66>
30-
; CHECK-NEXT: 62: 30 21 04 5d addiu $1, $1, 1117
30+
; CHECK-NEXT: 62: 30 21 04 5c addiu $1, $1, 1116
3131
; CHECK-NEXT: 66: 00 3f 09 50 addu $1, $ra, $1
3232
; CHECK-NEXT: 6a: ff fd 00 00 lw $ra, 0($sp)
3333
; CHECK-NEXT: 6e: 00 01 0f 3c jr $1
@@ -39,7 +39,7 @@
3939
; CHECK-NEXT: 86: fb fd 00 00 sw $ra, 0($sp)
4040
; CHECK-NEXT: 8a: 41 a1 00 01 lui $1, 1
4141
; CHECK-NEXT: 8e: 40 60 00 02 bal 0x96 <foo+0x96>
42-
; CHECK-NEXT: 92: 30 21 04 2d addiu $1, $1, 1069
42+
; CHECK-NEXT: 92: 30 21 04 2c addiu $1, $1, 1068
4343
; CHECK-NEXT: 96: 00 3f 09 50 addu $1, $ra, $1
4444
; CHECK-NEXT: 9a: ff fd 00 00 lw $ra, 0($sp)
4545
; CHECK-NEXT: 9e: 00 01 0f 3c jr $1
@@ -51,7 +51,7 @@
5151
; CHECK-NEXT: 10476: fb fd 00 00 sw $ra, 0($sp)
5252
; CHECK-NEXT: 1047a: 41 a1 00 01 lui $1, 1
5353
; CHECK-NEXT: 1047e: 40 60 00 02 bal 0x10486 <foo+0x10486>
54-
; CHECK-NEXT: 10482: 30 21 04 01 addiu $1, $1, 1025
54+
; CHECK-NEXT: 10482: 30 21 04 00 addiu $1, $1, 1024
5555
; CHECK-NEXT: 10486: 00 3f 09 50 addu $1, $ra, $1
5656
; CHECK-NEXT: 1048a: ff fd 00 00 lw $ra, 0($sp)
5757
; CHECK-NEXT: 1048e: 00 01 0f 3c jr $1

llvm/test/CodeGen/Mips/micromips-gcc-except-table.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
; RUN: llc -mtriple=mips-linux-gnu -mcpu=mips32r2 -mattr=+micromips -O3 -filetype=obj < %s | llvm-objdump -s -j .gcc_except_table - | FileCheck %s
22

33
; CHECK: Contents of section .gcc_except_table:
4-
; CHECK-NEXT: 0000 ff9b1501 0c011100 00110e1f 011f1800
4+
; CHECK-NEXT: 0000 ff9b1501 0c001000 00100e1e 011e1800
55
; CHECK-NEXT: 0010 00010000 00000000
66

77
@_ZTIi = external constant ptr

llvm/test/DebugInfo/Mips/eh_frame.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
; CHECK-READELF-PIC-NEXT: R_MIPS_PC32
2727
; CHECK-READELF-NEXT: .gcc_except_table
2828

29-
; EXCEPT-TABLE-STATIC: 0000 ff9b1501 0c011500 00150e23 01231e00 ...........#.#..
29+
; EXCEPT-TABLE-STATIC: 0000 ff9b1501 0c001400 00140e22 01221e00 ..........."."..
3030
; EXCEPT-TABLE-STATIC: 0010 00010000 00000000
31-
; EXCEPT-TABLE-PIC: 0000 ff9b1501 0c012d00 002d133f 013f2a00 ......-..-.?.?*.
31+
; EXCEPT-TABLE-PIC: 0000 ff9b1501 0c002c00 002c123e 013e2a00 ......,..,.>.>*.
3232
; EXCEPT-TABLE-PIC: 0010 00010000 00000000 ........
3333

3434
@_ZTIi = external constant ptr

0 commit comments

Comments
 (0)