[lld] r354312 - [mips] Create LA25 thunks for MIPS R6 code
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 19 03:11:13 PST 2019
Author: atanasyan
Date: Tue Feb 19 03:11:12 2019
New Revision: 354312
URL: http://llvm.org/viewvc/llvm-project?rev=354312&view=rev
Log:
[mips] Create LA25 thunks for MIPS R6 code
MIPS R6 code uses the `R_MIPS_PC26_S2` relocation for calls which might
cross boundaries of non-PIC-to-PIC code. We need to create a LA25 thunks
for that case.
Modified:
lld/trunk/ELF/Arch/Mips.cpp
lld/trunk/test/ELF/mips-npic-call-pic.s
Modified: lld/trunk/ELF/Arch/Mips.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/Mips.cpp?rev=354312&r1=354311&r2=354312&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/Mips.cpp (original)
+++ lld/trunk/ELF/Arch/Mips.cpp Tue Feb 19 03:11:12 2019
@@ -347,8 +347,8 @@ bool MIPS<ELFT>::needsThunk(RelExpr Expr
// we cannot make the jump directly and need to create a small stubs
// to save the target function address.
// See page 3-38 ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
- if (Type != R_MIPS_26 && Type != R_MICROMIPS_26_S1 &&
- Type != R_MICROMIPS_PC26_S1)
+ if (Type != R_MIPS_26 && Type != R_MIPS_PC26_S2 &&
+ Type != R_MICROMIPS_26_S1 && Type != R_MICROMIPS_PC26_S1)
return false;
auto *F = dyn_cast_or_null<ELFFileBase<ELFT>>(File);
if (!F)
Modified: lld/trunk/test/ELF/mips-npic-call-pic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-npic-call-pic.s?rev=354312&r1=354311&r2=354312&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-npic-call-pic.s (original)
+++ lld/trunk/test/ELF/mips-npic-call-pic.s Tue Feb 19 03:11:12 2019
@@ -2,16 +2,29 @@
# Check LA25 stubs creation. This stub code is necessary when
# non-PIC code calls PIC function.
-# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mcpu=mips32r2 \
# RUN: %p/Inputs/mips-fpic.s -o %t-fpic.o
-# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mcpu=mips32r2 \
# RUN: %p/Inputs/mips-fnpic.s -o %t-fnpic.o
-# RUN: ld.lld -r %t-fpic.o %t-fnpic.o -o %t-sto-pic.o
-# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \
-# RUN: %p/Inputs/mips-pic.s -o %t-pic.o
-# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-npic.o
-# RUN: ld.lld %t-npic.o %t-pic.o %t-sto-pic.o -o %t.exe
-# RUN: llvm-objdump -d %t.exe | FileCheck %s
+# RUN: ld.lld -r %t-fpic.o %t-fnpic.o -o %t-sto-pic-r2.o
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mcpu=mips32r2 \
+# RUN: %p/Inputs/mips-pic.s -o %t-pic-r2.o
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mcpu=mips32r2 \
+# RUN: %s -o %t-npic-r2.o
+# RUN: ld.lld %t-npic-r2.o %t-pic-r2.o %t-sto-pic-r2.o -o %t-r2.exe
+# RUN: llvm-objdump -d %t-r2.exe | FileCheck --check-prefixes=CHECK,R2 %s
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mcpu=mips32r6 \
+# RUN: %p/Inputs/mips-fpic.s -o %t-fpic.o
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mcpu=mips32r6 \
+# RUN: %p/Inputs/mips-fnpic.s -o %t-fnpic.o
+# RUN: ld.lld -r %t-fpic.o %t-fnpic.o -o %t-sto-pic-r6.o
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mcpu=mips32r6 \
+# RUN: %p/Inputs/mips-pic.s -o %t-pic-r6.o
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -mcpu=mips32r6 \
+# RUN: %s -o %t-npic-r6.o
+# RUN: ld.lld %t-npic-r6.o %t-pic-r6.o %t-sto-pic-r6.o -o %t-r6.exe
+# RUN: llvm-objdump -d %t-r6.exe | FileCheck --check-prefixes=CHECK,R6 %s
# CHECK: Disassembly of section .text:
# CHECK-NEXT: __start:
@@ -29,13 +42,15 @@
# CHECK-NEXT: 2002c: 00 00 00 00 nop
#
# CHECK: __LA25Thunk_foo1a:
-# CHECK-NEXT: 20030: 3c 19 00 02 lui $25, 2
-# CHECK-NEXT: 20034: 08 00 80 14 j 131152 <foo1a>
+# R2: 20030: 3c 19 00 02 lui $25, 2
+# R6: 20030: 3c 19 00 02 aui $25, $zero, 2
+# CHECK: 20034: 08 00 80 14 j 131152 <foo1a>
# CHECK-NEXT: 20038: 27 39 00 50 addiu $25, $25, 80
# CHECK-NEXT: 2003c: 00 00 00 00 nop
# CHECK: __LA25Thunk_foo1b:
-# CHECK-NEXT: 20040: 3c 19 00 02 lui $25, 2
+# R2: 20040: 3c 19 00 02 lui $25, 2
+# R6: 20040: 3c 19 00 02 aui $25, $zero, 2
# CHECK-NEXT: 20044: 08 00 80 15 j 131156 <foo1b>
# CHECK-NEXT: 20048: 27 39 00 54 addiu $25, $25, 84
# CHECK-NEXT: 2004c: 00 00 00 00 nop
@@ -47,7 +62,8 @@
# CHECK-NEXT: 20054: 00 00 00 00 nop
# CHECK: __LA25Thunk_foo2:
-# CHECK-NEXT: 20058: 3c 19 00 02 lui $25, 2
+# R2: 20058: 3c 19 00 02 lui $25, 2
+# R6: 20058: 3c 19 00 02 aui $25, $zero, 2
# CHECK-NEXT: 2005c: 08 00 80 1c j 131184 <foo2>
# CHECK-NEXT: 20060: 27 39 00 70 addiu $25, $25, 112
# CHECK-NEXT: 20064: 00 00 00 00 nop
@@ -56,7 +72,8 @@
# CHECK-NEXT: 20070: 00 00 00 00 nop
# CHECK: __LA25Thunk_fpic:
-# CHECK-NEXT: 20074: 3c 19 00 02 lui $25, 2
+# R2: 20074: 3c 19 00 02 lui $25, 2
+# R6: 20074: 3c 19 00 02 aui $25, $zero, 2
# CHECK-NEXT: 20078: 08 00 80 24 j 131216 <fpic>
# CHECK-NEXT: 2007c: 27 39 00 90 addiu $25, $25, 144
# CHECK-NEXT: 20080: 00 00 00 00 nop
@@ -70,19 +87,24 @@
# Make sure the thunks are created properly no matter how
# objects are laid out.
#
-# RUN: ld.lld %t-pic.o %t-npic.o %t-sto-pic.o -o %t.exe
-# RUN: llvm-objdump -d %t.exe | FileCheck -check-prefix=REVERSE %s
+# RUN: ld.lld %t-pic-r2.o %t-npic-r2.o %t-sto-pic-r2.o -o %t.exe
+# RUN: llvm-objdump -d %t.exe | FileCheck -check-prefixes=REVERSE,REV-R2 %s
+#
+# RUN: ld.lld %t-pic-r6.o %t-npic-r6.o %t-sto-pic-r6.o -o %t.exe
+# RUN: llvm-objdump -d %t.exe | FileCheck -check-prefixes=REVERSE,REV-R6 %s
# REVERSE: Disassembly of section .text:
# REVERSE-NEXT: __LA25Thunk_foo1a:
-# REVERSE-NEXT: 20000: 3c 19 00 02 lui $25, 2
-# REVERSE-NEXT: 20004: 08 00 80 08 j 131104 <foo1a>
+# REV-R2: 20000: 3c 19 00 02 lui $25, 2
+# REV-R6: 20000: 3c 19 00 02 aui $25, $zero, 2
+# REVERSE: 20004: 08 00 80 08 j 131104 <foo1a>
# REVERSE-NEXT: 20008: 27 39 00 20 addiu $25, $25, 32
# REVERSE-NEXT: 2000c: 00 00 00 00 nop
# REVERSE: __LA25Thunk_foo1b:
-# REVERSE-NEXT: 20010: 3c 19 00 02 lui $25, 2
-# REVERSE-NEXT: 20014: 08 00 80 09 j 131108 <foo1b>
+# REV-R2: 20010: 3c 19 00 02 lui $25, 2
+# REV-R6: 20010: 3c 19 00 02 aui $25, $zero, 2
+# REVERSE: 20014: 08 00 80 09 j 131108 <foo1b>
# REVERSE-NEXT: 20018: 27 39 00 24 addiu $25, $25, 36
# REVERSE-NEXT: 2001c: 00 00 00 00 nop
@@ -93,8 +115,9 @@
# REVERSE-NEXT: 20024: 00 00 00 00 nop
# REVERSE: __LA25Thunk_foo2:
-# REVERSE-NEXT: 20028: 3c 19 00 02 lui $25, 2
-# REVERSE-NEXT: 2002c: 08 00 80 10 j 131136 <foo2>
+# REV-R2: 20028: 3c 19 00 02 lui $25, 2
+# REV-R6: 20028: 3c 19 00 02 aui $25, $zero, 2
+# REVERSE: 2002c: 08 00 80 10 j 131136 <foo2>
# REVERSE-NEXT: 20030: 27 39 00 40 addiu $25, $25, 64
# REVERSE-NEXT: 20034: 00 00 00 00 nop
@@ -116,8 +139,9 @@
# REVERSE-NEXT: 2007c: 00 00 00 00 nop
# REVERSE: __LA25Thunk_fpic:
-# REVERSE-NEXT: 20080: 3c 19 00 02 lui $25, 2
-# REVERSE-NEXT: 20084: 08 00 80 24 j 131216 <fpic>
+# REV-R2: 20080: 3c 19 00 02 lui $25, 2
+# REV-R6: 20080: 3c 19 00 02 aui $25, $zero, 2
+# REVERSE: 20084: 08 00 80 24 j 131216 <fpic>
# REVERSE-NEXT: 20088: 27 39 00 90 addiu $25, $25, 144
# REVERSE-NEXT: 2008c: 00 00 00 00 nop
More information about the llvm-commits
mailing list