diff options
| author | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2020-01-12 10:55:15 +0000 |
|---|---|---|
| committer | Alex Richardson <Alexander.Richardson@cl.cam.ac.uk> | 2020-01-13 14:14:03 +0000 |
| commit | 894f742acb977a09285dcab024e50c2cf6bce578 (patch) | |
| tree | 3fb6f7d27dc63c9359554831b1516a277db3ad04 /lld/test | |
| parent | 26d2ace9e2305266be888e15392be29e3145163d (diff) | |
| download | bcm5719-llvm-894f742acb977a09285dcab024e50c2cf6bce578.tar.gz bcm5719-llvm-894f742acb977a09285dcab024e50c2cf6bce578.zip | |
[MIPS][ELF] Use PC-relative relocations in .eh_frame when possible
When compiling position-independent executables, we now use
DW_EH_PE_pcrel | DW_EH_PE_sdata4. However, the MIPS ABI does not define a
64-bit PC-relative ELF relocation so we cannot use sdata8 for the large
code model case. When using the large code model, we fall back to the
previous behaviour of generating absolute relocations.
With this change clang-generated .o files can be linked by LLD without
having to pass -Wl,-z,notext (which creates text relocations).
This is simpler than the approach used by ld.bfd, which rewrites the
.eh_frame section to convert absolute relocations into relative references.
I saw in D13104 that apparently ld.bfd did not accept pc-relative relocations
for MIPS ouput at some point. However, I also checked that recent ld.bfd
can process the clang-generated .o files so this no longer seems true.
Reviewed By: atanasyan
Differential Revision: https://reviews.llvm.org/D72228
Diffstat (limited to 'lld/test')
| -rw-r--r-- | lld/test/ELF/mips-eh_frame-pic.s | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/lld/test/ELF/mips-eh_frame-pic.s b/lld/test/ELF/mips-eh_frame-pic.s new file mode 100644 index 00000000000..f5acf165e9a --- /dev/null +++ b/lld/test/ELF/mips-eh_frame-pic.s @@ -0,0 +1,58 @@ +# REQUIRES: mips +## Check that we can link a shared library containing an eh_frame section without +## -z notext. This was not possible LLVM started emitting values using the +## DW_EH_PE_pcrel | DW_EH_PE_sdata4 encoding. + +## It should not be possible to link code compiled without -fPIC: +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t-nopic.o +# RUN: llvm-dwarfdump --eh-frame %t-nopic.o | FileCheck %s --check-prefix=ABS64-EH-FRAME +# RUN: llvm-readobj -r %t-nopic.o | FileCheck %s --check-prefixes=RELOCS,ABS64-RELOCS +# RUN: not ld.lld -shared %t-nopic.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOPIC-ERR +## Note: ld.bfd can link this file because it rewrites the .eh_frame section to use +## relative addressing. +# NOPIC-ERR: ld.lld: error: can't create dynamic relocation R_MIPS_64 against local symbol in readonly segment + +## For -fPIC, .eh_frame should contain DW_EH_PE_pcrel | DW_EH_PE_sdata4 values: +# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux --position-independent %s -o %t-pic.o +# RUN: llvm-readobj -r %t-pic.o | FileCheck %s --check-prefixes=RELOCS,PIC64-RELOCS +# RUN: ld.lld -shared %t-pic.o -o %t-pic.so +# RUN: llvm-dwarfdump --eh-frame %t-pic.so | FileCheck %s --check-prefix=PIC-EH-FRAME + +## Also check MIPS32: +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-nopic32.o +# RUN: llvm-dwarfdump --eh-frame %t-nopic32.o | FileCheck %s --check-prefix=ABS32-EH-FRAME +# RUN: llvm-readobj -r %t-nopic32.o | FileCheck %s --check-prefixes=RELOCS,ABS32-RELOCS +# RUN: not ld.lld -shared %t-nopic32.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOPIC32-ERR +## Note: ld.bfd can link this file because it rewrites the .eh_frame section to use +## relative addressing. +# NOPIC32-ERR: ld.lld: error: can't create dynamic relocation R_MIPS_32 against local symbol in readonly segment + +## For -fPIC, .eh_frame should contain DW_EH_PE_pcrel | DW_EH_PE_sdata4 values: +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux --position-independent %s -o %t-pic32.o +# RUN: llvm-readobj -r %t-pic32.o | FileCheck %s --check-prefixes=RELOCS,PIC32-RELOCS +# RUN: ld.lld -shared %t-pic32.o -o %t-pic32.so +# RUN: llvm-dwarfdump --eh-frame %t-pic32.so | FileCheck %s --check-prefix=PIC-EH-FRAME + +# RELOCS: .rel{{a?}}.eh_frame { +# ABS32-RELOCS-NEXT: 0x1C R_MIPS_32 .text 0x0 +# ABS64-RELOCS-NEXT: 0x1C R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE .text 0x0 +# PIC64-RELOCS-NEXT: 0x1C R_MIPS_PC32/R_MIPS_NONE/R_MIPS_NONE - 0x0 +# PIC32-RELOCS-NEXT: 0x1C R_MIPS_PC32 - 0x0 +# RELOCS-NEXT: } + +# ABS64-EH-FRAME: Augmentation data: 0C +## ^^ fde pointer encoding: DW_EH_PE_sdata8 +# ABS32-EH-FRAME: Augmentation data: 0B +## ^^ fde pointer encoding: DW_EH_PE_sdata4 +# PIC-EH-FRAME: Augmentation data: 1B +## ^^ fde pointer encoding: DW_EH_PE_pcrel | DW_EH_PE_sdata4 +## Note: ld.bfd converts the R_MIPS_64 relocs to DW_EH_PE_pcrel | DW_EH_PE_sdata8 +## for N64 ABI (and DW_EH_PE_pcrel | DW_EH_PE_sdata4 for MIPS32) + +.ent func +.global func +func: + .cfi_startproc + nop + .cfi_endproc +.end func |

