1# REQUIRES: mips
2## Check that we can link a shared library containing an eh_frame section without
3## -z notext. This was not possible LLVM started emitting values using the
4## DW_EH_PE_pcrel | DW_EH_PE_sdata4 encoding.
5
6## It should not be possible to link code compiled without -fPIC:
7# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t-nopic.o
8# RUN: llvm-dwarfdump --eh-frame %t-nopic.o | FileCheck %s --check-prefix=ABS64-EH-FRAME
9# RUN: llvm-readobj -r %t-nopic.o | FileCheck %s --check-prefixes=RELOCS,ABS64-RELOCS
10# RUN: not ld.lld -shared %t-nopic.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOPIC-ERR
11## Note: ld.bfd can link this file because it rewrites the .eh_frame section to use
12## relative addressing.
13# NOPIC-ERR: ld.lld: error: can't create dynamic relocation R_MIPS_64 against local symbol in readonly segment
14
15## For -fPIC, .eh_frame should contain DW_EH_PE_pcrel | DW_EH_PE_sdata4 values:
16# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux --position-independent %s -o %t-pic.o
17# RUN: llvm-readobj -r %t-pic.o | FileCheck %s --check-prefixes=RELOCS,PIC64-RELOCS
18# RUN: ld.lld -shared %t-pic.o -o %t-pic.so
19# RUN: llvm-dwarfdump --eh-frame %t-pic.so | FileCheck %s --check-prefix=PIC-EH-FRAME
20
21## Also check MIPS32:
22# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t-nopic32.o
23# RUN: llvm-dwarfdump --eh-frame %t-nopic32.o | FileCheck %s --check-prefix=ABS32-EH-FRAME
24# RUN: llvm-readobj -r %t-nopic32.o | FileCheck %s --check-prefixes=RELOCS,ABS32-RELOCS
25# RUN: not ld.lld -shared %t-nopic32.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=NOPIC32-ERR
26## Note: ld.bfd can link this file because it rewrites the .eh_frame section to use
27## relative addressing.
28# NOPIC32-ERR: ld.lld: error: can't create dynamic relocation R_MIPS_32 against local symbol in readonly segment
29
30## For -fPIC, .eh_frame should contain DW_EH_PE_pcrel | DW_EH_PE_sdata4 values:
31# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux --position-independent %s -o %t-pic32.o
32# RUN: llvm-readobj -r %t-pic32.o | FileCheck %s --check-prefixes=RELOCS,PIC32-RELOCS
33# RUN: ld.lld -shared %t-pic32.o -o %t-pic32.so
34# RUN: llvm-dwarfdump --eh-frame %t-pic32.so | FileCheck %s --check-prefix=PIC-EH-FRAME
35
36# RELOCS:            .rel{{a?}}.eh_frame {
37# ABS32-RELOCS-NEXT:   0x1C R_MIPS_32 .text
38# ABS64-RELOCS-NEXT:   0x1C R_MIPS_64/R_MIPS_NONE/R_MIPS_NONE .text
39# PIC64-RELOCS-NEXT:   0x1C R_MIPS_PC32/R_MIPS_NONE/R_MIPS_NONE -
40# PIC32-RELOCS-NEXT:   0x1C R_MIPS_PC32 -
41# RELOCS-NEXT:       }
42
43# ABS64-EH-FRAME: Augmentation data: 0C
44##                                   ^^ fde pointer encoding: DW_EH_PE_sdata8
45# ABS32-EH-FRAME: Augmentation data: 0B
46##                                   ^^ fde pointer encoding: DW_EH_PE_sdata4
47# PIC-EH-FRAME: Augmentation data: 1B
48##                                 ^^ fde pointer encoding: DW_EH_PE_pcrel | DW_EH_PE_sdata4
49## Note: ld.bfd converts the R_MIPS_64 relocs to DW_EH_PE_pcrel | DW_EH_PE_sdata8
50## for N64 ABI (and DW_EH_PE_pcrel | DW_EH_PE_sdata4 for MIPS32)
51
52.ent func
53.global func
54func:
55	.cfi_startproc
56	nop
57	.cfi_endproc
58.end func
59