diff options
author | Simon Atanasyan <simon@atanasyan.com> | 2018-05-08 15:34:06 +0000 |
---|---|---|
committer | Simon Atanasyan <simon@atanasyan.com> | 2018-05-08 15:34:06 +0000 |
commit | 05600506688bb40b08e3042f98da4d7a96fbd836 (patch) | |
tree | da0932d5adeccb38d44b6dfe495e0552cad489f6 /lld/test | |
parent | c7113cc9e4f13b28f9c943b0e2a62239e0f23106 (diff) | |
download | bcm5719-llvm-05600506688bb40b08e3042f98da4d7a96fbd836.tar.gz bcm5719-llvm-05600506688bb40b08e3042f98da4d7a96fbd836.zip |
[ELF][MIPS] Fix calculation of GP relative relocations in case of relocatable output
Some MIPS relocations depend on "gp" value. By default, this value has
0x7ff0 offset from a .got section. But relocatable files produced by a
compiler or a linker might redefine this default value and we have to
use it for a calculation of the relocation result. When we generate EXE
or DSO it's trivial. Generating a relocatable output is more difficult
case because the linker does calculate relocations in this case and
cannot store individual "gp" values used by each input object file.
As a workaround we add the "gp" value to the relocation addend.
This fixes https://llvm.org/pr31149
Differential revision: https://reviews.llvm.org/D45972
llvm-svn: 331772
Diffstat (limited to 'lld/test')
-rw-r--r-- | lld/test/ELF/Inputs/mips-micro-gp0-non-zero.o | bin | 0 -> 1344 bytes | |||
-rw-r--r-- | lld/test/ELF/Inputs/mips-n64-gp0-non-zero.o | bin | 0 -> 1128 bytes | |||
-rw-r--r-- | lld/test/ELF/mips-gprel32-relocs-gp0.s | 9 | ||||
-rw-r--r-- | lld/test/ELF/mips-non-zero-gp0.s | 66 |
4 files changed, 66 insertions, 9 deletions
diff --git a/lld/test/ELF/Inputs/mips-micro-gp0-non-zero.o b/lld/test/ELF/Inputs/mips-micro-gp0-non-zero.o Binary files differnew file mode 100644 index 00000000000..abd67bcd262 --- /dev/null +++ b/lld/test/ELF/Inputs/mips-micro-gp0-non-zero.o diff --git a/lld/test/ELF/Inputs/mips-n64-gp0-non-zero.o b/lld/test/ELF/Inputs/mips-n64-gp0-non-zero.o Binary files differnew file mode 100644 index 00000000000..43b930b9d9f --- /dev/null +++ b/lld/test/ELF/Inputs/mips-n64-gp0-non-zero.o diff --git a/lld/test/ELF/mips-gprel32-relocs-gp0.s b/lld/test/ELF/mips-gprel32-relocs-gp0.s index 507224e05d1..f27caa33010 100644 --- a/lld/test/ELF/mips-gprel32-relocs-gp0.s +++ b/lld/test/ELF/mips-gprel32-relocs-gp0.s @@ -1,8 +1,4 @@ # Check that relocatable object produced by LLD has zero gp0 value. -# Also check an error message if input object file has non-zero gp0 value -# and the linker generates a relocatable object. -# mips-gp0-non-zero.o is a relocatable object produced from the asm code -# below and linked by GNU bfd linker. # RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o # RUN: ld.lld -r -o %t-rel.o %t.o @@ -12,9 +8,6 @@ # RUN: llvm-readobj -mips-reginfo %t.so | FileCheck --check-prefix=DSO %s # RUN: llvm-objdump -s -t %t.so | FileCheck --check-prefix=DUMP %s -# RUN: not ld.lld -r -o %t-rel.o %S/Inputs/mips-gp0-non-zero.o 2>&1 \ -# RUN: | FileCheck --check-prefix=ERR %s - # REQUIRES: mips # REL: GP: 0x0 @@ -31,8 +24,6 @@ # DUMP: 00010004 .text 00000000 foo # DUMP: 00027ff0 .got 00000000 .hidden _gp -# ERR: error: {{.*}}mips-gp0-non-zero.o: unsupported non-zero ri_gp_value - .text .global __start __start: diff --git a/lld/test/ELF/mips-non-zero-gp0.s b/lld/test/ELF/mips-non-zero-gp0.s new file mode 100644 index 00000000000..3582e3ce676 --- /dev/null +++ b/lld/test/ELF/mips-non-zero-gp0.s @@ -0,0 +1,66 @@ +# REQUIRES: mips + +# Check addend adjustment in case of generating a relocatable object +# if some input files have non-zero GP0 value. + +# We have to use GNU as and ld.bfd 2.28 to generate relocatable object +# files with non-zero GP0 value using the following command lines: +# +# as -mips32 -o test.o \ +# && ld.bfd -m elf32btsmip -r test.o -o mips-gp0-non-zero.o +# as -mips64 -mmicromips -o test.o \ +# && ld.bfd -m elf64btsmip -r test.o -o mips-micro-gp0-non-zero.o +# as -mips64 -o test.o \ +# && ld.bfd -m elf64btsmip -r test.o -o mips-n64-gp0-non-zero.o + +# Source code for mips-gp0-non-zero.o: +# .text +# .global __start +# __start: +# lw $t0,%call16(__start)($gp) +# foo: +# nop +# bar: +# nop +# +# .section .rodata, "a" +# v: +# .gpword foo +# .gpword bar + +# Source code for mips-n64-gp0-non-zero.o and mips-micro-gp0-non-zero.o: +# .text +# .global __start +# __start: +# foo: +# lui $gp,%hi(%neg(%gp_rel(foo))) + +# RUN: ld.lld -r -o %t-32.r %S/Inputs/mips-gp0-non-zero.o +# RUN: llvm-readobj -mips-reginfo %t-32.r | FileCheck --check-prefix=GPVAL %s +# RUN: llvm-objdump -s %t-32.r | FileCheck --check-prefix=ADDEND32 %s + +# RUN: ld.lld -r -o %t-64.r %S/Inputs/mips-n64-gp0-non-zero.o +# RUN: llvm-readobj -mips-options %t-64.r | FileCheck --check-prefix=GPVAL %s +# RUN: llvm-readobj -r %S/Inputs/mips-n64-gp0-non-zero.o %t-64.r \ +# RUN: | FileCheck --check-prefix=ADDEND64 %s + +# RUN: ld.lld -r -o %t-micro.r %S/Inputs/mips-micro-gp0-non-zero.o +# RUN: llvm-readobj -mips-options %t-micro.r | FileCheck --check-prefix=GPVAL %s +# RUN: llvm-readobj -r %S/Inputs/mips-micro-gp0-non-zero.o %t-micro.r \ +# RUN: | FileCheck --check-prefix=ADDENDMM %s + +# GPVAL: GP: 0x0 + +# ADDEND32: Contents of section .rodata: +# ADDEND32-NEXT: 0000 00007ff4 00007ff8 +# ^ 4+GP0 ^ 8+GP0 + +# ADDEND64: File: {{.*}}/Inputs/mips-n64-gp0-non-zero.o +# ADDEND64: .text 0xFFFFFFFFFFFF8011 +# ADDEND64: File: {{.*}}/mips-non-zero-gp0.s.tmp-64.r +# ADDEND64: .text 0x0 + +# ADDENDMM: File: {{.*}}/Inputs/mips-micro-gp0-non-zero.o +# ADDENDMM: .text 0xFFFFFFFFFFFF8012 +# ADDENDMM: File: {{.*}}/mips-non-zero-gp0.s.tmp-micro.r +# ADDENDMM: .text 0x1 |