summaryrefslogtreecommitdiff
path: root/test/old-elf/Mips
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:57:38 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:57:38 +0000
commit5a5c549fe9a3fef595297bd21d36bed8409dc37d (patch)
treea964c8f5ac85b7b641cac022c5f9bf4eed3d2b9b /test/old-elf/Mips
parentfb911942f1434f3d1750f83f25f5e42c80e60638 (diff)
Notes
Diffstat (limited to 'test/old-elf/Mips')
-rw-r--r--test/old-elf/Mips/abi-flags-01.test35
-rw-r--r--test/old-elf/Mips/abi-flags-02.test92
-rw-r--r--test/old-elf/Mips/abi-flags-03.test149
-rw-r--r--test/old-elf/Mips/abi-flags-04.test125
-rw-r--r--test/old-elf/Mips/abi-flags-05.test186
-rw-r--r--test/old-elf/Mips/abi-flags-06.test79
-rw-r--r--test/old-elf/Mips/abi-flags-07.test60
-rw-r--r--test/old-elf/Mips/abi-flags-08.test71
-rw-r--r--test/old-elf/Mips/abi-flags-09.test67
-rw-r--r--test/old-elf/Mips/abi-flags-10.test60
-rw-r--r--test/old-elf/Mips/abi-flags-11.test59
-rw-r--r--test/old-elf/Mips/base-address-64.test80
-rw-r--r--test/old-elf/Mips/base-address.test95
-rw-r--r--test/old-elf/Mips/ctors-order.test164
-rw-r--r--test/old-elf/Mips/driver-hash-style.test15
-rw-r--r--test/old-elf/Mips/dt-textrel-64.test74
-rw-r--r--test/old-elf/Mips/dt-textrel.test74
-rw-r--r--test/old-elf/Mips/dynamic-linking.test22
-rw-r--r--test/old-elf/Mips/dynamic-sym.test41
-rw-r--r--test/old-elf/Mips/dynlib-dynamic.test110
-rw-r--r--test/old-elf/Mips/dynlib-dynsym-micro.test208
-rw-r--r--test/old-elf/Mips/dynlib-dynsym.test202
-rw-r--r--test/old-elf/Mips/dynlib-fileheader-64.test72
-rw-r--r--test/old-elf/Mips/dynlib-fileheader-micro-64.test75
-rw-r--r--test/old-elf/Mips/dynlib-fileheader-micro.test79
-rw-r--r--test/old-elf/Mips/dynlib-fileheader.test76
-rw-r--r--test/old-elf/Mips/dynsym-table-1.test127
-rw-r--r--test/old-elf/Mips/dynsym-table-2.test105
-rw-r--r--test/old-elf/Mips/e-flags-merge-1-64.test30
-rw-r--r--test/old-elf/Mips/e-flags-merge-1.test56
-rw-r--r--test/old-elf/Mips/e-flags-merge-10.test43
-rw-r--r--test/old-elf/Mips/e-flags-merge-11.test43
-rw-r--r--test/old-elf/Mips/e-flags-merge-12.test44
-rw-r--r--test/old-elf/Mips/e-flags-merge-2-64.test33
-rw-r--r--test/old-elf/Mips/e-flags-merge-2.test35
-rw-r--r--test/old-elf/Mips/e-flags-merge-3-64.test130
-rw-r--r--test/old-elf/Mips/e-flags-merge-3.test134
-rw-r--r--test/old-elf/Mips/e-flags-merge-4-64.test64
-rw-r--r--test/old-elf/Mips/e-flags-merge-4.test65
-rw-r--r--test/old-elf/Mips/e-flags-merge-5-64.test42
-rw-r--r--test/old-elf/Mips/e-flags-merge-5.test42
-rw-r--r--test/old-elf/Mips/e-flags-merge-6-64.test79
-rw-r--r--test/old-elf/Mips/e-flags-merge-6.test80
-rw-r--r--test/old-elf/Mips/e-flags-merge-7-64.test42
-rw-r--r--test/old-elf/Mips/e-flags-merge-7.test42
-rw-r--r--test/old-elf/Mips/e-flags-merge-8.test65
-rw-r--r--test/old-elf/Mips/e-flags-merge-9.test43
-rw-r--r--test/old-elf/Mips/entry-name.test26
-rw-r--r--test/old-elf/Mips/exe-dynamic.test110
-rw-r--r--test/old-elf/Mips/exe-dynsym-micro.test94
-rw-r--r--test/old-elf/Mips/exe-dynsym.test91
-rw-r--r--test/old-elf/Mips/exe-fileheader-02.test62
-rw-r--r--test/old-elf/Mips/exe-fileheader-03.test72
-rw-r--r--test/old-elf/Mips/exe-fileheader-64.test66
-rw-r--r--test/old-elf/Mips/exe-fileheader-be-64.test60
-rw-r--r--test/old-elf/Mips/exe-fileheader-be.test60
-rw-r--r--test/old-elf/Mips/exe-fileheader-micro-64.test68
-rw-r--r--test/old-elf/Mips/exe-fileheader-micro.test69
-rw-r--r--test/old-elf/Mips/exe-fileheader-n32.test65
-rw-r--r--test/old-elf/Mips/exe-fileheader.test105
-rw-r--r--test/old-elf/Mips/exe-got-micro.test115
-rw-r--r--test/old-elf/Mips/exe-got.test116
-rw-r--r--test/old-elf/Mips/got-page-32-micro.test251
-rw-r--r--test/old-elf/Mips/got-page-32.test244
-rw-r--r--test/old-elf/Mips/got-page-64-micro.test210
-rw-r--r--test/old-elf/Mips/got-page-64.test203
-rw-r--r--test/old-elf/Mips/got16-2.test73
-rw-r--r--test/old-elf/Mips/got16-micro.test165
-rw-r--r--test/old-elf/Mips/got16.test196
-rw-r--r--test/old-elf/Mips/gotsym.test43
-rw-r--r--test/old-elf/Mips/gp-sym-1-micro.test88
-rw-r--r--test/old-elf/Mips/gp-sym-1.test86
-rw-r--r--test/old-elf/Mips/gp-sym-2.test103
-rw-r--r--test/old-elf/Mips/hilo16-1.test40
-rw-r--r--test/old-elf/Mips/hilo16-2.test70
-rw-r--r--test/old-elf/Mips/hilo16-3-overflow.test44
-rw-r--r--test/old-elf/Mips/hilo16-3.test74
-rw-r--r--test/old-elf/Mips/hilo16-4.test93
-rw-r--r--test/old-elf/Mips/hilo16-5.test103
-rw-r--r--test/old-elf/Mips/hilo16-8-micro.test81
-rw-r--r--test/old-elf/Mips/hilo16-9-micro.test142
-rw-r--r--test/old-elf/Mips/initfini-micro.test45
-rw-r--r--test/old-elf/Mips/interpreter-64.test26
-rw-r--r--test/old-elf/Mips/interpreter-n32.test27
-rw-r--r--test/old-elf/Mips/interpreter.test26
-rw-r--r--test/old-elf/Mips/invalid-reginfo.test28
-rw-r--r--test/old-elf/Mips/jalx-align-err.test46
-rw-r--r--test/old-elf/Mips/jalx-jalr.test47
-rw-r--r--test/old-elf/Mips/jalx.test71
-rw-r--r--test/old-elf/Mips/jump-fix-err.test45
-rw-r--r--test/old-elf/Mips/la25-stub-be.test113
-rw-r--r--test/old-elf/Mips/la25-stub-micro-be.test121
-rw-r--r--test/old-elf/Mips/la25-stub-micro.test136
-rw-r--r--test/old-elf/Mips/la25-stub-npic-01.test153
-rw-r--r--test/old-elf/Mips/la25-stub-npic-02.test123
-rw-r--r--test/old-elf/Mips/la25-stub-npic-shared.test152
-rw-r--r--test/old-elf/Mips/la25-stub-pic.test144
-rw-r--r--test/old-elf/Mips/la25-stub.test133
-rw-r--r--test/old-elf/Mips/mips-options-01.test34
-rw-r--r--test/old-elf/Mips/mips-options-02.test104
-rw-r--r--test/old-elf/Mips/mips-options-03.test41
-rw-r--r--test/old-elf/Mips/mips-options-04.test77
-rw-r--r--test/old-elf/Mips/mips-options-05.test119
-rw-r--r--test/old-elf/Mips/mips-options-gp0.test77
-rw-r--r--test/old-elf/Mips/n32-rela-chain.test68
-rw-r--r--test/old-elf/Mips/n64-rel-chain.test204
-rw-r--r--test/old-elf/Mips/n64-rel-shift.test48
-rw-r--r--test/old-elf/Mips/opt-emulation.test43
-rw-r--r--test/old-elf/Mips/pc23-range.test54
-rw-r--r--test/old-elf/Mips/plt-entry-mixed-1.test114
-rw-r--r--test/old-elf/Mips/plt-entry-mixed-2.test93
-rw-r--r--test/old-elf/Mips/plt-entry-mixed-3.test98
-rw-r--r--test/old-elf/Mips/plt-entry-mixed-4.test85
-rw-r--r--test/old-elf/Mips/plt-entry-r6-be.test109
-rw-r--r--test/old-elf/Mips/plt-entry-r6.test109
-rw-r--r--test/old-elf/Mips/plt-header-be.test104
-rw-r--r--test/old-elf/Mips/plt-header-micro-be.test105
-rw-r--r--test/old-elf/Mips/plt-header-micro.test108
-rw-r--r--test/old-elf/Mips/plt-header-mixed.test105
-rw-r--r--test/old-elf/Mips/plt-header.test99
-rw-r--r--test/old-elf/Mips/r26-1-micro.test131
-rw-r--r--test/old-elf/Mips/r26-1.test132
-rw-r--r--test/old-elf/Mips/r26-2-micro.test31
-rw-r--r--test/old-elf/Mips/r26-2.test31
-rw-r--r--test/old-elf/Mips/reginfo-01.test30
-rw-r--r--test/old-elf/Mips/reginfo-02.test107
-rw-r--r--test/old-elf/Mips/reginfo-03.test45
-rw-r--r--test/old-elf/Mips/reginfo-04.test81
-rw-r--r--test/old-elf/Mips/reginfo-05.test123
-rw-r--r--test/old-elf/Mips/rel-16-overflow.test45
-rw-r--r--test/old-elf/Mips/rel-16.test51
-rw-r--r--test/old-elf/Mips/rel-32-be.test60
-rw-r--r--test/old-elf/Mips/rel-32.test59
-rw-r--r--test/old-elf/Mips/rel-64.test61
-rw-r--r--test/old-elf/Mips/rel-call-hilo-01.test109
-rw-r--r--test/old-elf/Mips/rel-call-hilo-micro.test154
-rw-r--r--test/old-elf/Mips/rel-copy-micro.test159
-rw-r--r--test/old-elf/Mips/rel-copy-pc.test113
-rw-r--r--test/old-elf/Mips/rel-copy.test177
-rw-r--r--test/old-elf/Mips/rel-dynamic-01-micro.test201
-rw-r--r--test/old-elf/Mips/rel-dynamic-01.test261
-rw-r--r--test/old-elf/Mips/rel-dynamic-02.test101
-rw-r--r--test/old-elf/Mips/rel-dynamic-03-micro.test133
-rw-r--r--test/old-elf/Mips/rel-dynamic-03.test129
-rw-r--r--test/old-elf/Mips/rel-dynamic-04-micro.test226
-rw-r--r--test/old-elf/Mips/rel-dynamic-04.test221
-rw-r--r--test/old-elf/Mips/rel-dynamic-05-micro.test192
-rw-r--r--test/old-elf/Mips/rel-dynamic-05.test188
-rw-r--r--test/old-elf/Mips/rel-dynamic-06-64.test114
-rw-r--r--test/old-elf/Mips/rel-dynamic-06.test115
-rw-r--r--test/old-elf/Mips/rel-dynamic-07-64.test348
-rw-r--r--test/old-elf/Mips/rel-dynamic-07.test363
-rw-r--r--test/old-elf/Mips/rel-dynamic-08-64.test275
-rw-r--r--test/old-elf/Mips/rel-dynamic-08-micro.test278
-rw-r--r--test/old-elf/Mips/rel-dynamic-08.test275
-rw-r--r--test/old-elf/Mips/rel-dynamic-09-micro.test109
-rw-r--r--test/old-elf/Mips/rel-dynamic-09.test107
-rw-r--r--test/old-elf/Mips/rel-dynamic-10-micro.test166
-rw-r--r--test/old-elf/Mips/rel-dynamic-10.test160
-rw-r--r--test/old-elf/Mips/rel-dynamic-11.test110
-rw-r--r--test/old-elf/Mips/rel-dynamic-12.test237
-rw-r--r--test/old-elf/Mips/rel-dynamic-13.test94
-rw-r--r--test/old-elf/Mips/rel-dynamic-14.test94
-rw-r--r--test/old-elf/Mips/rel-dynamic-15.test81
-rw-r--r--test/old-elf/Mips/rel-eh-01.test186
-rw-r--r--test/old-elf/Mips/rel-eh-02.test130
-rw-r--r--test/old-elf/Mips/rel-eh-03.test128
-rw-r--r--test/old-elf/Mips/rel-got-hilo-01.test109
-rw-r--r--test/old-elf/Mips/rel-got-hilo-micro.test154
-rw-r--r--test/old-elf/Mips/rel-gprel16-micro-overflow.test57
-rw-r--r--test/old-elf/Mips/rel-gprel16-micro.test78
-rw-r--r--test/old-elf/Mips/rel-gprel16-overflow.test48
-rw-r--r--test/old-elf/Mips/rel-gprel16.test104
-rw-r--r--test/old-elf/Mips/rel-gprel32-64.test84
-rw-r--r--test/old-elf/Mips/rel-gprel32.test84
-rw-r--r--test/old-elf/Mips/rel-gprel7-micro-overflow.test48
-rw-r--r--test/old-elf/Mips/rel-gprel7-micro.test65
-rw-r--r--test/old-elf/Mips/rel-hi0-lo16-micro.test58
-rw-r--r--test/old-elf/Mips/rel-high-01.test25
-rw-r--r--test/old-elf/Mips/rel-high-02.test25
-rw-r--r--test/old-elf/Mips/rel-jalr-01.test101
-rw-r--r--test/old-elf/Mips/rel-jalr-02.test68
-rw-r--r--test/old-elf/Mips/rel-lit-micro.test59
-rw-r--r--test/old-elf/Mips/rel-lit.test57
-rw-r--r--test/old-elf/Mips/rel-pc-hilo.test70
-rw-r--r--test/old-elf/Mips/rel-pc16-align.test43
-rw-r--r--test/old-elf/Mips/rel-pc16-overflow.test45
-rw-r--r--test/old-elf/Mips/rel-pc16.test53
-rw-r--r--test/old-elf/Mips/rel-pc18-s3-align.test44
-rw-r--r--test/old-elf/Mips/rel-pc18-s3-micro.test56
-rw-r--r--test/old-elf/Mips/rel-pc18-s3.test54
-rw-r--r--test/old-elf/Mips/rel-pc19-s2-align.test44
-rw-r--r--test/old-elf/Mips/rel-pc19-s2-micro.test56
-rw-r--r--test/old-elf/Mips/rel-pc19-s2.test54
-rw-r--r--test/old-elf/Mips/rel-pc21-s2-align.test44
-rw-r--r--test/old-elf/Mips/rel-pc21-s2-micro.test56
-rw-r--r--test/old-elf/Mips/rel-pc21-s2-overflow.test45
-rw-r--r--test/old-elf/Mips/rel-pc21-s2.test54
-rw-r--r--test/old-elf/Mips/rel-pc26-s2-align.test44
-rw-r--r--test/old-elf/Mips/rel-pc26-s2-micro.test56
-rw-r--r--test/old-elf/Mips/rel-pc26-s2.test54
-rw-r--r--test/old-elf/Mips/rel-pc32.test59
-rw-r--r--test/old-elf/Mips/rel-pc7-10-16-23.test86
-rw-r--r--test/old-elf/Mips/rel-sub-micro.test62
-rw-r--r--test/old-elf/Mips/rel-sub.test61
-rw-r--r--test/old-elf/Mips/rld_map.test42
-rw-r--r--test/old-elf/Mips/sign-rela.test54
-rw-r--r--test/old-elf/Mips/st-other.test90
-rw-r--r--test/old-elf/Mips/static-01.test119
-rw-r--r--test/old-elf/Mips/tls-1-micro.test65
-rw-r--r--test/old-elf/Mips/tls-1.test63
-rw-r--r--test/old-elf/Mips/tls-2-64-static.test71
-rw-r--r--test/old-elf/Mips/tls-2-64.test69
-rw-r--r--test/old-elf/Mips/tls-2-micro.test70
-rw-r--r--test/old-elf/Mips/tls-2-static.test125
-rw-r--r--test/old-elf/Mips/tls-2.test69
-rw-r--r--test/old-elf/Mips/tls-3-64-static.test70
-rw-r--r--test/old-elf/Mips/tls-3-micro.test183
-rw-r--r--test/old-elf/Mips/tls-3-static.test67
-rw-r--r--test/old-elf/Mips/tls-3.test180
-rw-r--r--test/old-elf/Mips/tls-4-64-static.test71
-rw-r--r--test/old-elf/Mips/tls-4-micro.test126
-rw-r--r--test/old-elf/Mips/tls-4-static.test68
-rw-r--r--test/old-elf/Mips/tls-4.test123
-rw-r--r--test/old-elf/Mips/tls-5-64.test71
-rw-r--r--test/old-elf/Mips/tls-5-micro.test70
-rw-r--r--test/old-elf/Mips/tls-5.test69
-rw-r--r--test/old-elf/Mips/validate-rel-01.test82
-rw-r--r--test/old-elf/Mips/validate-rel-03.test56
229 files changed, 21794 insertions, 0 deletions
diff --git a/test/old-elf/Mips/abi-flags-01.test b/test/old-elf/Mips/abi-flags-01.test
new file mode 100644
index 0000000000000..d2eb13f3186ab
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-01.test
@@ -0,0 +1,35 @@
+# Check rejecting .MIPS.abiflags section with a wrong version.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: {{.*}}abi-flags-01.test.tmp.o: .MIPS.abiflags section has unsupported version '1'
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ Version: 1
+ ISA: MIPS32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/abi-flags-02.test b/test/old-elf/Mips/abi-flags-02.test
new file mode 100644
index 0000000000000..f3c1f29abc55e
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-02.test
@@ -0,0 +1,92 @@
+# Check generation of .MIPS.abiflags section under the following conditions:
+# - There is the only input object file
+# - The input file has valid .MIPS.abiflags section
+#
+# The .MIPS.abiflags section in the output file should have the same
+# settings as the input section.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -s -program-headers -mips-abi-flags %t.so | FileCheck %s
+
+# CHECK: Section {
+# CHECK: Index: 1
+# CHECK-NEXT: Name: .MIPS.abiflags
+# CHECK-NEXT: Type: SHT_MIPS_ABIFLAGS
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: Size: 24
+# CHECK-NEXT: Link: 0
+# CHECK-NEXT: Info: 0
+# CHECK-NEXT: AddressAlignment: 8
+# CHECK-NEXT: EntrySize: 24
+# CHECK-NEXT: }
+
+# CHECK: ProgramHeaders [
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_MIPS_ABIFLAGS (0x70000003)
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: FileSize: 24
+# CHECK-NEXT: MemSize: 24
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: PF_R
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+
+# CHECK: MIPS ABI Flags {
+# CHECK-NEXT: Version: 0
+# CHECK-NEXT: ISA: MIPS32r2
+# CHECK-NEXT: ISA Extension: None (0x0)
+# CHECK-NEXT: ASEs [ (0x800)
+# CHECK-NEXT: microMIPS (0x800)
+# CHECK-NEXT: ]
+# CHECK-NEXT: FP ABI: Hard float (32-bit CPU, Any FPU) (0x5)
+# CHECK-NEXT: GPR size: 32
+# CHECK-NEXT: CPR1 size: 32
+# CHECK-NEXT: CPR2 size: 0
+# CHECK-NEXT: Flags 1 [ (0x0)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Flags 2: 0x0
+# CHECK-NEXT: }
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ ISAExtension: EXT_NONE
+ ASEs: [ MICROMIPS ]
+ FpABI: FP_XX
+ GPRSize: REG_32
+ CPR1Size: REG_32
+ CPR2Size: REG_NONE
+ Flags1: [ ]
+ Flags2: 0x0
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/abi-flags-03.test b/test/old-elf/Mips/abi-flags-03.test
new file mode 100644
index 0000000000000..a28bb28267307
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-03.test
@@ -0,0 +1,149 @@
+# Check generation of .MIPS.abiflags section under the following conditions:
+# - There are multiple input object files
+# - Every input file has valid .MIPS.abiflags section
+# - All .MIPS.abiflags sections are compatible with each other
+#
+# The .MIPS.abiflags section in the output file should reproduce result
+# of merging input object file sections.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t3.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t1.o %t2.o %t3.o
+# RUN: llvm-readobj -mips-abi-flags %t.so | FileCheck %s
+
+# CHECK: MIPS ABI Flags {
+# CHECK-NEXT: Version: 0
+# CHECK-NEXT: ISA: MIPS32r2
+# CHECK-NEXT: ISA Extension: None (0x0)
+# CHECK-NEXT: ASEs [ (0x810)
+# CHECK-NEXT: MDMX (0x10)
+# CHECK-NEXT: microMIPS (0x800)
+# CHECK-NEXT: ]
+# CHECK-NEXT: FP ABI: Hard float (double precision) (0x1)
+# CHECK-NEXT: GPR size: 32
+# CHECK-NEXT: CPR1 size: 64
+# CHECK-NEXT: CPR2 size: 0
+# CHECK-NEXT: Flags 1 [ (0x1)
+# CHECK-NEXT: ODDSPREG
+# CHECK-NEXT: ]
+# CHECK-NEXT: Flags 2: 0x0
+# CHECK-NEXT: }
+
+# o1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32, EF_MIPS_ARCH_ASE_MDMX]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ ISAExtension: EXT_NONE
+ ASEs: [ MDMX ]
+ FpABI: FP_DOUBLE
+ GPRSize: REG_32
+ CPR1Size: REG_64
+ CPR2Size: REG_NONE
+ Flags1: [ ]
+ Flags2: 0x0
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# o2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ ISAExtension: EXT_NONE
+ ASEs: [ MICROMIPS ]
+ FpABI: FP_XX
+ GPRSize: REG_32
+ CPR1Size: REG_32
+ CPR2Size: REG_NONE
+ Flags1: [ODDSPREG]
+ Flags2: 0x0
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# o3.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ ISAExtension: EXT_NONE
+ ASEs: [ MICROMIPS ]
+ FpABI: FP_XX
+ GPRSize: REG_32
+ CPR1Size: REG_32
+ CPR2Size: REG_NONE
+ Flags1: [ ]
+ Flags2: 0x0
+
+Symbols:
+ Global:
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/abi-flags-04.test b/test/old-elf/Mips/abi-flags-04.test
new file mode 100644
index 0000000000000..6cde797dd3a01
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-04.test
@@ -0,0 +1,125 @@
+# Check generation of .MIPS.abiflags section under the following conditions:
+# - There are multiple input object files
+# - Every input file has valid .MIPS.abiflags section
+# - .MIPS.abiflags sections have different but compatible FP ABI
+#
+# The .MIPS.abiflags section in the output file should reproduce result
+# of merging FP ABI flags.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-xx.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-double.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-64.o
+# RUN: yaml2obj -format=elf -docnum 4 %s > %t-64a.o
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1 %t-xx.o %t-double.o
+# RUN: llvm-readobj -mips-abi-flags %t1 | FileCheck -check-prefix=XX-DOUBLE %s
+
+# XX-DOUBLE: FP ABI: Hard float (double precision) (0x1)
+# XX-DOUBLE: GPR size: 32
+# XX-DOUBLE: CPR1 size: 32
+# XX-DOUBLE: Flags 1 [ (0x0)
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2 %t-xx.o %t-64.o
+# RUN: llvm-readobj -mips-abi-flags %t2 | FileCheck -check-prefix=XX-64 %s
+
+# XX-64: FP ABI: Hard float (32-bit CPU, 64-bit FPU) (0x6)
+# XX-64: GPR size: 32
+# XX-64: CPR1 size: 64
+# XX-64: Flags 1 [ (0x1)
+# XX-64: ODDSPREG (0x1)
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t3 %t-xx.o %t-64a.o
+# RUN: llvm-readobj -mips-abi-flags %t3 | FileCheck -check-prefix=XX-64A %s
+
+# XX-64A: FP ABI: Hard float compat (32-bit CPU, 64-bit FPU) (0x7)
+# XX-64A: GPR size: 32
+# XX-64A: CPR1 size: 64
+# XX-64A: Flags 1 [ (0x0)
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t4 %t-64.o %t-64a.o
+# RUN: llvm-readobj -mips-abi-flags %t4 | FileCheck -check-prefix=64-64A %s
+
+# 64-64A: FP ABI: Hard float (32-bit CPU, 64-bit FPU) (0x6)
+# 64-64A: GPR size: 32
+# 64-64A: CPR1 size: 64
+# 64-64A: Flags 1 [ (0x1)
+# 64-64A: ODDSPREG (0x1)
+
+# xx.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ FpABI: FP_XX
+ GPRSize: REG_32
+ CPR1Size: REG_32
+
+# double.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ FpABI: FP_DOUBLE
+ GPRSize: REG_32
+ CPR1Size: REG_32
+
+# 64.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ FpABI: FP_64
+ GPRSize: REG_32
+ CPR1Size: REG_64
+ Flags1: [ODDSPREG]
+
+# 64a.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ FpABI: FP_64A
+ GPRSize: REG_32
+ CPR1Size: REG_64
+ Flags1: []
+...
diff --git a/test/old-elf/Mips/abi-flags-05.test b/test/old-elf/Mips/abi-flags-05.test
new file mode 100644
index 0000000000000..6a009db7344ac
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-05.test
@@ -0,0 +1,186 @@
+# Check generation of .MIPS.abiflags section under the following conditions:
+# - There are multiple input object files
+# - Every input file has valid .MIPS.abiflags section
+# - .MIPS.abiflags sections have different and incompatible FP ABI
+#
+# The .MIPS.abiflags section in the output file should reproduce result
+# of merging FP ABI flags but the linker must show a warning.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-xx.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-dbl.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-sgl.o
+# RUN: yaml2obj -format=elf -docnum 4 %s > %t-soft.o
+# RUN: yaml2obj -format=elf -docnum 5 %s > %t-64.o
+# RUN: yaml2obj -format=elf -docnum 6 %s > %t-64a.o
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1 %t-xx.o %t-sgl.o 2>&1 \
+# RUN: | FileCheck -check-prefix=XX-SINGLE-WARN %s
+
+# XX-SINGLE-WARN: FP ABI {{-mfpxx|-msingle-float}} is incompatible with {{-msingle-float|-mfpxx}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2 %t-xx.o %t-soft.o 2>&1 \
+# RUN: | FileCheck -check-prefix=XX-SOFT-WARN %s
+
+# XX-SOFT-WARN: FP ABI {{-mfpxx|-msoft-float}} is incompatible with {{-msoft-float|-mfpxx}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t3 %t-dbl.o %t-sgl.o 2>&1 \
+# RUN: | FileCheck -check-prefix=DOUBLE-SINGLE-WARN %s
+
+# DOUBLE-SINGLE-WARN: FP ABI {{-mdouble-float|-msingle-float}} is incompatible with {{-msingle-float|-mdouble-float}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t4 %t-dbl.o %t-soft.o 2>&1 \
+# RUN: | FileCheck -check-prefix=DOUBLE-SOFT-WARN %s
+
+# DOUBLE-SOFT-WARN: FP ABI {{-mdouble-float|-msoft-float}} is incompatible with {{-msoft-float|-mdouble-float}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t5 %t-dbl.o %t-64.o 2>&1 \
+# RUN: | FileCheck -check-prefix=DOUBLE-64-WARN %s
+
+# DOUBLE-64-WARN: FP ABI {{-mdouble-float|-mgp32 -mfp64}} is incompatible with {{-mgp32 -mfp64|-mdouble-float}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t6 %t-dbl.o %t-64a.o 2>&1 \
+# RUN: | FileCheck -check-prefix=DOUBLE-64A-WARN %s
+
+# DOUBLE-64A-WARN: FP ABI {{-mdouble-float|-mgp32 -mfp64 -mno-odd-spreg}} is incompatible with {{-mgp32 -mfp64 -mno-odd-spreg|-mdouble-float}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t7 %t-sgl.o %t-soft.o 2>&1 \
+# RUN: | FileCheck -check-prefix=SINGLE-SOFT-WARN %s
+
+# SINGLE-SOFT-WARN: FP ABI {{-msingle-float|-msoft-float}} is incompatible with {{-msoft-float|-msingle-float}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t8 %t-sgl.o %t-64.o 2>&1 \
+# RUN: | FileCheck -check-prefix=SINGLE-64-WARN %s
+
+# SINGLE-64-WARN: FP ABI {{-msingle-float|-mgp32 -mfp64}} is incompatible with {{-mgp32 -mfp64|-msingle-float}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t9 %t-sgl.o %t-64a.o 2>&1 \
+# RUN: | FileCheck -check-prefix=SINGLE-64A-WARN %s
+
+# SINGLE-64A-WARN: FP ABI {{-msingle-float|-mgp32 -mfp64 -mno-odd-spreg}} is incompatible with {{-mgp32 -mfp64 -mno-odd-spreg|-msingle-float}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t10 %t-soft.o %t-64.o 2>&1 \
+# RUN: | FileCheck -check-prefix=SOFT-64-WARN %s
+
+# SOFT-64-WARN: FP ABI {{-msoft-float|-mgp32 -mfp64}} is incompatible with {{-mgp32 -mfp64|-msoft-float}}
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t11 %t-soft.o %t-64a.o 2>&1 \
+# RUN: | FileCheck -check-prefix=SOFT-64A-WARN %s
+
+# SOFT-64A-WARN: FP ABI {{-msoft-float|-mgp32 -mfp64 -mno-odd-spreg}} is incompatible with {{-mgp32 -mfp64 -mno-odd-spreg|-msoft-float}}
+
+# xx.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ FpABI: FP_XX
+ GPRSize: REG_32
+ CPR1Size: REG_32
+
+# double.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ FpABI: FP_DOUBLE
+ GPRSize: REG_32
+ CPR1Size: REG_32
+
+# single.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ FpABI: FP_SINGLE
+ GPRSize: REG_32
+ CPR1Size: REG_32
+
+# soft.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ FpABI: FP_SOFT
+ GPRSize: REG_32
+ CPR1Size: REG_NONE
+
+# 64.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ FpABI: FP_64
+ GPRSize: REG_32
+ CPR1Size: REG_64
+ Flags1: [ODDSPREG]
+
+# 64a.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ FpABI: FP_64A
+ GPRSize: REG_32
+ CPR1Size: REG_64
+ Flags1: []
+...
diff --git a/test/old-elf/Mips/abi-flags-06.test b/test/old-elf/Mips/abi-flags-06.test
new file mode 100644
index 0000000000000..d7df379039bb8
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-06.test
@@ -0,0 +1,79 @@
+# Check generation of .MIPS.abiflags section under the following conditions:
+# - There are multiple input object files
+# - Not all input files have a .MIPS.abiflags section
+#
+# The .MIPS.abiflags section in the output file should reproduce result
+# of merging input object file sections and data come from ELF header flags.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-abi.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-elf.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-abi.o %t-elf.o
+# RUN: llvm-readobj -mips-abi-flags %t.so | FileCheck %s
+
+# CHECK: MIPS ABI Flags {
+# CHECK-NEXT: Version: 0
+# CHECK-NEXT: ISA: MIPS32r2
+# CHECK-NEXT: ISA Extension: None (0x0)
+# CHECK-NEXT: ASEs [ (0x810)
+# CHECK-NEXT: MDMX (0x10)
+# CHECK-NEXT: microMIPS (0x800)
+# CHECK-NEXT: ]
+# CHECK-NEXT: FP ABI: Hard float (double precision) (0x1)
+# CHECK-NEXT: GPR size: 32
+# CHECK-NEXT: CPR1 size: 64
+# CHECK-NEXT: CPR2 size: 0
+# CHECK-NEXT: Flags 1 [ (0x0)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Flags 2: 0x0
+# CHECK-NEXT: }
+
+# abi.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32, EF_MIPS_ARCH_ASE_MDMX]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ ISAExtension: EXT_NONE
+ ASEs: [ MDMX ]
+ FpABI: FP_DOUBLE
+ GPRSize: REG_32
+ CPR1Size: REG_64
+ CPR2Size: REG_NONE
+ Flags1: [ ]
+ Flags2: 0x0
+
+# elf.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/abi-flags-07.test b/test/old-elf/Mips/abi-flags-07.test
new file mode 100644
index 0000000000000..6cae9b2feb4d9
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-07.test
@@ -0,0 +1,60 @@
+# Check that .MIPS.abiflags section is not written if no input object files
+# contain that section.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t1.o %t2.o
+# RUN: llvm-readobj -mips-abi-flags %t.so | FileCheck %s
+
+# CHECK: There is no .MIPS.abiflags section in the file.
+
+# abi.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32, EF_MIPS_ARCH_ASE_MDMX]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# elf.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/abi-flags-08.test b/test/old-elf/Mips/abi-flags-08.test
new file mode 100644
index 0000000000000..c4b75bcf4516a
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-08.test
@@ -0,0 +1,71 @@
+# Check that the linker shows errors if ELF header flags
+# and .MIPS.abiflags section are incompatible.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-isa.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-ext.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-ases.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t-isa.o 2>&1 \
+# RUN: | FileCheck -check-prefix=ISA-ERR %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2.so %t-ext.o 2>&1 \
+# RUN: | FileCheck -check-prefix=EXT-ERR %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t3.so %t-ases.o 2>&1 \
+# RUN: | FileCheck -check-prefix=ASE-ERR %s
+# RUN: llvm-readobj -mips-abi-flags %t1.so %t2.so %t3.so \
+# RUN: | FileCheck -check-prefix=SEC %s
+
+# ISA-ERR: inconsistent ISA between .MIPS.abiflags and ELF header e_flags field
+# EXT-ERR: inconsistent ISA between .MIPS.abiflags and ELF header e_flags field
+# ASE-ERR: inconsistent ASEs between .MIPS.abiflags and ELF header e_flags field
+
+# SEC: There is no .MIPS.abiflags section in the file.
+
+# isa.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+
+# ext.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_3, EF_MIPS_MACH_4650]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS3
+ ISAExtension: EXT_4120
+
+# ases.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ ASEs: []
+
+...
diff --git a/test/old-elf/Mips/abi-flags-09.test b/test/old-elf/Mips/abi-flags-09.test
new file mode 100644
index 0000000000000..1ab03abe38100
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-09.test
@@ -0,0 +1,67 @@
+# Check position of PT_MIPS_ABIFLAGS segment.
+# It should go right after the PT_INTERP segment.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s
+
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_INTERP
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: FileSize: 13
+# CHECK-NEXT: MemSize: 13
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: PF_R
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 1
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_MIPS_ABIFLAGS
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: FileSize: 24
+# CHECK-NEXT: MemSize: 24
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: PF_R
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ ISAExtension: EXT_NONE
+ ASEs: [ MICROMIPS ]
+ FpABI: FP_XX
+ GPRSize: REG_32
+ CPR1Size: REG_32
+ CPR2Size: REG_NONE
+ Flags1: [ ]
+ Flags2: 0x0
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/abi-flags-10.test b/test/old-elf/Mips/abi-flags-10.test
new file mode 100644
index 0000000000000..50732d5c1151d
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-10.test
@@ -0,0 +1,60 @@
+# Check that SHT_MIPS_REGINFO section does not get a separate segment
+# if there is a SHT_MIPS_ABIFLAGS section.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s
+
+# CHECK: ProgramHeaders [
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR
+# CHECK: }
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_INTERP
+# CHECK: }
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_MIPS_ABIFLAGS
+# CHECK: }
+# CHECK-NOT: Type: PT_MIPS_REGINFO
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "F0000000E0000000D0000000C0000000B000000000100000"
+
+- Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 2
+ ISAExtension: EXT_NONE
+ ASEs: [ MICROMIPS ]
+ FpABI: FP_XX
+ GPRSize: REG_32
+ CPR1Size: REG_32
+ CPR2Size: REG_NONE
+ Flags1: [ ]
+ Flags2: 0x0
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/abi-flags-11.test b/test/old-elf/Mips/abi-flags-11.test
new file mode 100644
index 0000000000000..e0e8547abbc73
--- /dev/null
+++ b/test/old-elf/Mips/abi-flags-11.test
@@ -0,0 +1,59 @@
+# Check position of PT_MIPS_REGINFO segment.
+# It should go right after the PT_INTERP segment.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -program-headers %t.exe | FileCheck %s
+
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_INTERP
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: FileSize: 13
+# CHECK-NEXT: MemSize: 13
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: PF_R
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 1
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_MIPS_REGINFO
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: FileSize: 24
+# CHECK-NEXT: MemSize: 24
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: PF_R
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 4
+# CHECK-NEXT: }
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ Size: 4
+ AddressAlign: 16
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "F0000000E0000000D0000000C0000000B000000000100000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/base-address-64.test b/test/old-elf/Mips/base-address-64.test
new file mode 100644
index 0000000000000..6b553d2278201
--- /dev/null
+++ b/test/old-elf/Mips/base-address-64.test
@@ -0,0 +1,80 @@
+# Check executable base address configuration. Base address should be
+# equal to 0x400000 and the MIPS_BASE_ADDRESS dynamic tag's value should
+# be the same.
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el --noinhibit-exec -o %t.exe %t.o
+# RUN: llvm-readobj -dynamic-table -program-headers %t.exe | FileCheck %s
+
+# CHECK: DynamicSection [ (15 entries)
+# CHECK: Tag Type Name/Value
+# CHECK-NEXT: 0x0000000000000004 HASH 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x0000000000000005 STRTAB 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x0000000000000006 SYMTAB 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x000000000000000A STRSZ 1 (bytes)
+# CHECK-NEXT: 0x000000000000000B SYMENT 24 (bytes)
+# CHECK-NEXT: 0x0000000070000001 MIPS_RLD_VERSION 1
+# CHECK-NEXT: 0x0000000070000016 MIPS_RLD_MAP 0x120002000
+# CHECK-NEXT: 0x0000000070000035 MIPS_RLD_MAP_REL 0x1DB8
+# CHECK-NEXT: 0x0000000070000005 MIPS_FLAGS NOTPOT
+# CHECK-NEXT: 0x0000000070000006 MIPS_BASE_ADDRESS 0x120000000
+# CHECK-NEXT: 0x000000007000000A MIPS_LOCAL_GOTNO 2
+# CHECK-NEXT: 0x0000000070000011 MIPS_SYMTABNO 1
+# CHECK-NEXT: 0x0000000070000013 MIPS_GOTSYM 0x1
+# CHECK-NEXT: 0x0000000000000003 PLTGOT 0x120001000
+# CHECK-NEXT: 0x0000000000000000 NULL 0x0
+# CHECK-NEXT: ]
+
+# CHECK: ProgramHeaders [
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_PHDR (0x6)
+# CHECK: Offset: 0x40
+# CHECK: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK: }
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_INTERP (0x3)
+# CHECK: Offset: 0x190
+# CHECK: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK: }
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_LOAD (0x1)
+# CHECK-NEXT: Offset: 0x0
+# CHECK-NEXT: VirtualAddress: 0x120000000
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_64R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x10
+ Size: 0x00
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x10
+ Size: 0x00
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+ - Name: .bss
+ Type: STT_SECTION
+ Section: .bss
+ Global:
+ - Name: main
+ Section: .text
diff --git a/test/old-elf/Mips/base-address.test b/test/old-elf/Mips/base-address.test
new file mode 100644
index 0000000000000..67c04326cc154
--- /dev/null
+++ b/test/old-elf/Mips/base-address.test
@@ -0,0 +1,95 @@
+# Check executable base address configuration. Base address should be
+# equal to 0x400000 and the MIPS_BASE_ADDRESS dynamic tag's value should
+# be the same.
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel --noinhibit-exec -o %t.exe %t.o
+# RUN: llvm-readobj -dynamic-table -program-headers %t.exe | FileCheck %s
+
+# CHECK: DynamicSection [ (15 entries)
+# CHECK: Tag Type Name/Value
+# CHECK-NEXT: 0x00000004 HASH 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000005 STRTAB 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000006 SYMTAB 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x0000000A STRSZ 1 (bytes)
+# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes)
+# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1
+# CHECK-NEXT: 0x70000016 MIPS_RLD_MAP 0x402000
+# CHECK-NEXT: 0x70000035 MIPS_RLD_MAP_REL 0x1E9C
+# CHECK-NEXT: 0x70000005 MIPS_FLAGS NOTPOT
+# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x400000
+# CHECK-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 2
+# CHECK-NEXT: 0x70000011 MIPS_SYMTABNO 1
+# CHECK-NEXT: 0x70000013 MIPS_GOTSYM 0x1
+# CHECK-NEXT: 0x00000003 PLTGOT 0x401000
+# CHECK-NEXT: 0x00000000 NULL 0x0
+# CHECK-NEXT: ]
+
+# CHECK: ProgramHeaders [
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_PHDR (0x6)
+# CHECK: Offset: 0x34
+# CHECK: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK: }
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_INTERP (0x3)
+# CHECK: Offset: 0xF4
+# CHECK: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK: }
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_LOAD (0x1)
+# CHECK: Offset: 0x0
+# CHECK: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK: }
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_LOAD (0x1)
+# CHECK: Offset: 0x1000
+# CHECK: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK: }
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_LOAD (0x1)
+# CHECK: Offset: 0x2000
+# CHECK: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK: }
+# CHECK: ProgramHeader {
+# CHECK: Type: PT_DYNAMIC (0x2)
+# CHECK: Offset: 0x12C
+# CHECK: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK: }
+# CHECK: ]
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x00
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x00
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+ - Name: .bss
+ Type: STT_SECTION
+ Section: .bss
+ Global:
+ - Name: main
+ Section: .text
diff --git a/test/old-elf/Mips/ctors-order.test b/test/old-elf/Mips/ctors-order.test
new file mode 100644
index 0000000000000..b33ed43292e7b
--- /dev/null
+++ b/test/old-elf/Mips/ctors-order.test
@@ -0,0 +1,164 @@
+# Check ordering of .ctors.* sections.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-crtbeginS.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-crtendS.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-obj.o
+# RUN: lld -flavor old-gnu -target mipsel -shared --output-filetype=yaml \
+# RUN: %t-crtbeginS.o %t-obj.o %t-crtendS.o | FileCheck %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so \
+# RUN: %t-crtbeginS.o %t-obj.o %t-crtendS.o
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=RAW %s
+
+# CHECK: defined-atoms:
+# CHECK-NEXT: - type: data
+# CHECK-NEXT: alignment: 4
+# CHECK-NEXT: section-choice: custom-required
+# CHECK-NEXT: section-name: .ctors
+# CHECK-NEXT: references:
+# CHECK-NEXT: - kind: layout-after
+# CHECK-NEXT: offset: 0
+# CHECK-NEXT: target: __CTOR_LIST__
+# CHECK-NEXT: - name: __CTOR_LIST__
+# CHECK-NEXT: type: data
+# CHECK-NEXT: content: [ FF, FF, FF, FF ]
+# CHECK-NEXT: alignment: 4
+# CHECK-NEXT: section-choice: custom-required
+# CHECK-NEXT: section-name: .ctors
+# CHECK-NEXT: - type: data
+# CHECK-NEXT: content: [ 11, 11, 11, 11 ]
+# CHECK-NEXT: alignment: 4
+# CHECK-NEXT: section-choice: custom-required
+# CHECK-NEXT: section-name: .ctors.1
+# CHECK-NEXT: - type: data
+# CHECK-NEXT: content: [ 22, 22, 22, 22 ]
+# CHECK-NEXT: alignment: 4
+# CHECK-NEXT: section-choice: custom-required
+# CHECK-NEXT: section-name: .ctors.2
+# CHECK-NEXT: - ref-name: L004
+# CHECK-NEXT: type: data
+# CHECK-NEXT: alignment: 4
+# CHECK-NEXT: section-choice: custom-required
+# CHECK-NEXT: section-name: .ctors
+# CHECK-NEXT: references:
+# CHECK-NEXT: - kind: layout-after
+# CHECK-NEXT: offset: 0
+# CHECK-NEXT: target: __CTOR_END__
+# CHECK-NEXT: - name: __CTOR_END__
+# CHECK-NEXT: type: data
+# CHECK-NEXT: content: [ 00, 00, 00, 00 ]
+# CHECK-NEXT: alignment: 4
+# CHECK-NEXT: section-choice: custom-required
+# CHECK-NEXT: section-name: .ctors
+
+# RAW: Contents of section .ctors:
+# RAW-NEXT: 1000 ffffffff 11111111 22222222 00000000
+
+# crtbeginS.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .ctors
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Content: 'FFFFFFFF'
+
+Symbols:
+ Local:
+ - Name: .ctors
+ Type: STT_SECTION
+ Section: .ctors
+ - Name: __CTOR_LIST__
+ Type: STT_OBJECT
+ Section: .ctors
+
+# crtendS.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x0F
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: .ctors
+ Type: R_MIPS_GOT16
+ - Offset: 0x04
+ Symbol: .ctors
+ Type: R_MIPS_LO16
+ - Offset: 0x08
+ Symbol: .ctors
+ Type: R_MIPS_GOT16
+ - Offset: 0x0C
+ Symbol: .ctors
+ Type: R_MIPS_LO16
+ - Name: .ctors
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .ctors
+ Type: STT_SECTION
+ Section: .ctors
+ - Name: __CTOR_END__
+ Type: STT_OBJECT
+ Section: .ctors
+ - Name: __do_global_ctors_aux
+ Type: STT_FUNC
+ Section: .text
+
+# obj.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .ctors.2
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Content: '22222222'
+ - Name: .ctors.1
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Content: '11111111'
+
+Symbols:
+ Local:
+ - Name: .ctors.2
+ Type: STT_SECTION
+ Section: .ctors.2
+ - Name: .ctors.1
+ Type: STT_SECTION
+ Section: .ctors.1
+...
diff --git a/test/old-elf/Mips/driver-hash-style.test b/test/old-elf/Mips/driver-hash-style.test
new file mode 100644
index 0000000000000..0ab636c427c9f
--- /dev/null
+++ b/test/old-elf/Mips/driver-hash-style.test
@@ -0,0 +1,15 @@
+# REQUIRES: mips
+
+# Check that the driver rejects all --hash-style arguments except 'sysv'
+# because it is the only style supported by MIPS ABI.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: not lld -flavor old-gnu -target mips --hash-style=both %t.o -o %t.exe 2>&1 \
+# RUN: | FileCheck %s
+# RUN: not lld -flavor old-gnu -target mips --hash-style=gnu %t.o -o %t.exe 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: error: .gnu.hash is incompatible with the MIPS ABI
+
+ .globl __start;
+__start:
diff --git a/test/old-elf/Mips/dt-textrel-64.test b/test/old-elf/Mips/dt-textrel-64.test
new file mode 100644
index 0000000000000..152e823727998
--- /dev/null
+++ b/test/old-elf/Mips/dt-textrel-64.test
@@ -0,0 +1,74 @@
+# Check that if a dynamic relocation R_MIPS_64 modify a read-only section,
+# .dynamic section contains the DT_TEXTREL tag.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck %s
+
+# CHECK: 0x{{[0-9A-F]+}} TEXTREL
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x08
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x8
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_64
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/dt-textrel.test b/test/old-elf/Mips/dt-textrel.test
new file mode 100644
index 0000000000000..af86f4926273b
--- /dev/null
+++ b/test/old-elf/Mips/dt-textrel.test
@@ -0,0 +1,74 @@
+# Check that if a dynamic relocation modify a read-only section,
+# .dynamic section contains the DT_TEXTREL tag.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck %s
+
+# CHECK: 0x{{[0-9A-F]+}} TEXTREL
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x04
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x04
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: '00000000'
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_32
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/dynamic-linking.test b/test/old-elf/Mips/dynamic-linking.test
new file mode 100644
index 0000000000000..aeab7645ed518
--- /dev/null
+++ b/test/old-elf/Mips/dynamic-linking.test
@@ -0,0 +1,22 @@
+# REQUIRES: mips
+
+# Check _DYNAMIC_LINKING symbol definition.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: lld -flavor old-gnu -target mips %t.o -o %t.exe
+# RUN: llvm-nm %t.exe | FileCheck -check-prefix=EXE-DYN %s
+
+# EXE-DYN: 00000001 A _DYNAMIC_LINKING
+
+# RUN: lld -flavor old-gnu -target mips -static %t.o -o %t.exe
+# RUN: llvm-nm -just-symbol-name %t.exe | FileCheck -check-prefix=EXE-STATIC %s
+
+# EXE-STATIC-NOT: _DYNAMIC_LINKING
+
+# RUN: lld -flavor old-gnu -target mips -shared %t.o -o %t.so
+# RUN: llvm-nm -just-symbol-name %t.so | FileCheck -check-prefix=DYNLIB %s
+
+# DYNLIB-NOT: _DYNAMIC_LINKING
+
+ .globl __start;
+__start:
diff --git a/test/old-elf/Mips/dynamic-sym.test b/test/old-elf/Mips/dynamic-sym.test
new file mode 100644
index 0000000000000..43a69d82c3a33
--- /dev/null
+++ b/test/old-elf/Mips/dynamic-sym.test
@@ -0,0 +1,41 @@
+# Check _DYNAMIC symbol's value
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -e T0 -o %t.so %t.o
+# RUN: llvm-objdump -h -t %t.so | FileCheck -check-prefix=SHARED %s
+
+# SHARED: Sections:
+# SHARED: Idx Name Size Address Type
+# SHARED: 5 .dynamic 00000068 00000000[[ADDR:[0-9a-f]+]]
+
+# SHARED: SYMBOL TABLE:
+# SHARED: [[ADDR]] g .dynamic 00000000 _DYNAMIC
+
+# RUN: lld -flavor old-gnu -target mipsel -e main -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -h -t %t.exe | FileCheck -check-prefix=EXE %s
+
+# EXE: Sections:
+# EXE: Idx Name Size Address Type
+# EXE: 6 .dynamic 00000078 00000000[[ADDR:[0-9a-f]+]]
+
+# EXE: SYMBOL TABLE:
+# EXE: [[ADDR]] g .dynamic 00000000 _DYNAMIC
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ AddressAlign: 0x10
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
diff --git a/test/old-elf/Mips/dynlib-dynamic.test b/test/old-elf/Mips/dynlib-dynamic.test
new file mode 100644
index 0000000000000..fca036a52624f
--- /dev/null
+++ b/test/old-elf/Mips/dynlib-dynamic.test
@@ -0,0 +1,110 @@
+# Check MIPS specific tags in the dynamic table.
+
+# Build shared library
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec -o %t.so %t.o
+# RUN: llvm-readobj -dynamic-table %t.so | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mipsel
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: DynamicSection [ (13 entries)
+# CHECK: Tag Type Name/Value
+# CHECK-NEXT: 0x00000004 HASH 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000005 STRTAB 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000006 SYMTAB 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x0000000A STRSZ 17 (bytes)
+# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes)
+# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1
+# CHECK-NEXT: 0x70000005 MIPS_FLAGS NOTPOT
+# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x0
+# CHECK-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 4
+# CHECK-NEXT: 0x70000011 MIPS_SYMTABNO 4
+# CHECK-NEXT: 0x70000013 MIPS_GOTSYM 0x2
+# CHECK-NEXT: 0x00000003 PLTGOT 0x1000
+# CHECK-NEXT: 0x00000000 NULL 0x0
+# CHECK-NEXT: ]
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x18
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: '$.str1'
+ Type: R_MIPS_GOT16
+ - Offset: 0x04
+ Symbol: '$.str1'
+ Type: R_MIPS_LO16
+ - Offset: 0x08
+ Symbol: '$.str2'
+ Type: R_MIPS_GOT16
+ - Offset: 0x0C
+ Symbol: '$.str2'
+ Type: R_MIPS_LO16
+ - Offset: 0x10
+ Symbol: glob2
+ Type: R_MIPS_CALL16
+ - Offset: 0x14
+ Symbol: ext1
+ Type: R_MIPS_CALL16
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x00
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x00
+ - Name: .rodata.str1
+ Type: SHT_PROGBITS
+ AddressAlign: 0x01
+ Size: 0x05
+ - Name: .rodata.str2
+ Type: SHT_PROGBITS
+ AddressAlign: 0x01
+ Size: 0x05
+
+Symbols:
+ Local:
+ - Name: '$.str1'
+ Section: .rodata.str1
+ - Name: '$.str2'
+ Section: .rodata.str2
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+ - Name: .bss
+ Type: STT_SECTION
+ Section: .bss
+ - Name: .rodata.str1
+ Type: STT_SECTION
+ Section: .rodata.str1
+ - Name: .rodata.str2
+ Type: STT_SECTION
+ Section: .rodata.str2
+ Global:
+ - Name: glob
+ Section: .text
+ - Name: ext1
+ - Name: glob2
diff --git a/test/old-elf/Mips/dynlib-dynsym-micro.test b/test/old-elf/Mips/dynlib-dynsym-micro.test
new file mode 100644
index 0000000000000..6757847fac73d
--- /dev/null
+++ b/test/old-elf/Mips/dynlib-dynsym-micro.test
@@ -0,0 +1,208 @@
+# 1. Check sorting of .dynsym content accordingly to .got section
+# in case of using microMIPS relocations.
+# 2. Check that microMIPS records in a dynamic symbol table have:
+# - cleared the STO_MIPS_MICROMIPS flag
+# - adjusted adress
+
+# Build shared library
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec -o %t-so %t.o
+# RUN: llvm-readobj -dyn-symbols %t-so | FileCheck -check-prefix=CHECK-DYN %s
+
+# Build shared library (yaml format)
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec \
+# RUN: --output-filetype=yaml -o %t-yaml %t.o
+# RUN: FileCheck -check-prefix=CHECK-GOT %s < %t-yaml
+
+# CHECK-DYN: Format: ELF32-mips
+# CHECK-DYN: Arch: mipsel
+# CHECK-DYN: AddressSize: 32bit
+# CHECK-DYN: LoadName:
+# CHECK-DYN: DynamicSymbols [
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: @ (0)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Local (0x0)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: bar@ (5)
+# CHECK-DYN: Value: 0x139
+# CHECK-DYN: Size: 4
+# CHECK-DYN: Binding: Global (0x1)
+# CHECK-DYN: Type: Function (0x2)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: .text (0x4)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: foo@ (1)
+# CHECK-DYN: Value: 0x121
+# CHECK-DYN: Size: 24
+# CHECK-DYN: Binding: Global (0x1)
+# CHECK-DYN: Type: Function (0x2)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: .text (0x4)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: ext1@ (9)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Global (0x1)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: ext2@ (14)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Global (0x1)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: ]
+
+# CHECK-GOT: - type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: - type: got
+# CHECK-GOT: content: [ 00, 00, 00, 80 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: - ref-name: L000
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_32_HI16
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: L007
+# CHECK-GOT: - ref-name: L002
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_32_HI16
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: L008
+# CHECK-GOT: - ref-name: L004
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: foo
+# CHECK-GOT: - ref-name: L005
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: ext1
+# CHECK-GOT: - ref-name: L006
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: ext2
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x1C
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: .rodata.str1
+ Type: R_MICROMIPS_GOT16
+ - Offset: 0x04
+ Symbol: .rodata.str1
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x08
+ Symbol: .rodata.str2
+ Type: R_MICROMIPS_GOT16
+ - Offset: 0x0C
+ Symbol: .rodata.str2
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x10
+ Symbol: foo
+ Type: R_MICROMIPS_CALL16
+ - Offset: 0x14
+ Symbol: ext1
+ Type: R_MICROMIPS_CALL16
+ - Offset: 0x18
+ Symbol: ext2
+ Type: R_MICROMIPS_CALL16
+ - Name: .rodata.str1
+ Type: SHT_PROGBITS
+ AddressAlign: 0x01
+ Size: 0x05
+ - Name: .rodata.str2
+ Type: SHT_PROGBITS
+ AddressAlign: 0x01
+ Size: 0x05
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .rodata.str1
+ Type: STT_SECTION
+ Section: .rodata.str1
+ - Name: .rodata.str2
+ Type: STT_SECTION
+ Section: .rodata.str2
+ Global:
+ - Name: bar
+ Section: .text
+ Value: 0x18
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: foo
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: ext1
+ - Name: ext2
+...
diff --git a/test/old-elf/Mips/dynlib-dynsym.test b/test/old-elf/Mips/dynlib-dynsym.test
new file mode 100644
index 0000000000000..23b0cd6a90c22
--- /dev/null
+++ b/test/old-elf/Mips/dynlib-dynsym.test
@@ -0,0 +1,202 @@
+# Check sorting of .dynsym content accordingly to .got section.
+
+# Build shared library
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec -o %t-so %t.o
+# RUN: llvm-readobj -dyn-symbols %t-so | FileCheck -check-prefix=CHECK-DYN %s
+
+# Build shared library (yaml format)
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec \
+# RUN: --output-filetype=yaml -o %t-yaml %t.o
+# RUN: FileCheck -check-prefix=CHECK-GOT %s < %t-yaml
+
+# CHECK-DYN: Format: ELF32-mips
+# CHECK-DYN: Arch: mipsel
+# CHECK-DYN: AddressSize: 32bit
+# CHECK-DYN: LoadName:
+# CHECK-DYN: DynamicSymbols [
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: @ (0)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Local (0x0)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: bar@ (5)
+# CHECK-DYN: Value: 0x138
+# CHECK-DYN: Size: 4
+# CHECK-DYN: Binding: Global (0x1)
+# CHECK-DYN: Type: Function (0x2)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: .text (0x4)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: foo@ (1)
+# CHECK-DYN: Value: 0x120
+# CHECK-DYN: Size: 24
+# CHECK-DYN: Binding: Global (0x1)
+# CHECK-DYN: Type: Function (0x2)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: .text (0x4)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: ext1@ (9)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Global (0x1)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: ext2@ (14)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Global (0x1)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: ]
+
+# CHECK-GOT: - type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: - type: got
+# CHECK-GOT: content: [ 00, 00, 00, 80 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: - ref-name: L000
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_32_HI16
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: L007
+# CHECK-GOT: - ref-name: L002
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_32_HI16
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: L008
+# CHECK-GOT: - ref-name: L004
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: foo
+# CHECK-GOT: - ref-name: L005
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: ext1
+# CHECK-GOT: - ref-name: L006
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: ext2
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x1C
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: .rodata.str1
+ Type: R_MIPS_GOT16
+ - Offset: 0x04
+ Symbol: .rodata.str1
+ Type: R_MIPS_LO16
+ - Offset: 0x08
+ Symbol: .rodata.str2
+ Type: R_MIPS_GOT16
+ - Offset: 0x0C
+ Symbol: .rodata.str2
+ Type: R_MIPS_LO16
+ - Offset: 0x10
+ Symbol: foo
+ Type: R_MIPS_CALL16
+ - Offset: 0x14
+ Symbol: ext1
+ Type: R_MIPS_CALL16
+ - Offset: 0x18
+ Symbol: ext2
+ Type: R_MIPS_CALL16
+ - Name: .rodata.str1
+ Type: SHT_PROGBITS
+ AddressAlign: 0x01
+ Size: 0x05
+ - Name: .rodata.str2
+ Type: SHT_PROGBITS
+ AddressAlign: 0x01
+ Size: 0x05
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .rodata.str1
+ Type: STT_SECTION
+ Section: .rodata.str1
+ - Name: .rodata.str2
+ Type: STT_SECTION
+ Section: .rodata.str2
+ Global:
+ - Name: bar
+ Section: .text
+ Value: 0x18
+ - Name: foo
+ Section: .text
+ - Name: ext1
+ - Name: ext2
+...
diff --git a/test/old-elf/Mips/dynlib-fileheader-64.test b/test/old-elf/Mips/dynlib-fileheader-64.test
new file mode 100644
index 0000000000000..f3b45d4d738e7
--- /dev/null
+++ b/test/old-elf/Mips/dynlib-fileheader-64.test
@@ -0,0 +1,72 @@
+# Check ELF Header for 64-bit shared library.
+
+# Build shared library
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Format: ELF64-mips
+# CHECK: Arch: mips64el
+# CHECK: AddressSize: 64bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 64-bit (0x2)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 0
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: SharedObject (0x3)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x80000006)
+# CHECK: EF_MIPS_ARCH_64R2 (0x80000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_PIC (0x2)
+# CHECK: ]
+# CHECK: HeaderSize: 64
+# CHECK: ProgramHeaderEntrySize: 56
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 64
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+ Global:
+ - Name: data
+ Type: STT_OBJECT
+ Section: .data
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/dynlib-fileheader-micro-64.test b/test/old-elf/Mips/dynlib-fileheader-micro-64.test
new file mode 100644
index 0000000000000..531cee134cafb
--- /dev/null
+++ b/test/old-elf/Mips/dynlib-fileheader-micro-64.test
@@ -0,0 +1,75 @@
+# Check ELF Header for shared library in case of microMIPS symbols.
+
+# Build shared library
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Format: ELF64-mips
+# CHECK-NEXT: Arch: mips64el
+# CHECK-NEXT: AddressSize: 64bit
+# CHECK-NEXT: LoadName:
+# CHECK-NEXT: ElfHeader {
+# CHECK-NEXT: Ident {
+# CHECK-NEXT: Magic: (7F 45 4C 46)
+# CHECK-NEXT: Class: 64-bit (0x2)
+# CHECK-NEXT: DataEncoding: LittleEndian (0x1)
+# CHECK-NEXT: FileVersion: 1
+# CHECK-NEXT: OS/ABI: SystemV (0x0)
+# CHECK-NEXT: ABIVersion: 0
+# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
+# CHECK-NEXT: }
+# CHECK-NEXT: Type: SharedObject (0x3)
+# CHECK-NEXT: Machine: EM_MIPS (0x8)
+# CHECK-NEXT: Version: 1
+# CHECK-NEXT: Entry: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: Flags [ (0x82000007)
+# CHECK-NEXT: EF_MIPS_ARCH_64R2 (0x80000000)
+# CHECK-NEXT: EF_MIPS_CPIC (0x4)
+# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000)
+# CHECK-NEXT: EF_MIPS_NOREORDER (0x1)
+# CHECK-NEXT: EF_MIPS_PIC (0x2)
+# CHECK-NEXT: ]
+# CHECK-NEXT: HeaderSize: 64
+# CHECK-NEXT: ProgramHeaderEntrySize: 56
+# CHECK-NEXT: ProgramHeaderCount: {{[0-9]+}}
+# CHECK-NEXT: SectionHeaderEntrySize: 64
+# CHECK-NEXT: SectionHeaderCount: {{[0-9]+}}
+# CHECK-NEXT: StringTableSectionIndex: {{[0-9]+}}
+# CHECK-NEXT:}
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_MICROMIPS, EF_MIPS_ARCH_64R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+ Global:
+ - Name: foo
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ Other: [ STO_MIPS_MICROMIPS ]
diff --git a/test/old-elf/Mips/dynlib-fileheader-micro.test b/test/old-elf/Mips/dynlib-fileheader-micro.test
new file mode 100644
index 0000000000000..dcd38f1036d08
--- /dev/null
+++ b/test/old-elf/Mips/dynlib-fileheader-micro.test
@@ -0,0 +1,79 @@
+# Check ELF Header for shared library in case of microMIPS symbols.
+
+# Build shared library
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK-NEXT: Arch: mipsel
+# CHECK-NEXT: AddressSize: 32bit
+# CHECK-NEXT: LoadName:
+# CHECK-NEXT: ElfHeader {
+# CHECK-NEXT: Ident {
+# CHECK-NEXT: Magic: (7F 45 4C 46)
+# CHECK-NEXT: Class: 32-bit (0x1)
+# CHECK-NEXT: DataEncoding: LittleEndian (0x1)
+# CHECK-NEXT: FileVersion: 1
+# CHECK-NEXT: OS/ABI: SystemV (0x0)
+# CHECK-NEXT: ABIVersion: 0
+# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
+# CHECK-NEXT: }
+# CHECK-NEXT: Type: SharedObject (0x3)
+# CHECK-NEXT: Machine: EM_MIPS (0x8)
+# CHECK-NEXT: Version: 1
+# CHECK-NEXT: Entry: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: Flags [ (0x72001007)
+# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# CHECK-NEXT: EF_MIPS_ARCH_32R2 (0x70000000)
+# CHECK-NEXT: EF_MIPS_CPIC (0x4)
+# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000)
+# CHECK-NEXT: EF_MIPS_NOREORDER (0x1)
+# CHECK-NEXT: EF_MIPS_PIC (0x2)
+# CHECK-NEXT: ]
+# CHECK-NEXT: HeaderSize: 52
+# CHECK-NEXT: ProgramHeaderEntrySize: 32
+# CHECK-NEXT: ProgramHeaderCount: {{[0-9]+}}
+# CHECK-NEXT: SectionHeaderEntrySize: 40
+# CHECK-NEXT: SectionHeaderCount: {{[0-9]+}}
+# CHECK-NEXT: StringTableSectionIndex: {{[0-9]+}}
+# CHECK-NEXT:}
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x00
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x00
+ - Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x08
+ ISA: MIPS32
+ ISARevision: 2
+ ASEs: [ MICROMIPS ]
+
+Symbols:
+ Global:
+ - Name: glob
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
diff --git a/test/old-elf/Mips/dynlib-fileheader.test b/test/old-elf/Mips/dynlib-fileheader.test
new file mode 100644
index 0000000000000..a3b4a19a90f1e
--- /dev/null
+++ b/test/old-elf/Mips/dynlib-fileheader.test
@@ -0,0 +1,76 @@
+# Check ELF Header for shared library.
+
+# Build shared library
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mipsel
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 32-bit (0x1)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 0
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: SharedObject (0x3)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x70001007)
+# CHECK: EF_MIPS_ABI_O32 (0x1000)
+# CHECK: EF_MIPS_ARCH_32R2 (0x70000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: EF_MIPS_PIC (0x2)
+# CHECK: ]
+# CHECK: HeaderSize: 52
+# CHECK: ProgramHeaderEntrySize: 32
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 40
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK:}
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x00
+ - Name: .bss
+ Type: SHT_NOBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x00
+ - Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x08
+ ISA: MIPS32
+ ISARevision: 2
+
+Symbols:
+ Global:
+ - Name: glob
+ Section: .text
diff --git a/test/old-elf/Mips/dynsym-table-1.test b/test/old-elf/Mips/dynsym-table-1.test
new file mode 100644
index 0000000000000..8821ae3582543
--- /dev/null
+++ b/test/old-elf/Mips/dynsym-table-1.test
@@ -0,0 +1,127 @@
+# Check that LLD does not populate an executable file dynamic symbol table
+# by unnecessary symbols.
+# 1. bar.so defines T2
+# 2. foo.so defines T1 and references T2
+# 3. main.o reference T1
+# 4. a.out dynamic table should contain T1 entry only
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-bar.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-foo.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-main.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t-bar.so %t-bar.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t-foo.so %t-foo.o %t-bar.so
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe --as-needed \
+# RUN: %t-main.o %t-foo.so %t-bar.so
+# RUN: llvm-readobj -dt -dynamic-table %t.exe | FileCheck %s
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T1@ ({{.*}})
+# CHECK-NEXT: Value: {{.*}}
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 8
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: 0x00000003 PLTGOT 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000001 NEEDED SharedLibrary (dynsym-table-1.test.tmp-foo.so)
+# CHECK-NEXT: 0x00000000 NULL 0x0
+
+# bar.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+Symbols:
+ Global:
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+
+# foo.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x08
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T2
+ Type: R_MIPS_CALL16
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ - Name: T2
+
+# main.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x08
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_32
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/dynsym-table-2.test b/test/old-elf/Mips/dynsym-table-2.test
new file mode 100644
index 0000000000000..ad85bfe84e43c
--- /dev/null
+++ b/test/old-elf/Mips/dynsym-table-2.test
@@ -0,0 +1,105 @@
+# Check that LLD does not populate a shared library dynamic symbol table
+# by unnecessary symbols.
+# 1. bar.so defines T2 and T3
+# 2. foo.so defines T1 and references T2
+# 4. foo.so dynamic table should contain T1 and T2 entries only
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-bar.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-foo.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t-bar.so %t-bar.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t-foo.so %t-foo.o %t-bar.so
+# RUN: llvm-readobj -dt -dynamic-table %t-foo.so | FileCheck %s
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T1@ ({{.*}})
+# CHECK-NEXT: Value: {{.*}}
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .text (0x4)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T2@ ({{.*}})
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: 0x00000003 PLTGOT 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000001 NEEDED SharedLibrary (dynsym-table-2.test.tmp-bar.so)
+# CHECK-NEXT: 0x00000000 NULL 0x0
+
+# bar.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+Symbols:
+ Global:
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ - Name: T3
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x04
+ Size: 0x04
+
+# foo.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x08
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T2
+ Type: R_MIPS_CALL16
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/e-flags-merge-1-64.test b/test/old-elf/Mips/e-flags-merge-1-64.test
new file mode 100644
index 0000000000000..3e52afd223cdc
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-1-64.test
@@ -0,0 +1,30 @@
+# Check that the linker shows an error when object
+# file has unsupported ASE flags.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-mips16.o
+# RUN: not lld -flavor old-gnu -target mips64el -e T -o %t.exe %t-mips16.o 2>&1 | \
+# RUN: FileCheck -check-prefix=MIPS16 %s
+
+# MIPS16: Unsupported extension: MIPS16
+
+# mips16.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64, EF_MIPS_ARCH_ASE_M16]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Global:
+ - Name: T
+ Section: .text
+...
diff --git a/test/old-elf/Mips/e-flags-merge-1.test b/test/old-elf/Mips/e-flags-merge-1.test
new file mode 100644
index 0000000000000..bc100534112df
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-1.test
@@ -0,0 +1,56 @@
+# Check that the linker shows an error when object file has missed
+# or unsupported ABI and ARCH flags or unsupported ASE flags.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-no-abi.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T -o %t.exe %t-no-abi.o 2>&1 | \
+# RUN: FileCheck -check-prefix=INVALID-ABI %s
+
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-mips16.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T -o %t.exe %t-mips16.o 2>&1 | \
+# RUN: FileCheck -check-prefix=MIPS16 %s
+
+# INVALID-ABI: Unsupported ABI
+# MIPS16: Unsupported extension: MIPS16
+
+# no-abi.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: []
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T
+ Section: .text
+
+# mips16.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_ARCH_ASE_M16]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T
+ Section: .text
+...
diff --git a/test/old-elf/Mips/e-flags-merge-10.test b/test/old-elf/Mips/e-flags-merge-10.test
new file mode 100644
index 0000000000000..5dacaa0e069d0
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-10.test
@@ -0,0 +1,43 @@
+# Check that LLD shows an error and does not link files with mips32r2
+# and mips32r6 instructions sets.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32r2.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-32r6.o
+
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so \
+# RUN: %t-32r2.o %t-32r6.o 2>&1 | FileCheck %s
+
+# CHECK: Linking modules with incompatible ISA
+
+# 32r2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# 32r6.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/e-flags-merge-11.test b/test/old-elf/Mips/e-flags-merge-11.test
new file mode 100644
index 0000000000000..e61eb0d6d65a2
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-11.test
@@ -0,0 +1,43 @@
+# Check that LLD shows an error and does not link files with mips64r2
+# and mips64r6 instructions sets.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-64r2.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64r6.o
+
+# RUN: not lld -flavor old-gnu -target mips64el -shared -o %t.so \
+# RUN: %t-64r2.o %t-64r6.o 2>&1 | FileCheck %s
+
+# CHECK: Linking modules with incompatible ISA
+
+# 64r2.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# 64r6.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64R6]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/e-flags-merge-12.test b/test/old-elf/Mips/e-flags-merge-12.test
new file mode 100644
index 0000000000000..0a0c43fc996a2
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-12.test
@@ -0,0 +1,44 @@
+# Check that LLD shows an error and does not link files with O32 and N32 ABIs.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-o32.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-n32.o
+
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so \
+# RUN: %t-o32.o %t-n32.o 2>&1 | FileCheck %s
+
+# CHECK: Linking modules with incompatible ABI
+
+# o32.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_32BITMODE, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# n32.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI2,
+ EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/e-flags-merge-2-64.test b/test/old-elf/Mips/e-flags-merge-2-64.test
new file mode 100644
index 0000000000000..4e024d2a465bf
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-2-64.test
@@ -0,0 +1,33 @@
+# Check that the linker copies ELF header flags from the single input object
+# file to the generated executable
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -e T -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Flags [ (0x62000001)
+# CHECK-NEXT: EF_MIPS_ARCH_64 (0x60000000)
+# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000)
+# CHECK-NEXT: EF_MIPS_NOREORDER (0x1)
+# CHECK-NEXT: ]
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ARCH_64, EF_MIPS_NOREORDER, EF_MIPS_MICROMIPS ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Global:
+ - Name: T
+ Section: .text
+...
diff --git a/test/old-elf/Mips/e-flags-merge-2.test b/test/old-elf/Mips/e-flags-merge-2.test
new file mode 100644
index 0000000000000..3ca5317287286
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-2.test
@@ -0,0 +1,35 @@
+# Check that the linker copies ELF header flags from the single input object
+# file to the generated executable
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Flags [ (0x52001001)
+# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# CHECK-NEXT: EF_MIPS_ARCH_32 (0x50000000)
+# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000)
+# CHECK-NEXT: EF_MIPS_NOREORDER (0x1)
+# CHECK-NEXT: ]
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+ EF_MIPS_NOREORDER, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T
+ Section: .text
+...
diff --git a/test/old-elf/Mips/e-flags-merge-3-64.test b/test/old-elf/Mips/e-flags-merge-3-64.test
new file mode 100644
index 0000000000000..45326813e12f7
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-3-64.test
@@ -0,0 +1,130 @@
+# Check PIC/CPIC flags merging in case of multiple input objects.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-none.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-cpic.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 4 %s > %t-both.o
+
+# RUN: lld -flavor old-gnu -target mips64el -e T1 -o %t-abi1.exe \
+# RUN: %t-none.o %t-pic.o 2>&1 | FileCheck -check-prefix=ABI-CALLS-WARN %s
+# RUN: llvm-readobj -file-headers %t-abi1.exe \
+# RUN: | FileCheck -check-prefix=ABI-CALLS1 %s
+
+# RUN: lld -flavor old-gnu -target mips64el -e T1 -o %t-abi2.exe \
+# RUN: %t-cpic.o %t-none.o 2>&1 | FileCheck -check-prefix=ABI-CALLS-WARN %s
+# RUN: llvm-readobj -file-headers %t-abi2.exe \
+# RUN: | FileCheck -check-prefix=ABI-CALLS2 %s
+
+# RUN: lld -flavor old-gnu -target mips64el -e T2 -o %t-cpic.exe %t-cpic.o %t-pic.o
+# RUN: llvm-readobj -file-headers %t-cpic.exe | FileCheck -check-prefix=CPIC %s
+
+# RUN: lld -flavor old-gnu -target mips64el -e T3 -o %t-both.exe %t-pic.o %t-both.o
+# RUN: llvm-readobj -file-headers %t-both.exe | FileCheck -check-prefix=BOTH %s
+
+# ABI-CALLS-WARN: lld warning: linking abicalls and non-abicalls files
+
+# ABI-CALLS1: Flags [ (0x60000004)
+# ABI-CALLS1-NEXT: EF_MIPS_ARCH_64 (0x60000000)
+# ABI-CALLS1-NEXT: EF_MIPS_CPIC (0x4)
+# ABI-CALLS1-NEXT: ]
+
+# ABI-CALLS2: Flags [ (0x60000004)
+# ABI-CALLS2-NEXT: EF_MIPS_ARCH_64 (0x60000000)
+# ABI-CALLS2-NEXT: EF_MIPS_CPIC (0x4)
+# ABI-CALLS2-NEXT: ]
+
+# CPIC: Flags [ (0x60000004)
+# CPIC-NEXT: EF_MIPS_ARCH_64 (0x60000000)
+# CPIC-NEXT: EF_MIPS_CPIC (0x4)
+# CPIC-NEXT: ]
+
+# BOTH: Flags [ (0x60000006)
+# BOTH-NEXT: EF_MIPS_ARCH_64 (0x60000000)
+# BOTH-NEXT: EF_MIPS_CPIC (0x4)
+# BOTH-NEXT: EF_MIPS_PIC (0x2)
+# BOTH-NEXT: ]
+
+# none.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+
+# cpic.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64, EF_MIPS_CPIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64, EF_MIPS_PIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Global:
+ - Name: T3
+ Section: .text
+
+# both.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64, EF_MIPS_CPIC, EF_MIPS_PIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Global:
+ - Name: T4
+ Section: .text
+...
diff --git a/test/old-elf/Mips/e-flags-merge-3.test b/test/old-elf/Mips/e-flags-merge-3.test
new file mode 100644
index 0000000000000..612f0b458631a
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-3.test
@@ -0,0 +1,134 @@
+# Check PIC/CPIC flags merging in case of multiple input objects.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-none.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-cpic.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 4 %s > %t-both.o
+
+# RUN: lld -flavor old-gnu -target mipsel -e T1 -o %t-abi1.exe \
+# RUN: %t-none.o %t-pic.o 2>&1 | FileCheck -check-prefix=ABI-CALLS-WARN %s
+# RUN: llvm-readobj -file-headers %t-abi1.exe \
+# RUN: | FileCheck -check-prefix=ABI-CALLS1 %s
+
+# RUN: lld -flavor old-gnu -target mipsel -e T1 -o %t-abi2.exe \
+# RUN: %t-cpic.o %t-none.o 2>&1 | FileCheck -check-prefix=ABI-CALLS-WARN %s
+# RUN: llvm-readobj -file-headers %t-abi2.exe \
+# RUN: | FileCheck -check-prefix=ABI-CALLS2 %s
+
+# RUN: lld -flavor old-gnu -target mipsel -e T2 -o %t-cpic.exe %t-cpic.o %t-pic.o
+# RUN: llvm-readobj -file-headers %t-cpic.exe | FileCheck -check-prefix=CPIC %s
+
+# RUN: lld -flavor old-gnu -target mipsel -e T3 -o %t-both.exe %t-pic.o %t-both.o
+# RUN: llvm-readobj -file-headers %t-both.exe | FileCheck -check-prefix=BOTH %s
+
+# ABI-CALLS-WARN: lld warning: linking abicalls and non-abicalls files
+
+# ABI-CALLS1: Flags [ (0x50001004)
+# ABI-CALLS1-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# ABI-CALLS1-NEXT: EF_MIPS_ARCH_32 (0x50000000)
+# ABI-CALLS1-NEXT: EF_MIPS_CPIC (0x4)
+# ABI-CALLS1-NEXT: ]
+
+# ABI-CALLS2: Flags [ (0x50001004)
+# ABI-CALLS2-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# ABI-CALLS2-NEXT: EF_MIPS_ARCH_32 (0x50000000)
+# ABI-CALLS2-NEXT: EF_MIPS_CPIC (0x4)
+# ABI-CALLS2-NEXT: ]
+
+# CPIC: Flags [ (0x50001004)
+# CPIC-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# CPIC-NEXT: EF_MIPS_ARCH_32 (0x50000000)
+# CPIC-NEXT: EF_MIPS_CPIC (0x4)
+# CPIC-NEXT: ]
+
+# BOTH: Flags [ (0x50001006)
+# BOTH-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# BOTH-NEXT: EF_MIPS_ARCH_32 (0x50000000)
+# BOTH-NEXT: EF_MIPS_CPIC (0x4)
+# BOTH-NEXT: EF_MIPS_PIC (0x2)
+# BOTH-NEXT: ]
+
+# none.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+
+# cpic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_PIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T3
+ Section: .text
+
+# both.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_PIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T4
+ Section: .text
+...
diff --git a/test/old-elf/Mips/e-flags-merge-4-64.test b/test/old-elf/Mips/e-flags-merge-4-64.test
new file mode 100644
index 0000000000000..59a8bf131d95f
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-4-64.test
@@ -0,0 +1,64 @@
+# Check ELF flags merging.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-none.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-noreorder.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o
+
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so \
+# RUN: %t-none.o %t-noreorder.o %t-micro.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Flags [ (0x82000001)
+# CHECK-NEXT: EF_MIPS_ARCH_64R2 (0x80000000)
+# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000)
+# CHECK-NEXT: EF_MIPS_NOREORDER (0x1)
+# CHECK-NEXT: ]
+
+# none.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_5]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+# noreorder.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64, EF_MIPS_NOREORDER]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+# micro.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64R2, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+...
diff --git a/test/old-elf/Mips/e-flags-merge-4.test b/test/old-elf/Mips/e-flags-merge-4.test
new file mode 100644
index 0000000000000..6a2de375e6249
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-4.test
@@ -0,0 +1,65 @@
+# Check ELF flags merging.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-none.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-noreorder.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so \
+# RUN: %t-none.o %t-noreorder.o %t-micro.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Flags [ (0x52001001)
+# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# CHECK-NEXT: EF_MIPS_ARCH_32 (0x50000000)
+# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000)
+# CHECK-NEXT: EF_MIPS_NOREORDER (0x1)
+# CHECK-NEXT: ]
+
+# none.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# noreorder.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_NOREORDER]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# micro.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/e-flags-merge-5-64.test b/test/old-elf/Mips/e-flags-merge-5-64.test
new file mode 100644
index 0000000000000..f1fdac2c8c059
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-5-64.test
@@ -0,0 +1,42 @@
+# Check that LLD does not allow to mix 32 and 64-bit MIPS object files.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64.o
+
+# RUN: not lld -flavor old-gnu -target mips64el -shared -o %t.so \
+# RUN: %t-32.o %t-64.o 2>&1 | FileCheck %s
+
+# CHECK: ELF64 expected, but got ELF32
+
+# 32.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# 64.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+...
diff --git a/test/old-elf/Mips/e-flags-merge-5.test b/test/old-elf/Mips/e-flags-merge-5.test
new file mode 100644
index 0000000000000..56edc4bfa10ff
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-5.test
@@ -0,0 +1,42 @@
+# Check that LLD does not allow to mix 32 and 64-bit MIPS object files.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64.o
+
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so \
+# RUN: %t-32.o %t-64.o 2>&1 | FileCheck %s
+
+# CHECK: ELF32 expected, but got ELF64
+
+# 32.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# 64.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/e-flags-merge-6-64.test b/test/old-elf/Mips/e-flags-merge-6-64.test
new file mode 100644
index 0000000000000..9f83365441af4
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-6-64.test
@@ -0,0 +1,79 @@
+# Check selecting ELF header ARCH flag.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-m3.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-m5.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-m64.o
+# RUN: yaml2obj -format=elf -docnum 4 %s > %t-m64r2.o
+
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so \
+# RUN: %t-m64.o %t-m5.o %t-m64r2.o %t-m3.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Flags [ (0x80000000)
+# CHECK-NEXT: EF_MIPS_ARCH_64R2 (0x80000000)
+# CHECK-NEXT: ]
+
+# m3.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_3]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+# m5.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_5]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+# m64.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+# m64r2.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+...
diff --git a/test/old-elf/Mips/e-flags-merge-6.test b/test/old-elf/Mips/e-flags-merge-6.test
new file mode 100644
index 0000000000000..0d8bcee5ad646
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-6.test
@@ -0,0 +1,80 @@
+# Check selecting ELF header ARCH flag.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-m1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-m2.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-m32.o
+# RUN: yaml2obj -format=elf -docnum 4 %s > %t-m32r2.o
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so \
+# RUN: %t-m32.o %t-m2.o %t-m32r2.o %t-m1.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Flags [ (0x70001000)
+# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# CHECK-NEXT: EF_MIPS_ARCH_32R2 (0x70000000)
+# CHECK-NEXT: ]
+
+# m1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_1]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# m2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# m32.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# m32r2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/e-flags-merge-7-64.test b/test/old-elf/Mips/e-flags-merge-7-64.test
new file mode 100644
index 0000000000000..0e74ac53684a2
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-7-64.test
@@ -0,0 +1,42 @@
+# Check that LLD does not allow to mix nan2008 and legacy MIPS object files.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-2008.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-legacy.o
+
+# RUN: not lld -flavor old-gnu -target mips64el -shared -o %t.so \
+# RUN: %t-2008.o %t-legacy.o 2>&1 | FileCheck %s
+
+# CHECK: Linking -mnan=2008 and -mnan=legacy modules
+
+# 2008.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64, EF_MIPS_NAN2008]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+# legacy.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+...
diff --git a/test/old-elf/Mips/e-flags-merge-7.test b/test/old-elf/Mips/e-flags-merge-7.test
new file mode 100644
index 0000000000000..08051df506be3
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-7.test
@@ -0,0 +1,42 @@
+# Check that LLD does not allow to mix nan2008 and legacy MIPS object files.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-2008.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-legacy.o
+
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so \
+# RUN: %t-2008.o %t-legacy.o 2>&1 | FileCheck %s
+
+# CHECK: Linking -mnan=2008 and -mnan=legacy modules
+
+# 2008.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_NAN2008]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# legacy.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/e-flags-merge-8.test b/test/old-elf/Mips/e-flags-merge-8.test
new file mode 100644
index 0000000000000..2a2fdfee3c463
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-8.test
@@ -0,0 +1,65 @@
+# Check that LLD links files with mips32 and mips64 instructions
+# if all these files satisfy O32 ABI.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-64r2.o
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-32.o %t-64.o %t-64r2.o
+# RUN: llvm-readobj -file-headers %t.so | FileCheck %s
+
+# CHECK: Flags [ (0x80001100)
+# CHECK-NEXT: EF_MIPS_32BITMODE (0x100)
+# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# CHECK-NEXT: EF_MIPS_ARCH_64R2 (0x80000000)
+# CHECK-NEXT: ]
+
+
+# 32.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# 64.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_64, EF_MIPS_32BITMODE]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# 64r2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_64R2, EF_MIPS_32BITMODE]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/e-flags-merge-9.test b/test/old-elf/Mips/e-flags-merge-9.test
new file mode 100644
index 0000000000000..ada24d788c9ac
--- /dev/null
+++ b/test/old-elf/Mips/e-flags-merge-9.test
@@ -0,0 +1,43 @@
+# Check that LLD shows an error and does not link files with mips32r2
+# and mips64 instructions sets.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-32r2.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-64.o
+
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so \
+# RUN: %t-32r2.o %t-64.o 2>&1 | FileCheck %s
+
+# CHECK: Linking modules with incompatible ISA
+
+# 32r2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+# 64.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_64, EF_MIPS_32BITMODE]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/entry-name.test b/test/old-elf/Mips/entry-name.test
new file mode 100644
index 0000000000000..f6ce0c4f223b0
--- /dev/null
+++ b/test/old-elf/Mips/entry-name.test
@@ -0,0 +1,26 @@
+# Check name of executable entry symbol.
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel --noinhibit-exec -o %t.exe %t.o
+# RUN: llvm-nm %t.exe | FileCheck %s
+
+# CHECK: U __start
+# CHECK: {{[0-9A-F]+}} T main
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: main
+ Section: .text
diff --git a/test/old-elf/Mips/exe-dynamic.test b/test/old-elf/Mips/exe-dynamic.test
new file mode 100644
index 0000000000000..93fdce9fdc7dd
--- /dev/null
+++ b/test/old-elf/Mips/exe-dynamic.test
@@ -0,0 +1,110 @@
+# Check MIPS specific tags in the dynamic table in case executable linking.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mipsel
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: DynamicSection [ (20 entries)
+# CHECK: Tag Type Name/Value
+# CHECK-NEXT: 0x00000004 HASH 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000005 STRTAB 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000006 SYMTAB 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x0000000A STRSZ 28 (bytes)
+# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes)
+# CHECK-NEXT: 0x00000002 PLTRELSZ 8 (bytes)
+# CHECK-NEXT: 0x70000032 MIPS_PLTGOT 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000014 PLTREL REL
+# CHECK-NEXT: 0x00000017 JMPREL 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1
+# CHECK-NEXT: 0x70000016 MIPS_RLD_MAP 0x40200C
+# CHECK-NEXT: 0x70000035 MIPS_RLD_MAP_REL 0x1E0C
+# CHECK-NEXT: 0x70000005 MIPS_FLAGS NOTPOT
+# CHECK-NEXT: 0x70000006 MIPS_BASE_ADDRESS 0x400000
+# CHECK-NEXT: 0x7000000A MIPS_LOCAL_GOTNO 2
+# CHECK-NEXT: 0x70000011 MIPS_SYMTABNO 2
+# CHECK-NEXT: 0x70000013 MIPS_GOTSYM 0x2
+# CHECK-NEXT: 0x00000003 PLTGOT 0x{{[0-9A-F]+}}
+# CHECK-NEXT: 0x00000001 NEEDED SharedLibrary (exe-dynamic.test.tmp.so)
+# CHECK-NEXT: 0x00000000 NULL 0x0
+# CHECK-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: 0000000C000000000000000C000000000000000C00000000
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_26
+ Addend: 0
+ - Offset: 0x08
+ Symbol: .text
+ Type: R_MIPS_26
+ Addend: 0
+ - Offset: 0x10
+ Symbol: glob
+ Type: R_MIPS_26
+ Addend: 0
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ Value: 0x08
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/exe-dynsym-micro.test b/test/old-elf/Mips/exe-dynsym-micro.test
new file mode 100644
index 0000000000000..477e174f3d6c3
--- /dev/null
+++ b/test/old-elf/Mips/exe-dynsym-micro.test
@@ -0,0 +1,94 @@
+# Check that symbol referenced by an entry in the global part of GOT
+# has a corresponded entry in the .dynsym section. This test covers
+# the case when the GOT entry created because of the R_MICROMIPS_GOT16
+# relocation.
+
+# Build executable
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t.o
+# RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck -check-prefix=CHECK-DYN %s
+
+# Build executabl (yaml format)e
+# RUN: lld -flavor old-gnu -target mipsel -e glob \
+# RUN: --output-filetype=yaml -o %t.yaml %t.o
+# RUN: FileCheck -check-prefix=CHECK-GOT %s < %t.yaml
+
+# CHECK-DYN: Format: ELF32-mips
+# CHECK-DYN: Arch: mipsel
+# CHECK-DYN: AddressSize: 32bit
+# CHECK-DYN: LoadName:
+# CHECK-DYN: DynamicSymbols [
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: @ (0)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Local (0x0)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: weakf@ (1)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Weak (0x2)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: ]
+
+# CHECK-GOT: - type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: - type: got
+# CHECK-GOT: content: [ 00, 00, 00, 80 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: - ref-name: L000
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: weakf
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: weakf
+ Type: R_MICROMIPS_GOT16
+
+Symbols:
+ Global:
+ - Name: glob
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
+ Weak:
+ - Name: weakf
diff --git a/test/old-elf/Mips/exe-dynsym.test b/test/old-elf/Mips/exe-dynsym.test
new file mode 100644
index 0000000000000..c50ce67d5f57b
--- /dev/null
+++ b/test/old-elf/Mips/exe-dynsym.test
@@ -0,0 +1,91 @@
+# Check that symbol referenced by an entry in the global part of GOT
+# has a corresponded entry in the .dynsym section.
+
+# Build executable
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t.o
+# RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck -check-prefix=CHECK-DYN %s
+
+# Build executabl (yaml format)e
+# RUN: lld -flavor old-gnu -target mipsel -e glob \
+# RUN: --output-filetype=yaml -o %t.yaml %t.o
+# RUN: FileCheck -check-prefix=CHECK-GOT %s < %t.yaml
+
+# CHECK-DYN: Format: ELF32-mips
+# CHECK-DYN: Arch: mipsel
+# CHECK-DYN: AddressSize: 32bit
+# CHECK-DYN: LoadName:
+# CHECK-DYN: DynamicSymbols [
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: @ (0)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Local (0x0)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: Symbol {
+# CHECK-DYN: Name: weakf@ (1)
+# CHECK-DYN: Value: 0x0
+# CHECK-DYN: Size: 0
+# CHECK-DYN: Binding: Weak (0x2)
+# CHECK-DYN: Type: None (0x0)
+# CHECK-DYN: Other: 0
+# CHECK-DYN: Section: Undefined (0x0)
+# CHECK-DYN: }
+# CHECK-DYN: ]
+
+# CHECK-GOT: - type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: - type: got
+# CHECK-GOT: content: [ 00, 00, 00, 80 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: - ref-name: L000
+# CHECK-GOT: type: got
+# CHECK-GOT: content: [ 00, 00, 00, 00 ]
+# CHECK-GOT: alignment: 4
+# CHECK-GOT: section-choice: custom-required
+# CHECK-GOT: section-name: .got
+# CHECK-GOT: permissions: rw-
+# CHECK-GOT: references:
+# CHECK-GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# CHECK-GOT: offset: 0
+# CHECK-GOT: target: weakf
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: weakf
+ Type: R_MIPS_GOT16
+
+Symbols:
+ Global:
+ - Name: glob
+ Section: .text
+ Weak:
+ - Name: weakf
diff --git a/test/old-elf/Mips/exe-fileheader-02.test b/test/old-elf/Mips/exe-fileheader-02.test
new file mode 100644
index 0000000000000..b3cd88c139b65
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader-02.test
@@ -0,0 +1,62 @@
+# Check that LLD set ABIVersion to '1' if it generates executable
+# file without EF_MIPS_PIC in the ELF header.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mipsel
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 32-bit (0x1)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 1
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x50001005)
+# CHECK: EF_MIPS_ABI_O32 (0x1000)
+# CHECK: EF_MIPS_ARCH_32 (0x50000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: ]
+# CHECK: HeaderSize: 52
+# CHECK: ProgramHeaderEntrySize: 32
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 40
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+...
diff --git a/test/old-elf/Mips/exe-fileheader-03.test b/test/old-elf/Mips/exe-fileheader-03.test
new file mode 100644
index 0000000000000..dfe4fcc43e672
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader-03.test
@@ -0,0 +1,72 @@
+# Check that LLD set ABIVersion to '3' if it generates executable
+# file with FP_64 / FP_64A floating point abi flags.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mipsel
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 32-bit (0x1)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 3
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x50001005)
+# CHECK: EF_MIPS_ABI_O32 (0x1000)
+# CHECK: EF_MIPS_ARCH_32 (0x50000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: ]
+# CHECK: HeaderSize: 52
+# CHECK: ProgramHeaderEntrySize: 32
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 40
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .MIPS.abiflags
+ Type: SHT_MIPS_ABIFLAGS
+ AddressAlign: 8
+ ISA: MIPS32
+ ISARevision: 1
+ ISAExtension: EXT_NONE
+ FpABI: FP_64
+ GPRSize: REG_32
+ CPR1Size: REG_64
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+...
diff --git a/test/old-elf/Mips/exe-fileheader-64.test b/test/old-elf/Mips/exe-fileheader-64.test
new file mode 100644
index 0000000000000..20bb43a216d59
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader-64.test
@@ -0,0 +1,66 @@
+# Check ELF Header for 64-bit executable file.
+
+# Build executable
+# RUN: yaml2obj -format=elf %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -e glob -o %t.exe %t-o.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF64-mips
+# CHECK: Arch: mips64el
+# CHECK: AddressSize: 64bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 64-bit (0x2)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 0
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x60000007)
+# CHECK: EF_MIPS_ARCH_64 (0x60000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: EF_MIPS_PIC (0x2)
+# CHECK: ]
+# CHECK: HeaderSize: 64
+# CHECK: ProgramHeaderEntrySize: 56
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 64
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_64 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+...
diff --git a/test/old-elf/Mips/exe-fileheader-be-64.test b/test/old-elf/Mips/exe-fileheader-be-64.test
new file mode 100644
index 0000000000000..70457fe217c66
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader-be-64.test
@@ -0,0 +1,60 @@
+# Check ELF Header for non-pic big-endian 64-bit executable file.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64 -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF64-mips
+# CHECK: Arch: mips64
+# CHECK: AddressSize: 64bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 64-bit (0x2)
+# CHECK: DataEncoding: BigEndian (0x2)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 0
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x60000007)
+# CHECK: EF_MIPS_ARCH_64 (0x60000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: EF_MIPS_PIC (0x2)
+# CHECK: ]
+# CHECK: HeaderSize: 64
+# CHECK: ProgramHeaderEntrySize: 56
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 64
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+...
diff --git a/test/old-elf/Mips/exe-fileheader-be.test b/test/old-elf/Mips/exe-fileheader-be.test
new file mode 100644
index 0000000000000..292a92e590978
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader-be.test
@@ -0,0 +1,60 @@
+# Check ELF Header for non-pic big-endian 32-bit executable file.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mips
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 32-bit (0x1)
+# CHECK: DataEncoding: BigEndian (0x2)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 1
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x50001005)
+# CHECK: EF_MIPS_ABI_O32 (0x1000)
+# CHECK: EF_MIPS_ARCH_32 (0x50000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: ]
+# CHECK: HeaderSize: 52
+# CHECK: ProgramHeaderEntrySize: 32
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 40
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+...
diff --git a/test/old-elf/Mips/exe-fileheader-micro-64.test b/test/old-elf/Mips/exe-fileheader-micro-64.test
new file mode 100644
index 0000000000000..a37d2d7106376
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader-micro-64.test
@@ -0,0 +1,68 @@
+# Check ELF Header for 64-bit executable file in case of microMIPS entry symbol.
+
+# Build executable
+# RUN: yaml2obj -format=elf %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -e glob -o %t.exe %t-o.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF64-mips
+# CHECK: Arch: mips64el
+# CHECK: AddressSize: 64bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 64-bit (0x2)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 0
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x82000007)
+# CHECK: EF_MIPS_ARCH_64R2 (0x80000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_MICROMIPS (0x2000000)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: EF_MIPS_PIC (0x2)
+# CHECK: ]
+# CHECK: HeaderSize: 64
+# CHECK: ProgramHeaderEntrySize: 56
+# CHECK: ProgramHeaderCount: 6
+# CHECK: SectionHeaderEntrySize: 64
+# CHECK: SectionHeaderCount: 12
+# CHECK: StringTableSectionIndex: 9
+# CHECK: }
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_MICROMIPS, EF_MIPS_ARCH_64R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
+...
diff --git a/test/old-elf/Mips/exe-fileheader-micro.test b/test/old-elf/Mips/exe-fileheader-micro.test
new file mode 100644
index 0000000000000..0adaf5b173738
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader-micro.test
@@ -0,0 +1,69 @@
+# Check ELF Header for non-pic executable file in case
+# of microMIPS entry symbol.
+
+# Build executable
+# RUN: yaml2obj -format=elf %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t-o.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK-NEXT: Arch: mipsel
+# CHECK-NEXT: AddressSize: 32bit
+# CHECK-NEXT: LoadName:
+# CHECK-NEXT: ElfHeader {
+# CHECK-NEXT: Ident {
+# CHECK-NEXT: Magic: (7F 45 4C 46)
+# CHECK-NEXT: Class: 32-bit (0x1)
+# CHECK-NEXT: DataEncoding: LittleEndian (0x1)
+# CHECK-NEXT: FileVersion: 1
+# CHECK-NEXT: OS/ABI: SystemV (0x0)
+# CHECK-NEXT: ABIVersion: 1
+# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
+# CHECK-NEXT: }
+# CHECK-NEXT: Type: Executable (0x2)
+# CHECK-NEXT: Machine: EM_MIPS (0x8)
+# CHECK-NEXT: Version: 1
+# CHECK-NEXT: Entry: 0x{{[0-9A-F]+[13579bdf]}}
+# CHECK-NEXT: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: Flags [ (0x72001005)
+# CHECK-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# CHECK-NEXT: EF_MIPS_ARCH_32R2 (0x70000000)
+# CHECK-NEXT: EF_MIPS_CPIC (0x4)
+# CHECK-NEXT: EF_MIPS_MICROMIPS (0x2000000)
+# CHECK-NEXT: EF_MIPS_NOREORDER (0x1)
+# CHECK-NEXT: ]
+# CHECK-NEXT: HeaderSize: 52
+# CHECK-NEXT: ProgramHeaderEntrySize: 32
+# CHECK-NEXT: ProgramHeaderCount: 6
+# CHECK-NEXT: SectionHeaderEntrySize: 40
+# CHECK-NEXT: SectionHeaderCount: 12
+# CHECK-NEXT: StringTableSectionIndex: 9
+# CHECK-NEXT: }
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
+...
diff --git a/test/old-elf/Mips/exe-fileheader-n32.test b/test/old-elf/Mips/exe-fileheader-n32.test
new file mode 100644
index 0000000000000..f6a1725b4443c
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader-n32.test
@@ -0,0 +1,65 @@
+# Check ELF Header for N32 ABI executable file.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -o %t.exe %t.o
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK-NEXT: Arch: mipsel
+# CHECK-NEXT: AddressSize: 32bit
+# CHECK-NEXT: LoadName:
+# CHECK-NEXT: ElfHeader {
+# CHECK-NEXT: Ident {
+# CHECK-NEXT: Magic: (7F 45 4C 46)
+# CHECK-NEXT: Class: 32-bit
+# CHECK-NEXT: DataEncoding: LittleEndian
+# CHECK-NEXT: FileVersion: 1
+# CHECK-NEXT: OS/ABI: SystemV
+# CHECK-NEXT: ABIVersion: 0
+# CHECK-NEXT: Unused: (00 00 00 00 00 00 00)
+# CHECK-NEXT: }
+# CHECK-NEXT: Type: Executable
+# CHECK-NEXT: Machine: EM_MIPS
+# CHECK-NEXT: Version: 1
+# CHECK-NEXT: Entry: 0x10000130
+# CHECK-NEXT: ProgramHeaderOffset: 0x34
+# CHECK-NEXT: SectionHeaderOffset: 0x22C0
+# CHECK-NEXT: Flags [ (0x60000027)
+# CHECK-NEXT: EF_MIPS_ABI2
+# CHECK-NEXT: EF_MIPS_ARCH_64
+# CHECK-NEXT: EF_MIPS_CPIC
+# CHECK-NEXT: EF_MIPS_NOREORDER
+# CHECK-NEXT: EF_MIPS_PIC
+# CHECK-NEXT: ]
+# CHECK-NEXT: HeaderSize: 52
+# CHECK-NEXT: ProgramHeaderEntrySize: 32
+# CHECK-NEXT: ProgramHeaderCount: {{[0-9]+}}
+# CHECK-NEXT: SectionHeaderEntrySize: 40
+# CHECK-NEXT: SectionHeaderCount: {{[0-9]+}}
+# CHECK-NEXT: StringTableSectionIndex: {{[0-9]+}}
+# CHECK-NEXT: }
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI2, EF_MIPS_ARCH_64 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 8
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: __start
+ Section: .text
+...
diff --git a/test/old-elf/Mips/exe-fileheader.test b/test/old-elf/Mips/exe-fileheader.test
new file mode 100644
index 0000000000000..0188a682b3fbd
--- /dev/null
+++ b/test/old-elf/Mips/exe-fileheader.test
@@ -0,0 +1,105 @@
+# Check ELF Header for non-pic executable file.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
+
+# CHECK: Format: ELF32-mips
+# CHECK: Arch: mipsel
+# CHECK: AddressSize: 32bit
+# CHECK: LoadName:
+# CHECK: ElfHeader {
+# CHECK: Ident {
+# CHECK: Magic: (7F 45 4C 46)
+# CHECK: Class: 32-bit (0x1)
+# CHECK: DataEncoding: LittleEndian (0x1)
+# CHECK: FileVersion: 1
+# CHECK: OS/ABI: SystemV (0x0)
+# CHECK: ABIVersion: 1
+# CHECK: Unused: (00 00 00 00 00 00 00)
+# CHECK: }
+# CHECK: Type: Executable (0x2)
+# CHECK: Machine: EM_MIPS (0x8)
+# CHECK: Version: 1
+# CHECK: Entry: 0x{{[0-9A-F]+}}
+# CHECK: ProgramHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: SectionHeaderOffset: 0x{{[0-9A-F]+}}
+# CHECK: Flags [ (0x50001005)
+# CHECK: EF_MIPS_ABI_O32 (0x1000)
+# CHECK: EF_MIPS_ARCH_32 (0x50000000)
+# CHECK: EF_MIPS_CPIC (0x4)
+# CHECK: EF_MIPS_NOREORDER (0x1)
+# CHECK: ]
+# CHECK: HeaderSize: 52
+# CHECK: ProgramHeaderEntrySize: 32
+# CHECK: ProgramHeaderCount: {{[0-9]+}}
+# CHECK: SectionHeaderEntrySize: 40
+# CHECK: SectionHeaderCount: {{[0-9]+}}
+# CHECK: StringTableSectionIndex: {{[0-9]+}}
+# CHECK: }
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_26
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/exe-got-micro.test b/test/old-elf/Mips/exe-got-micro.test
new file mode 100644
index 0000000000000..7b3a919880de0
--- /dev/null
+++ b/test/old-elf/Mips/exe-got-micro.test
@@ -0,0 +1,115 @@
+# Check that external symbol defined in the executable file
+# and referenced by R_MICROMIPS_CALL16 relocation has a corresponded
+# entry in the local GOT section.
+#
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob \
+# RUN: --output-filetype=yaml -o %t.exe %t-o.o %t.so
+# RUN: FileCheck -check-prefix=GOT %s < %t.exe
+
+# GOT header
+# GOT: - type: got
+# GOT: content: [ 00, 00, 00, 00 ]
+# GOT: alignment: 4
+# GOT: section-choice: custom-required
+# GOT: section-name: .got
+# GOT: permissions: rw-
+# GOT: - type: got
+# GOT: content: [ 00, 00, 00, 80 ]
+# GOT: alignment: 4
+# GOT: section-choice: custom-required
+# GOT: section-name: .got
+# GOT: permissions: rw-
+# Local GOT entry for 'glob' symbol
+# GOT: - ref-name: L000
+# GOT: type: got
+# GOT: content: [ 00, 00, 00, 00 ]
+# GOT: alignment: 4
+# GOT: section-choice: custom-required
+# GOT: section-name: .got
+# GOT: permissions: rw-
+# GOT: references:
+# GOT: - kind: R_MIPS_32
+# GOT: offset: 0
+# GOT: target: glob
+# Global GOT entry for 'T1' symbol
+# GOT: - ref-name: L001
+# GOT: type: got
+# GOT: content: [ 00, 00, 00, 00 ]
+# GOT: alignment: 4
+# GOT: section-choice: custom-required
+# GOT: section-name: .got
+# GOT: permissions: rw-
+# GOT: references:
+# GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# GOT: offset: 0
+# GOT: target: T1
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: glob
+ Type: R_MICROMIPS_CALL16
+ - Offset: 0x04
+ Symbol: T1
+ Type: R_MICROMIPS_CALL16
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/exe-got.test b/test/old-elf/Mips/exe-got.test
new file mode 100644
index 0000000000000..636de16b4202c
--- /dev/null
+++ b/test/old-elf/Mips/exe-got.test
@@ -0,0 +1,116 @@
+# Check that external symbol defined in the executable file
+# and referenced by R_MIPS_CALL16 relocation has a corresponded
+# entry in the local GOT section.
+#
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob \
+# RUN: --output-filetype=yaml -o %t.exe %t-o.o %t.so
+# RUN: FileCheck -check-prefix=GOT %s < %t.exe
+
+# GOT header
+# GOT: - type: got
+# GOT: content: [ 00, 00, 00, 00 ]
+# GOT: alignment: 4
+# GOT: section-choice: custom-required
+# GOT: section-name: .got
+# GOT: permissions: rw-
+# GOT: - type: got
+# GOT: content: [ 00, 00, 00, 80 ]
+# GOT: alignment: 4
+# GOT: section-choice: custom-required
+# GOT: section-name: .got
+# GOT: permissions: rw-
+# Local GOT entry for 'glob' symbol
+# GOT: - ref-name: L000
+# GOT: type: got
+# GOT: content: [ 00, 00, 00, 00 ]
+# GOT: alignment: 4
+# GOT: section-choice: custom-required
+# GOT: section-name: .got
+# GOT: permissions: rw-
+# GOT: references:
+# GOT: - kind: R_MIPS_32
+# GOT: offset: 0
+# GOT: target: glob
+# Global GOT entry for 'T1' symbol
+# GOT: - ref-name: L001
+# GOT: type: got
+# GOT: content: [ 00, 00, 00, 00 ]
+# GOT: alignment: 4
+# GOT: section-choice: custom-required
+# GOT: section-name: .got
+# GOT: permissions: rw-
+# GOT: references:
+# GOT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# GOT: offset: 0
+# GOT: target: T1
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: glob
+ Type: R_MIPS_CALL16
+ Addend: 0
+ - Offset: 0x04
+ Symbol: T1
+ Type: R_MIPS_CALL16
+ Addend: 0
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/got-page-32-micro.test b/test/old-elf/Mips/got-page-32-micro.test
new file mode 100644
index 0000000000000..5457ab9f18793
--- /dev/null
+++ b/test/old-elf/Mips/got-page-32-micro.test
@@ -0,0 +1,251 @@
+# Check handling of R_MICROMIPS_GOT_DISP / PAGE / OFST relocations
+# in case of O32 ABI.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \
+# RUN: | FileCheck -check-prefix=GOT %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# GOT: Symbol {
+# GOT: Name: LT3
+# GOT-NEXT: Value: 0x[[LT3:[0-9A-F]+]]
+# GOT: Symbol {
+# GOT: Name: LT4
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: T0
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: LT1
+# GOT-NEXT: Value: 0x[[LT1:[0-9A-F]+]]
+# GOT: Symbol {
+# GOT: Name: LT2
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: T1@
+# GOT-NEXT: Value: 0x0
+# GOT: Symbol {
+# GOT: Name: T2@
+# GOT-NEXT: Value: 0x0
+
+# GOT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x408FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401004
+# GOT-NEXT: Access: -32748
+# GOT-NEXT: Initial: 0x80000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x[[LT1]]
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x[[LT3]]
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40101C
+# GOT-NEXT: Access: -32724
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+# RAW: Contents of section .text:
+# RAW-NEXT: {{[0-9a-f]+}} 00002c80 00001880 00002c80 00003080
+# ^ = -32724 (T1)
+# ^ = -32744 (LT1)
+# ^ -32724 (T1)
+# ^ -32720 (T2)
+# RAW-NEXT: {{[0-9a-f]+}} 00001c80 00002080 00000000 00000000
+# ^ -32740 (PAGE)
+# ^ -32736 (PAGE)
+# ^ T1 OFST
+# ^ T2 OFST
+# RAW-NEXT: {{[0-9a-f]+}} 0000a501 0000a901 00002480 00002880
+# ^ LT1 OFST
+# ^ LT2 OFST
+# ^ = -32732 (LT3)
+# ^ -32728 (PAGE)
+# RAW-NEXT: {{[0-9a-f]+}} 0000b101 00000000
+# ^ LT4 OFST
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_32R2, EF_MIPS_ABI_O32, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 0x4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_32R2, EF_MIPS_ABI_O32, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x38
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_DISP
+ - Offset: 0x4
+ Symbol: LT1
+ Type: R_MICROMIPS_GOT_DISP
+ - Offset: 0x8
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0xC
+ Symbol: T2
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0x14
+ Symbol: LT2
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_OFST
+ - Offset: 0x1C
+ Symbol: T2
+ Type: R_MICROMIPS_GOT_OFST
+ - Offset: 0x20
+ Symbol: LT1
+ Type: R_MICROMIPS_GOT_OFST
+ - Offset: 0x24
+ Symbol: LT2
+ Type: R_MICROMIPS_GOT_OFST
+ - Offset: 0x28
+ Symbol: LT3
+ Type: R_MICROMIPS_GOT_DISP
+ - Offset: 0x2C
+ Symbol: LT4
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0x30
+ Symbol: LT4
+ Type: R_MICROMIPS_GOT_OFST
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: LT3
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x30
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT4
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x34
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x28
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x2c
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/got-page-32.test b/test/old-elf/Mips/got-page-32.test
new file mode 100644
index 0000000000000..44f45536d5016
--- /dev/null
+++ b/test/old-elf/Mips/got-page-32.test
@@ -0,0 +1,244 @@
+# Check handling of R_MIPS_GOT_DISP / PAGE / OFST relocations.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \
+# RUN: | FileCheck -check-prefix=GOT %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# GOT: Symbol {
+# GOT: Name: LT3 (12)
+# GOT-NEXT: Value: 0x[[LT3:[0-9A-F]+]]
+# GOT: Symbol {
+# GOT: Name: LT4 (16)
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: T0 (1)
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: LT1 (4)
+# GOT-NEXT: Value: 0x[[LT1:[0-9A-F]+]]
+# GOT: Symbol {
+# GOT: Name: LT2 (8)
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: T1@ (1)
+# GOT-NEXT: Value: 0x0
+# GOT: Symbol {
+# GOT: Name: T2@ (4)
+# GOT-NEXT: Value: 0x0
+
+# GOT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x408FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401004
+# GOT-NEXT: Access: -32748
+# GOT-NEXT: Initial: 0x80000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x[[LT1]]
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x[[LT3]]
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40101C
+# GOT-NEXT: Access: -32724
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+# RAW: Contents of section .text:
+# RAW-NEXT: {{[0-9a-f]+}} 2c800000 18800000 2c800000 30800000
+# ^ = -32724 (T1)
+# ^ = -32744 (LT1)
+# ^ -32724 (T1)
+# ^ -32720 (T2)
+# RAW-NEXT: {{[0-9a-f]+}} 1c800000 20800000 00000000 00000000
+# ^ -32740 (PAGE)
+# ^ -32736 (PAGE)
+# ^ T1 OFST
+# ^ T2 OFST
+# RAW-NEXT: {{[0-9a-f]+}} 9c010000 a0010000 24800000 28800000
+# ^ LT1 OFST
+# ^ LT2 OFST
+# ^ = -32732 (LT3)
+# ^ -32728 (PAGE)
+# RAW-NEXT: {{[0-9a-f]+}} a8010000 00000000
+# ^ LT4 OFST
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_32, EF_MIPS_ABI_O32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 0x4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_32, EF_MIPS_ABI_O32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x38
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x4
+ Symbol: LT1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x8
+ Symbol: T1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0xC
+ Symbol: T2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x14
+ Symbol: LT2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x1C
+ Symbol: T2
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x20
+ Symbol: LT1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x24
+ Symbol: LT2
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x28
+ Symbol: LT3
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x2C
+ Symbol: LT4
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x30
+ Symbol: LT4
+ Type: R_MIPS_GOT_OFST
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: LT3
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x30
+ Size: 0x4
+ - Name: LT4
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x34
+ Size: 0x4
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x28
+ Size: 0x4
+ - Name: LT2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x2c
+ Size: 0x4
+ - Name: T1
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/got-page-64-micro.test b/test/old-elf/Mips/got-page-64-micro.test
new file mode 100644
index 0000000000000..37bae77001e4a
--- /dev/null
+++ b/test/old-elf/Mips/got-page-64-micro.test
@@ -0,0 +1,210 @@
+# Check handling of R_MICROMIPS_GOT_DISP / PAGE / OFST relocations
+# in case of N64 ABI.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \
+# RUN: | FileCheck -check-prefix=GOT %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# GOT: Symbol {
+# GOT: Name: T0
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: LT1
+# GOT-NEXT: Value: 0x[[LT1:[0-9A-F]+]]
+# GOT: Symbol {
+# GOT: Name: LT2
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: T1@
+# GOT-NEXT: Value: 0x0
+# GOT: Symbol {
+# GOT: Name: T2@
+# GOT-NEXT: Value: 0x0
+
+# GOT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x120008FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x8000000000000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x[[LT1]]
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x120000000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x120000000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001028
+# GOT-NEXT: Access: -32712
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001030
+# GOT-NEXT: Access: -32704
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+# RAW: Contents of section .text:
+# RAW-NEXT: {{[0-9a-f]+}} 38800000 20800000 38800000 40800000
+# ^ = -32712 (T1)
+# ^ = -32736 (LT1)
+# ^ -32712 (T1)
+# ^ -32704 (T2)
+# RAW-NEXT: {{[0-9a-f]+}} 28800000 30800000 00000000 00000000
+# ^ -32728 (PAGE)
+# ^ -32720 (PAGE)
+# ^ T1 OFST
+# ^ T2 OFST
+# RAW-NEXT: {{[0-9a-f]+}} 59020000 5d020000 00000000 00000000
+# ^ LT1 OFST
+# ^ LT2 OFST
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_64R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 0x4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_64R2, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x30
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x4
+ Symbol: LT1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x8
+ Symbol: T1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0xC
+ Symbol: T2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x14
+ Symbol: LT2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x1C
+ Symbol: T2
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x20
+ Symbol: LT1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x24
+ Symbol: LT2
+ Type: R_MIPS_GOT_OFST
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x28
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x2c
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/got-page-64.test b/test/old-elf/Mips/got-page-64.test
new file mode 100644
index 0000000000000..3c6ef57c78f50
--- /dev/null
+++ b/test/old-elf/Mips/got-page-64.test
@@ -0,0 +1,203 @@
+# Check handling of R_MIPS_GOT_DISP / PAGE / OFST relocations.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \
+# RUN: | FileCheck -check-prefix=GOT %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# GOT: Symbol {
+# GOT: Name: T0 (1)
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: LT1 (4)
+# GOT-NEXT: Value: 0x[[LT1:[0-9A-F]+]]
+# GOT: Symbol {
+# GOT: Name: LT2 (8)
+# GOT-NEXT: Value: 0x{{[0-9A-F]+}}
+# GOT: Symbol {
+# GOT: Name: T1@ (1)
+# GOT-NEXT: Value: 0x0
+# GOT: Symbol {
+# GOT: Name: T2@ (4)
+# GOT-NEXT: Value: 0x0
+
+# GOT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x120008FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x8000000000000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x[[LT1]]
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x120000000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x120000000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001028
+# GOT-NEXT: Access: -32712
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001030
+# GOT-NEXT: Access: -32704
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+# RAW: Contents of section .text:
+# RAW-NEXT: {{[0-9a-f]+}} 38800000 20800000 38800000 40800000
+# ^ = -32712 (T1)
+# ^ = -32736 (LT1)
+# ^ -32712 (T1)
+# ^ -32704 (T2)
+# RAW-NEXT: {{[0-9a-f]+}} 28800000 30800000 00000000 00000000
+# ^ -32728 (PAGE)
+# ^ -32720 (PAGE)
+# ^ T1 OFST
+# ^ T2 OFST
+# RAW-NEXT: {{[0-9a-f]+}} 50020000 54020000 00000000 00000000
+# ^ LT1 OFST
+# ^ LT2 OFST
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 0x4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x30
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x4
+ Symbol: LT1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x8
+ Symbol: T1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0xC
+ Symbol: T2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x14
+ Symbol: LT2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x1C
+ Symbol: T2
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x20
+ Symbol: LT1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x24
+ Symbol: LT2
+ Type: R_MIPS_GOT_OFST
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x28
+ Size: 0x4
+ - Name: LT2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x2c
+ Size: 0x4
+ - Name: T1
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/got16-2.test b/test/old-elf/Mips/got16-2.test
new file mode 100644
index 0000000000000..01f11a5920cd2
--- /dev/null
+++ b/test/old-elf/Mips/got16-2.test
@@ -0,0 +1,73 @@
+# Check handling of R_MIPS_GOT16 relocation against local
+# symbols when addresses of local data cross 64 KBytes border.
+
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t-exe %t-obj
+# RUN: llvm-objdump -s %t-exe | FileCheck %s
+
+# CHECK: Contents of section .got:
+# CHECK-NEXT: 40a000 00000000 00000080 00004000 00004100 ..........@...A.
+# lazy module 0x400000 0x410000
+# resolver pointer for L1 for L2
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: '00000000000000000000000000000000'
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Address: 0x1000
+ Relocations:
+ - Offset: 0
+ Symbol: L1
+ Type: R_MIPS_GOT16
+ - Offset: 4
+ Symbol: L1
+ Type: R_MIPS_LO16
+ - Offset: 8
+ Symbol: L2
+ Type: R_MIPS_GOT16
+ - Offset: 12
+ Symbol: L2
+ Type: R_MIPS_LO16
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x9000
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: L1
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0x00
+ Size: 0x8000
+ - Name: L2
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0x8000
+ Size: 0x04
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
diff --git a/test/old-elf/Mips/got16-micro.test b/test/old-elf/Mips/got16-micro.test
new file mode 100644
index 0000000000000..25de08e95c4e3
--- /dev/null
+++ b/test/old-elf/Mips/got16-micro.test
@@ -0,0 +1,165 @@
+# REQUIRES: mips
+
+# Check handling of global/local R_MICROMIPS_GOT16 relocations.
+# RUN: llvm-mc -triple=mipsel -mattr=micromips -relocation-model=pic \
+# RUN: -filetype=obj -o=%t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec \
+# RUN: --output-filetype=yaml %t.o \
+# RUN: | FileCheck -check-prefix YAML %s
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec -o %t2 %t.o
+# RUN: llvm-objdump -t -disassemble -mattr=micromips %t2 \
+# RUN: | FileCheck -check-prefix RAW %s
+
+# Function glob
+# YAML: - name: main
+# YAML: scope: global
+# YAML: content: [ 5C, FC, 00, 00, 42, 30, 00, 00, 5C, FC, 00, 00,
+# YAML: 42, 30, 00, 00, 5C, FC, 00, 00, 5C, FC, 00, 00,
+# YAML: 5C, FC, 00, 00 ]
+# YAML: alignment: 4 mod 16
+# YAML: code-model: mips-micro
+# YAML: references:
+# YAML-NEXT: - kind: R_MICROMIPS_GOT16
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: L000
+# YAML-NEXT: - kind: R_MICROMIPS_LO16
+# YAML-NEXT: offset: 4
+# YAML-NEXT: target: data_1
+# YAML-NEXT: - kind: R_MICROMIPS_GOT16
+# YAML-NEXT: offset: 8
+# YAML-NEXT: target: L001
+# YAML-NEXT: - kind: R_MICROMIPS_LO16
+# YAML-NEXT: offset: 12
+# YAML-NEXT: target: data_2
+# YAML-NEXT: - kind: R_MICROMIPS_GOT16
+# YAML-NEXT: offset: 16
+# YAML-NEXT: target: L002
+# YAML-NEXT: - kind: R_MICROMIPS_CALL16
+# YAML-NEXT: offset: 20
+# YAML-NEXT: target: L003
+# YAML-NEXT: - kind: R_MICROMIPS_CALL16
+# YAML-NEXT: offset: 24
+# YAML-NEXT: target: L004
+
+# Local GOT entries:
+# YAML: - ref-name: L000
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: LLD_R_MIPS_32_HI16
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: data_1
+# YAML-NEXT: - ref-name: L001
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: LLD_R_MIPS_32_HI16
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: data_2
+# YAML-NEXT: - ref-name: L002
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: R_MIPS_32
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: data_h
+
+# Global GOT entries:
+# YAML-NEXT: - ref-name: L003
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: bar
+# YAML-NEXT: - kind: R_MIPS_32
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: bar
+# YAML-NEXT: - ref-name: L004
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: foo
+
+# RAW: Disassembly of section .text:
+# RAW: main:
+# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 18 80 lw $2, -32744($gp)
+# RAW-NEXT: {{[0x0-9a-f]+}}: 42 30 40 10 addiu $2, $2, 4160
+# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 1c 80 lw $2, -32740($gp)
+# RAW-NEXT: {{[0x0-9a-f]+}}: 42 30 60 20 addiu $2, $2, 8288
+# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 20 80 lw $2, -32736($gp)
+# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 24 80 lw $2, -32732($gp)
+# RAW-NEXT: {{[0x0-9a-f]+}}: 5c fc 28 80 lw $2, -32728($gp)
+
+# RAW: SYMBOL TABLE:
+# RAW: {{[0x0-9a-f]+}} *UND* 00000000
+# RAW: {{[0x0-9a-f]+}} l .data 00001020 data_1
+# RAW: {{[0x0-9a-f]+}} l .data 00000001 data_2
+# RAW: {{[0x0-9a-f]+}} g F .text 00000004 bar
+# RAW: {{[0x0-9a-f]+}} g F .text 0000001c main
+# RAW: {{[0x0-9a-f]+}} g .data 00000001 data_h
+
+ .data
+ .type data_1, @object
+ .size data_1, 4128
+data_1:
+ .byte 1
+ .space 4127
+ .type data_2, @object
+ .size data_2, 1
+data_2:
+ .byte 2
+ .hidden data_h
+ .globl data_h
+ .type data_h, @object
+ .size data_h, 1
+data_h:
+ .byte 3
+
+ .text
+ .globl bar
+ .set micromips
+ .ent bar
+ .type bar, @function
+bar:
+ nop
+ .end bar
+ .size bar, .-bar
+
+ .globl main
+ .set micromips
+ .ent main
+ .type main, @function
+main:
+ lw $2,%got(data_1)($28)
+ addiu $2,$2,%lo(data_1)
+ lw $2,%got(data_2)($28)
+ addiu $2,$2,%lo(data_2)
+ lw $2,%got(data_h)($28)
+ lw $2,%call16(bar)($28)
+ lw $2,%call16(foo)($28)
+
+ .end main
+ .size main, .-main
diff --git a/test/old-elf/Mips/got16.test b/test/old-elf/Mips/got16.test
new file mode 100644
index 0000000000000..4dde15a11c263
--- /dev/null
+++ b/test/old-elf/Mips/got16.test
@@ -0,0 +1,196 @@
+# REQUIRES: mips
+
+# Check handling of global/local GOT16 relocations.
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec \
+# RUN: --output-filetype=yaml %t.o \
+# RUN: | FileCheck -check-prefix YAML %s
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec -o %t2 %t.o
+# RUN: llvm-objdump -t -disassemble %t2 | FileCheck -check-prefix RAW %s
+
+# Function glob
+# YAML: - name: glob
+# YAML: scope: global
+# YAML: content: [ 00, 00, 84, 8F, 00, 00, 84, 24, 01, 00, 84, 8F,
+# YAML: 00, 02, 84, 24, 00, 00, 84, 8F, 00, 00, 84, 8F,
+# YAML: 00, 00, 84, 8F ]
+# YAML: alignment: 4
+# YAML: references:
+# YAML: - kind: R_MIPS_GOT16
+# YAML: offset: 0
+# YAML: target: L000
+# YAML: - kind: R_MIPS_LO16
+# YAML: offset: 4
+# YAML: target: L009
+# YAML: - kind: R_MIPS_GOT16
+# YAML: offset: 8
+# YAML: target: L002
+# YAML: addend: 66048
+# YAML: - kind: R_MIPS_LO16
+# YAML: offset: 12
+# YAML: target: L009
+# YAML: addend: 512
+# YAML: - kind: R_MIPS_GOT16
+# YAML: offset: 16
+# YAML: target: L004
+# YAML: - kind: R_MIPS_CALL16
+# YAML: offset: 20
+# YAML: target: L005
+# YAML: - kind: R_MIPS_CALL16
+# YAML: offset: 24
+# YAML: target: L006
+
+# Local GOT entries:
+# YAML: - ref-name: L000
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: LLD_R_MIPS_32_HI16
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: L009
+# YAML-NEXT: - ref-name: L002
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: LLD_R_MIPS_32_HI16
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: L009
+# YAML-NEXT: addend: 66048
+# YAML-NEXT: - ref-name: L004
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: R_MIPS_32
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: hidden
+
+# Global GOT entries:
+# YAML-NEXT: - ref-name: L005
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: glob
+# YAML-NEXT: - kind: R_MIPS_32
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: glob
+# YAML-NEXT: - ref-name: L006
+# YAML-NEXT: type: got
+# YAML-NEXT: content: [ 00, 00, 00, 00 ]
+# YAML-NEXT: alignment: 4
+# YAML-NEXT: section-choice: custom-required
+# YAML-NEXT: section-name: .got
+# YAML-NEXT: permissions: rw-
+# YAML-NEXT: references:
+# YAML-NEXT: - kind: LLD_R_MIPS_GLOBAL_GOT
+# YAML-NEXT: offset: 0
+# YAML-NEXT: target: extern
+
+# RAW: Disassembly of section .text:
+# RAW: glob:
+# RAW-NEXT: {{[0x0-9a-f]+}}: 18 80 84 8f lw $4, -32744($gp)
+# RAW-NEXT: {{[0x0-9a-f]+}}: 00 20 84 24 addiu $4, $4, 8192
+# RAW-NEXT: {{[0x0-9a-f]+}}: 1c 80 84 8f lw $4, -32740($gp)
+# RAW-NEXT: {{[0x0-9a-f]+}}: 00 22 84 24 addiu $4, $4, 8704
+# RAW-NEXT: {{[0x0-9a-f]+}}: 20 80 84 8f lw $4, -32736($gp)
+# RAW-NEXT: {{[0x0-9a-f]+}}: 24 80 84 8f lw $4, -32732($gp)
+# RAW-NEXT: {{[0x0-9a-f]+}}: 28 80 84 8f lw $4, -32728($gp)
+
+# RAW: SYMBOL TABLE:
+# RAW: {{[0x0-9a-f]+}} *UND* 00000000
+# RAW: {{[0x0-9a-f]+}} l .data 00000000 str1
+# RAW: {{[0x0-9a-f]+}} l .data 00000005 str2
+# RAW: {{[0x0-9a-f]+}} g F .text 0000001c glob
+# RAW: {{[0x0-9a-f]+}} g .data 00000004 hidden
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: '0000848F000084240100848F000284240000848F0000848F0000848F'
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: .data
+ Type: R_MIPS_GOT16
+ - Offset: 0x04
+ Symbol: .data
+ Type: R_MIPS_LO16
+ - Offset: 0x08
+ Symbol: .data
+ Type: R_MIPS_GOT16
+ - Offset: 0x0C
+ Symbol: .data
+ Type: R_MIPS_LO16
+ - Offset: 0x10
+ Symbol: hidden
+ Type: R_MIPS_GOT16
+ - Offset: 0x14
+ Symbol: glob
+ Type: R_MIPS_CALL16
+ - Offset: 0x18
+ Symbol: extern
+ Type: R_MIPS_CALL16
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x10209
+
+Symbols:
+ Local:
+ - Name: str1
+ Type: STT_OBJECT
+ Section: .data
+ Size: 0x10200
+ - Name: str2
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0x10200
+ Size: 0x05
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+ Global:
+ - Name: glob
+ Section: .text
+ - Name: hidden
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0x10205
+ Size: 0x04
+ Visibility: STV_HIDDEN
+ - Name: extern
diff --git a/test/old-elf/Mips/gotsym.test b/test/old-elf/Mips/gotsym.test
new file mode 100644
index 0000000000000..bc89ba5d37680
--- /dev/null
+++ b/test/old-elf/Mips/gotsym.test
@@ -0,0 +1,43 @@
+# Check _gp_disp and GOT_OFFSET_TABLE value
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec -o %t.so %t.o
+# RUN: llvm-objdump -h -t %t.so | FileCheck -check-prefix=SHARED %s
+
+# SHARED: Sections:
+# SHARED: Idx Name Size Address Type
+# SHARED: 6 .got 00000008 0000000000001000 DATA
+# SHARED: SYMBOL TABLE:
+# SHARED: 00001000 .got 00000000 _GLOBAL_OFFSET_TABLE_
+# SHARED: 00008ff0 g *ABS* 00000000 _gp
+# SHARED: 00008ff0 g *ABS* 00000000 _gp_disp
+
+# RUN: lld -flavor old-gnu -target mipsel -e main --noinhibit-exec -o %t.exe %t.o
+# RUN: llvm-objdump -h -t %t.exe | FileCheck -check-prefix=EXE %s
+
+# EXE: Sections:
+# EXE: Idx Name Size Address Type
+# EXE: 7 .got 00000008 0000000000401000 DATA
+# EXE: SYMBOL TABLE:
+# EXE: 00401000 .got 00000000 _GLOBAL_OFFSET_TABLE_
+# EXE: 00408ff0 g *ABS* 00000000 _gp
+# EXE: 00408ff0 g *ABS* 00000000 _gp_disp
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: main
+ Section: .text
diff --git a/test/old-elf/Mips/gp-sym-1-micro.test b/test/old-elf/Mips/gp-sym-1-micro.test
new file mode 100644
index 0000000000000..0e1bea9c38da3
--- /dev/null
+++ b/test/old-elf/Mips/gp-sym-1-micro.test
@@ -0,0 +1,88 @@
+# Check that microMIPS relocations against __gnu_local_gp
+# use "gp" value as target.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=SEC %s
+
+# SYM: Name: _gp
+# SYM-NEXT: Value: 0x408FF0
+
+# SEC: Contents of section .text:
+# SEC-NEXT: 400184 00004100 0000f08f 2000bc00 ..A..... ...
+# SEC: Contents of section .got:
+# SEC-NEXT: 401000 00000000 00000080 ........
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 12
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: __gnu_local_gp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x04
+ Symbol: __gnu_local_gp
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x08
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: __gnu_local_gp
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/gp-sym-1.test b/test/old-elf/Mips/gp-sym-1.test
new file mode 100644
index 0000000000000..ebb73c3afd609
--- /dev/null
+++ b/test/old-elf/Mips/gp-sym-1.test
@@ -0,0 +1,86 @@
+# Check that relocations against __gnu_local_gp use "gp" value as target.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=SEC %s
+
+# SYM: Name: _gp
+# SYM-NEXT: Value: 0x408FF0
+
+# SEC: Contents of section .text:
+# SEC-NEXT: 400190 41000000 f08f0000 60001000
+# SEC: Contents of section .got:
+# SEC-NEXT: 401000 00000000 00000080
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 12
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: __gnu_local_gp
+ Type: R_MIPS_HI16
+ - Offset: 0x04
+ Symbol: __gnu_local_gp
+ Type: R_MIPS_LO16
+ - Offset: 0x08
+ Symbol: T1
+ Type: R_MIPS_26
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ - Name: __gnu_local_gp
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/gp-sym-2.test b/test/old-elf/Mips/gp-sym-2.test
new file mode 100644
index 0000000000000..b6d95f350af3b
--- /dev/null
+++ b/test/old-elf/Mips/gp-sym-2.test
@@ -0,0 +1,103 @@
+# Check that R_MIPS32 relocation against __gnu_local_gp causes emitting
+# of R_MIPS_REL32 relocation in case of shared library file linking
+# and does not produce any dynamic relocation in case of linking a non-shared
+# executable file.
+
+# Now the test failed because the __gnu_local_gp symbol becomes defined
+# absolute symbol and we do not generate R_MIPS_REL32 in case of shared
+# library linking.
+# XFAIL: *
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t-1.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t-1.so
+# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=EXE %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t-2.so %t-o.o %t-1.so
+# RUN: llvm-readobj -r %t-2.so | FileCheck -check-prefix=SO %s
+
+# EXE: Relocations [
+# EXE-NEXT: ]
+
+# SO: Relocations [
+# SO-NEXT: Section (5) .rel.dyn {
+# SO-NEXT: 0x0 R_MIPS_NONE - 0x0
+# SO-NEXT: 0x2EC R_MIPS_REL32 __gnu_local_gp 0x0
+# SO-NEXT: }
+# SO-NEXT: ]
+
+# so.so
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 12
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: __gnu_local_gp
+ Type: R_MIPS_32
+ - Offset: 0x04
+ Symbol: T1
+ Type: R_MIPS_LO16
+ - Offset: 0x08
+ Symbol: T2
+ Type: R_MIPS_CALL16
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ - Name: __gnu_local_gp
+ - Name: T1
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/hilo16-1.test b/test/old-elf/Mips/hilo16-1.test
new file mode 100644
index 0000000000000..b284140f748f3
--- /dev/null
+++ b/test/old-elf/Mips/hilo16-1.test
@@ -0,0 +1,40 @@
+# REQUIRES: mips
+
+# Check handling multiple HI16 relocation followed by a single LO16 relocation.
+
+# RUN: llvm-mc -arch=mipsel -filetype=obj -o=%t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -d -t %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: T0:
+# CHECK-NEXT: 400180: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: {{[0-9a-f]+}}: 42 00 08 3c lui $8, 66
+# CHECK-NEXT: {{[0-9a-f]+}}: 3e 00 08 3c lui $8, 62
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 02 08 3c lui $8, 576
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 fe 08 3c lui $8, 65088
+# CHECK-NEXT: {{[0-9a-f]+}}: a5 01 08 25 addiu $8, $8, 421
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400180 g F .text 00000024 T0
+# CHECK: 004001a4 g F .text 00000004 T1
+
+ .text
+ .globl T0
+T0:
+ lui $8, %hi(T1+1)
+ lui $8, %hi(T1-1)
+ lui $8, %hi(T1+0x1ff)
+ lui $8, %hi(T1+(-0x1ff))
+ lui $8, %hi(T1+0x1ffff)
+ lui $8, %hi(T1+(-0x1ffff))
+ lui $8, %hi(T1+0x1ffffff)
+ lui $8, %hi(T1+(-0x1ffffff))
+ addiu $8, $8, %lo(T1+(-0x1ffffff))
+
+ .globl T1
+T1:
+ nop
diff --git a/test/old-elf/Mips/hilo16-2.test b/test/old-elf/Mips/hilo16-2.test
new file mode 100644
index 0000000000000..e47b9003a8dd9
--- /dev/null
+++ b/test/old-elf/Mips/hilo16-2.test
@@ -0,0 +1,70 @@
+# REQUIRES: mips
+
+# Check handling of HI16 and LO16 relocations for regular symbol.
+#
+# R_MIPS_HI16: (AHL + S) - (short)(AHL + S)
+# R_MIPS_LO16: AHL + S
+# where AHL = (AHI << 16) + ALO
+
+# RUN: llvm-mc -arch=mipsel -filetype=obj -o=%t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: T0:
+# CHECK-NEXT: 400180: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: {{[0-9a-f]+}}: c1 01 08 25 addiu $8, $8, 449
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: {{[0-9a-f]+}}: bf 01 08 25 addiu $8, $8, 447
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: {{[0-9a-f]+}}: bf 03 08 25 addiu $8, $8, 959
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64
+# CHECK-NEXT: {{[0-9a-f]+}}: c1 ff 08 25 addiu $8, $8, -63
+#
+# CHECK: T1:
+# CHECK-NEXT: 4001a0: 42 00 08 3c lui $8, 66
+# CHECK-NEXT: {{[0-9a-f]+}}: bf 01 08 25 addiu $8, $8, 447
+# CHECK-NEXT: {{[0-9a-f]+}}: 3e 00 08 3c lui $8, 62
+# CHECK-NEXT: {{[0-9a-f]+}}: c1 01 08 25 addiu $8, $8, 449
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 02 08 3c lui $8, 576
+# CHECK-NEXT: {{[0-9a-f]+}}: bf 01 08 25 addiu $8, $8, 447
+# CHECK-NEXT: {{[0-9a-f]+}}: 40 fe 08 3c lui $8, 65088
+# CHECK-NEXT: {{[0-9a-f]+}}: c1 01 08 25 addiu $8, $8, 449
+#
+# CHECK: T2:
+# CHECK-NEXT: 4001c0: 00 00 00 00 nop
+
+ .section .text.1,"ax",@progbits
+ .align 4
+ .globl T0
+T0:
+ lui $8, %hi(T2+1)
+ addiu $8, $8, %lo(T2+1)
+ lui $8, %hi(T2+(-1))
+ addiu $8, $8, %lo(T2+(-1))
+ lui $8, %hi(T2+0x1ff)
+ addiu $8, $8, %lo(T2+0x1ff)
+ lui $8, %hi(T2+(-0x1ff))
+ addiu $8, $8, %lo(T2+(-0x1ff))
+ .size T0, .-T0
+
+ .section .text.2,"ax",@progbits
+ .align 4
+ .globl T1
+T1:
+ lui $8, %hi(T2+0x1ffff)
+ addiu $8, $8, %lo(T2+0x1ffff)
+ lui $8, %hi(T2+(-0x1ffff))
+ addiu $8, $8, %lo(T2+(-0x1ffff))
+ lui $8, %hi(T2+0x1ffffff)
+ addiu $8, $8, %lo(T2+0x1ffffff)
+ lui $8, %hi(T2+(-0x1ffffff))
+ addiu $8, $8, %lo(T2+(-0x1ffffff))
+ .size T1, .-T1
+
+ .section .text.3,"ax",@progbits
+ .align 4
+ .globl T2
+T2:
+ nop
+ .size T2, .-T2
diff --git a/test/old-elf/Mips/hilo16-3-overflow.test b/test/old-elf/Mips/hilo16-3-overflow.test
new file mode 100644
index 0000000000000..94fc90b3be54b
--- /dev/null
+++ b/test/old-elf/Mips/hilo16-3-overflow.test
@@ -0,0 +1,44 @@
+# Check R_MIPS_HI16 relocation overflow handling.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}} reference from T0+0 to _gp_disp+2147483648 of type 5 (R_MIPS_HI16)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0080000000000000"
+# ^ %hi(gp+0x80000000)
+# ^ %lo(gp+0x80000000)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: _gp_disp
+ Type: R_MIPS_HI16
+ - Offset: 0x4
+ Symbol: _gp_disp
+ Type: R_MIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: _gp_disp
diff --git a/test/old-elf/Mips/hilo16-3.test b/test/old-elf/Mips/hilo16-3.test
new file mode 100644
index 0000000000000..17873c0a629cf
--- /dev/null
+++ b/test/old-elf/Mips/hilo16-3.test
@@ -0,0 +1,74 @@
+# Check handling of HI16 and LO16 relocations for _gp_disp.
+#
+# R_MIPS_HI16: (AHL + GP - P) - (short)(AHL + GP - P)
+# R_MIPS_LO16: AHL + GP - P + 4
+# where AHL = (AHI << 16) + ALO
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-objdump -s -t %t.so | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 00d0 0100083c 218f0885 0100083c 178f0885
+# CHECK-NEXT: 00e0 0100083c 0f910885 0100083c 098d0885
+# CHECK-NEXT: 00f0 0200083c ffff0885
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 000000d0 g F .text 00000028 T0
+# CHECK: 00008ff0 g *ABS* 00000000 _gp_disp
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000083C010008850000083CFFFF08850000083CFF0108850000083C01FE08850200083CFFFF0885"
+# ^ %hi(gp+1) ^ %hi(gp-1) ^ %hi(gp+0x1ff) ^ %hi(gp-0x1ff) ^ %lo(gp+0x1ffff)
+# ^ %lo(gp+1) ^ %lo(gp-1) ^ %lo(gp+0x1ff) ^ %lo(gp-0x1ff)
+# ^ %hi(gp+0x1ffff)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: _gp_disp
+ Type: R_MIPS_HI16
+ - Offset: 0x4
+ Symbol: _gp_disp
+ Type: R_MIPS_LO16
+ - Offset: 0x8
+ Symbol: _gp_disp
+ Type: R_MIPS_HI16
+ - Offset: 0xC
+ Symbol: _gp_disp
+ Type: R_MIPS_LO16
+ - Offset: 0x10
+ Symbol: _gp_disp
+ Type: R_MIPS_HI16
+ - Offset: 0x14
+ Symbol: _gp_disp
+ Type: R_MIPS_LO16
+ - Offset: 0x18
+ Symbol: _gp_disp
+ Type: R_MIPS_HI16
+ - Offset: 0x1C
+ Symbol: _gp_disp
+ Type: R_MIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 80
+ - Name: _gp_disp
diff --git a/test/old-elf/Mips/hilo16-4.test b/test/old-elf/Mips/hilo16-4.test
new file mode 100644
index 0000000000000..2db17344e30fd
--- /dev/null
+++ b/test/old-elf/Mips/hilo16-4.test
@@ -0,0 +1,93 @@
+# REQUIRES: mips
+
+# Check pairing of R_MIPS_HI16 and R_MIPS_LO16 relocations.
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel -e glob1 -o %t-exe %t-obj
+# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK: glob1:
+# CHECK-NEXT: 400130: 40 00 04 3c lui $4, 64
+# CHECK-NEXT: 400134: ff 9f a6 8c lw $6, -24577($5)
+
+# CHECK: glob2:
+# CHECK-NEXT: 400138: 00 20 c7 80 lb $7, 8192($6)
+# CHECK-NEXT: 40013c: 04 20 c8 80 lb $8, 8196($6)
+
+# CHECK: glob3:
+# CHECK-NEXT: 400140: 40 80 05 3c lui $5, 32832
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400130 g F .text 00000008 glob1
+# CHECK: 00400138 g F .text 00000008 glob2
+# CHECK: 00400140 g F .text 00000004 glob3
+# CHECK: 00402000 g .data 0000000c X
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+# glob1:
+# lui $4,%hi(X) # rel A
+# lw $6,%lo(X+32767)($5) # rel B
+# glob2:
+# lb $7,%lo(X)($6) # rel C
+# lb $8,%lo(X+4)($6) # rel D
+# glob3:
+# lui $5,%hi(X+32767) # rel E
+ Content: "0000043CFF7FA68C0000C7800400C880FF7F053C"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: "000000000000000000000000"
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x10 # rel E
+ Symbol: X
+ Type: R_MIPS_HI16
+ - Offset: 0x04 # rel B
+ Symbol: X
+ Type: R_MIPS_LO16
+ - Offset: 0x00 # rel A
+ Symbol: X
+ Type: R_MIPS_HI16
+ - Offset: 0x0C # rel D
+ Symbol: X
+ Type: R_MIPS_LO16
+ - Offset: 0x08 # rel C
+ Symbol: X
+ Type: R_MIPS_LO16
+
+Symbols:
+ Global:
+ - Name: glob1
+ Section: .text
+ Value: 0x0
+ Size: 8
+ - Name: glob2
+ Section: .text
+ Value: 0x8
+ Size: 8
+ - Name: glob3
+ Section: .text
+ Value: 0x10
+ Size: 4
+ - Name: X
+ Section: .data
+ Value: 0x0
+ Size: 12
diff --git a/test/old-elf/Mips/hilo16-5.test b/test/old-elf/Mips/hilo16-5.test
new file mode 100644
index 0000000000000..597425e8ba74b
--- /dev/null
+++ b/test/old-elf/Mips/hilo16-5.test
@@ -0,0 +1,103 @@
+# Check that linker shows a warning when
+# there is orphaned R_MIPS_HI16 relocation.
+
+# RUN: yaml2obj -format=elf -o %t-so.o -docnum 1 %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -o %t-o.o -docnum 2 %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so 2>&1 \
+# RUN: | FileCheck -check-prefix=DIAG %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=DATA %s
+
+# DIAG: lld warning: cannot matching LO16 relocation
+# DIAG: lld warning: cannot matching LO16 relocation
+
+# DATA: Contents of section .data:
+# DATA-NEXT: 402000 40000000 10200000 40000000 @.... ..@...
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "00000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: "000000000000000000000000"
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MIPS_HI16
+ - Offset: 0x08
+ Symbol: D2
+ Type: R_MIPS_HI16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_LO16
+ - Offset: 0x08
+ Symbol: .text
+ Type: R_MIPS_HI16
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .data
+ Type: STT_SECTION
+ Section: .data
+
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: D1
+ - Name: D2
+...
diff --git a/test/old-elf/Mips/hilo16-8-micro.test b/test/old-elf/Mips/hilo16-8-micro.test
new file mode 100644
index 0000000000000..ef8ac782341cb
--- /dev/null
+++ b/test/old-elf/Mips/hilo16-8-micro.test
@@ -0,0 +1,81 @@
+# REQUIRES: mips
+
+# Check calculation of AHL addendums for R_MICROMIPS_HI16 / R_MICROMIPS_LO16
+# relocations for a regular symbol.
+
+# RUN: llvm-mc -arch=mipsel -filetype=obj -mattr=micromips -o=%t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: T0:
+# CHECK-NEXT: 400180: a8 41 40 00 lui $8, 64
+# CHECK-NEXT: 400184: 08 31 c1 01 addiu $8, $8, 449
+# CHECK-NEXT: 400188: a8 41 41 00 lui $8, 65
+# CHECK-NEXT: 40018c: 08 31 bf 81 addiu $8, $8, -32321
+# CHECK-NEXT: 400190: a8 41 41 00 lui $8, 65
+# CHECK-NEXT: 400194: 08 31 40 82 addiu $8, $8, -32192
+# CHECK-NEXT: 400198: a8 41 42 00 lui $8, 66
+# CHECK-NEXT: 40019c: 08 31 c0 81 addiu $8, $8, -32320
+#
+# CHECK: T1:
+# CHECK-NEXT: 4001a0: a8 41 40 40 lui $8, 16448
+# CHECK-NEXT: 4001a4: 08 31 c0 01 addiu $8, $8, 448
+# CHECK-NEXT: 4001a8: a8 41 40 80 lui $8, 32832
+# CHECK-NEXT: 4001ac: 08 31 c0 01 addiu $8, $8, 448
+# CHECK-NEXT: 4001b0: a8 41 c1 80 lui $8, 32961
+# CHECK-NEXT: 4001b4: 08 31 40 82 addiu $8, $8, -32192
+# CHECK-NEXT: 4001b8: 00 00 00 00 nop
+# CHECK-NEXT: 4001bc: 00 00 00 00 nop
+#
+# CHECK: T2:
+# CHECK-NEXT: 4001c0: 00 00 00 00 nop
+# CHECK-NEXT: 4001c4: a8 41 40 00 lui $8, 64
+# CHECK-NEXT: 4001c8: a8 41 40 00 lui $8, 64
+# CHECK-NEXT: 4001cc: a8 41 41 00 lui $8, 65
+# CHECK-NEXT: 4001d0: a8 41 42 00 lui $8, 66
+# CHECK-NEXT: 4001d4: a8 41 40 40 lui $8, 16448
+# CHECK-NEXT: 4001d8: a8 41 40 80 lui $8, 32832
+# CHECK-NEXT: 4001dc: a8 41 c1 80 lui $8, 32961
+# CHECK-NEXT: 4001e0: 08 31 00 82 addiu $8, $8, -32256
+
+ .section .text.1,"ax",@progbits
+ .align 4
+ .globl T0
+T0:
+ lui $8, %hi(T2+1)
+ addiu $8, $8, %lo(T2+1)
+ lui $8, %hi(T2+0x7fff)
+ addiu $8, $8, %lo(T2+0x7fff)
+ lui $8, %hi(T2+0x8080)
+ addiu $8, $8, %lo(T2+0x8080)
+ lui $8, %hi(T2+0x18000)
+ addiu $8, $8, %lo(T2+0x18000)
+ .size T0, .-T0
+
+ .section .text.2,"ax",@progbits
+ .align 4
+ .globl T1
+T1:
+ lui $8, %hi(T2+0x40000000)
+ addiu $8, $8, %lo(T2+0x40000000)
+ lui $8, %hi(T2+0x80000000)
+ addiu $8, $8, %lo(T2+0x80000000)
+ lui $8, %hi(T2+0x80808080)
+ addiu $8, $8, %lo(T2+0x80808080)
+ .size T1, .-T1
+
+ .section .text.3,"ax",@progbits
+ .align 4
+ .globl T2
+T2:
+ nop
+ lui $8, %hi(T0+0x1)
+ lui $8, %hi(T0+0x7fff)
+ lui $8, %hi(T0+0x8080)
+ lui $8, %hi(T0+0x18000)
+ lui $8, %hi(T0+0x40000000)
+ lui $8, %hi(T0+0x80000000)
+ lui $8, %hi(T0+0x80808080)
+ addiu $8, $8, %lo(T0+0x80808080)
+ .size T2, .-T2
diff --git a/test/old-elf/Mips/hilo16-9-micro.test b/test/old-elf/Mips/hilo16-9-micro.test
new file mode 100644
index 0000000000000..293e35f36cd52
--- /dev/null
+++ b/test/old-elf/Mips/hilo16-9-micro.test
@@ -0,0 +1,142 @@
+# Check calculation of AHL addendums for R_MICROMIPS_HI16 / R_MICROMIPS_LO16
+# relocations for the _gp_disp symbol.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-objdump -s -t %t.so | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 0110 00000100 0000e08e 00000100 0000d60e
+# CHECK-NEXT: 0120 00000100 00004f0f 00000000 00000000
+# CHECK-NEXT: 0130 00000200 0000bf0e 00000140 0000378f
+# CHECK-NEXT: 0140 00000100 00000100 00000200 00000300
+# CHECK-NEXT: 0150 00000140 00001f8f
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00000110 g F .text 00000018 T0
+# CHECK: 00000130 g F .text 00000010 T1
+# CHECK: 00000140 g F .text 00000018 T2
+# CHECK: 00008ff0 g *ABS* 00000000 _gp_disp
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text.1
+ Type: SHT_PROGBITS
+ Content: "0000000000000100000000000000FF7F0000010000008080"
+# ^ %hi(gp+0x1) ^ %hi(gp+0x7fff) ^ %lo(gp+0x8080)
+# ^ %lo(gp+0x1) ^ %lo(gp+0x7fff)
+# ^ %hi(gp+0x8080)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text.1
+ Type: SHT_REL
+ Info: .text.1
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x4
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x8
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0xC
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x10
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x14
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_LO16
+
+- Name: .text.2
+ Type: SHT_PROGBITS
+ Content: "00000200000000800000004000008000"
+# ^ %hi(gp+0x18000) ^ %lo(gp+0x40000080)
+# ^ %lo(gp+0x18000)
+# ^ %hi(gp+0x40000080)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text.2
+ Type: SHT_REL
+ Info: .text.2
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x4
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x8
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0xC
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_LO16
+
+- Name: .text.3
+ Type: SHT_PROGBITS
+ Content: "000000000000000000000100000002000000004000008000"
+# ^ %hi(gp+0x1) ^ %hi(gp+0x8080) ^ %lo(gp+0x40000080)
+# ^ %hi(gp+0x7fff) ^ %hi(gp+0x40000080)
+# ^ %hi(gp+0x18000)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text.3
+ Type: SHT_REL
+ Info: .text.3
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x4
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x8
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0xC
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x10
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x14
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text.1
+ Type: STT_FUNC
+ Value: 0
+ Size: 24
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ Section: .text.2
+ Type: STT_FUNC
+ Value: 0
+ Size: 16
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ Section: .text.3
+ Type: STT_FUNC
+ Value: 0
+ Size: 24
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: _gp_disp
diff --git a/test/old-elf/Mips/initfini-micro.test b/test/old-elf/Mips/initfini-micro.test
new file mode 100644
index 0000000000000..ca2708f1bb296
--- /dev/null
+++ b/test/old-elf/Mips/initfini-micro.test
@@ -0,0 +1,45 @@
+# Check that if _init/_fini symbols are microMIPS encoded, DT_INIT/DT_FINI tags
+# use adjusted values with set the last bit.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -symbols -dynamic-table %t.so | FileCheck %s
+
+# CHECK: Name: _init (1)
+# CHECK-NEXT: Value: 0xF5
+# CHECK: Name: _fini (7)
+# CHECK-NEXT: Value: 0xF9
+#
+# CHECK: 0x0000000C INIT 0xF5
+# CHECK: 0x0000000D FINI 0xF9
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x18
+
+Symbols:
+ Global:
+ - Name: _init
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x0
+ Size: 0x4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: _fini
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x4
+ Size: 0x4
+ Other: [ STO_MIPS_MICROMIPS ]
+...
diff --git a/test/old-elf/Mips/interpreter-64.test b/test/old-elf/Mips/interpreter-64.test
new file mode 100644
index 0000000000000..7cfd0c51a3c46
--- /dev/null
+++ b/test/old-elf/Mips/interpreter-64.test
@@ -0,0 +1,26 @@
+# Check program interpreter setup.
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -e main -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .interp:
+# CHECK-NEXT: {{[0-9a-f]+}} 2f6c6962 36342f6c 642e736f 2e3100 /lib64/ld.so.1.
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64 ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x08
+
+Symbols:
+ Global:
+ - Name: main
+ Section: .text
diff --git a/test/old-elf/Mips/interpreter-n32.test b/test/old-elf/Mips/interpreter-n32.test
new file mode 100644
index 0000000000000..7d17256ba43cb
--- /dev/null
+++ b/test/old-elf/Mips/interpreter-n32.test
@@ -0,0 +1,27 @@
+# Check program interpreter setup in case of N32 ABI.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .interp:
+# CHECK-NEXT: {{[0-9a-f ]+}} /lib32/ld.so.1.
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64, EF_MIPS_ABI2 ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
diff --git a/test/old-elf/Mips/interpreter.test b/test/old-elf/Mips/interpreter.test
new file mode 100644
index 0000000000000..4ae17b42df1cc
--- /dev/null
+++ b/test/old-elf/Mips/interpreter.test
@@ -0,0 +1,26 @@
+# Check program interpreter setup.
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e main -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .interp:
+# CHECK-NEXT: {{[0-9a-f]+}} 2f6c6962 2f6c642e 736f2e31 00 /lib/ld.so.1.
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: main
+ Section: .text
diff --git a/test/old-elf/Mips/invalid-reginfo.test b/test/old-elf/Mips/invalid-reginfo.test
new file mode 100644
index 0000000000000..2856ecc92607a
--- /dev/null
+++ b/test/old-elf/Mips/invalid-reginfo.test
@@ -0,0 +1,28 @@
+# Check that LLD shows an error if .reginfo section has invalid size
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -o %t.exe %t.o 2>&1 | FileCheck %s
+
+# CHECK: Invalid size of MIPS_REGINFO section
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x01
+ Size: 0x25
+Symbols:
+ Global:
+ - Name: main
+ Section: .text
diff --git a/test/old-elf/Mips/jalx-align-err.test b/test/old-elf/Mips/jalx-align-err.test
new file mode 100644
index 0000000000000..8fc5310bbad81
--- /dev/null
+++ b/test/old-elf/Mips/jalx-align-err.test
@@ -0,0 +1,46 @@
+# Check that LLD shows an error if jalx target value is not word-aligned.
+
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t-exe %t-obj 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: The jalx target 0x{{[0-9a-f]+}} is not word-aligned
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 6
+ Size: 2
diff --git a/test/old-elf/Mips/jalx-jalr.test b/test/old-elf/Mips/jalx-jalr.test
new file mode 100644
index 0000000000000..d02e9d7c2baca
--- /dev/null
+++ b/test/old-elf/Mips/jalx-jalr.test
@@ -0,0 +1,47 @@
+# Check that R_MIPS_JALR relocation does not affect code in case of cross jump.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9a-f]+}} 08002003 00000000
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_MICROMIPS, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "0800200300000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: M1
+ Type: R_MIPS_JALR
+
+Symbols:
+ Global:
+ - Name: __start
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: M1
+ Type: STT_FUNC
+ Section: .text
+ Value: 4
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
diff --git a/test/old-elf/Mips/jalx.test b/test/old-elf/Mips/jalx.test
new file mode 100644
index 0000000000000..60d6ea71193c3
--- /dev/null
+++ b/test/old-elf/Mips/jalx.test
@@ -0,0 +1,71 @@
+# Check jal => jalx conversion in case of mixed microMIPS and regular code.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T1 -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+# RUN: llvm-nm %t.exe | FileCheck -check-prefix=SYM %s
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 400130 00000000 4c001074 10f04d00 4e001074
+
+# SYM: 00400138 T M1
+# SYM: 00400130 T M2
+# SYM: 0040013c T T1
+# SYM: 00400134 T T2
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_MICROMIPS, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "000000000000000c00f400000000000c"
+# ^ M2 ^ T2 ^ M1 ^ T1
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 4
+ Symbol: M2
+ Type: R_MIPS_26
+ - Offset: 8
+ Symbol: T2
+ Type: R_MICROMIPS_26_S1
+ - Offset: 12
+ Symbol: M1
+ Type: R_MIPS_26
+
+Symbols:
+ Global:
+ - Name: M2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Value: 4
+ Size: 4
+ - Name: M1
+ Type: STT_FUNC
+ Section: .text
+ Value: 8
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 12
+ Size: 4
diff --git a/test/old-elf/Mips/jump-fix-err.test b/test/old-elf/Mips/jump-fix-err.test
new file mode 100644
index 0000000000000..0e5a5298a7316
--- /dev/null
+++ b/test/old-elf/Mips/jump-fix-err.test
@@ -0,0 +1,45 @@
+# Check that LLD shows an error in case
+# of replacing an unknown unstruction by jalx.
+
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: not lld -flavor old-gnu -target mipsel -o %t-exe %t-obj 2>&1 | FileCheck %s
+
+# CHECK: Unsupported jump opcode (0x0) for ISA modes cross call
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T0
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Type: STT_FUNC
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
diff --git a/test/old-elf/Mips/la25-stub-be.test b/test/old-elf/Mips/la25-stub-be.test
new file mode 100644
index 0000000000000..9527e7a80644e
--- /dev/null
+++ b/test/old-elf/Mips/la25-stub-be.test
@@ -0,0 +1,113 @@
+# REQUIRES: mips
+
+# Check LA25 stubs creation in the big-endian case.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-npic.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-main.o
+# RUN: lld -flavor old-gnu -target mips -o %t.exe %t-npic.o %t-pic.o %t-main.o
+
+# RUN: llvm-objdump -disassemble %t.exe | FileCheck %s
+
+# CHECK: 400170: 3c 19 00 40 lui $25, 64
+# CHECK-NEXT: 400174: 08 10 00 50 j 4194624
+# CHECK-NEXT: 400178: 27 39 01 40 addiu $25, $25, 320
+# CHECK-NEXT: 40017c: 00 00 00 00 nop
+
+# npic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1N
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_PIC]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# main.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 40
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 8
+ Symbol: .text
+ Type: R_MIPS_26
+ - Offset: 16
+ Symbol: __start
+ Type: R_MIPS_26
+ - Offset: 24
+ Symbol: T1N
+ Type: R_MIPS_26
+ - Offset: 32
+ Symbol: T1
+ Type: R_MIPS_26
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 16
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: __start
+ Section: .text
+ - Name: T1
+ - Name: T1N
+...
diff --git a/test/old-elf/Mips/la25-stub-micro-be.test b/test/old-elf/Mips/la25-stub-micro-be.test
new file mode 100644
index 0000000000000..0bea3e6ac8b02
--- /dev/null
+++ b/test/old-elf/Mips/la25-stub-micro-be.test
@@ -0,0 +1,121 @@
+# REQUIRES: mips
+
+# Check LA25 stubs creation in the big-endian case.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-npic.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-main.o
+# RUN: lld -flavor old-gnu -target mips -o %t.exe %t-npic.o %t-pic.o %t-main.o
+
+# RUN: llvm-objdump -disassemble -mattr=micromips %t.exe | FileCheck %s
+
+# CHECK: 400170: 41 be 00 40 lui $fp, 64
+# CHECK-NEXT: 400174: d4 20 00 a0 j 4194624
+# CHECK-NEXT: 400178: 33 39 01 41 addiu $25, $25, 321
+# CHECK-NEXT: 40017c: 00 00 00 00 nop
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1N
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+
+# main.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: '0000000000000000f400000000000000f400000000000000f400000000000000f400000000000000'
+# jal loc jal glob jal T1N jal T1
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 8
+ Symbol: .text
+ Type: R_MICROMIPS_26_S1
+ - Offset: 16
+ Symbol: glob
+ Type: R_MICROMIPS_26_S1
+ - Offset: 24
+ Symbol: T1N
+ Type: R_MICROMIPS_26_S1
+ - Offset: 32
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 16
+ Size: 24
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: __start
+ Section: .text
+ Size: 16
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ - Name: T1N
+...
diff --git a/test/old-elf/Mips/la25-stub-micro.test b/test/old-elf/Mips/la25-stub-micro.test
new file mode 100644
index 0000000000000..c01da5908829c
--- /dev/null
+++ b/test/old-elf/Mips/la25-stub-micro.test
@@ -0,0 +1,136 @@
+# Check microMIPS LA25 stubs creation when PIC code
+# is called from non-PIC routines.
+
+# Build executable from pic and non-pic code.
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-npic.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-main.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe \
+# RUN: %t-npic.o %t-pic.o %t-main.o
+
+# RUN: llvm-nm %t.exe | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=ASM %s
+
+# SYM: 00400140 T T1
+# SYM: 00400130 T T1N
+# SYM: 00400144 T glob
+# SYM: 00400154 t loc
+
+# ASM: Contents of section .text:
+# ASM-NEXT: 400130 00000000 00000000 00000000 00000000
+# ASM-NEXT: 400140 00000000 00000000 00000000 10f05100
+# 0x100055 << 2 == 0x400154 (jalx glob) --^
+# ASM-NEXT: 400150 00000000 20f4a200 00000000 20f49800
+# ^-- 0x100055 << 2 == 0x400154 (jal glob)
+# 0x10004c << 2 == 0x400130 (jal T1N) --^
+# ASM-NEXT: 400160 00000000 20f4b800 00000000 00000000
+# ^-- 0x100054 << 2 == 0x400170 (jal T1 stub)
+# ASM-NEXT: 400170 b9414000 20d4a000 39334101 00000000
+# ^-- j 0x400140 (T1)
+
+# npic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_CPIC, EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x04
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1N
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x04
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+
+# main.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_CPIC, EF_MIPS_MICROMIPS ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: '000000000000000000f400000000000000f400000000000000f400000000000000f4000000000000'
+# jal loc jal glob jal T1N jal T1
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x08
+ Symbol: .text
+ Type: R_MICROMIPS_26_S1
+ - Offset: 0x10
+ Symbol: glob
+ Type: R_MICROMIPS_26_S1
+ - Offset: 0x18
+ Symbol: T1N
+ Type: R_MICROMIPS_26_S1
+ - Offset: 0x20
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 0x10
+ Size: 0x18
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ Size: 0x10
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ - Name: T1N
+...
diff --git a/test/old-elf/Mips/la25-stub-npic-01.test b/test/old-elf/Mips/la25-stub-npic-01.test
new file mode 100644
index 0000000000000..9ff6af06cb2b7
--- /dev/null
+++ b/test/old-elf/Mips/la25-stub-npic-01.test
@@ -0,0 +1,153 @@
+# Check that LA25 stubs are created for branch relocations
+# when a PIC function is called from non-pic code.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-reg.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe \
+# RUN: %t-reg.o %t-micro.o %t-pic.o
+
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK-NOT: Contents of section .plt:
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 400130 5c001000 0f000000 0e000000 0d000000
+# ^ T0 ^ .pic.T1 (0x400170)
+# ^ 0x400134 + 0x3c = 0x400170
+# ^ ...
+# CHECK-NEXT: 400140 2000c000 1e000000 1c000000 00001a00
+# ^ T3 ^ .pic.T2
+# ^ ...
+# CHECK-NEXT: 400150 00000c00 00000000 00000000 00000000
+# CHECK-NEXT: 400160 00000000 00000000 00000000 00000000
+# ^ T1 ^ T2
+# CHECK-NEXT: 400170 4000193c 58001008 60013927 00000000
+# ^ .pic.T1
+# CHECK-NEXT: 400180 b9414000 20d4b200 39336501 00000000
+# ^ .pic.T2
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400130 g F .text 00000010 T0
+# CHECK: 00400140 g F .text 00000014 T3
+# CHECK: 00400160 g F .text 00000004 T1
+# CHECK: 00400164 g F .text 00000004 T2
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+ EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+
+# reg.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 16
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_26
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_PC16
+ - Offset: 8
+ Symbol: T1
+ Type: R_MIPS_PC21_S2
+ - Offset: 12
+ Symbol: T1
+ Type: R_MIPS_PC26_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Size: 16
+ - Name: T1
+
+# micro.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 20
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T2
+ Type: R_MICROMIPS_26_S1
+ - Offset: 4
+ Symbol: T2
+ Type: R_MICROMIPS_PC7_S1
+ - Offset: 8
+ Symbol: T2
+ Type: R_MICROMIPS_PC10_S1
+ - Offset: 12
+ Symbol: T2
+ Type: R_MICROMIPS_PC16_S1
+ - Offset: 16
+ Symbol: T2
+ Type: R_MICROMIPS_PC23_S2
+
+Symbols:
+ Global:
+ - Name: T3
+ Section: .text
+ Size: 20
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/la25-stub-npic-02.test b/test/old-elf/Mips/la25-stub-npic-02.test
new file mode 100644
index 0000000000000..4f2eb14d8c92b
--- /dev/null
+++ b/test/old-elf/Mips/la25-stub-npic-02.test
@@ -0,0 +1,123 @@
+# Check that LA25 stubs are created for branch relocations
+# when a PIC function is defined in a non-PIC file and
+# is called from non-pic code.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t1.o %t2.o
+
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK-NOT: Contents of section .plt:
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 400130 00000000 00000000 58001000 09000000
+# ^ T1 ^ T2 ^ .pic.T1 (0x400160)
+# CHECK-NEXT: 400140 08000000 07000000 2000b800 12000000
+# ^ .pic.T2 (0x400170)
+# CHECK-NEXT: 400150 10000000 00000e00 00000600 00000000
+# CHECK-NEXT: 400160 4000193c 4c001008 30013927 00000000
+# ^ .pic.T1
+# CHECK-NEXT: 400170 b9414000 20d49a00 39333501 00000000
+# ^ .pic.T2
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400130 g F .text 00000004 T1
+# CHECK: 00400134 g F .text 00000004 T2
+# CHECK: 00400138 g F .text 00000010 T0
+# CHECK: 00400148 g F .text 00000014 T3
+
+# 1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ Other: [STO_MIPS_PIC]
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS, STO_MIPS_PIC]
+
+# 2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 36
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_26
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_PC16
+ - Offset: 8
+ Symbol: T1
+ Type: R_MIPS_PC21_S2
+ - Offset: 12
+ Symbol: T1
+ Type: R_MIPS_PC26_S2
+ - Offset: 16
+ Symbol: T2
+ Type: R_MICROMIPS_26_S1
+ - Offset: 20
+ Symbol: T2
+ Type: R_MICROMIPS_PC7_S1
+ - Offset: 24
+ Symbol: T2
+ Type: R_MICROMIPS_PC10_S1
+ - Offset: 28
+ Symbol: T2
+ Type: R_MICROMIPS_PC16_S1
+ - Offset: 32
+ Symbol: T2
+ Type: R_MICROMIPS_PC23_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Value: 0
+ Size: 16
+ - Name: T3
+ Section: .text
+ Value: 16
+ Size: 20
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/la25-stub-npic-shared.test b/test/old-elf/Mips/la25-stub-npic-shared.test
new file mode 100644
index 0000000000000..72bac30f86adb
--- /dev/null
+++ b/test/old-elf/Mips/la25-stub-npic-shared.test
@@ -0,0 +1,152 @@
+# Check that PLT entries are created for branch relocations
+# when a PIC shared library function is called from non-pic code.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-reg.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-pic.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-reg.o %t-micro.o %t.so
+
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .plt:
+# CHECK-NEXT: 400190 40001c3c 0020998f 00209c27 23c01c03
+# CHECK-NEXT: 4001a0 2578e003 82c01800 09f82003 feff1827
+# CHECK-NEXT: 4001b0 40000f3c 0820f98d 08002003 0820f825
+# ^ PLT.T1
+# CHECK-NEXT: 4001c0 00799307 22ff0000 9945020f
+# ^ PLT.T2
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 4001cc 6c001000 f8ff0000 f7ff1f00 f6ffff03
+# ^ T0 ^ PLT.T1 (0x4001b0)
+# ^ 0x4001d0 -32 = 0x4001b0
+# ^ ...
+# CHECK-NEXT: 4001dc 2000e000 70000000 ee030000 0000ecff
+# ^ T3 ^ PLT.T2
+# ^ ...
+# CHECK-NEXT: 4001ec 7f00f5ff
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 004001cc g F .text 00000010 T0
+# CHECK: 004001dc g F .text 00000014 T3
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+ EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+
+# reg.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 16
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_26
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_PC16
+ - Offset: 8
+ Symbol: T1
+ Type: R_MIPS_PC21_S2
+ - Offset: 12
+ Symbol: T1
+ Type: R_MIPS_PC26_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Size: 16
+ - Name: T1
+
+# micro.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 20
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T2
+ Type: R_MICROMIPS_26_S1
+ - Offset: 4
+ Symbol: T2
+ Type: R_MICROMIPS_PC7_S1
+ - Offset: 8
+ Symbol: T2
+ Type: R_MICROMIPS_PC10_S1
+ - Offset: 12
+ Symbol: T2
+ Type: R_MICROMIPS_PC16_S1
+ - Offset: 16
+ Symbol: T2
+ Type: R_MICROMIPS_PC23_S2
+
+Symbols:
+ Global:
+ - Name: T3
+ Section: .text
+ Size: 20
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/la25-stub-pic.test b/test/old-elf/Mips/la25-stub-pic.test
new file mode 100644
index 0000000000000..8db88404aaefa
--- /dev/null
+++ b/test/old-elf/Mips/la25-stub-pic.test
@@ -0,0 +1,144 @@
+# Check that we do not create LA26 stubs and PLT entries
+# when a PIC function is called from PIC code.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-reg.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-micro.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o %t-reg.o %t-micro.o
+
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK-NOT: Contents of section .plt:
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 400130 00000000 00000000 4c001000 fdff0000
+# ^ T1 ^ T2 ^ T1 (0x400130)
+# ^ 0x40013c - 12 = 0x0x400130
+# CHECK-NEXT: 400140 fcff1f00 fbffff03 20009a00 74000000
+# ^ T2 (0x400134)
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00400130 g F .text 00000004 T1
+# CHECK: 00400134 g F .text 00000004 T2
+# CHECK: 00400138 g F .text 00000010 T0
+# CHECK: 00400148 g F .text 00000014 T3
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+ EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+
+# reg.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_PIC]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 16
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_26
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_PC16
+ - Offset: 8
+ Symbol: T1
+ Type: R_MIPS_PC21_S2
+ - Offset: 12
+ Symbol: T1
+ Type: R_MIPS_PC26_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Size: 16
+ - Name: T1
+
+# micro.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32,
+ EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 20
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T2
+ Type: R_MICROMIPS_26_S1
+ - Offset: 4
+ Symbol: T2
+ Type: R_MICROMIPS_PC7_S1
+ - Offset: 8
+ Symbol: T2
+ Type: R_MICROMIPS_PC10_S1
+ - Offset: 12
+ Symbol: T2
+ Type: R_MICROMIPS_PC16_S1
+ - Offset: 16
+ Symbol: T2
+ Type: R_MICROMIPS_PC23_S2
+
+Symbols:
+ Global:
+ - Name: T3
+ Section: .text
+ Size: 20
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/la25-stub.test b/test/old-elf/Mips/la25-stub.test
new file mode 100644
index 0000000000000..4df7f85e8c89b
--- /dev/null
+++ b/test/old-elf/Mips/la25-stub.test
@@ -0,0 +1,133 @@
+# Check LA25 stubs creation when PIC code is called from non-PIC routines.
+
+# Build executable from pic and non-pic code.
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-npic.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-pic.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-main.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe \
+# RUN: %t-npic.o %t-pic.o %t-main.o
+
+# RUN: llvm-readobj -t %t.exe | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=ASM %s
+
+# SYM: Name: loc (13)
+# SYM-NEXT: Value: 0x400154
+# SYM: Name: T1N (1)
+# SYM-NEXT: Value: 0x400130
+# SYM: Name: T1 (5)
+# SYM-NEXT: Value: 0x400140
+# SYM: Name: glob (8)
+# SYM-NEXT: Value: 0x400144
+
+# ASM: Contents of section .text:
+# ASM-NEXT: 400130 00000000 00000000 00000000 00000000
+# ASM-NEXT: 400140 00000000 00000000 00000000 51001000
+# 0x100051 << 2 == 0x400144 (glob) --^
+# ASM-NEXT: 400150 00000000 51001000 00000000 4c001000
+# ^-- 0x100051 << 2 == 0x400144 (glob)
+# 0x100044 << 2 == 0x400110 (T1N) --^
+# ASM-NEXT: 400160 00000000 5c001000 00000000 00000000
+# ^-- 0x10005c << 2 == 0x400170 (T1 stub)
+# ASM-NEXT: 400170 4000193c 50001008 40013927 00000000
+# ^-- j 0x400140 (T1)
+
+# npic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x04
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1N
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# pic.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC, EF_MIPS_PIC ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x04
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# main.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32, EF_MIPS_CPIC ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x28
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x08
+ Symbol: .text
+ Type: R_MIPS_26
+ Addend: 0
+ - Offset: 0x10
+ Symbol: glob
+ Type: R_MIPS_26
+ Addend: 0
+ - Offset: 0x18
+ Symbol: T1N
+ Type: R_MIPS_26
+ Addend: 0
+ - Offset: 0x20
+ Symbol: T1
+ Type: R_MIPS_26
+ Addend: 0
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 0x10
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ - Name: T1
+ - Name: T1N
+...
diff --git a/test/old-elf/Mips/mips-options-01.test b/test/old-elf/Mips/mips-options-01.test
new file mode 100644
index 0000000000000..8f2e63ca3b5f0
--- /dev/null
+++ b/test/old-elf/Mips/mips-options-01.test
@@ -0,0 +1,34 @@
+# Check that LLD does not write a .MIPS.options section if input
+# object file does not contain such section.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t.o
+# RUN: llvm-readobj -s -dynamic-table %t.so | FileCheck %s
+
+# CHECK: Sections [
+# CHECK-NOT: Name: .MIPS.options
+
+# CHECK: DynamicSection [
+# CHECK-NOT: 0x{{[0-9A-F]+}} MIPS_OPTIONS
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/mips-options-02.test b/test/old-elf/Mips/mips-options-02.test
new file mode 100644
index 0000000000000..a5f19e55735f0
--- /dev/null
+++ b/test/old-elf/Mips/mips-options-02.test
@@ -0,0 +1,104 @@
+# Check merging input .MIPS.options sections.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t1.o %t2.o
+# RUN: llvm-readobj -s -dynamic-table %t.so | FileCheck -check-prefix=SEC %s
+# RUN: llvm-objdump -s -t %t.so | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -program-headers %t.so | FileCheck -check-prefix=PHDR %s
+
+# SEC: Index: 1
+# SEC-NEXT: Name: .MIPS.options (1)
+# SEC-NEXT: Type: SHT_MIPS_OPTIONS (0x7000000D)
+# SEC-NEXT: Flags [ (0x8000002)
+# SEC-NEXT: SHF_ALLOC (0x2)
+# SEC-NEXT: SHF_MIPS_NOSTRIP (0x8000000)
+# SEC-NEXT: ]
+# SEC-NEXT: Address: 0x[[OPT_ADDR:[0-9A-F]+]]
+# SEC-NEXT: Offset: {{[0-9A-F]+}}
+# SEC-NEXT: Size: 40
+# SEC-NEXT: Link: 0
+# SEC-NEXT: Info: 0
+# SEC-NEXT: AddressAlignment: 8
+# SEC-NEXT: EntrySize: 1
+
+# SEC: DynamicSection [
+# SEC: 0x{{[0-9A-F]+}} MIPS_OPTIONS 0x[[OPT_ADDR]]
+
+# RAW: Contents of section .MIPS.options:
+# RAW-NEXT: {{[0-9a-f]+}} 01280000 00000000 f0000001 00000000
+# RAW-NEXT: {{[0-9a-f]+}} e0000002 d0000003 b0000004 c0000005
+# RAW-NEXT: {{[0-9a-f]+}} f08f0000 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 0000000000008ff0 g *ABS* 00000000 _gp
+
+# Check that %t.so contains only two PT_LOAD segments
+# PHDR: ProgramHeaders
+# PHDR: Type: PT_LOAD
+# PHDR: Type: PT_LOAD
+# PHDR-NOT: Type: PT_LOAD
+# PHDR: Type: PT_DYNAMIC
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 8
+# v ODK_NULL 0x18 bytes long v ODK_REGINFO
+ Content: "0018000000000000000000000000000000000000000000000128000000000000F000000000000000E0000000D0000000B0000000C00000000010000000000000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 8
+# v ODK_NULL 0x18 bytes long v ODK_REGINFO
+ Content: "00180000000000000000000000000000000000000000000001280000000000000000000100000000000000020000000300000004000000050000010000000000"
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/mips-options-03.test b/test/old-elf/Mips/mips-options-03.test
new file mode 100644
index 0000000000000..a0dea5709b6fd
--- /dev/null
+++ b/test/old-elf/Mips/mips-options-03.test
@@ -0,0 +1,41 @@
+# Check handling a zero-filled input .MIPS.options section.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t.o
+# RUN: llvm-objdump -s -t %t.so | FileCheck %s
+
+# CHECK: Contents of section .MIPS.options:
+# CHECK-NEXT: {{[0-9a-f]+}} 01280000 00000000 00000000 00000000
+# CHECK-NEXT: {{[0-9a-f]+}} 00000000 00000000 00000000 00000000
+# CHECK-NEXT: {{[0-9a-f]+}} f08f0000 00000000
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 00008ff0 g *ABS* 00000000 _gp
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 8
+ Content: "01280000000000000000000000000000000000000000000000000000000000000000000000000000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/mips-options-04.test b/test/old-elf/Mips/mips-options-04.test
new file mode 100644
index 0000000000000..5df94aae92570
--- /dev/null
+++ b/test/old-elf/Mips/mips-options-04.test
@@ -0,0 +1,77 @@
+# Check that .MIPS.options sections from shared libraries do not affect
+# output .MIPS.options section content.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t.so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t.exe.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t.so %t.exe.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .MIPS.options:
+# CHECK-NEXT: {{[0-9a-f]+}} 01280000 00000000 44444444 00000000
+# CHECK-NEXT: {{[0-9a-f]+}} 44444444 44444444 44444444 44444444
+# CHECK-NEXT: {{[0-9a-f]+}} f08f0020 01000000
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 20008ff0 g *ABS* 00000000 _gp
+
+# t.so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 8
+ Content: "01280000000000001111111100000000111111111111111111111111111111110010000000000000"
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t.exe.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 8
+ Content: "01280000000000004444444400000000444444444444444444444444444444440010000000000000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/mips-options-05.test b/test/old-elf/Mips/mips-options-05.test
new file mode 100644
index 0000000000000..f7e9728b3cf4f
--- /dev/null
+++ b/test/old-elf/Mips/mips-options-05.test
@@ -0,0 +1,119 @@
+# Check that .MIPS.options section gets register usage mask from "used" files
+# only. In this test case we take only t2.o from liboptions.a and should not
+# add register usage masks from t1.o to the output .MIPS.options section.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: llvm-ar q %T/liboptions.a %t1.o %t2.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t3.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t3.o -L%T -loptions
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .MIPS.options:
+# CHECK-NEXT: {{[0-9a-f]+}} 01280000 00000000 66666666 00000000
+# CHECK-NEXT: {{[0-9a-f]+}} 66666666 66666666 66666666 66666666
+# CHECK-NEXT: {{[0-9a-f]+}} f08f0020 01000000
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 20008ff0 g *ABS* 00000000 _gp
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 8
+ Content: "01280000000000001111111100000000111111111111111111111111111111110010000000000000"
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 8
+ Content: "01280000000000002222222200000000222222222222222222222222222222220010000000000000"
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t3.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T2
+ Type: R_MIPS_32
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 8
+ Content: "01280000000000004444444400000000444444444444444444444444444444440010000000000000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/mips-options-gp0.test b/test/old-elf/Mips/mips-options-gp0.test
new file mode 100644
index 0000000000000..73e578347f2c9
--- /dev/null
+++ b/test/old-elf/Mips/mips-options-gp0.test
@@ -0,0 +1,77 @@
+# Check reading GP0 value from .MIPS.options section
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -e G1 -shared -o %t.so %t.o
+# RUN: llvm-readobj -symbols %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=SEC %s
+
+# SYM: Name: L1
+# SYM-NEXT: Value: 0x15C
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Local (0x0)
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text (0x5)
+
+# SYM: Name: _gp
+# SYM-NEXT: Value: 0x8FF0
+# SYM-NEXT: Size: 0
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: Object (0x1)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: Absolute (0xFFF1)
+
+# 0xffff816c == 0x0 (addend) + 0x015C (L1) + 0x1000 (GP0) - 0x8ff0 (_gp)
+# SEC: Contents of section .rodata:
+# SEC-NEXT: {{[0-9a-f]+}} 6c81ffff 00000000 00000000 00000000
+
+!ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64R2 ]
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+
+- Name: .rodata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 16
+
+- Name: .rel.rodata
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .rodata
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0
+ Symbol: L1
+ Type: R_MIPS_GPREL32
+
+- Name: .MIPS.options
+ Type: SHT_MIPS_OPTIONS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x01
+ Content: "012800000000000000000000000000000000000000000000000000000000000000100000"
+
+Symbols:
+ Local:
+ - Name: L1
+ Section: .text
+ Value: 0x00
+ Size: 0x04
+ - Name: .rodata
+ Type: STT_SECTION
+ Section: .rodata
+ Global:
+ - Name: G1
+ Section: .text
+ Value: 0x04
+ Size: 0x04
diff --git a/test/old-elf/Mips/n32-rela-chain.test b/test/old-elf/Mips/n32-rela-chain.test
new file mode 100644
index 0000000000000..9569eb7c5855b
--- /dev/null
+++ b/test/old-elf/Mips/n32-rela-chain.test
@@ -0,0 +1,68 @@
+# Check grouping of multiple consecutive relocations in case of N32
+# and 64-bit MIPS ABIs.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 10000130 00001001 00002004
+
+# CHECK: 10002000 l .data 00000004 D0
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64, EF_MIPS_ABI2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 8
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: D0
+ Type: R_MIPS_32
+ Addend: 0x10000
+ - Offset: 0
+ Symbol: D0
+ Type: R_MIPS_HI16
+ - Offset: 4
+ Symbol: D0
+ Type: R_MIPS_32
+ Addend: 4
+ - Offset: 4
+ Symbol: D0
+ Type: R_MIPS_LO16
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Local:
+ - Name: D0
+ Type: STT_FUNC
+ Section: .data
+ Value: 0
+ Size: 4
+ Global:
+ - Name: __start
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 8
+...
diff --git a/test/old-elf/Mips/n64-rel-chain.test b/test/old-elf/Mips/n64-rel-chain.test
new file mode 100644
index 0000000000000..3797c43217014
--- /dev/null
+++ b/test/old-elf/Mips/n64-rel-chain.test
@@ -0,0 +1,204 @@
+# Check handling MIPS N64 ABI relocation "chains".
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -s -t -dt -mips-plt-got %t.exe | \
+# RUN: FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# SYM: Section {
+# SYM: Index: 6
+# SYM-NEXT: Name: .rodata
+# SYM-NEXT: Type: SHT_PROGBITS
+# SYM-NEXT: Flags [
+# SYM-NEXT: SHF_ALLOC
+# SYM-NEXT: ]
+# SYM-NEXT: Address: 0x120000230
+#
+# SYM: Symbol {
+# SYM: Name: LT1
+# SYM-NEXT: Value: 0x120000210
+# SYM-NEXT: Size: 16
+# SYM-NEXT: Binding: Global
+# SYM-NEXT: Type: Function
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text
+# SYM-NEXT: }
+# SYM: Symbol {
+# SYM: Name: T0
+# SYM-NEXT: Value: 0x120000220
+# SYM-NEXT: Size: 16
+# SYM-NEXT: Binding: Global
+# SYM-NEXT: Type: Function
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text
+# SYM-NEXT: }
+# SYM: Symbol {
+# SYM: Name: T1@
+# SYM-NEXT: Value: 0x0
+# SYM-NEXT: Size: 0
+# SYM-NEXT: Binding: Global
+# SYM-NEXT: Type: Function
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: Undefined
+# SYM-NEXT: }
+#
+# SYM: Canonical gp value: 0x120008FF0
+# SYM: Local entries [
+# SYM-NEXT: Entry {
+# SYM-NEXT: Address: 0x{{[0-9A-F]+}}
+# SYM-NEXT: Access: -32736
+# SYM-NEXT: Initial: 0x120000000
+# SYM-NEXT: }
+# SYM-NEXT: ]
+# SYM-NEXT: Global entries [
+# SYM-NEXT: Entry {
+# SYM-NEXT: Address: 0x{{[0-9A-F]+}}
+# SYM-NEXT: Access: -32728
+# SYM-NEXT: Initial: 0x0
+# SYM-NEXT: Value: 0x0
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Section: Undefined (0x0)
+# SYM-NEXT: Name: T1@ (1)
+# SYM-NEXT: }
+# SYM-NEXT: ]
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 120000210 01000000 00000000 e08d0000 00000000
+# ^
+# S - GP = 0x120000210 - 0x120008ff0 = -36320
+# S - A = 0 - (-36320) = 36320
+# (AHL + S + 0x8000) >> 16 = 1
+# ^
+# S - GP = 0x120000210 - 0x120008ff0 = -36320
+# S - A = 0 - (-36320) = 36320
+# AHL + S = 0x8DE0
+# RAW-NEXT: 120000220 20800000 38020000 28800000 00000000
+# ^ 0x8020 = -32736 GOT
+# ^ (0x120000230 + 8 - page) = 0x238
+# ^ 0x8028 = -32728
+# RAW: Contents of section .pdr:
+# RAW-NEXT: 0000 10020020 20020020
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 8
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 8
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 32
+
+ - Name: .rela.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 8
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: LT1
+ Type: R_MIPS_GPREL16
+ Type2: R_MIPS_SUB
+ Type3: R_MIPS_HI16
+ - Offset: 0x08
+ Symbol: LT1
+ Type: R_MIPS_GPREL16
+ Type2: R_MIPS_SUB
+ Type3: R_MIPS_LO16
+ - Offset: 0x10
+ Symbol: .rodata
+ Type: R_MIPS_GOT_PAGE
+ Addend: 8
+ - Offset: 0x14
+ Symbol: .rodata
+ Type: R_MIPS_GOT_OFST
+ Addend: 8
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_CALL16
+
+ - Name: .pdr
+ Type: SHT_PROGBITS
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .rela.pdr
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 8
+ Info: .pdr
+ Relocations:
+ - Offset: 0x00
+ Symbol: LT1
+ Type: R_MIPS_32
+ - Offset: 0x04
+ Symbol: T0
+ Type: R_MIPS_32
+
+ - Name: .rodata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 16
+ Size: 16
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .rodata
+ Type: STT_SECTION
+ Section: .rodata
+ - Name: .pdr
+ Type: STT_SECTION
+ Section: .pdr
+
+ Global:
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x00
+ Size: 0x10
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x10
+ Size: 0x10
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/n64-rel-shift.test b/test/old-elf/Mips/n64-rel-shift.test
new file mode 100644
index 0000000000000..31a780beb9981
--- /dev/null
+++ b/test/old-elf/Mips/n64-rel-shift.test
@@ -0,0 +1,48 @@
+# Check that LLD shift right relocation result after calculation
+# each relocations in N64 relocation chain.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t.o
+# RUN: llvm-objdump -s %t.so | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9a-f]+}} 00000000 01000000 00000000 00000000
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 16
+
+ - Name: .rela.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 8
+ Info: .text
+ Relocations:
+ - Offset: 4
+ Symbol: T1
+ Addend: 8
+ Type: R_MIPS_PC19_S2
+ Type2: R_MIPS_64
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 8
+ - Name: bar
+ Type: STT_FUNC
+ Section: .text
+ Value: 8
+ Size: 8
diff --git a/test/old-elf/Mips/opt-emulation.test b/test/old-elf/Mips/opt-emulation.test
new file mode 100644
index 0000000000000..a48b49bfaa022
--- /dev/null
+++ b/test/old-elf/Mips/opt-emulation.test
@@ -0,0 +1,43 @@
+# Check MIPS specific arguments of the -m command line option.
+
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel -m elf32ltsmip -o %t-exe %t-obj
+# RUN: llvm-readobj -file-headers %t-exe | FileCheck -check-prefix=LE-O32 %s
+# RUN: lld -flavor old-gnu -target mipsel -melf32ltsmip -o %t-exe %t-obj
+# RUN: llvm-readobj -file-headers %t-exe | FileCheck -check-prefix=LE-O32 %s
+
+# LE-O32: Class: 32-bit (0x1)
+# LE-O32: DataEncoding: LittleEndian (0x1)
+# LE-O32: FileVersion: 1
+# LE-O32: OS/ABI: SystemV (0x0)
+# LE-O32: ABIVersion: 1
+# LE-O32: Machine: EM_MIPS (0x8)
+# LE-O32: Version: 1
+# LE-O32: Flags [ (0x70001005)
+# LE-O32-NEXT: EF_MIPS_ABI_O32 (0x1000)
+# LE-O32-NEXT: EF_MIPS_ARCH_32R2 (0x70000000)
+# LE-O32-NEXT: EF_MIPS_CPIC (0x4)
+# LE-O32-NEXT: EF_MIPS_NOREORDER (0x1)
+# LE-O32-NEXT: ]
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "00000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Value: 0x0
+ Size: 4
diff --git a/test/old-elf/Mips/pc23-range.test b/test/old-elf/Mips/pc23-range.test
new file mode 100644
index 0000000000000..89e9ab7bb73fc
--- /dev/null
+++ b/test/old-elf/Mips/pc23-range.test
@@ -0,0 +1,54 @@
+# Check that LLD shows an error if ADDIUPC immediate is out of range.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -o %t.exe %t.o 2>&1 | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}}: reference from __start+4 to T0+4 of type 173 (R_MICROMIPS_PC23_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000080780100"
+# ^ PC23: 1 << 2 = 4 => T0 + 4 - 4 = T0
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x04
+ Size: 0x4000000
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 4
+ Symbol: T0
+ Type: R_MICROMIPS_PC23_S2
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Type: STT_FUNC
+ Size: 8
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: TZ
+ Section: .data
+ Type: STT_FUNC
+ Value: 0
+ Size: 0x2000000
+ - Name: T0
+ Section: .data
+ Type: STT_FUNC
+ Value: 0x2000000
+ Size: 4
diff --git a/test/old-elf/Mips/plt-entry-mixed-1.test b/test/old-elf/Mips/plt-entry-mixed-1.test
new file mode 100644
index 0000000000000..e05eec4c8109a
--- /dev/null
+++ b/test/old-elf/Mips/plt-entry-mixed-1.test
@@ -0,0 +1,114 @@
+# REQUIRES: mips
+
+# Conditions:
+# a) Object file contains both R_MIPS_26 and microMIPS non-jal relocations.
+# b) The R_MIPS_26 relocation handled first.
+# Check:
+# a) PLT contains the only regular entry.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t.o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o.o %t.so
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .plt:
+# CHECK-NEXT: .plt:
+# CHECK-NEXT: 400170: 40 00 1c 3c lui $gp, 64
+# CHECK-NEXT: 400174: 00 20 99 8f lw $25, 8192($gp)
+# CHECK-NEXT: 400178: 00 20 9c 27 addiu $gp, $gp, 8192
+# CHECK-NEXT: 40017c: 23 c0 1c 03 subu $24, $24, $gp
+# CHECK-NEXT: 400180: 25 78 e0 03 move $15, $ra
+# CHECK-NEXT: 400184: 82 c0 18 00 srl $24, $24, 2
+# CHECK-NEXT: 400188: 09 f8 20 03 jalr $25
+# CHECK-NEXT: 40018c: fe ff 18 27 addiu $24, $24, -2
+# CHECK-NEXT: 400190: 40 00 0f 3c lui $15, 64
+# CHECK-NEXT: 400194: 08 20 f9 8d lw $25, 8200($15)
+# CHECK-NEXT: 400198: 08 00 20 03 jr $25
+# CHECK-NEXT: 40019c: 08 20 f8 25 addiu $24, $15, 8200
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000C00000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_26
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x8
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-entry-mixed-2.test b/test/old-elf/Mips/plt-entry-mixed-2.test
new file mode 100644
index 0000000000000..299aa5ce065c1
--- /dev/null
+++ b/test/old-elf/Mips/plt-entry-mixed-2.test
@@ -0,0 +1,93 @@
+# REQUIRES: mips
+
+# Conditions:
+# a) Object file contains both R_MIPS_26 and R_MICROMIPS_26_S1 relocations.
+# Check:
+# a) PLT contains both regular and compressed PLT entries
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t.o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o.o %t.so
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# FIXME (simon): Check the disassembler output when llvm-objdump starts
+# to support microMIPS instruction encoding.
+
+# CHECK: Contents of section .plt:
+# CHECK-NEXT: 400170 40001c3c 0020998f 00209c27 23c01c03
+# CHECK-NEXT: 400180 2578e003 82c01800 09f82003 feff1827
+# CHECK-NEXT: 400190 40000f3c 0820f98d 08002003 0820f825
+# CHECK-NEXT: 4001a0 00799a07 22ff0000 9945020f
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000C000000000000000000000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: T2
+ Type: R_MIPS_26
+ - Offset: 0x8
+ Symbol: T2
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 0x8
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/plt-entry-mixed-3.test b/test/old-elf/Mips/plt-entry-mixed-3.test
new file mode 100644
index 0000000000000..c946ecc82d2f6
--- /dev/null
+++ b/test/old-elf/Mips/plt-entry-mixed-3.test
@@ -0,0 +1,98 @@
+# REQUIRES: mips
+
+# Conditions:
+# a) Object file contains microMIPS instructions.
+# b) There is a relocation refers arbitrary symbols and requires a PLT entry.
+# Check:
+# a) PLT contains a compressed entry.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t.o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o.o %t.so
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# FIXME (simon): Check the disassembler output when llvm-objdump starts
+# to support microMIPS instruction encoding.
+
+# CHECK: Contents of section .plt:
+# CHECK-NEXT: 400170 8079a407 23ff0000 35052525 0233feff .y..#...5.%%.3..
+# CHECK-NEXT: 400180 ff0df945 830f000c 0079a007 22ff0000 ...E.....y.."...
+# CHECK-NEXT: 400190 9945020f .E..
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 16
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 16
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-entry-mixed-4.test b/test/old-elf/Mips/plt-entry-mixed-4.test
new file mode 100644
index 0000000000000..ba8b04866b984
--- /dev/null
+++ b/test/old-elf/Mips/plt-entry-mixed-4.test
@@ -0,0 +1,85 @@
+# REQUIRES: mips
+
+# Conditions:
+# a) Object file contains R_MIPS_26 relocation refers to the microMIPS symbol.
+# Check:
+# a) PLT contains a regular non-compressed entry.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t.o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o.o %t.so
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# FIXME (simon): Check the disassembler output when llvm-objdump starts
+# to support microMIPS instruction encoding.
+
+# CHECK: Contents of section .plt:
+# CHECK-NEXT: 400170 40001c3c 0020998f 00209c27 23c01c03
+# CHECK-NEXT: 400180 2578e003 82c01800 09f82003 feff1827
+# CHECK-NEXT: 400190 40000f3c 0820f98d 08002003 0820f825
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000C00000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_26
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x8
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-entry-r6-be.test b/test/old-elf/Mips/plt-entry-r6-be.test
new file mode 100644
index 0000000000000..3e15ece894e05
--- /dev/null
+++ b/test/old-elf/Mips/plt-entry-r6-be.test
@@ -0,0 +1,109 @@
+# REQUIRES: mips
+
+# Check generation of PLT entries in case of R6 big-endian target ABI.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .plt:
+# CHECK-NEXT: .plt:
+# CHECK-NEXT: 400160: 3c 1c 00 40 lui $gp, 64
+# CHECK-NEXT: 400164: 8f 99 20 00 lw $25, 8192($gp)
+# CHECK-NEXT: 400168: 27 9c 20 00 addiu $gp, $gp, 8192
+# CHECK-NEXT: 40016c: 03 1c c0 23 subu $24, $24, $gp
+# CHECK-NEXT: 400170: 03 e0 78 25 move $15, $ra
+# CHECK-NEXT: 400174: 00 18 c0 82 srl $24, $24, 2
+# CHECK-NEXT: 400178: 03 20 f8 09 jalr $25
+# CHECK-NEXT: 40017c: 27 18 ff fe addiu $24, $24, -2
+# CHECK-NEXT: 400180: 3c 0f 00 40 lui $15, 64
+# CHECK-NEXT: 400184: 8d f9 20 08 lw $25, 8200($15)
+# CHECK-NEXT: 400188: 03 20 00 09 jr $25
+# CHECK-NEXT: 40018c: 25 f8 20 08 addiu $24, $15, 8200
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0C00000000000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_26
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x8
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-entry-r6.test b/test/old-elf/Mips/plt-entry-r6.test
new file mode 100644
index 0000000000000..0d8bbf494afe4
--- /dev/null
+++ b/test/old-elf/Mips/plt-entry-r6.test
@@ -0,0 +1,109 @@
+# REQUIRES: mips
+
+# Check generation of PLT entries in case of R6 target ABI.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .plt:
+# CHECK-NEXT: .plt:
+# CHECK-NEXT: 400160: 40 00 1c 3c lui $gp, 64
+# CHECK-NEXT: 400164: 00 20 99 8f lw $25, 8192($gp)
+# CHECK-NEXT: 400168: 00 20 9c 27 addiu $gp, $gp, 8192
+# CHECK-NEXT: 40016c: 23 c0 1c 03 subu $24, $24, $gp
+# CHECK-NEXT: 400170: 25 78 e0 03 move $15, $ra
+# CHECK-NEXT: 400174: 82 c0 18 00 srl $24, $24, 2
+# CHECK-NEXT: 400178: 09 f8 20 03 jalr $25
+# CHECK-NEXT: 40017c: fe ff 18 27 addiu $24, $24, -2
+# CHECK-NEXT: 400180: 40 00 0f 3c lui $15, 64
+# CHECK-NEXT: 400184: 08 20 f9 8d lw $25, 8200($15)
+# CHECK-NEXT: 400188: 09 00 20 03 jr $25
+# CHECK-NEXT: 40018c: 08 20 f8 25 addiu $24, $15, 8200
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000C00000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_26
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x8
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-header-be.test b/test/old-elf/Mips/plt-header-be.test
new file mode 100644
index 0000000000000..e453e44f76d6a
--- /dev/null
+++ b/test/old-elf/Mips/plt-header-be.test
@@ -0,0 +1,104 @@
+# REQUIRES: mips
+
+# Check initialization of big-endian .plt header entries.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -section-headers -disassemble %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .plt:
+# CHECK-NEXT: .plt:
+# CHECK-NEXT: 400160: 3c 1c 00 40 lui $gp, 64
+# CHECK-NEXT: 400164: 8f 99 20 00 lw $25, 8192($gp)
+# CHECK-NEXT: 400168: 27 9c 20 00 addiu $gp, $gp, 8192
+# CHECK-NEXT: 40016c: 03 1c c0 23 subu $24, $24, $gp
+# CHECK-NEXT: 400170: 03 e0 78 25 move $15, $ra
+# CHECK-NEXT: 400174: 00 18 c0 82 srl $24, $24, 2
+# CHECK-NEXT: 400178: 03 20 f8 09 jalr $25
+# CHECK-NEXT: 40017c: 27 18 ff fe addiu $24, $24, -2
+
+# CHECK-NEXT: 400180: 3c 0f 00 40 lui $15, 64
+# CHECK-NEXT: 400184: 8d f9 20 08 lw $25, 8200($15)
+# CHECK-NEXT: 400188: 03 20 00 08 jr $25
+# CHECK-NEXT: 40018c: 25 f8 20 08 addiu $24, $15, 8200
+
+# CHECK: Sections:
+# CHECK: Idx Name Size Address Type
+# CHECK: 6 .plt 00000030 0000000000400160 TEXT DATA
+# CHECK: 10 .got.plt 0000000c 0000000000402000 DATA
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 12
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 32
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 8
+ Symbol: .text
+ Type: R_MIPS_26
+ - Offset: 16
+ Symbol: __start
+ Type: R_MIPS_26
+ - Offset: 24
+ Symbol: T1
+ Type: R_MIPS_26
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 16
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: __start
+ Section: .text
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-header-micro-be.test b/test/old-elf/Mips/plt-header-micro-be.test
new file mode 100644
index 0000000000000..e9aa51ef85ebc
--- /dev/null
+++ b/test/old-elf/Mips/plt-header-micro-be.test
@@ -0,0 +1,105 @@
+# REQUIRES: mips
+
+# Check initialization of .plt header entries
+# if all PLT entries use microMIPS big-endian encoding.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: lld -flavor old-gnu -target mips -shared -o %t.so %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mips -o %t.exe %t2.o %t.so
+# RUN: llvm-objdump -section-headers -d -mattr=micromips %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .plt:
+# CHECK-NEXT: .plt:
+# CHECK-NEXT: 400170: 79 80 07 a4 addiupc $3, 7824
+# CHECK-NEXT: 400174: ff 23 00 00 lw $25, 0($3)
+# CHECK-NEXT: 400178: 05 35 subu16 $2, $2, $3
+# CHECK-NEXT: 40017a: 25 25 srl16 $2, $2, 2
+# CHECK-NEXT: 40017c: 33 02 ff fe addiu $24, $2, -2
+# CHECK-NEXT: 400180: 0d ff move $15, $ra
+# CHECK-NEXT: 400182: 45 f9 jalrs16 $25
+# CHECK-NEXT: 400184: 0f 83 move $gp, $3
+# CHECK-NEXT: 400186: 0c 00 nop
+
+# CHECK-NEXT: 400188: 79 00 07 a0 addiupc $2, 7808
+# CHECK-NEXT: 40018c: ff 22 00 00 lw $25, 0($2)
+# CHECK-NEXT: 400190: 45 99 jr16 $25
+# CHECK-NEXT: 400192: 0f 02 move $24, $2
+
+# CHECK: Sections:
+# CHECK: Idx Name Size Address Type
+# CHECK: 6 .plt 00000024 0000000000400170 TEXT DATA
+# CHECK: 10 .got.plt 0000000c 0000000000402000 DATA
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 12
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: '0000000000000000f40000000000000000000000f400000000000000f4000000'
+# jal .text jal __start jal T1
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 8
+ Symbol: .text
+ Type: R_MICROMIPS_26_S1
+ - Offset: 20
+ Symbol: __start
+ Type: R_MICROMIPS_26_S1
+ - Offset: 28
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 16
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: __start
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-header-micro.test b/test/old-elf/Mips/plt-header-micro.test
new file mode 100644
index 0000000000000..743c4c332184d
--- /dev/null
+++ b/test/old-elf/Mips/plt-header-micro.test
@@ -0,0 +1,108 @@
+# REQUIRES: mips
+
+# Check initialization of .plt header entries
+# if all PLT entries use microMIPS encoding.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck -check-prefix=DIS %s
+# RUN: llvm-objdump -section-headers %t.exe | FileCheck -check-prefix=EXE %s
+
+# DIS: Disassembly of section .plt:
+# DIS-NEXT: .plt:
+# DIS-NEXT: 400170: 80 79 a4 07 addiupc $3, 7824
+# DIS-NEXT: 400174: 23 ff 00 00 lw $25, 0($3)
+# DIS-NEXT: 400178: 35 05 subu16 $2, $2, $3
+# DIS-NEXT: 40017a: 25 25 srl16 $2, $2, 2
+# DIS-NEXT: 40017c: 02 33 fe ff addiu $24, $2, -2
+# DIS-NEXT: 400180: ff 0d move $15, $ra
+# DIS-NEXT: 400182: f9 45 jalrs16 $25
+# DIS-NEXT: 400184: 83 0f move $gp, $3
+# DIS-NEXT: 400186: 00 0c nop
+
+# DIS-NEXT: 400188: 00 79 a0 07 addiupc $2, 7808
+# DIS-NEXT: 40018c: 22 ff 00 00 lw $25, 0($2)
+# DIS-NEXT: 400190: 99 45 jr16 $25
+# DIS-NEXT: 400192: 02 0f move $24, $2
+
+# EXE: Sections:
+# EXE: Idx Name Size Address Type
+# EXE: 6 .plt 00000024 0000000000400170 TEXT DATA
+# EXE: 10 .got.plt 0000000c 0000000000402000 DATA
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: '000000000000000000f4000000000000f400000000000000f400000000000000'
+# jal .text jal glob jal T1
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x08
+ Symbol: .text
+ Type: R_MICROMIPS_26_S1
+ - Offset: 0x10
+ Symbol: glob
+ Type: R_MICROMIPS_26_S1
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 0x10
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-header-mixed.test b/test/old-elf/Mips/plt-header-mixed.test
new file mode 100644
index 0000000000000..456f5a91c98b0
--- /dev/null
+++ b/test/old-elf/Mips/plt-header-mixed.test
@@ -0,0 +1,105 @@
+# REQUIRES: mips
+
+# Check initialization of .plt header entries if there are both regular
+# and microMIPS encoded PLT entries. Check that R_MIPS_26 and R_MICROMIPS_26_S1
+# relocation with the same target cause generation of two distinct PLT entries.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e globR -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -d %t.exe | FileCheck -check-prefix=DIS %s
+# RUN: llvm-objdump -section-headers %t.exe | FileCheck -check-prefix=EXE %s
+
+# DIS: Disassembly of section .plt:
+# DIS-NEXT: .plt:
+# DIS-NEXT: 400170: 40 00 1c 3c lui $gp, 64
+# DIS-NEXT: 400174: 00 20 99 8f lw $25, 8192($gp)
+# DIS-NEXT: 400178: 00 20 9c 27 addiu $gp, $gp, 8192
+# DIS-NEXT: 40017c: 23 c0 1c 03 subu $24, $24, $gp
+# DIS-NEXT: 400180: 25 78 e0 03 move $15, $ra
+# DIS-NEXT: 400184: 82 c0 18 00 srl $24, $24, 2
+# DIS-NEXT: 400188: 09 f8 20 03 jalr $25
+# DIS-NEXT: 40018c: fe ff 18 27 addiu $24, $24, -2
+
+# DIS-NEXT: 400190: 40 00 0f 3c lui $15, 64
+# DIS-NEXT: 400194: 08 20 f9 8d lw $25, 8200($15)
+# DIS-NEXT: 400198: 08 00 20 03 jr $25
+# DIS-NEXT: 40019c: 08 20 f8 25 addiu $24, $15, 8200
+
+# FIXME (simon): Check micromips PLT entry
+# DIS-NEXT: 4001a8: 99 45 02 0f jal 201922148
+
+# EXE: Sections:
+# EXE: Idx Name Size Address Type
+# EXE: 6 .plt 0000003c 0000000000400170 TEXT DATA
+# EXE: 10 .got.plt 0000000c 0000000000402000 DATA
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x8
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_26
+ - Offset: 0x4
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Global:
+ - Name: globR
+ Section: .text
+ Value: 0x0
+ Size: 0x4
+ - Name: globM
+ Section: .text
+ Value: 0x4
+ Size: 0x4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/plt-header.test b/test/old-elf/Mips/plt-header.test
new file mode 100644
index 0000000000000..6d303254d16d5
--- /dev/null
+++ b/test/old-elf/Mips/plt-header.test
@@ -0,0 +1,99 @@
+# REQUIRES: mips
+
+# Check initialization of .plt header entries.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -section-headers -disassemble %t.exe | \
+# RUN: FileCheck -check-prefix=EXE %s
+
+# EXE: Disassembly of section .plt:
+# EXE: .plt:
+# PLT0 entry. Points to the .got.plt[0]
+# EXE-NEXT: 400160: 40 00 1c 3c lui $gp, 64
+# EXE-NEXT: 400164: 00 20 99 8f lw $25, 8192($gp)
+# EXE-NEXT: 400168: 00 20 9c 27 addiu $gp, $gp, 8192
+# EXE-NEXT: 40016c: 23 c0 1c 03 subu $24, $24, $gp
+# EXE-NEXT: 400170: 25 78 e0 03 move $15, $ra
+# EXE-NEXT: 400174: 82 c0 18 00 srl $24, $24, 2
+# EXE-NEXT: 400178: 09 f8 20 03 jalr $25
+# EXE-NEXT: 40017c: fe ff 18 27 addiu $24, $24, -2
+
+# EXE: Sections:
+# EXE: Idx Name Size Address Type
+# EXE: 6 .plt 00000030 0000000000400160 TEXT DATA
+# EXE: 10 .got.plt 0000000c 0000000000402000 DATA
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x20
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x08
+ Symbol: .text
+ Type: R_MIPS_26
+ - Offset: 0x10
+ Symbol: glob
+ Type: R_MIPS_26
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_26
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 0x10
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/r26-1-micro.test b/test/old-elf/Mips/r26-1-micro.test
new file mode 100644
index 0000000000000..c59b5aa61a532
--- /dev/null
+++ b/test/old-elf/Mips/r26-1-micro.test
@@ -0,0 +1,131 @@
+# REQUIRES: mips
+
+# Check handling of R_MICROMIPS_26_S1 relocation.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: llvm-readobj -relocations %t-o.o | \
+# RUN: FileCheck -check-prefix=OBJ-REL %s
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -relocations %t.exe | FileCheck -check-prefix=EXE-REL %s
+# RUN: llvm-objdump -section-headers %t.exe | FileCheck -check-prefix=EXE %s
+# RUN: llvm-objdump -s -d -mattr=micromips %t.exe | \
+# RUN: FileCheck -check-prefix=DIS %s
+
+# Object file has three R_MICROMIPS_26_S1 relocations
+# OBJ-REL: Relocations [
+# OBJ-REL-NEXT: Section (2) .rel.text {
+# OBJ-REL-NEXT: 0x8 R_MICROMIPS_26_S1 loc 0x0
+# OBJ-REL-NEXT: 0x10 R_MICROMIPS_26_S1 glob 0x0
+# OBJ-REL-NEXT: 0x18 R_MICROMIPS_26_S1 T1 0x0
+# OBJ-REL-NEXT: }
+# OBJ-REL-NEXT: ]
+
+# Executable file has the only relocation for external symbol
+# EXE-REL: Relocations [
+# EXE-REL-NEXT: Section (5) .rel.plt {
+# EXE-REL-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0
+# EXE-REL-NEXT: }
+# EXE-REL-NEXT: ]
+
+# EXE: Sections:
+# EXE: Idx Name Size Address Type
+# EXE: 6 .plt 00000024 0000000000400160 TEXT DATA
+# EXE: 10 .got.plt 0000000c 0000000000402000 DATA
+
+# DIS: Disassembly of section .plt:
+# DIS-NEXT: .plt:
+# DIS-NEXT: 400160: 80 79 a8 07 addiupc $3, 7840
+# DIS-NEXT: 400164: 23 ff 00 00 lw $25, 0($3)
+# DIS-NEXT: 400168: 35 05 subu16 $2, $2, $3
+# DIS-NEXT: 40016a: 25 25 srl16 $2, $2, 2
+# DIS-NEXT: 40016c: 02 33 fe ff addiu $24, $2, -2
+# DIS-NEXT: 400170: ff 0d move $15, $ra
+# DIS-NEXT: 400172: f9 45 jalrs16 $25
+# DIS-NEXT: 400174: 83 0f move $gp, $3
+# DIS-NEXT: 400176: 00 0c nop
+
+# DIS-NEXT: 400178: 00 79 a4 07 addiupc $2, 7824
+# DIS-NEXT: 40017c: 22 ff 00 00 lw $25, 0($2)
+# DIS-NEXT: 400180: 99 45 jr16 $25
+# DIS-NEXT: 400182: 02 0f move $24, $2
+
+# DIS: Contents of section .text:
+# DIS-NEXT: 400184 09f82003 00000000 2400ca0c 00000000 .. .....$.......
+# DIS-NEXT: 400194 2000c20c 00000000 2000bc0c 00000000 ....... .......
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: '09F82003000000000400000C000000000000000C000000000000000C00000000'
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x08
+ Symbol: loc
+ Type: R_MICROMIPS_26_S1
+ - Offset: 0x10
+ Symbol: glob
+ Type: R_MICROMIPS_26_S1
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 0x10
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/r26-1.test b/test/old-elf/Mips/r26-1.test
new file mode 100644
index 0000000000000..41c58deceedbc
--- /dev/null
+++ b/test/old-elf/Mips/r26-1.test
@@ -0,0 +1,132 @@
+# REQUIRES: mips
+
+# Check handling of R_MIPS_26 relocation.
+
+# Build shared library
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Build executable
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: llvm-readobj -relocations %t-o.o | \
+# RUN: FileCheck -check-prefix=OBJ-REL %s
+# RUN: lld -flavor old-gnu -target mipsel -e glob -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -section-headers -disassemble %t.exe | \
+# RUN: FileCheck -check-prefix=EXE %s
+# RUN: llvm-readobj -relocations %t.exe | FileCheck -check-prefix=EXE-REL %s
+
+# Object file has three R_MIPS_26 relocations
+# OBJ-REL: Relocations [
+# OBJ-REL-NEXT: Section (2) .rel.text {
+# OBJ-REL-NEXT: 0x8 R_MIPS_26 .text 0x0
+# OBJ-REL-NEXT: 0x10 R_MIPS_26 glob 0x0
+# OBJ-REL-NEXT: 0x18 R_MIPS_26 T1 0x0
+# OBJ-REL-NEXT: }
+# OBJ-REL-NEXT: ]
+
+# Executable file has the only relocation for external symbol
+# EXE-REL: Relocations [
+# EXE-REL-NEXT: Section (5) .rel.plt {
+# EXE-REL-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0
+# EXE-REL-NEXT: }
+# EXE-REL-NEXT: ]
+
+# EXE: Disassembly of section .plt:
+# EXE: .plt:
+# PLTA entry. Points to the .got.plt[1]
+# EXE: 400180: 40 00 0f 3c lui $15, 64
+# EXE-NEXT: 400184: 08 20 f9 8d lw $25, 8200($15)
+# EXE-NEXT: 400188: 08 00 20 03 jr $25
+# EXE-NEXT: 40018c: 08 20 f8 25 addiu $24, $15, 8200
+
+# EXE: Disassembly of section .text:
+# EXE: glob:
+# EXE-NEXT: 400190: 09 f8 20 03 jalr $25
+# EXE-NEXT: 400194: 00 00 00 00 nop
+#
+# Jump to 'loc' label address
+# EXE-NEXT: 400198: 68 00 10 0c jal 4194720
+# EXE-NEXT: 40019c: 00 00 00 00 nop
+#
+# EXE: loc:
+# Jump to 'glob' label address
+# EXE-NEXT: 4001a0: 64 00 10 0c jal 4194704
+# EXE-NEXT: 4001a4: 00 00 00 00 nop
+#
+# Jump to the first PLT entry (.plt + 32) for T1 entry
+# EXE-NEXT: 4001a8: 60 00 10 0c jal 4194688
+# EXE-NEXT: 4001ac: 00 00 00 00 nop
+
+# EXE: Sections:
+# EXE: Idx Name Size Address Type
+# EXE: 6 .plt 00000030 0000000000400160 TEXT DATA
+# EXE: 10 .got.plt 0000000c 0000000000402000 DATA
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: '09F82003000000000400000C000000000000000C000000000000000C00000000'
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x08
+ Symbol: .text
+ Type: R_MIPS_26
+ - Offset: 0x10
+ Symbol: glob
+ Type: R_MIPS_26
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_26
+
+Symbols:
+ Local:
+ - Name: loc
+ Section: .text
+ Value: 0x10
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ Global:
+ - Name: glob
+ Section: .text
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/r26-2-micro.test b/test/old-elf/Mips/r26-2-micro.test
new file mode 100644
index 0000000000000..7d4f86e57f70f
--- /dev/null
+++ b/test/old-elf/Mips/r26-2-micro.test
@@ -0,0 +1,31 @@
+# REQUIRES: mips
+
+# Check reading addendum for R_MICROMIPS_26_S1 relocation.
+# RUN: llvm-mc -arch=mipsel -filetype=obj -mattr=micromips -o=%t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -o %t.exe %t.o
+# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: __start:
+# CHECK-NEXT: 400180: 10 f0 60 70 jalx 2154688
+# CHECK-NEXT: 400184: 00 00 00 00 nop
+# CHECK-NEXT: 400188: 10 f0 68 70 jalx 2154704
+# CHECK-NEXT: 40018c: 00 00 00 00 nop
+# CHECK-NEXT: 400190: 10 f0 58 00 jalx 2097328
+# CHECK-NEXT: 400194: 00 00 00 00 nop
+# CHECK-NEXT: 400198: 10 f0 62 00 jalx 2097348
+# CHECK-NEXT: 40019c: 00 00 00 00 nop
+#
+# CHECK: loc:
+# CHECK-NEXT: 4001a0: 00 00 00 00 nop
+
+ .text
+ .globl __start
+__start:
+ jal __start + 0x1C000
+ jal loc + 0x1C000
+ jal __start + 0x7ffffe2
+ jal loc + 0x7ffffea
+
+loc:
+ nop
diff --git a/test/old-elf/Mips/r26-2.test b/test/old-elf/Mips/r26-2.test
new file mode 100644
index 0000000000000..b9db959d3ea75
--- /dev/null
+++ b/test/old-elf/Mips/r26-2.test
@@ -0,0 +1,31 @@
+# REQUIRES: mips
+
+# Check reading addendum for R_MIPS_26 relocation.
+# RUN: llvm-mc -arch=mipsel -filetype=obj -o=%t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -o %t.exe %t.o
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: __start:
+# CHECK-NEXT: 400180: 60 70 10 0c jal 4309376
+# CHECK-NEXT: 400184: 00 00 00 00 nop
+# CHECK-NEXT: 400188: 68 70 10 0c jal 4309408
+# CHECK-NEXT: 40018c: 00 00 00 00 nop
+# CHECK-NEXT: 400190: 5f 00 10 0c jal 4194684
+# CHECK-NEXT: 400194: 00 00 00 00 nop
+# CHECK-NEXT: 400198: 67 00 10 0c jal 4194716
+# CHECK-NEXT: 40019c: 00 00 00 00 nop
+#
+# CHECK: loc:
+# CHECK-NEXT: 4001a0: 00 00 00 00 nop
+
+ .text
+ .globl __start
+__start:
+ jal __start + 0x1C000
+ jal loc + 0x1C000
+ jal __start + (-1)
+ jal loc + (-1)
+
+loc:
+ nop
diff --git a/test/old-elf/Mips/reginfo-01.test b/test/old-elf/Mips/reginfo-01.test
new file mode 100644
index 0000000000000..ee7cd6a5fceed
--- /dev/null
+++ b/test/old-elf/Mips/reginfo-01.test
@@ -0,0 +1,30 @@
+# Check that LLD does not write a .reginfo section if input
+# object file does not contain such section.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -s %t.so | FileCheck %s
+
+# CHECK-NOT: Name: .reginfo
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/reginfo-02.test b/test/old-elf/Mips/reginfo-02.test
new file mode 100644
index 0000000000000..41eac01a11b17
--- /dev/null
+++ b/test/old-elf/Mips/reginfo-02.test
@@ -0,0 +1,107 @@
+# Check merging input .reginfo sections.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t1.o %t2.o
+# RUN: llvm-readobj -program-headers -s -t -mips-reginfo %t.so | FileCheck %s
+
+# CHECK: Index: 1
+# CHECK-NEXT: Name: .reginfo (1)
+# CHECK-NEXT: Type: SHT_MIPS_REGINFO
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: SHF_ALLOC
+# CHECK-NEXT: ]
+# CHECK-NEXT: Address: {{[0-9A-F]+}}
+# CHECK-NEXT: Offset: {{[0-9A-F]+}}
+# CHECK-NEXT: Size: 24
+# CHECK-NEXT: Link: 0
+# CHECK-NEXT: Info: 0
+# CHECK-NEXT: AddressAlignment: 4
+# CHECK-NEXT: EntrySize: 24
+
+# CHECK: Name: _gp
+# CHECK-NEXT: 0x8FF0
+
+# CHECK: ProgramHeaders [
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_MIPS_REGINFO
+# CHECK-NEXT: Offset: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: VirtualAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: PhysicalAddress: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: FileSize: 24
+# CHECK-NEXT: MemSize: 24
+# CHECK-NEXT: Flags [
+# CHECK-NEXT: PF_R
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 4
+# CHECK-NEXT: }
+
+# CHECK: MIPS RegInfo {
+# CHECK-NEXT: GP: 0x8FF0
+# CHECK-NEXT: General Mask: 0x10000F0
+# CHECK-NEXT: Co-Proc Mask0: 0x20000E0
+# CHECK-NEXT: Co-Proc Mask1: 0x30000D0
+# CHECK-NEXT: Co-Proc Mask2: 0x40000C0
+# CHECK-NEXT: Co-Proc Mask3: 0x50000B0
+# CHECK-NEXT: }
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "F0000000E0000000D0000000C0000000B000000000100000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "000000010000000200000003000000040000000500000100"
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/reginfo-03.test b/test/old-elf/Mips/reginfo-03.test
new file mode 100644
index 0000000000000..edee1440d358e
--- /dev/null
+++ b/test/old-elf/Mips/reginfo-03.test
@@ -0,0 +1,45 @@
+# Check handling a zero-filled input .reginfo section.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -t -mips-reginfo %t.so | FileCheck %s
+
+# CHECK: Name: _gp
+# CHECK-NEXT: 0x8FF0
+
+# CHECK: MIPS RegInfo {
+# CHECK-NEXT: GP: 0x8FF0
+# CHECK-NEXT: General Mask: 0x0
+# CHECK-NEXT: Co-Proc Mask0: 0x0
+# CHECK-NEXT: Co-Proc Mask1: 0x0
+# CHECK-NEXT: Co-Proc Mask2: 0x0
+# CHECK-NEXT: Co-Proc Mask3: 0x0
+# CHECK-NEXT: }
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "000000000000000000000000000000000000000000000000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/reginfo-04.test b/test/old-elf/Mips/reginfo-04.test
new file mode 100644
index 0000000000000..bad34e5003f74
--- /dev/null
+++ b/test/old-elf/Mips/reginfo-04.test
@@ -0,0 +1,81 @@
+# Check that .reginfo sections from shared libraries do not affect
+# output .reginfo section content.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t.exe.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.so %t.exe.o
+# RUN: llvm-readobj -t -mips-reginfo %t.exe | FileCheck %s
+
+# CHECK: Name: _gp
+# CHECK-NEXT: 0x408FF0
+
+# CHECK: MIPS RegInfo {
+# CHECK-NEXT: GP: 0x408FF0
+# CHECK-NEXT: General Mask: 0x44444444
+# CHECK-NEXT: Co-Proc Mask0: 0x44444444
+# CHECK-NEXT: Co-Proc Mask1: 0x44444444
+# CHECK-NEXT: Co-Proc Mask2: 0x44444444
+# CHECK-NEXT: Co-Proc Mask3: 0x44444444
+# CHECK-NEXT: }
+
+# t.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "111111111111111111111111111111111111111100100000"
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t.exe.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "444444444444444444444444444444444444444400000000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/reginfo-05.test b/test/old-elf/Mips/reginfo-05.test
new file mode 100644
index 0000000000000..9de9fa62149ab
--- /dev/null
+++ b/test/old-elf/Mips/reginfo-05.test
@@ -0,0 +1,123 @@
+# Check that .reginfo section gets register usage mask from "used" files only.
+# In this test case we take only t2.o from libreginfo.a and should not add
+# register usage masks from t1.o to the output .reginfo section.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: llvm-ar q %T/libreginfo.a %t1.o %t2.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t3.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t3.o -L%T -lreginfo
+# RUN: llvm-readobj -t -mips-reginfo %t.exe | FileCheck %s
+
+# CHECK: Name: _gp
+# CHECK-NEXT: 0x408FF0
+
+# CHECK: MIPS RegInfo {
+# CHECK-NEXT: GP: 0x408FF0
+# CHECK-NEXT: General Mask: 0x66666666
+# CHECK-NEXT: Co-Proc Mask0: 0x66666666
+# CHECK-NEXT: Co-Proc Mask1: 0x66666666
+# CHECK-NEXT: Co-Proc Mask2: 0x66666666
+# CHECK-NEXT: Co-Proc Mask3: 0x66666666
+# CHECK-NEXT: }
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "111111111111111111111111111111111111111100000000"
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "222222222222222222222222222222222222222200000000"
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t3.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T2
+ Type: R_MIPS_32
+
+- Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: "444444444444444444444444444444444444444400000000"
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/rel-16-overflow.test b/test/old-elf/Mips/rel-16-overflow.test
new file mode 100644
index 0000000000000..e2a73f6933611
--- /dev/null
+++ b/test/old-elf/Mips/rel-16-overflow.test
@@ -0,0 +1,45 @@
+# Check R_MIPS_16 relocation overflow handling.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}} reference from T0+0 to T1+32767 of type 1 (R_MIPS_16)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "ff7f00000000000000000000"
+# ^ T1
+# ^ T0 A := 0x7fff
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-16.test b/test/old-elf/Mips/rel-16.test
new file mode 100644
index 0000000000000..24961e8b78ff2
--- /dev/null
+++ b/test/old-elf/Mips/rel-16.test
@@ -0,0 +1,51 @@
+# Check handling of R_MIPS_16 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 00f0 f0000000 00000000 00000000
+# ^ V = (T1 - 8) = T0
+
+# CHECK: SYMBOL TABLE:
+# CHECK: 000000f0 g F .text 00000008 T0
+# CHECK: 000000f8 g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "f8ff00000000000000000000"
+# ^ T1
+# ^ T0 A := 0xfff8 = -8
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-32-be.test b/test/old-elf/Mips/rel-32-be.test
new file mode 100644
index 0000000000000..3eac8a2848f06
--- /dev/null
+++ b/test/old-elf/Mips/rel-32-be.test
@@ -0,0 +1,60 @@
+# Check handling of R_MIPS_32 relocation in the big-endian case.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: 402000 00000000 01402088 01402084
+# ^^ D2 + 0x1000080 = 0x1402088
+# ^^ D1 + 0x1000080 = 0x1402084
+# CHECK: SYMBOL TABLE:
+# CHECK: 00402004 g .data 00000004 D1
+# CHECK: 00402008 g .data 00000004 D2
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2MSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ AddressAlign: 16
+ Flags: [SHF_ALLOC]
+ Size: 4
+
+- Name: .data
+ Type: SHT_PROGBITS
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_WRITE]
+ Content: "000000000100008001000080"
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_32
+ - Offset: 8
+ Symbol: D1
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: D1
+ Section: .data
+ Value: 4
+ Size: 4
+ - Name: D2
+ Section: .data
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-32.test b/test/old-elf/Mips/rel-32.test
new file mode 100644
index 0000000000000..f028d79c86882
--- /dev/null
+++ b/test/old-elf/Mips/rel-32.test
@@ -0,0 +1,59 @@
+# Check handling of R_MIPS_32 relocation.
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel -o %t-exe %t-obj
+# RUN: llvm-objdump -s -t %t-exe | FileCheck %s
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: 402000 00000000 09204080 05204080 ..... @.. @.
+# ^^ data2 + 0x80000001 = 0x80402009
+# ^^ data1 + 0x80000001 = 0x80402005
+# CHECK: SYMBOL TABLE:
+# CHECK: 00402004 g .data 00000004 data1
+# CHECK: 00402008 g .data 00000004 data2
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "00000000"
+ AddressAlign: 16
+ Flags: [SHF_ALLOC]
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: "000000000100008001000080"
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x4
+ Symbol: data2
+ Type: R_MIPS_32
+ - Offset: 0x8
+ Symbol: data1
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Value: 0x0
+ Size: 4
+ - Name: data1
+ Section: .data
+ Value: 0x4
+ Size: 4
+ - Name: data2
+ Section: .data
+ Value: 0x8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-64.test b/test/old-elf/Mips/rel-64.test
new file mode 100644
index 0000000000000..c97ff991c0c44
--- /dev/null
+++ b/test/old-elf/Mips/rel-64.test
@@ -0,0 +1,61 @@
+# Check handling of R_MIPS_64 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: 120002000 d1010020 01000000 d0010020 01000100 ... ....... ....
+# ^^ __start + 1 = 0x1200001d1
+# ^^ __start + 0x1000000000000
+# = 0x10001200001d0
+# CHECK: SYMBOL TABLE:
+# CHECK: 00000001200001d0 g .rodata 00000008 __start
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_ALLOC]
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x10
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rela.data
+ Type: SHT_RELA
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: __start
+ Type: R_MIPS_64
+ Addend: 1
+ - Offset: 0x8
+ Symbol: __start
+ Type: R_MIPS_64
+ Addend: 0x1000000000000
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Value: 0x0
+ Size: 8
+ - Name: data1
+ Section: .data
+ Value: 0x0
+ Size: 8
+ - Name: data2
+ Section: .data
+ Value: 0x8
+ Size: 8
diff --git a/test/old-elf/Mips/rel-call-hilo-01.test b/test/old-elf/Mips/rel-call-hilo-01.test
new file mode 100644
index 0000000000000..88f2e337d9282
--- /dev/null
+++ b/test/old-elf/Mips/rel-call-hilo-01.test
@@ -0,0 +1,109 @@
+# Check handling of R_MIPS_CALL_HI16 / R_MIPS_CALL_LO16 relocations.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t1.so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2.so %t2.so.o %t1.so
+# RUN: llvm-objdump -s -t %t2.so | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -mips-plt-got %t2.so | FileCheck -check-prefix=GOT %s
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 0110 00000000 18800000 00000000 1c800000
+# ^ -32744 ^ -32740
+# RAW-NEXT: 0120 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 00000120 l F .text 00000004 T1
+
+# GOT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x120
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# t1.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t2.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 20
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_CALL_HI16
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_CALL_LO16
+ - Offset: 8
+ Symbol: T2
+ Type: R_MIPS_CALL_HI16
+ - Offset: 12
+ Symbol: T2
+ Type: R_MIPS_CALL_LO16
+
+Symbols:
+ Local:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 16
+ Size: 4
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 16
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/rel-call-hilo-micro.test b/test/old-elf/Mips/rel-call-hilo-micro.test
new file mode 100644
index 0000000000000..0df68def92b31
--- /dev/null
+++ b/test/old-elf/Mips/rel-call-hilo-micro.test
@@ -0,0 +1,154 @@
+# Check handling of R_MICROMIPS_CALL_HI16 / R_MICROMIPS_CALL_LO16 relocations.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t1.so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2.so %t2.so.o %t1.so
+# RUN: llvm-objdump -s -t %t2.so | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -mips-plt-got %t2.so | FileCheck -check-prefix=GOT %s
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 0130 00000000 00001880 00000000 00002080
+# ^ -32744 ^ -32736
+# RAW-NEXT: 0140 00000000 00001c80 00000000 00002480
+# ^ -32740 ^ -32732
+# RAW-NEXT: 0150 00000000 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 00000140 l F .text 00000014 T1
+# RAW: 00000154 l F .text 00000004 M1
+
+# GOT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x140
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x155
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: M2@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# t1.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: M2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+
+# t2.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 40
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MICROMIPS_CALL_HI16
+ - Offset: 4
+ Symbol: T1
+ Type: R_MICROMIPS_CALL_LO16
+ - Offset: 8
+ Symbol: T2
+ Type: R_MICROMIPS_CALL_HI16
+ - Offset: 12
+ Symbol: T2
+ Type: R_MICROMIPS_CALL_LO16
+ - Offset: 16
+ Symbol: M1
+ Type: R_MICROMIPS_CALL_HI16
+ - Offset: 20
+ Symbol: M1
+ Type: R_MICROMIPS_CALL_LO16
+ - Offset: 24
+ Symbol: M2
+ Type: R_MICROMIPS_CALL_HI16
+ - Offset: 28
+ Symbol: M2
+ Type: R_MICROMIPS_CALL_LO16
+
+Symbols:
+ Local:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 16
+ Size: 4
+ - Name: M1
+ Section: .text
+ Type: STT_FUNC
+ Value: 36
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 16
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ - Name: M2
+...
diff --git a/test/old-elf/Mips/rel-copy-micro.test b/test/old-elf/Mips/rel-copy-micro.test
new file mode 100644
index 0000000000000..ba47c84a2c5c5
--- /dev/null
+++ b/test/old-elf/Mips/rel-copy-micro.test
@@ -0,0 +1,159 @@
+# Check R_MIPS_COPY relocation emitting
+# when linking non-shared executable file.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so1.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t-so1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-so2.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2.so %t-so2.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t1.so %t2.so
+# RUN: llvm-readobj -dt -r -dynamic-table %t.exe | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (5) .rel.dyn {
+# CHECK-NEXT: 0x402010 R_MIPS_COPY D1 0x0
+# CHECK-NEXT: 0x402018 R_MIPS_COPY D2 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D1@ (1)
+# CHECK-NEXT: Value: 0x402010
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .bss
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D2@ (4)
+# CHECK-NEXT: Value: 0x402018
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .bss
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSection [ ({{.*}} entries)
+# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy-micro.test.tmp1.so)
+# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy-micro.test.tmp2.so)
+# CHECK-NEXT: 0x00000000 NULL 0x0
+# CHECK-NEXT: ]
+
+# so1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+
+# so2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x04
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x08
+ Symbol: D2
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x08
+ Symbol: D2
+ Type: R_MICROMIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+...
diff --git a/test/old-elf/Mips/rel-copy-pc.test b/test/old-elf/Mips/rel-copy-pc.test
new file mode 100644
index 0000000000000..cf723f53719c8
--- /dev/null
+++ b/test/old-elf/Mips/rel-copy-pc.test
@@ -0,0 +1,113 @@
+# Check R_MIPS_COPY relocation emitting caused by R_MIPS_PCHI16 / R_MIPS_PCLO16
+# relocations when linking non-shared executable file.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r -dynamic-table %t.exe | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (5) .rel.dyn {
+# CHECK-NEXT: 0x402008 R_MIPS_COPY D1 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D1@ (1)
+# CHECK-NEXT: Value: 0x402008
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .bss
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSection [ ({{.*}} entries)
+# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy-pc.test.tmp.so)
+# CHECK-NEXT: 0x00000000 NULL 0x0
+# CHECK-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_PCHI16
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_PCLO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0
+ Size: 4
+ - Name: D1
+...
diff --git a/test/old-elf/Mips/rel-copy.test b/test/old-elf/Mips/rel-copy.test
new file mode 100644
index 0000000000000..751034dcd7289
--- /dev/null
+++ b/test/old-elf/Mips/rel-copy.test
@@ -0,0 +1,177 @@
+# Check R_MIPS_COPY relocation emitting
+# when linking non-shared executable file.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so1.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t-so1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-so2.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2.so %t-so2.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t1.so %t2.so
+# RUN: llvm-readobj -dt -r -dynamic-table %t.exe | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (5) .rel.dyn {
+# CHECK-NEXT: 0x402004 R_MIPS_REL32 D2 0x0
+# CHECK-NEXT: 0x402010 R_MIPS_COPY D1 0x0
+# CHECK-NEXT: 0x402018 R_MIPS_COPY D3 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D1@ (1)
+# CHECK-NEXT: Value: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .bss
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D3@ (4)
+# CHECK-NEXT: Value: 0x{{[0-9A-F]+}}
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .bss
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D2@ (7)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSection [ ({{.*}} entries)
+# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy.test.tmp1.so)
+# CHECK: 0x00000001 NEEDED SharedLibrary (rel-copy.test.tmp2.so)
+# CHECK-NEXT: 0x00000000 NULL 0x0
+# CHECK-NEXT: ]
+
+# so1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# so2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x04
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: D3
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MIPS_LO16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MIPS_32
+ - Offset: 0x08
+ Symbol: D3
+ Type: R_MIPS_HI16
+ - Offset: 0x08
+ Symbol: D3
+ Type: R_MIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ - Name: D3
+...
diff --git a/test/old-elf/Mips/rel-dynamic-01-micro.test b/test/old-elf/Mips/rel-dynamic-01-micro.test
new file mode 100644
index 0000000000000..56dd7dfdeccd9
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-01-micro.test
@@ -0,0 +1,201 @@
+# REQUIRES: mips
+
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# Check:
+# a) Emitting R_MIPS_COPY, R_MIPS_JUMP_SLOT relocations.
+# b) PLT entries creation.
+# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck -check-prefix=DIS %s
+# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s
+
+# DIS: Disassembly of section .plt:
+# DIS-NEXT: .plt:
+# DIS-NEXT: 4001b0: 80 79 94 07 addiupc $3, 7760
+# DIS-NEXT: 4001b4: 23 ff 00 00 lw $25, 0($3)
+# DIS-NEXT: 4001b8: 35 05 subu16 $2, $2, $3
+# DIS-NEXT: 4001ba: 25 25 srl16 $2, $2, 2
+# DIS-NEXT: 4001bc: 02 33 fe ff addiu $24, $2, -2
+# DIS-NEXT: 4001c0: ff 0d move $15, $ra
+# DIS-NEXT: 4001c2: f9 45 jalrs16 $25
+# DIS-NEXT: 4001c4: 83 0f move $gp, $3
+# DIS-NEXT: 4001c6: 00 0c nop
+
+# DIS-NEXT: 4001c8: 00 79 90 07 addiupc $2, 7744
+# DIS-NEXT: 4001cc: 22 ff 00 00 lw $25, 0($2)
+# DIS-NEXT: 4001d0: 99 45 jr16 $25
+# DIS-NEXT: 4001d2: 02 0f move $24, $2
+
+# DIS-NEXT: 4001d4: 00 79 8e 07 addiupc $2, 7736
+# DIS-NEXT: 4001d8: 22 ff 00 00 lw $25, 0($2)
+# DIS-NEXT: 4001dc: 99 45 jr16 $25
+# DIS-NEXT: 4001de: 02 0f move $24, $2
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: Section (5) .rel.dyn {
+# PLT-SYM-NEXT: 0x402020 R_MIPS_COPY D1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Section (6) .rel.plt {
+# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T3 0x0
+# PLT-SYM-NEXT: 0x40200C R_MIPS_JUMP_SLOT T1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: DynamicSymbols [
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: @ (0)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Local (0x0)
+# PLT-SYM-NEXT: Type: None (0x0)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: D1@ (1)
+# PLT-SYM-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-SYM-NEXT: Size: 8
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Object (0x1)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: .bss
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: T1@ (4)
+# PLT-SYM-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 8
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: T3@ (7)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+
+# o.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MICROMIPS_26_S1
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MICROMIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+...
diff --git a/test/old-elf/Mips/rel-dynamic-01.test b/test/old-elf/Mips/rel-dynamic-01.test
new file mode 100644
index 0000000000000..e24449eeeb583
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-01.test
@@ -0,0 +1,261 @@
+# REQUIRES: mips
+
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# Check:
+# a) Emitting R_MIPS_REL32, R_MIPS_COPY, R_MIPS_JUMP_SLOT relocations.
+# b) PLT entries creation.
+# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -disassemble %t.exe | FileCheck -check-prefix=PLT %s
+# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# PLT: Disassembly of section .plt:
+# PLT-NEXT: .plt:
+# PLT-NEXT: 4001f0: 40 00 1c 3c lui $gp, 64
+# PLT-NEXT: 4001f4: 00 20 99 8f lw $25, 8192($gp)
+# PLT-NEXT: 4001f8: 00 20 9c 27 addiu $gp, $gp, 8192
+# PLT-NEXT: 4001fc: 23 c0 1c 03 subu $24, $24, $gp
+# PLT-NEXT: 400200: 25 78 e0 03 move $15, $ra
+# PLT-NEXT: 400204: 82 c0 18 00 srl $24, $24, 2
+# PLT-NEXT: 400208: 09 f8 20 03 jalr $25
+# PLT-NEXT: 40020c: fe ff 18 27 addiu $24, $24, -2
+#
+# PLT-NEXT: 400210: 40 00 0f 3c lui $15, 64
+# PLT-NEXT: 400214: 08 20 f9 8d lw $25, 8200($15)
+# PLT-NEXT: 400218: 08 00 20 03 jr $25
+# PLT-NEXT: 40021c: 08 20 f8 25 addiu $24, $15, 8200
+#
+# PLT-NEXT: 400220: 40 00 0f 3c lui $15, 64
+# PLT-NEXT: 400224: 0c 20 f9 8d lw $25, 8204($15)
+# PLT-NEXT: 400228: 08 00 20 03 jr $25
+# PLT-NEXT: 40022c: 0c 20 f8 25 addiu $24, $15, 8204
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: Section (5) .rel.dyn {
+# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 T2 0x0
+# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 D2 0x0
+# PLT-SYM-NEXT: 0x402020 R_MIPS_COPY D1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Section (6) .rel.plt {
+# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T3 0x0
+# PLT-SYM-NEXT: 0x40200C R_MIPS_JUMP_SLOT T1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: DynamicSymbols [
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: @ (0)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Local (0x0)
+# PLT-SYM-NEXT: Type: None (0x0)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: D1@ (1)
+# PLT-SYM-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-SYM-NEXT: Size: 4
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Object (0x1)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: .bss
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: T1@ (4)
+# PLT-SYM-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 8
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: T3@ (10)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: T2@ (7)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: D2@ (13)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 4
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Object (0x1)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x{{[0-9A-F]+}}
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x{{[0-9A-F]+}}
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D2@ (13)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MIPS_26
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_LO16
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_32
+
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_HI16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_LO16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ Type: STT_OBJECT
+...
diff --git a/test/old-elf/Mips/rel-dynamic-02.test b/test/old-elf/Mips/rel-dynamic-02.test
new file mode 100644
index 0000000000000..24b7c624c6a0a
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-02.test
@@ -0,0 +1,101 @@
+# Conditions:
+# a) Linking a shared library.
+# b) Relocations' targets are undefined symbols.
+# Check:
+# a) Emitting R_MIPS_REL32 relocations for both undefined symbols.
+# b) There should be no PLT entries.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec -o %t.so %t.o
+# RUN: llvm-readobj -dt -r -s %t.so | FileCheck %s
+
+# CHECK: Sections [
+# CHECK: Section {
+# CHECK-NOT: Name: .plt ({{[0-9]+}})
+#
+# CHECK: Relocations [
+# CHECK-NEXT: Section (4) .rel.dyn {
+# CHECK-NEXT: 0x[[ADDR1:[0-9A-Z]+]] R_MIPS_REL32 T1 0x0
+# CHECK-NEXT: 0x[[ADDR2:[0-9A-Z]+]] R_MIPS_REL32 T1 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+#
+# CHECK: Symbol {
+# CHECK: Name: T0@
+# CHECK-NEXT: Value: 0x[[ADDR1]]
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type: Function
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .text
+# CHECK-NEXT: }
+# CHECK: Symbol {
+# CHECK: Name: D0@
+# CHECK-NEXT: Value: 0x[[ADDR2]]
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type: Object
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .data
+# CHECK-NEXT: }
+# CHECK: Symbol {
+# CHECK: Name: T1@
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global
+# CHECK-NEXT: Type: None
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined
+# CHECK-NEXT: }
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_32
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0
+ Size: 8
diff --git a/test/old-elf/Mips/rel-dynamic-03-micro.test b/test/old-elf/Mips/rel-dynamic-03-micro.test
new file mode 100644
index 0000000000000..891649d8cdbc5
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-03-micro.test
@@ -0,0 +1,133 @@
+# REQUIRES: mips
+
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' target is a symbol defined in the shared object.
+# c) The target symbol is referenced by both branch (R_MICROMIPS_26_S1)
+# and regular (R_MIPS_32) relocations.
+# Check:
+# a) There should be no R_MIPS_REL32 relocation.
+# b) Linker creates a single PLT entry.
+# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -d -mattr=micromips %t.exe | FileCheck -check-prefix=DIS %s
+# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s
+
+# DIS: Disassembly of section .plt:
+# DIS-NEXT: .plt:
+# DIS-NEXT: 400170: 80 79 a4 07 addiupc $3, 7824
+# DIS-NEXT: 400174: 23 ff 00 00 lw $25, 0($3)
+# DIS-NEXT: 400178: 35 05 subu16 $2, $2, $3
+# DIS-NEXT: 40017a: 25 25 srl16 $2, $2, 2
+# DIS-NEXT: 40017c: 02 33 fe ff addiu $24, $2, -2
+# DIS-NEXT: 400180: ff 0d move $15, $ra
+# DIS-NEXT: 400182: f9 45 jalrs16 $25
+# DIS-NEXT: 400184: 83 0f move $gp, $3
+# DIS-NEXT: 400186: 00 0c nop
+
+# DIS-NEXT: 400188: 00 79 a0 07 addiupc $2, 7808
+# DIS-NEXT: 40018c: 22 ff 00 00 lw $25, 0($2)
+# DIS-NEXT: 400190: 99 45 jr16 $25
+# DIS-NEXT: 400192: 02 0f move $24, $2
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: Section (5) .rel.plt {
+# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: Name: T1@ (1)
+# PLT-SYM-NEXT: Value: 0x400189
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 8
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+
+# o.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T1
+ Type: R_MICROMIPS_26_S1
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T1
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+...
diff --git a/test/old-elf/Mips/rel-dynamic-03.test b/test/old-elf/Mips/rel-dynamic-03.test
new file mode 100644
index 0000000000000..2552473ca80fc
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-03.test
@@ -0,0 +1,129 @@
+# REQUIRES: mips
+
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' target is a symbol defined in the shared object.
+# c) The target symbol is referenced by both branch (R_MIPS_26)
+# and regular (R_MIPS_32) relocations.
+# Check:
+# a) There should be no R_MIPS_REL32 relocation.
+# b) Linker creates a single PLT entry.
+# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -disassemble %t.exe | FileCheck -check-prefix=PLT %s
+# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s
+
+# PLT: Disassembly of section .plt:
+# PLT-NEXT: .plt:
+# PLT-NEXT: 400160: 40 00 1c 3c lui $gp, 64
+# PLT-NEXT: 400164: 00 20 99 8f lw $25, 8192($gp)
+# PLT-NEXT: 400168: 00 20 9c 27 addiu $gp, $gp, 8192
+# PLT-NEXT: 40016c: 23 c0 1c 03 subu $24, $24, $gp
+# PLT-NEXT: 400170: 25 78 e0 03 move $15, $ra
+# PLT-NEXT: 400174: 82 c0 18 00 srl $24, $24, 2
+# PLT-NEXT: 400178: 09 f8 20 03 jalr $25
+# PLT-NEXT: 40017c: fe ff 18 27 addiu $24, $24, -2
+#
+# PLT-NEXT: 400180: 40 00 0f 3c lui $15, 64
+# PLT-NEXT: 400184: 08 20 f9 8d lw $25, 8200($15)
+# PLT-NEXT: 400188: 08 00 20 03 jr $25
+# PLT-NEXT: 40018c: 08 20 f8 25 addiu $24, $15, 8200
+#
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: Section (5) .rel.plt {
+# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: Name: T1@ (1)
+# PLT-SYM-NEXT: Value: 0x400180
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 8
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T1
+ Type: R_MIPS_26
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T1
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+...
diff --git a/test/old-elf/Mips/rel-dynamic-04-micro.test b/test/old-elf/Mips/rel-dynamic-04-micro.test
new file mode 100644
index 0000000000000..de1131c67f43c
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-04-micro.test
@@ -0,0 +1,226 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# c) Relocations modify a writable section.
+# d) The first symbol is referenced by R_MIPS32 relocation only
+# e) The second symbol is referenced by R_MIPS_32
+# and R_MICROMIPS_26_S1 relocations.
+# f) The third symbol is referenced by R_MICROMIPS_26_S1
+# and R_MIPS_32 relocations.
+# Check:
+# a) There should be the only R_MIPS_REL32 relocation.
+# b) Linker creates a couple of PLT entry for both symbols referenced
+# by the R_MICROMIPS_26_S1 branch relocation.
+# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# PLT: Section {
+# PLT: Index: 5
+# PLT-NEXT: Name: .rel.dyn (31)
+# PLT-NEXT: Type: SHT_REL (0x9)
+# PLT-NEXT: Flags [ (0x2)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x4010A0
+# PLT-NEXT: Offset: 0x10A0
+# PLT-NEXT: Size: 8
+# PLT-NEXT: Link: 3
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 4
+# PLT-NEXT: EntrySize: 8
+# PLT-NEXT: }
+# PLT-NEXT: Section {
+# PLT-NEXT: Index: 6
+# PLT-NEXT: Name: .rel.plt (40)
+# PLT-NEXT: Type: SHT_REL (0x9)
+# PLT-NEXT: Flags [ (0x2)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x4010A8
+# PLT-NEXT: Offset: 0x10A8
+# PLT-NEXT: Size: 16
+# PLT-NEXT: Link: 3
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 4
+# PLT-NEXT: EntrySize: 8
+# PLT-NEXT: }
+# PLT-NEXT: Section {
+# PLT-NEXT: Index: 7
+# PLT-NEXT: Name: .plt (49)
+# PLT-NEXT: Type: SHT_PROGBITS (0x1)
+# PLT-NEXT: Flags [ (0x6)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: SHF_EXECINSTR (0x4)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x4010C0
+# PLT-NEXT: Offset: 0x10C0
+# PLT-NEXT: Size: 48
+# PLT-NEXT: Link: 0
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 16
+# PLT-NEXT: EntrySize: 0
+# PLT-NEXT: }
+
+# PLT: Relocations [
+# PLT-NEXT: Section (5) .rel.dyn {
+# PLT-NEXT: 0x400120 R_MIPS_REL32 T1 0x0
+# PLT-NEXT: }
+# PLT-NEXT: Section (6) .rel.plt {
+# PLT-NEXT: 0x403008 R_MIPS_JUMP_SLOT T2 0x0
+# PLT-NEXT: 0x40300C R_MIPS_JUMP_SLOT T3 0x0
+# PLT-NEXT: }
+# PLT-NEXT: ]
+
+# PLT: DynamicSymbols [
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: @ (0)
+# PLT-NEXT: Value: 0x0
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Local (0x0)
+# PLT-NEXT: Type: None (0x0)
+# PLT-NEXT: Other: 0
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T2@ (4)
+# PLT-NEXT: Value: 0x4010D9
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T3@ (7)
+# PLT-NEXT: Value: 0x4010E5
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T1@ (1)
+# PLT-NEXT: Value: 0x0
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 0
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x402008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+
+# o.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x14
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ # There is no branch relocation for T1.
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_32
+ # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ...
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_32
+ # ... but R_MICROMIPS_26_S1 creates PLT entry
+ # and makes R_MIPS_REL32 redundant.
+ - Offset: 0x08
+ Symbol: T2
+ Type: R_MICROMIPS_26_S1
+ # Create PLT entry for T3 symbol.
+ - Offset: 0x0c
+ Symbol: T3
+ Type: R_MICROMIPS_26_S1
+ # Take in account existing PLT entry and do not create R_MIPS_REL32.
+ - Offset: 0x10
+ Symbol: T3
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x14
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+...
diff --git a/test/old-elf/Mips/rel-dynamic-04.test b/test/old-elf/Mips/rel-dynamic-04.test
new file mode 100644
index 0000000000000..df8c676af3306
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-04.test
@@ -0,0 +1,221 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# c) Relocations modify a writable section.
+# d) The first symbol is referenced by R_MIPS32 relocation only
+# e) The second symbol is referenced by R_MIPS_32 and R_MIPS26 relocations.
+# f) The third symbol is referenced by R_MIPS26 and R_MIPS_32 relocations.
+# Check:
+# a) There should be the only R_MIPS_REL32 relocation.
+# b) Linker creates a couple of PLT entry for both symbols referenced
+# by the R_MIPS_26 branch relocation.
+# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# PLT: Section {
+# PLT: Index: 5
+# PLT-NEXT: Name: .rel.dyn (31)
+# PLT-NEXT: Type: SHT_REL (0x9)
+# PLT-NEXT: Flags [ (0x2)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x40109C
+# PLT-NEXT: Offset: 0x109C
+# PLT-NEXT: Size: 8
+# PLT-NEXT: Link: 3
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 4
+# PLT-NEXT: EntrySize: 8
+# PLT-NEXT: }
+# PLT-NEXT: Section {
+# PLT-NEXT: Index: 6
+# PLT-NEXT: Name: .rel.plt (40)
+# PLT-NEXT: Type: SHT_REL (0x9)
+# PLT-NEXT: Flags [ (0x2)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x4010A4
+# PLT-NEXT: Offset: 0x10A4
+# PLT-NEXT: Size: 16
+# PLT-NEXT: Link: 3
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 4
+# PLT-NEXT: EntrySize: 8
+# PLT-NEXT: }
+# PLT-NEXT: Section {
+# PLT-NEXT: Index: 7
+# PLT-NEXT: Name: .plt (49)
+# PLT-NEXT: Type: SHT_PROGBITS (0x1)
+# PLT-NEXT: Flags [ (0x6)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: SHF_EXECINSTR (0x4)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x4010C0
+# PLT-NEXT: Offset: 0x10C0
+# PLT-NEXT: Size: 64
+# PLT-NEXT: Link: 0
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 16
+# PLT-NEXT: EntrySize: 0
+# PLT-NEXT: }
+
+# PLT: Relocations [
+# PLT-NEXT: Section (5) .rel.dyn {
+# PLT-NEXT: 0x400120 R_MIPS_REL32 T1 0x0
+# PLT-NEXT: }
+# PLT-NEXT: Section (6) .rel.plt {
+# PLT-NEXT: 0x403008 R_MIPS_JUMP_SLOT T2 0x0
+# PLT-NEXT: 0x40300C R_MIPS_JUMP_SLOT T3 0x0
+# PLT-NEXT: }
+# PLT-NEXT: ]
+
+# PLT: DynamicSymbols [
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: @ (0)
+# PLT-NEXT: Value: 0x0
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Local (0x0)
+# PLT-NEXT: Type: None (0x0)
+# PLT-NEXT: Other: 0
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T2@ (4)
+# PLT-NEXT: Value: 0x4010E0
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T3@ (7)
+# PLT-NEXT: Value: 0x4010F0
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T1@ (1)
+# PLT-NEXT: Value: 0x0
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 0
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x402008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+
+# o.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ # There is no branch relocation for T1.
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_32
+ # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ...
+ - Offset: 0x00
+ Symbol: T2
+ Type: R_MIPS_32
+ # ... but R_MIPS_26 creates PLT entry and makes R_MIPS_REL32 redundant.
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_26
+ # Create PLT entry for T3 symbol.
+ - Offset: 0x00
+ Symbol: T3
+ Type: R_MIPS_26
+ # Take in account existing PLT entry and do not create R_MIPS_REL32.
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+...
diff --git a/test/old-elf/Mips/rel-dynamic-05-micro.test b/test/old-elf/Mips/rel-dynamic-05-micro.test
new file mode 100644
index 0000000000000..16c6a9c6aad5a
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-05-micro.test
@@ -0,0 +1,192 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# c) Relocations modify a read-only section.
+# d) The first symbol is referenced by R_MIPS32 relocation only
+# e) The second symbol is referenced by R_MIPS_32
+# and R_MICROMIPS_26_S1 relocations.
+# f) The third symbol is referenced by R_MICROMIPS_26_S1
+# and R_MIPS_32 relocations.
+# Check:
+# a) There should be no R_MIPS_REL32 relocations.
+# b) Linker creates PLT entries for all three relocations.
+# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s
+
+# PLT: Section {
+# PLT: Index: 5
+# PLT-NEXT: Name: .rel.plt (31)
+# PLT-NEXT: Type: SHT_REL (0x9)
+# PLT-NEXT: Flags [ (0x2)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x400194
+# PLT-NEXT: Offset: 0x194
+# PLT-NEXT: Size: 24
+# PLT-NEXT: Link: 3
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 4
+# PLT-NEXT: EntrySize: 8
+# PLT-NEXT: }
+# PLT-NEXT: Section {
+# PLT-NEXT: Index: 6
+# PLT-NEXT: Name: .plt (40)
+# PLT-NEXT: Type: SHT_PROGBITS (0x1)
+# PLT-NEXT: Flags [ (0x6)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: SHF_EXECINSTR (0x4)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x4001B0
+# PLT-NEXT: Offset: 0x1B0
+# PLT-NEXT: Size: 60
+# PLT-NEXT: Link: 0
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 16
+# PLT-NEXT: EntrySize: 0
+# PLT-NEXT: }
+
+# PLT: Relocations [
+# PLT-NEXT: Section (5) .rel.plt {
+# PLT-NEXT: 0x402008 R_MIPS_JUMP_SLOT T1 0x0
+# PLT-NEXT: 0x40200C R_MIPS_JUMP_SLOT T2 0x0
+# PLT-NEXT: 0x402010 R_MIPS_JUMP_SLOT T3 0x0
+# PLT-NEXT: }
+# PLT-NEXT: ]
+
+# PLT: DynamicSymbols [
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: @ (0)
+# PLT-NEXT: Value: 0x0
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Local (0x0)
+# PLT-NEXT: Type: None (0x0)
+# PLT-NEXT: Other: 0
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T1@ (1)
+# PLT-NEXT: Value: 0x4001C9
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T2@ (4)
+# PLT-NEXT: Value: 0x4001D5
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T3@ (7)
+# PLT-NEXT: Value: 0x4001E1
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+
+# o.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x14
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ # There is no branch relocation for T1.
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_32
+ # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ...
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_32
+ # ... but R_MICROMIPS_26_S1 creates PLT entry and makes R_MIPS_REL32 redundant.
+ - Offset: 0x08
+ Symbol: T2
+ Type: R_MICROMIPS_26_S1
+ # Create PLT entry for T3 symbol.
+ - Offset: 0x0C
+ Symbol: T3
+ Type: R_MICROMIPS_26_S1
+ # Take in account existing PLT entry and do not create R_MIPS_REL32.
+ - Offset: 0x10
+ Symbol: T3
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x14
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+...
diff --git a/test/old-elf/Mips/rel-dynamic-05.test b/test/old-elf/Mips/rel-dynamic-05.test
new file mode 100644
index 0000000000000..8348bc511fbd0
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-05.test
@@ -0,0 +1,188 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# c) Relocations modify a read-only section.
+# d) The first symbol is referenced by R_MIPS32 relocation only
+# e) The second symbol is referenced by R_MIPS_32 and R_MIPS26 relocations.
+# f) The third symbol is referenced by R_MIPS26 and R_MIPS_32 relocations.
+# Check:
+# a) There should be no R_MIPS_REL32 relocations.
+# b) Linker creates PLT entries for all three relocations.
+# c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s
+
+# PLT: Section {
+# PLT: Index: 5
+# PLT-NEXT: Name: .rel.plt (31)
+# PLT-NEXT: Type: SHT_REL (0x9)
+# PLT-NEXT: Flags [ (0x2)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x{{[0-9A-F]+}}
+# PLT-NEXT: Offset: 0x{{[0-9A-F]+}}
+# PLT-NEXT: Size: 24
+# PLT-NEXT: Link: 3
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 4
+# PLT-NEXT: EntrySize: 8
+# PLT-NEXT: }
+# PLT-NEXT: Section {
+# PLT-NEXT: Index: 6
+# PLT-NEXT: Name: .plt (40)
+# PLT-NEXT: Type: SHT_PROGBITS (0x1)
+# PLT-NEXT: Flags [ (0x6)
+# PLT-NEXT: SHF_ALLOC (0x2)
+# PLT-NEXT: SHF_EXECINSTR (0x4)
+# PLT-NEXT: ]
+# PLT-NEXT: Address: 0x{{[0-9A-F]+}}
+# PLT-NEXT: Offset: 0x{{[0-9A-F]+}}
+# PLT-NEXT: Size: 80
+# PLT-NEXT: Link: 0
+# PLT-NEXT: Info: 0
+# PLT-NEXT: AddressAlignment: 16
+# PLT-NEXT: EntrySize: 0
+# PLT-NEXT: }
+
+# PLT: Relocations [
+# PLT-NEXT: Section (5) .rel.plt {
+# PLT-NEXT: {{[0-9A-F]+}} R_MIPS_JUMP_SLOT T1 0x0
+# PLT-NEXT: {{[0-9A-F]+}} R_MIPS_JUMP_SLOT T2 0x0
+# PLT-NEXT: {{[0-9A-F]+}} R_MIPS_JUMP_SLOT T3 0x0
+# PLT-NEXT: }
+# PLT-NEXT: ]
+
+# PLT: DynamicSymbols [
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: @ (0)
+# PLT-NEXT: Value: 0x0
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Local (0x0)
+# PLT-NEXT: Type: None (0x0)
+# PLT-NEXT: Other: 0
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T1@ (1)
+# PLT-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T2@ (4)
+# PLT-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: Symbol {
+# PLT-NEXT: Name: T3@ (7)
+# PLT-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-NEXT: Size: 0
+# PLT-NEXT: Binding: Global (0x1)
+# PLT-NEXT: Type: Function (0x2)
+# PLT-NEXT: Other: 8
+# PLT-NEXT: Section: Undefined (0x0)
+# PLT-NEXT: }
+# PLT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+
+# o.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ # There is no branch relocation for T1.
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_32
+ # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ...
+ - Offset: 0x00
+ Symbol: T2
+ Type: R_MIPS_32
+ # ... but R_MIPS_26 creates PLT entry and makes R_MIPS_REL32 redundant.
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_26
+ # Create PLT entry for T3 symbol.
+ - Offset: 0x00
+ Symbol: T3
+ Type: R_MIPS_26
+ # Take in account existing PLT entry and do not create R_MIPS_REL32.
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+...
diff --git a/test/old-elf/Mips/rel-dynamic-06-64.test b/test/old-elf/Mips/rel-dynamic-06-64.test
new file mode 100644
index 0000000000000..6b0d28993f942
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-06-64.test
@@ -0,0 +1,114 @@
+# Conditions:
+# a) Linking a shared library.
+# b) The first relocation modifies a regular .text section.
+# c) The second relocation modifies a .pdr section without SHF_ALLOC flag.
+# Check:
+# a) There should be no PLT entries.
+# b) Linker creates a single R_MIPS_REL32 relocation.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t.o
+# RUN: llvm-readobj -dt -r -s %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-readobj -mips-plt-got %t.so | FileCheck -check-prefix=GOT %s
+
+# SYM: Sections [
+# SYM: Section {
+# SYM-NOT: Name: .plt ({{[0-9]+}})
+
+# SYM: Relocations [
+# SYM-NEXT: Section (4) .rel.dyn {
+# SYM-NEXT: 0x[[ADDR:[0-9A-Z]+]] R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T0 0x0
+# SYM-NEXT: }
+# SYM-NEXT: ]
+
+# SYM: Symbol {
+# SYM: Name: @ (0)
+# SYM-NEXT: Value: 0x0
+# SYM-NEXT: Size: 0
+# SYM-NEXT: Binding: Local (0x0)
+# SYM-NEXT: Type: None (0x0)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: Undefined (0x0)
+# SYM-NEXT: }
+# SYM: Symbol {
+# SYM: Name: T1@ (4)
+# SYM-NEXT: Value: 0x174
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text (0x5)
+# SYM-NEXT: }
+# SYM: Symbol {
+# SYM: Name: T0@ (1)
+# SYM-NEXT: Value: 0x[[ADDR]]
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text (0x5)
+# SYM-NEXT: }
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x170
+# GOT-NEXT: Value: 0x170
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: .text (0x5)
+# GOT-NEXT: Name: T0@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_RELA
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T0
+ Type: R_MIPS_64
+
+- Name: .pdr
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+
+- Name: .rel.pdr
+ Type: SHT_RELA
+ Info: .pdr
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_64
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
diff --git a/test/old-elf/Mips/rel-dynamic-06.test b/test/old-elf/Mips/rel-dynamic-06.test
new file mode 100644
index 0000000000000..ead7dfb08ddf1
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-06.test
@@ -0,0 +1,115 @@
+# Conditions:
+# a) Linking a shared library.
+# b) The first relocation modifies a regular .text section.
+# c) The second relocation modifies a .pdr section without SHF_ALLOC flag.
+# Check:
+# a) There should be no PLT entries.
+# b) Linker creates a single R_MIPS_REL32 relocation.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -dt -r -s %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-readobj -mips-plt-got %t.so | FileCheck -check-prefix=GOT %s
+
+# SYM: Sections [
+# SYM: Section {
+# SYM-NOT: Name: .plt ({{[0-9]+}})
+
+# SYM: Relocations [
+# SYM-NEXT: Section (4) .rel.dyn {
+# SYM-NEXT: 0x[[ADDR:[0-9A-Z]+]] R_MIPS_REL32 T0 0x0
+# SYM-NEXT: }
+# SYM-NEXT: ]
+
+# SYM: Symbol {
+# SYM: Name: @ (0)
+# SYM-NEXT: Value: 0x0
+# SYM-NEXT: Size: 0
+# SYM-NEXT: Binding: Local (0x0)
+# SYM-NEXT: Type: None (0x0)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: Undefined (0x0)
+# SYM-NEXT: }
+# SYM: Symbol {
+# SYM: Name: T1@ (4)
+# SYM-NEXT: Value: 0x104
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text (0x5)
+# SYM-NEXT: }
+# SYM: Symbol {
+# SYM: Name: T0@ (1)
+# SYM-NEXT: Value: 0x[[ADDR]]
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text (0x5)
+# SYM-NEXT: }
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x100
+# GOT-NEXT: Value: 0x100
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: .text (0x5)
+# GOT-NEXT: Name: T0@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T0
+ Type: R_MIPS_32
+
+- Name: .pdr
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: []
+
+- Name: .rel.pdr
+ Type: SHT_REL
+ Info: .pdr
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
diff --git a/test/old-elf/Mips/rel-dynamic-07-64.test b/test/old-elf/Mips/rel-dynamic-07-64.test
new file mode 100644
index 0000000000000..823a66d521e20
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-07-64.test
@@ -0,0 +1,348 @@
+# Conditions:
+# a) Linking a shared library.
+# b) There ars multiple R_MIPS_64 relocations with various targets.
+# Check:
+# a) Emitting of R_MIPS_REL32 relocations.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t1.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -shared --noinhibit-exec \
+# RUN: -o %t2.so %t-o.o %t1.so
+# RUN: llvm-readobj -dt -r -sections %t2.so | FileCheck %s
+# RUN: llvm-readobj -mips-plt-got %t2.so | FileCheck -check-prefix=GOT %s
+
+# CHECK: Sections [
+# CHECK: Section {
+# CHECK-NOT: Name: .plt ({{[0-9]+}})
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (4) .rel.dyn {
+# CHECK-NEXT: 0x2000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T0 0x0
+# CHECK-NEXT: 0x2000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T4 0x0
+# CHECK-NEXT: 0x2000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D2 0x0
+# CHECK-NEXT: 0x2004 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T1 0x0
+# CHECK-NEXT: 0x2008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T2 0x0
+# CHECK-NEXT: 0x2004 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D0 0x0
+# CHECK-NEXT: 0x2008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D1 0x0
+# CHECK-NEXT: 0x2004 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D4 0x0
+# CHECK-NEXT: 0x2008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE U1 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T0@ (1)
+# CHECK-NEXT: Value: 0x324
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .text (0x5)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T4@ (7)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D2@ (25)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T1@ (16)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T2@ (19)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D0@ (4)
+# CHECK-NEXT: Value: 0x2004
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .data (0x8)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D1@ (22)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D4@ (10)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: U1@ (13)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x324
+# GOT-NEXT: Value: 0x324
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: .text (0x5)
+# GOT-NEXT: Name: T0@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: None (0x0)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T4@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D2@ (25)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1028
+# GOT-NEXT: Access: -32712
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (16)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1030
+# GOT-NEXT: Access: -32704
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (19)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1038
+# GOT-NEXT: Access: -32696
+# GOT-NEXT: Initial: 0x2004
+# GOT-NEXT: Value: 0x2004
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: .data (0x8)
+# GOT-NEXT: Name: D0@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1040
+# GOT-NEXT: Access: -32688
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D1@ (22)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1048
+# GOT-NEXT: Access: -32680
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: None (0x0)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D4@ (10)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1050
+# GOT-NEXT: Access: -32672
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: None (0x0)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: U1@ (13)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+ Type: SHT_RELA
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00 # T0 is a defined function
+ Symbol: T0
+ Type: R_MIPS_64
+ - Offset: 0x04 # T1 is a function from shared lib
+ Symbol: T1
+ Type: R_MIPS_64
+ - Offset: 0x08 # T2 has unknown type and defined in shared lib
+ Symbol: T2
+ Type: R_MIPS_64
+ - Offset: 0x00 # T4 is an undefined function
+ Symbol: T4
+ Type: R_MIPS_64
+ - Offset: 0x04 # D0 is a defined data object
+ Symbol: D0
+ Type: R_MIPS_64
+ - Offset: 0x08 # D1 is a data object from shared lib
+ Symbol: D1
+ Type: R_MIPS_64
+ - Offset: 0x00 # D2 has unknown type and defined in shared lib
+ Symbol: D2
+ Type: R_MIPS_64
+ - Offset: 0x04 # D4 is an undefined data object
+ Symbol: D4
+ Type: R_MIPS_64
+ - Offset: 0x08 # U1 is undefined and has unknown type
+ Symbol: U1
+ Type: R_MIPS_64
+
+Symbols:
+ Local:
+ - Name: LT0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: LD0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0
+ Size: 4
+
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ - Name: T4
+ Type: STT_FUNC
+
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ - Name: D4
+ Type: STT_OBJECT
+ - Name: U1
+...
diff --git a/test/old-elf/Mips/rel-dynamic-07.test b/test/old-elf/Mips/rel-dynamic-07.test
new file mode 100644
index 0000000000000..41c31c66a5f33
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-07.test
@@ -0,0 +1,363 @@
+# Conditions:
+# a) Linking a shared library.
+# b) There ars multiple R_MIPS_32 relocations with various targets.
+# Check:
+# a) Emitting of R_MIPS_REL32 relocations.
+# b) There should be no R_MIPS_REL32 relocations for the _gp_disp symbol.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -shared --noinhibit-exec \
+# RUN: -o %t2.so %t-o.o %t1.so
+# RUN: llvm-readobj -dt -r -sections %t2.so | FileCheck %s
+# RUN: llvm-readobj -mips-plt-got %t2.so | FileCheck -check-prefix=GOT %s
+
+# CHECK: Sections [
+# CHECK: Section {
+# CHECK-NOT: Name: .plt ({{[0-9]+}})
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (4) .rel.dyn {
+# CHECK-NEXT: 0x2000 R_MIPS_REL32 T0 0x0
+# CHECK-NEXT: 0x2000 R_MIPS_REL32 T4 0x0
+# CHECK-NEXT: 0x2000 R_MIPS_REL32 D2 0x0
+# CHECK-NEXT: 0x2004 R_MIPS_REL32 T1 0x0
+# CHECK-NEXT: 0x2008 R_MIPS_REL32 T2 0x0
+# CHECK-NEXT: 0x2004 R_MIPS_REL32 D0 0x0
+# CHECK-NEXT: 0x2008 R_MIPS_REL32 D1 0x0
+# CHECK-NEXT: 0x2004 R_MIPS_REL32 D4 0x0
+# CHECK-NEXT: 0x2008 R_MIPS_REL32 U1 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T0@ (1)
+# CHECK-NEXT: Value: 0x214
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .text (0x5)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T4@ (7)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D2@ (25)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T1@ (16)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T2@ (19)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D0@ (4)
+# CHECK-NEXT: Value: 0x2004
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: .data (0x8)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D1@ (22)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D4@ (10)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: U1@ (13)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x214
+# GOT-NEXT: Value: 0x214
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: .text (0x5)
+# GOT-NEXT: Name: T0@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: None (0x0)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T4@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D2@ (25)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (16)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (19)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x101C
+# GOT-NEXT: Access: -32724
+# GOT-NEXT: Initial: 0x2004
+# GOT-NEXT: Value: 0x2004
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: .data (0x8)
+# GOT-NEXT: Name: D0@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D1@ (22)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1024
+# GOT-NEXT: Access: -32716
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: None (0x0)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D4@ (10)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1028
+# GOT-NEXT: Access: -32712
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: None (0x0)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: U1@ (13)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: _gp_disp
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: _gp_disp
+ Type: R_MIPS_LO16
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00 # T0 is a defined function
+ Symbol: T0
+ Type: R_MIPS_32
+ - Offset: 0x04 # T1 is a function from shared lib
+ Symbol: T1
+ Type: R_MIPS_32
+ - Offset: 0x08 # T2 has unknown type and defined in shared lib
+ Symbol: T2
+ Type: R_MIPS_32
+ - Offset: 0x00 # T4 is an undefined function
+ Symbol: T4
+ Type: R_MIPS_32
+ - Offset: 0x04 # D0 is a defined data object
+ Symbol: D0
+ Type: R_MIPS_32
+ - Offset: 0x08 # D1 is a data object from shared lib
+ Symbol: D1
+ Type: R_MIPS_32
+ - Offset: 0x00 # D2 has unknown type and defined in shared lib
+ Symbol: D2
+ Type: R_MIPS_32
+ - Offset: 0x04 # D4 is an undefined data object
+ Symbol: D4
+ Type: R_MIPS_32
+ - Offset: 0x08 # U1 is undefined and has unknown type
+ Symbol: U1
+ Type: R_MIPS_32
+
+Symbols:
+ Local:
+ - Name: LT0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: LD0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+
+ Global:
+ - Name: _gp_disp
+ Type: STT_OBJECT
+
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ - Name: T4
+ Type: STT_FUNC
+
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ - Name: D4
+ Type: STT_OBJECT
+ - Name: U1
diff --git a/test/old-elf/Mips/rel-dynamic-08-64.test b/test/old-elf/Mips/rel-dynamic-08-64.test
new file mode 100644
index 0000000000000..019b8e5161a8a
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-08-64.test
@@ -0,0 +1,275 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) There ars multiple R_MIPS_64/R_MIPS_HI16/R_MIPS_LO16 relocations
+# with various targets.
+# Check:
+# a) Emitting of R_MIPS_REL32 relocations.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 --noinhibit-exec \
+# RUN: -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r -sections %t.exe | FileCheck %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# CHECK: Sections [
+# CHECK: Section {
+# CHECK-NOT: Name: .plt ({{[0-9]+}})
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (5) .rel.dyn {
+# CHECK-NEXT: 0x120002000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D2 0x0
+# CHECK-NEXT: 0x120002004 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T1 0x0
+# CHECK-NEXT: 0x120002008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T2 0x0
+# CHECK-NEXT: 0x120002008 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE D1 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D2@ (10)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T1@ (1)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T2@ (4)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D1@ (7)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D2@ (10)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001028
+# GOT-NEXT: Access: -32712
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D1@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_RELA
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: _gp_disp
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: _gp_disp
+ Type: R_MIPS_LO16
+
+- Name: .rel.data
+ Type: SHT_RELA
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00 # LT0 is a locally defined function
+ Symbol: LT0
+ Type: R_MIPS_64
+ - Offset: 0x00 # LD0 is a locally defined data object
+ Symbol: LD0
+ Type: R_MIPS_64
+ - Offset: 0x00 # T0 is a defined function
+ Symbol: T0
+ Type: R_MIPS_64
+ - Offset: 0x04 # T1 is a function from shared lib
+ Symbol: T1
+ Type: R_MIPS_64
+ - Offset: 0x08 # T2 has unknown type and defined in shared lib
+ Symbol: T2
+ Type: R_MIPS_64
+ - Offset: 0x00 # T4 is an undefined function
+ Symbol: T4
+ Type: R_MIPS_64
+ - Offset: 0x04 # D0 is a defined data object
+ Symbol: D0
+ Type: R_MIPS_64
+ - Offset: 0x08 # D1 is a data object from shared lib
+ Symbol: D1
+ Type: R_MIPS_64
+ - Offset: 0x00 # D2 has unknown type and defined in shared lib
+ Symbol: D2
+ Type: R_MIPS_64
+ - Offset: 0x04 # D4 is an undefined data object
+ Symbol: D4
+ Type: R_MIPS_64
+ - Offset: 0x08 # U1 is undefined and has unknown type
+ Symbol: U1
+ Type: R_MIPS_64
+
+Symbols:
+ Local:
+ - Name: LT0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: LD0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0
+ Size: 4
+
+ Global:
+ - Name: _gp_disp
+ Type: STT_OBJECT
+
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ - Name: T4
+ Type: STT_FUNC
+
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ - Name: D4
+ Type: STT_OBJECT
+ - Name: U1
+...
diff --git a/test/old-elf/Mips/rel-dynamic-08-micro.test b/test/old-elf/Mips/rel-dynamic-08-micro.test
new file mode 100644
index 0000000000000..2d25b504ee287
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-08-micro.test
@@ -0,0 +1,278 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) There ars multiple R_MIPS_32/R_MICROMIPS_HI16/R_MICROMIPS_LO16
+# relocations with various targets.
+# Check:
+# a) Emitting of R_MIPS_REL32 relocations.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 --noinhibit-exec \
+# RUN: -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r -sections %t.exe | FileCheck %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# CHECK: Sections [
+# CHECK: Section {
+# CHECK-NOT: Name: .plt ({{[0-9]+}})
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (5) .rel.dyn {
+# CHECK-NEXT: 0x402000 R_MIPS_REL32 D2 0x0
+# CHECK-NEXT: 0x402004 R_MIPS_REL32 T1 0x0
+# CHECK-NEXT: 0x402008 R_MIPS_REL32 T2 0x0
+# CHECK-NEXT: 0x402008 R_MIPS_REL32 D1 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D2@ (10)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T1@ (1)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T2@ (4)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D1@ (7)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D2@ (10)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D1@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x00
+ Symbol: _gp_disp
+ Type: R_MICROMIPS_LO16
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00 # LT0 is a locally defined function
+ Symbol: LT0
+ Type: R_MIPS_32
+ - Offset: 0x00 # LD0 is a locally defined data object
+ Symbol: LD0
+ Type: R_MIPS_32
+ - Offset: 0x00 # T0 is a defined function
+ Symbol: T0
+ Type: R_MIPS_32
+ - Offset: 0x04 # T1 is a function from shared lib
+ Symbol: T1
+ Type: R_MIPS_32
+ - Offset: 0x08 # T2 has unknown type and defined in shared lib
+ Symbol: T2
+ Type: R_MIPS_32
+ - Offset: 0x00 # T4 is an undefined function
+ Symbol: T4
+ Type: R_MIPS_32
+ - Offset: 0x04 # D0 is a defined data object
+ Symbol: D0
+ Type: R_MIPS_32
+ - Offset: 0x08 # D1 is a data object from shared lib
+ Symbol: D1
+ Type: R_MIPS_32
+ - Offset: 0x00 # D2 has unknown type and defined in shared lib
+ Symbol: D2
+ Type: R_MIPS_32
+ - Offset: 0x04 # D4 is an undefined data object
+ Symbol: D4
+ Type: R_MIPS_32
+ - Offset: 0x08 # U1 is undefined and has unknown type
+ Symbol: U1
+ Type: R_MIPS_32
+
+Symbols:
+ Local:
+ - Name: LT0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: LD0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+
+ Global:
+ - Name: _gp_disp
+ Type: STT_OBJECT
+
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 8
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ - Name: T4
+ Type: STT_FUNC
+
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ - Name: D4
+ Type: STT_OBJECT
+ - Name: U1
+...
diff --git a/test/old-elf/Mips/rel-dynamic-08.test b/test/old-elf/Mips/rel-dynamic-08.test
new file mode 100644
index 0000000000000..a89e6ecf480e3
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-08.test
@@ -0,0 +1,275 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) There ars multiple R_MIPS_32/R_MIPS_HI16/R_MIPS_LO16 relocations
+# with various targets.
+# Check:
+# a) Emitting of R_MIPS_REL32 relocations.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 --noinhibit-exec \
+# RUN: -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r -sections %t.exe | FileCheck %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# CHECK: Sections [
+# CHECK: Section {
+# CHECK-NOT: Name: .plt ({{[0-9]+}})
+
+# CHECK: Relocations [
+# CHECK-NEXT: Section (5) .rel.dyn {
+# CHECK-NEXT: 0x402000 R_MIPS_REL32 D2 0x0
+# CHECK-NEXT: 0x402004 R_MIPS_REL32 T1 0x0
+# CHECK-NEXT: 0x402008 R_MIPS_REL32 T2 0x0
+# CHECK-NEXT: 0x402008 R_MIPS_REL32 D1 0x0
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# CHECK: DynamicSymbols [
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: @ (0)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Local (0x0)
+# CHECK-NEXT: Type: None (0x0)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D2@ (10)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T1@ (1)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: T2@ (4)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 0
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Function (0x2)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: Symbol {
+# CHECK-NEXT: Name: D1@ (7)
+# CHECK-NEXT: Value: 0x0
+# CHECK-NEXT: Size: 4
+# CHECK-NEXT: Binding: Global (0x1)
+# CHECK-NEXT: Type: Object (0x1)
+# CHECK-NEXT: Other: 0
+# CHECK-NEXT: Section: Undefined (0x0)
+# CHECK-NEXT: }
+# CHECK-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D2@ (10)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D1@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: _gp_disp
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: _gp_disp
+ Type: R_MIPS_LO16
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00 # LT0 is a locally defined function
+ Symbol: LT0
+ Type: R_MIPS_32
+ - Offset: 0x00 # LD0 is a locally defined data object
+ Symbol: LD0
+ Type: R_MIPS_32
+ - Offset: 0x00 # T0 is a defined function
+ Symbol: T0
+ Type: R_MIPS_32
+ - Offset: 0x04 # T1 is a function from shared lib
+ Symbol: T1
+ Type: R_MIPS_32
+ - Offset: 0x08 # T2 has unknown type and defined in shared lib
+ Symbol: T2
+ Type: R_MIPS_32
+ - Offset: 0x00 # T4 is an undefined function
+ Symbol: T4
+ Type: R_MIPS_32
+ - Offset: 0x04 # D0 is a defined data object
+ Symbol: D0
+ Type: R_MIPS_32
+ - Offset: 0x08 # D1 is a data object from shared lib
+ Symbol: D1
+ Type: R_MIPS_32
+ - Offset: 0x00 # D2 has unknown type and defined in shared lib
+ Symbol: D2
+ Type: R_MIPS_32
+ - Offset: 0x04 # D4 is an undefined data object
+ Symbol: D4
+ Type: R_MIPS_32
+ - Offset: 0x08 # U1 is undefined and has unknown type
+ Symbol: U1
+ Type: R_MIPS_32
+
+Symbols:
+ Local:
+ - Name: LT0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: LD0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+
+ Global:
+ - Name: _gp_disp
+ Type: STT_OBJECT
+
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ - Name: T4
+ Type: STT_FUNC
+
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ - Name: D4
+ Type: STT_OBJECT
+ - Name: U1
+...
diff --git a/test/old-elf/Mips/rel-dynamic-09-micro.test b/test/old-elf/Mips/rel-dynamic-09-micro.test
new file mode 100644
index 0000000000000..2011ae0796458
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-09-micro.test
@@ -0,0 +1,109 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are undefined symbols.
+# Check:
+# a) There should be no dynamic relocations.
+# b) There should be no PLT entries.
+#
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel --noinhibit-exec -e T0 -o %t2-exe %t-obj
+# RUN: llvm-readobj -dt -r -s %t2-exe | FileCheck -check-prefix=PLT-SYM %s
+
+# PLT-SYM: Sections [
+# PLT-SYM: Section {
+# PLT-SYM-NOT: Name: .plt ({{[0-9]+}})
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: DynamicSymbols [
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: @ (0)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Local (0x0)
+# PLT-SYM-NEXT: Type: None (0x0)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MICROMIPS_26_S1
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_32
+
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ Type: STT_OBJECT
diff --git a/test/old-elf/Mips/rel-dynamic-09.test b/test/old-elf/Mips/rel-dynamic-09.test
new file mode 100644
index 0000000000000..9b02ec1b57074
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-09.test
@@ -0,0 +1,107 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are undefined symbols.
+# Check:
+# a) There should be no dynamic relocations.
+# b) There should be no PLT entries.
+#
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel --noinhibit-exec -e T0 -o %t2-exe %t-obj
+# RUN: llvm-readobj -dt -r -s %t2-exe | FileCheck -check-prefix=PLT-SYM %s
+
+# PLT-SYM: Sections [
+# PLT-SYM: Section {
+# PLT-SYM-NOT: Name: .plt ({{[0-9]+}})
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: DynamicSymbols [
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: @ (0)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Local (0x0)
+# PLT-SYM-NEXT: Type: None (0x0)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32 ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MIPS_26
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_LO16
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_32
+
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_HI16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_LO16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ Type: STT_OBJECT
diff --git a/test/old-elf/Mips/rel-dynamic-10-micro.test b/test/old-elf/Mips/rel-dynamic-10-micro.test
new file mode 100644
index 0000000000000..4600af85c27cf
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-10-micro.test
@@ -0,0 +1,166 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the other object.
+# Check:
+# a) There should be no dynamic relocations.
+# b) There should be no PLT entries.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-o1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o2.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o1.o %t-o2.o
+# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT-SYM %s
+
+# PLT-SYM: Sections [
+# PLT-SYM: Section {
+# PLT-SYM-NOT: Name: .plt ({{[0-9]+}})
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: DynamicSymbols [
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: @ (0)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Local (0x0)
+# PLT-SYM-NEXT: Type: None (0x0)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# o1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o2.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MICROMIPS_26_S1
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_32
+
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MICROMIPS_HI16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MICROMIPS_LO16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ Type: STT_OBJECT
+...
diff --git a/test/old-elf/Mips/rel-dynamic-10.test b/test/old-elf/Mips/rel-dynamic-10.test
new file mode 100644
index 0000000000000..68a311df73e4c
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-10.test
@@ -0,0 +1,160 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the other object.
+# Check:
+# a) There should be no dynamic relocations.
+# b) There should be no PLT entries.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-o1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o2.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o1.o %t-o2.o
+# RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT-SYM %s
+
+# PLT-SYM: Sections [
+# PLT-SYM: Section {
+# PLT-SYM-NOT: Name: .plt ({{[0-9]+}})
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: DynamicSymbols [
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: @ (0)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Local (0x0)
+# PLT-SYM-NEXT: Type: None (0x0)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# o1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o2.o
+---
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MIPS_26
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_HI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_LO16
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_32
+
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_HI16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_LO16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ Type: STT_OBJECT
+...
diff --git a/test/old-elf/Mips/rel-dynamic-11.test b/test/old-elf/Mips/rel-dynamic-11.test
new file mode 100644
index 0000000000000..01edbd64812fe
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-11.test
@@ -0,0 +1,110 @@
+# Conditions:
+# a) Linking a shared library.
+# b) Relocations' targets are symbols defined in the other shared object.
+# Check:
+# a) Emitting R_MIPS_REL32 relocations for both symbols.
+# b) There should be no PLT entries.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2.so %t-o.o %t1.so
+# RUN: llvm-readobj -dt -r -s %t2.so | FileCheck -check-prefix=PLT-SYM %s
+
+# PLT-SYM: Sections [
+# PLT-SYM: Section {
+# PLT-SYM-NOT: Name: .plt ({{[0-9]+}})
+#
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: Section (4) .rel.dyn {
+# PLT-SYM-NEXT: 0x150 R_MIPS_REL32 T1 0x0
+# PLT-SYM-NEXT: 0x2000 R_MIPS_REL32 T1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+#
+# PLT-SYM: Name: T1@ (7)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_32
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T1
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+...
diff --git a/test/old-elf/Mips/rel-dynamic-12.test b/test/old-elf/Mips/rel-dynamic-12.test
new file mode 100644
index 0000000000000..c684df3f2628f
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-12.test
@@ -0,0 +1,237 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# c) Relocations are R_MIPS_PCHI16 / R_MIPS_PCLO16.
+# Check:
+# a) Emitting R_MIPS_REL32, R_MIPS_COPY, R_MIPS_JUMP_SLOT relocations.
+# b) STO_MIPS_PLT flag in the dynamic symbol table for symbols require
+# a pointer equality.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: Section (5) .rel.dyn {
+# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 T2 0x0
+# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 D2 0x0
+# PLT-SYM-NEXT: 0x402020 R_MIPS_COPY D1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Section (6) .rel.plt {
+# PLT-SYM-NEXT: 0x402008 R_MIPS_JUMP_SLOT T3 0x0
+# PLT-SYM-NEXT: 0x40200C R_MIPS_JUMP_SLOT T1 0x0
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# PLT-SYM: DynamicSymbols [
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: @ (0)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Local (0x0)
+# PLT-SYM-NEXT: Type: None (0x0)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: D1@ (1)
+# PLT-SYM-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-SYM-NEXT: Size: 4
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Object (0x1)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: .bss
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: T1@ (4)
+# PLT-SYM-NEXT: Value: 0x{{[0-9A-F]+}}
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 8
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: T3@ (10)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: T2@ (7)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 0
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Function (0x2)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: Symbol {
+# PLT-SYM-NEXT: Name: D2@ (13)
+# PLT-SYM-NEXT: Value: 0x0
+# PLT-SYM-NEXT: Size: 4
+# PLT-SYM-NEXT: Binding: Global (0x1)
+# PLT-SYM-NEXT: Type: Object (0x1)
+# PLT-SYM-NEXT: Other: 0
+# PLT-SYM-NEXT: Section: Undefined (0x0)
+# PLT-SYM-NEXT: }
+# PLT-SYM-NEXT: ]
+
+# GOT: Local entries [
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x{{[0-9A-F]+}}
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x{{[0-9A-F]+}}
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Object (0x1)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: D2@ (13)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x0C
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 4
+ - Name: T3
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x8
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 4
+ - Name: D2
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x4
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x04
+ Symbol: T3
+ Type: R_MIPS_26
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_PCHI16
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_PCLO16
+ - Offset: 0x04
+ Symbol: T2
+ Type: R_MIPS_32
+
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_PCHI16
+ - Offset: 0x04
+ Symbol: D1
+ Type: R_MIPS_PCLO16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MIPS_32
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: T3
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+ - Name: D2
+ Type: STT_OBJECT
+...
diff --git a/test/old-elf/Mips/rel-dynamic-13.test b/test/old-elf/Mips/rel-dynamic-13.test
new file mode 100644
index 0000000000000..2bf014e510259
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-13.test
@@ -0,0 +1,94 @@
+# Conditions:
+# a) Linking a non-shared 32-bit executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# Check:
+# a) Emitting R_MIPS_REL32 relocation.
+# b) Applying addendum from the original relocation.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s
+
+# RAW: Contents of section .data:
+# RAW-NEXT: 402000 01000000
+
+# REL: Relocations [
+# REL-NEXT: Section (5) .rel.dyn {
+# REL-NEXT: 0x402000 R_MIPS_REL32 T1 0x0
+# REL-NEXT: }
+# REL-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+ Type: SHT_RELA
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_32
+ Addend: 1
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/rel-dynamic-14.test b/test/old-elf/Mips/rel-dynamic-14.test
new file mode 100644
index 0000000000000..33197ae92b81c
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-14.test
@@ -0,0 +1,94 @@
+# Conditions:
+# a) Linking a non-shared 64-bit executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# Check:
+# a) Emitting R_MIPS_REL32/R_MIPS_64 relocation.
+# b) Applying addendum from the original relocation.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s
+
+# RAW: Contents of section .data:
+# RAW-NEXT: 120002000 04000000 00000000
+
+# REL: Relocations [
+# REL-NEXT: Section (5) .rel.dyn {
+# REL-NEXT: 0x120002000 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T1 0x0
+# REL-NEXT: }
+# REL-NEXT: ]
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.data
+ Type: SHT_RELA
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_64
+ Addend: 4
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/rel-dynamic-15.test b/test/old-elf/Mips/rel-dynamic-15.test
new file mode 100644
index 0000000000000..13e2083bfc028
--- /dev/null
+++ b/test/old-elf/Mips/rel-dynamic-15.test
@@ -0,0 +1,81 @@
+# Check that LLD generates dynamic relocation R_MIPS_REL32 for local
+# symbols if the symbols referenced by R_MIPS_32 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 0120 00000000 00000000
+# RAW: Contents of section .data.rel.local:
+# RAW-NEXT: 2000 20010000 00000000
+
+# REL: Relocations [
+# REL-NEXT: Section (4) .rel.dyn {
+# REL-NEXT: 0x2000 R_MIPS_REL32 - 0x0
+# REL-NEXT: 0x2004 R_MIPS_REL32 T1 0x0
+# REL-NEXT: }
+# REL-NEXT: ]
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 8
+
+ - Name: .data.rel.local
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .rel.data.rel.local
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .data.rel.local
+ Relocations:
+ - Offset: 0
+ Symbol: .text
+ Type: R_MIPS_32
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_32
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: .data.rel.local
+ Type: STT_SECTION
+ Section: .data.rel.local
+
+ Global:
+ - Name: D0
+ Type: STT_OBJECT
+ Section: .data.rel.local
+ Value: 0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 4
+ Size: 4
+...
diff --git a/test/old-elf/Mips/rel-eh-01.test b/test/old-elf/Mips/rel-eh-01.test
new file mode 100644
index 0000000000000..08e5d78683a8f
--- /dev/null
+++ b/test/old-elf/Mips/rel-eh-01.test
@@ -0,0 +1,186 @@
+# Check R_MIPS_EH relocation handling: writing result of a relocation
+# calculation, adding GOT entries etc.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 3 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t1.o %t2.o %t.so
+# RUN: llvm-objdump -s -t %t.exe | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# RAW: Contents of section .gnu_extab:
+# RAW-NEXT: 400178 001880ff ff000000 1c80ffff 2080ffff
+# ^ T1 GOT entry = 0xffff8018 = -32744
+# ^ L1 GOT entry = 0xffff801c = -32740
+# E1 GOT entry = 0xffff8020 = -32736 ^
+# RAW: Contents of section .got:
+# RAW-NEXT: 401000 00000000 00000080 60014000 00204000
+# RAW-NEXT: 401010 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 00402000 l .data 00000004 L1
+# RAW: 00400160 g F .text 00000004 T1
+
+# GOT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x400160
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x402000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: E1@ (1)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: E1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ AddressAlign: 16
+ Size: 8
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [SHF_WRITE, SHF_ALLOC]
+ AddressAlign: 16
+ Size: 4
+
+ - Name: .gnu_extab
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC]
+ AddressAlign: 4
+ Size: 16
+
+ - Name: .rel.gnu_extab
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .gnu_extab
+ Relocations:
+ - Offset: 1
+ Symbol: T1
+ Type: R_MIPS_EH
+ - Offset: 8
+ Symbol: L1
+ Type: R_MIPS_EH
+ - Offset: 12
+ Symbol: E1
+ Type: R_MIPS_EH
+
+ - Name: .eh_frame_entry
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC]
+ AddressAlign: 4
+ Content: "0000000100000001"
+
+ - Name: .rel.eh_frame_entry
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .eh_frame_entry
+ Relocations:
+ - Offset: 0
+ Symbol: .text
+ Type: R_MIPS_PC32
+ - Offset: 4
+ Symbol: .gnu_extab
+ Type: R_MIPS_PC32
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .gnu_extab
+ Type: STT_SECTION
+ Section: .gnu_extab
+ - Name: L1
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0
+ Size: 4
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 8
+ - Name: E1
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/rel-eh-02.test b/test/old-elf/Mips/rel-eh-02.test
new file mode 100644
index 0000000000000..e78c967ed301a
--- /dev/null
+++ b/test/old-elf/Mips/rel-eh-02.test
@@ -0,0 +1,130 @@
+# Conditions:
+# a) Linking a non-shared executable file.
+# b) Relocations' targets are symbols defined in the shared object.
+# Check:
+# a) The R_MIPS_REL32 relocation is not created for any symbols.
+# b) The R_MIPS_COPY relocation is created for the D1 symbol.
+# c) No entries in the dynamic symbols table has the STO_MIPS_PLT flag.
+#
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s
+
+# PLT-SYM: Relocations [
+# PLT-SYM-NEXT: Section (5) .rel.dyn {
+# PLT-SYM-NEXT: 0x{{[0-9A-F]+}} R_MIPS_COPY D1 0x0
+# PLT-SYM-NEXT: }
+
+# PLT-SYM: DynamicSymbols [
+# PLT-SYM-NOT: Other: 8
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 4
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ - Name: D1
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0
+ Size: 4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_WRITE, SHF_ALLOC]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_26
+ - Offset: 4
+ Symbol: D1
+ Type: R_MIPS_PC32
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_EH
+ - Offset: 4
+ Symbol: T2
+ Type: R_MIPS_EH
+ - Offset: 8
+ Symbol: D1
+ Type: R_MIPS_EH
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 8
+ - Name: T1
+ Type: STT_FUNC
+ - Name: T2
+ Type: STT_FUNC
+ - Name: D0
+ Section: .data
+ Type: STT_OBJECT
+ Value: 0x0
+ Size: 8
+ - Name: D1
+ Type: STT_OBJECT
+...
diff --git a/test/old-elf/Mips/rel-eh-03.test b/test/old-elf/Mips/rel-eh-03.test
new file mode 100644
index 0000000000000..63ed74cd56f88
--- /dev/null
+++ b/test/old-elf/Mips/rel-eh-03.test
@@ -0,0 +1,128 @@
+# Check R_MIPS_EH relocation handling in case of -pcrel-eh-reloc option.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 \
+# RUN: -pcrel-eh-reloc -o %t.exe %t1.o %t2.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck -check-prefix=RAW %s
+
+# RAW: Contents of section .gnu_extab:
+# RAW-NEXT: 400148 00e7ffff ff000000 b01e0000 00000000
+# ^ 0x400130 + 0 - 0x400149 = 0xffffffe7
+# ^ 0x402000 + 0 - 0x400150 = 0x1eb0
+# E1 GOT entry = 0xffff8020 = -32736 ^
+# RAW: Contents of section .got:
+# RAW-NEXT: 401000 00000000 00000080
+
+# RAW: SYMBOL TABLE:
+# RAW: 00402000 l .data 00000004 L1
+# RAW: 00400130 g F .text 00000004 T1
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+ AddressAlign: 16
+ Size: 8
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [SHF_WRITE, SHF_ALLOC]
+ AddressAlign: 16
+ Size: 4
+
+ - Name: .gnu_extab
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC]
+ AddressAlign: 4
+ Size: 16
+
+ - Name: .rel.gnu_extab
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .gnu_extab
+ Relocations:
+ - Offset: 1
+ Symbol: T1
+ Type: R_MIPS_EH
+ - Offset: 8
+ Symbol: L1
+ Type: R_MIPS_EH
+
+ - Name: .eh_frame_entry
+ Type: SHT_PROGBITS
+ Flags: [SHF_ALLOC]
+ AddressAlign: 4
+ Content: "0000000100000001"
+
+ - Name: .rel.eh_frame_entry
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .eh_frame_entry
+ Relocations:
+ - Offset: 0
+ Symbol: .text
+ Type: R_MIPS_PC32
+ - Offset: 4
+ Symbol: .gnu_extab
+ Type: R_MIPS_PC32
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: .gnu_extab
+ Type: STT_SECTION
+ Section: .gnu_extab
+ - Name: L1
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0
+ Size: 4
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 8
+ - Name: T1
+...
diff --git a/test/old-elf/Mips/rel-got-hilo-01.test b/test/old-elf/Mips/rel-got-hilo-01.test
new file mode 100644
index 0000000000000..c73d8765cbd52
--- /dev/null
+++ b/test/old-elf/Mips/rel-got-hilo-01.test
@@ -0,0 +1,109 @@
+# Check handling of R_MIPS_GOT_HI16 / R_MIPS_GOT_LO16 relocations.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t1.so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2.so %t2.so.o %t1.so
+# RUN: llvm-objdump -s -t %t2.so | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -mips-plt-got %t2.so | FileCheck -check-prefix=GOT %s
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 0110 00000000 18800000 00000000 1c800000
+# ^ -32744 ^ -32740
+# RAW-NEXT: 0120 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 00000120 l F .text 00000004 T1
+
+# GOT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x120
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# t1.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 4
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+
+# t2.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 20
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_GOT_HI16
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_GOT_LO16
+ - Offset: 8
+ Symbol: T2
+ Type: R_MIPS_GOT_HI16
+ - Offset: 12
+ Symbol: T2
+ Type: R_MIPS_GOT_LO16
+
+Symbols:
+ Local:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 16
+ Size: 4
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 16
+ - Name: T2
+...
diff --git a/test/old-elf/Mips/rel-got-hilo-micro.test b/test/old-elf/Mips/rel-got-hilo-micro.test
new file mode 100644
index 0000000000000..39dd1848f92ed
--- /dev/null
+++ b/test/old-elf/Mips/rel-got-hilo-micro.test
@@ -0,0 +1,154 @@
+# Check handling of R_MICROMIPS_GOT_HI16 / R_MICROMIPS_GOT_LO16 relocations.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t1.so %t1.so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.so.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t2.so %t2.so.o %t1.so
+# RUN: llvm-objdump -s -t %t2.so | FileCheck -check-prefix=RAW %s
+# RUN: llvm-readobj -mips-plt-got %t2.so | FileCheck -check-prefix=GOT %s
+
+# RAW: Contents of section .text:
+# RAW-NEXT: 0130 00000000 00001880 00000000 00002080
+# ^ -32744 ^ -32736
+# RAW-NEXT: 0140 00000000 00001c80 00000000 00002480
+# ^ -32740 ^ -32732
+# RAW-NEXT: 0150 00000000 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 00000150 l F .text 00000004 T1
+# RAW: 00000154 l F .text 00000004 M1
+
+# GOT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x150
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x155
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@ (4)
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: M2@ (7)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+
+# t1.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: M2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+
+# t2.so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 40
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_HI16
+ - Offset: 4
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_LO16
+ - Offset: 8
+ Symbol: T2
+ Type: R_MICROMIPS_GOT_HI16
+ - Offset: 12
+ Symbol: T2
+ Type: R_MICROMIPS_GOT_LO16
+ - Offset: 16
+ Symbol: M1
+ Type: R_MICROMIPS_GOT_HI16
+ - Offset: 20
+ Symbol: M1
+ Type: R_MICROMIPS_GOT_LO16
+ - Offset: 24
+ Symbol: M2
+ Type: R_MICROMIPS_GOT_HI16
+ - Offset: 28
+ Symbol: M2
+ Type: R_MICROMIPS_GOT_LO16
+
+Symbols:
+ Local:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 32
+ Size: 4
+ - Name: M1
+ Section: .text
+ Type: STT_FUNC
+ Value: 36
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 32
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ - Name: M2
+...
diff --git a/test/old-elf/Mips/rel-gprel16-micro-overflow.test b/test/old-elf/Mips/rel-gprel16-micro-overflow.test
new file mode 100644
index 0000000000000..7b023aecba415
--- /dev/null
+++ b/test/old-elf/Mips/rel-gprel16-micro-overflow.test
@@ -0,0 +1,57 @@
+# Check R_MICROMIPS_GPREL16 relocation overflow handling.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}} reference from +0 to L0+0 of type 136 (R_MICROMIPS_GPREL16)
+# CHECK: Relocation out of range in file {{.*}} reference from +4 to G0+0 of type 136 (R_MICROMIPS_GPREL16)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Type: SHT_PROGBITS
+ Name: .text
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+- Type: SHT_PROGBITS
+ Name: .rodata
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Size: 8
+
+- Type: SHT_REL
+ Name: .rel.rodata
+ Link: .symtab
+ Info: .rodata
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: L0
+ Type: R_MICROMIPS_GPREL16
+ - Offset: 4
+ Symbol: G0
+ Type: R_MICROMIPS_GPREL16
+
+Symbols:
+ Local:
+ - Name: L0
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: .rodata
+ Type: STT_SECTION
+ Section: .rodata
+ Global:
+ - Name: G0
+ Section: .text
+ Value: 4
+ Size: 4
diff --git a/test/old-elf/Mips/rel-gprel16-micro.test b/test/old-elf/Mips/rel-gprel16-micro.test
new file mode 100644
index 0000000000000..c0119a51e484e
--- /dev/null
+++ b/test/old-elf/Mips/rel-gprel16-micro.test
@@ -0,0 +1,78 @@
+# Check R_MICROMIPS_GPREL16 relocation handling.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -symbols %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=SEC %s
+
+# SYM: Name: L0
+# SYM-NEXT: Value: 0x104
+# SYM-NEXT: Size: 4
+
+# SYM: Name: G0
+# SYM-NEXT: Value: 0x108
+# SYM-NEXT: Size: 4
+
+# SYM: Name: _gp
+# SYM-NEXT: Value: 0x8FF0
+# SYM-NEXT: Size: 0
+
+# SEC: Contents of section .rodata:
+# SEC-NEXT: 010c 00001071 000017f1
+# ^ 0x104 (L0) + 0x10000 (GP0) - 0x8ff0 (_gp) - 4 = 0x7110
+# ^ 0x108 (G0) - 0x8ff0 (_gp) + 0x7fff = 0xf117
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Type: SHT_PROGBITS
+ Name: .text
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+- Type: SHT_PROGBITS
+ Name: .rodata
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: 0000fcff0000ff7f
+
+- Type: SHT_REL
+ Name: .rel.rodata
+ Link: .symtab
+ Info: .rodata
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: L0
+ Type: R_MICROMIPS_GPREL16
+ - Offset: 4
+ Symbol: G0
+ Type: R_MICROMIPS_GPREL16
+
+- Type: SHT_MIPS_REGINFO
+ Name: .reginfo
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 1
+ Content: 000000000000000000000000000000000000000000000100
+
+Symbols:
+ Local:
+ - Name: L0
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: .rodata
+ Type: STT_SECTION
+ Section: .rodata
+ Global:
+ - Name: G0
+ Section: .text
+ Value: 4
+ Size: 4
diff --git a/test/old-elf/Mips/rel-gprel16-overflow.test b/test/old-elf/Mips/rel-gprel16-overflow.test
new file mode 100644
index 0000000000000..2943b5d200f41
--- /dev/null
+++ b/test/old-elf/Mips/rel-gprel16-overflow.test
@@ -0,0 +1,48 @@
+# Check R_MIPS_GPREL16 relocation overflow handling.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}} reference from +0 to T1+-32768 of type 7 (R_MIPS_GPREL16)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Type: SHT_PROGBITS
+ Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 4
+
+- Type: SHT_PROGBITS
+ Name: .rodata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: 00800000
+
+- Type: SHT_REL
+ Name: .rel.rodata
+ Type: SHT_REL
+ Link: .symtab
+ Info: .rodata
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_GPREL16
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Value: 0
+ Size: 4
diff --git a/test/old-elf/Mips/rel-gprel16.test b/test/old-elf/Mips/rel-gprel16.test
new file mode 100644
index 0000000000000..d7e8a1a925980
--- /dev/null
+++ b/test/old-elf/Mips/rel-gprel16.test
@@ -0,0 +1,104 @@
+# Check R_MIPS_GPREL16 relocation handling.
+#
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel -e G1 -shared -o %t.so %t-obj
+# RUN: llvm-readobj -symbols %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=SEC %s
+
+# SYM: Name: L1
+# SYM-NEXT: Value: 0x104
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Local (0x0)
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text (0x5)
+
+# SYM: Name: G1
+# SYM-NEXT: Value: 0x108
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text (0x5)
+
+# SYM: Name: _gp
+# SYM-NEXT: Value: 0x8FF0
+# SYM-NEXT: Size: 0
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: Object (0x1)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: Absolute (0xFFF1)
+
+# 0x6110 == 0xfffc (addend) + 0x0104 (L1) + 0xf000 (GP0) - 0x8ff0 (_gp)
+# SEC: Contents of section .rodata:
+# SEC-NEXT: 010c 10610008 00000000 00000000 00000000
+
+!ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+- Type: SHT_PROGBITS
+ Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+
+- Type: SHT_REL
+ Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0
+ Symbol: .rodata
+ Type: R_MIPS_GOT16
+ - Offset: 4
+ Symbol: .rodata
+ Type: R_MIPS_LO16
+
+- Type: SHT_PROGBITS
+ Name: .rodata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x04
+ Content: fcff0008000000000000000000000000
+
+- Type: SHT_REL
+ Name: .rel.rodata
+ Type: SHT_REL
+ Link: .symtab
+ Info: .rodata
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0
+ Symbol: L1
+ Type: R_MIPS_GPREL16
+
+- Type: SHT_MIPS_REGINFO
+ Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x01
+ Content: 000000000000000000000000000000000000000000f00000
+
+Symbols:
+ Local:
+ - Name: L1
+ Section: .text
+ Value: 0x00
+ Size: 0x04
+ - Name: .rodata
+ Type: STT_SECTION
+ Section: .rodata
+ Global:
+ - Name: G1
+ Section: .text
+ Value: 0x04
+ Size: 0x04
diff --git a/test/old-elf/Mips/rel-gprel32-64.test b/test/old-elf/Mips/rel-gprel32-64.test
new file mode 100644
index 0000000000000..15498a693e4d0
--- /dev/null
+++ b/test/old-elf/Mips/rel-gprel32-64.test
@@ -0,0 +1,84 @@
+# Check R_MIPS_GPREL32/R_MIPS_64 relocations handling.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t.o
+# RUN: llvm-readobj -r %t.exe | FileCheck --check-prefix=REL-EXE %s
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+# RUN: llvm-nm %t.exe | FileCheck --check-prefix=SYM %s
+
+# REL-EXE: Relocations [
+# REL-EXE-NEXT: ]
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 1200001d0 f871ffff ffffffff f871ffff f871ffff
+# CHECK-NEXT: 1200001e0 f871ffff ffffffff 00000000 00000000
+
+# SYM: 00000001200001e8 t LT1
+# SYM: 0000000120001000 N _GLOBAL_OFFSET_TABLE_
+
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t.o
+# RUN: llvm-readobj -r %t.so | FileCheck --check-prefix=REL-SO %s
+
+# REL-SO: Relocations [
+# REL-SO-NEXT: ]
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 32
+
+ - Name: .rela.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 8
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: LT1
+ Type: R_MIPS_GPREL16
+ Type2: R_MIPS_64
+ Type3: R_MIPS_NONE
+ - Offset: 0x08
+ Symbol: LT1
+ Type: R_MIPS_GPREL16
+ Type2: R_MIPS_64
+ Type3: R_MIPS_NONE
+ - Offset: 0x0C
+ Symbol: LT1
+ Type: R_MIPS_GPREL32
+ Type2: R_MIPS_64
+ Type3: R_MIPS_NONE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MIPS_GPREL32
+ Type2: R_MIPS_64
+ Type3: R_MIPS_NONE
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x18
+ Size: 0x8
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x0
+ Size: 0x18
+...
diff --git a/test/old-elf/Mips/rel-gprel32.test b/test/old-elf/Mips/rel-gprel32.test
new file mode 100644
index 0000000000000..14ec8cebcabd3
--- /dev/null
+++ b/test/old-elf/Mips/rel-gprel32.test
@@ -0,0 +1,84 @@
+# Check R_MIPS_GPREL32 relocation handling.
+#
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel -o %t-exe %t-obj
+# RUN: llvm-readobj -symbols %t-exe | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t-exe | FileCheck -check-prefix=SEC %s
+
+# SYM: Name: $L1
+# SYM-NEXT: Value: 0x400160
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Local (0x0)
+# SYM-NEXT: Type: Function (0x2)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .text (0x6)
+#
+# SYM: Name: _gp
+# SYM-NEXT: Value: 0x408FF0
+# SYM-NEXT: Size: 0
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: Object (0x1)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: Absolute (0xFFF1)
+
+# 0x08ff7153 == 0x8000001 (addend) + 0x400140 ($L1) +
+# 0x1000002 (GP0) - 0x408FF0 (_gp)
+# SEC: Contents of section .rodata:
+# SEC-NEXT: 400170 7371ff08 00000000 00000000 00000000
+
+!ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+- Type: SHT_PROGBITS
+ Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Content: 00000000000000000000000000000000
+
+- Type: SHT_PROGBITS
+ Name: .rodata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x04
+ Content: 01000008000000000000000000000000
+
+- Type: SHT_REL
+ Name: .rel.rodata
+ Type: SHT_REL
+ Link: .symtab
+ Info: .rodata
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0
+ Symbol: $L1
+ Type: R_MIPS_GPREL32
+
+- Type: SHT_MIPS_REGINFO
+ Name: .reginfo
+ Type: SHT_MIPS_REGINFO
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 0x01
+ Content: 000000000000000000000000000000000000000002000001
+
+Symbols:
+ Local:
+ - Name: $L1
+ Section: .text
+ Value: 0x00
+ - Name: .rodata
+ Type: STT_SECTION
+ Section: .rodata
+ Global:
+ - Name: __start
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x04
+ Size: 12
+ - Name: _gp_disp
diff --git a/test/old-elf/Mips/rel-gprel7-micro-overflow.test b/test/old-elf/Mips/rel-gprel7-micro-overflow.test
new file mode 100644
index 0000000000000..5609786aa04aa
--- /dev/null
+++ b/test/old-elf/Mips/rel-gprel7-micro-overflow.test
@@ -0,0 +1,48 @@
+# Check R_MICROMIPS_GPREL7_S2 relocation overflow handling.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}} reference from +0 to L0+-4 of type 172 (R_MICROMIPS_GPREL7_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Type: SHT_PROGBITS
+ Name: .text
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 4
+
+- Type: SHT_PROGBITS
+ Name: .rodata
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: 7f000000
+
+- Type: SHT_REL
+ Name: .rel.rodata
+ Link: .symtab
+ Info: .rodata
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: L0
+ Type: R_MICROMIPS_GPREL7_S2
+
+Symbols:
+ Local:
+ - Name: L0
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: .rodata
+ Type: STT_SECTION
+ Section: .rodata
diff --git a/test/old-elf/Mips/rel-gprel7-micro.test b/test/old-elf/Mips/rel-gprel7-micro.test
new file mode 100644
index 0000000000000..b7790d9d169c3
--- /dev/null
+++ b/test/old-elf/Mips/rel-gprel7-micro.test
@@ -0,0 +1,65 @@
+# Check R_MICROMIPS_GPREL7_S2 relocation handling.
+#
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-readobj -symbols %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=SEC %s
+
+# SYM: Name: L0
+# SYM-NEXT: Value: 0xF0
+# SYM-NEXT: Size: 4
+
+# SYM: Name: _gp
+# SYM-NEXT: Value: 0x8FF0
+# SYM-NEXT: Size: 0
+
+# SEC: Contents of section .rodata:
+# SEC-NEXT: 0f4 3b000000
+# ^ 0xf0 (L0) + 0x8ff0 (GP0) - 0x8ff0 (_gp) - 4 = 0xec >> 2
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Type: SHT_PROGBITS
+ Name: .text
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 4
+
+- Type: SHT_PROGBITS
+ Name: .rodata
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 4
+ Content: 7f000000
+
+- Type: SHT_REL
+ Name: .rel.rodata
+ Link: .symtab
+ Info: .rodata
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: L0
+ Type: R_MICROMIPS_GPREL7_S2
+
+- Type: SHT_MIPS_REGINFO
+ Name: .reginfo
+ Flags: [ SHF_ALLOC ]
+ AddressAlign: 1
+ Content: 0000000000000000000000000000000000000000f08f0000
+
+Symbols:
+ Local:
+ - Name: L0
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: .rodata
+ Type: STT_SECTION
+ Section: .rodata
diff --git a/test/old-elf/Mips/rel-hi0-lo16-micro.test b/test/old-elf/Mips/rel-hi0-lo16-micro.test
new file mode 100644
index 0000000000000..82f62954b992a
--- /dev/null
+++ b/test/old-elf/Mips/rel-hi0-lo16-micro.test
@@ -0,0 +1,58 @@
+# Check handling of R_MICROMIPS_HI0_LO16 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 400130 00000420
+# ^ 0x402000 + 0x4 = 0x402004
+
+# CHECK: 00402000 g .data 00000004 D0
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "00000400"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: D0
+ Type: R_MICROMIPS_HI0_LO16
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: D0
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/rel-high-01.test b/test/old-elf/Mips/rel-high-01.test
new file mode 100644
index 0000000000000..613fedbe31db6
--- /dev/null
+++ b/test/old-elf/Mips/rel-high-01.test
@@ -0,0 +1,25 @@
+# REQUIRES: mips
+
+# Check handling R_MIPS_HIGHER / R_MIPS_HIGHEST relocations.
+
+# RUN: llvm-mc -arch=mips64el -filetype=obj -o=%t.o %s
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: T0:
+# CHECK-NEXT: 120000250: 01 00 62 64 daddiu $2, $3, 1
+# CHECK-NEXT: 120000254: 00 00 62 64 daddiu $2, $3, 0
+#
+# CHECK: T1:
+# CHECK-NEXT: 120000258: 00 00 00 00 nop
+
+ .text
+ .globl T0
+T0:
+ daddiu $2, $3, %higher(T1)
+ daddiu $2, $3, %highest(T1)
+
+ .globl T1
+T1:
+ nop
diff --git a/test/old-elf/Mips/rel-high-02.test b/test/old-elf/Mips/rel-high-02.test
new file mode 100644
index 0000000000000..7a40a617a680e
--- /dev/null
+++ b/test/old-elf/Mips/rel-high-02.test
@@ -0,0 +1,25 @@
+# REQUIRES: mips
+
+# Check handling R_MICROMIPS_HIGHER / R_MICROMIPS_HIGHEST relocations.
+
+# RUN: llvm-mc -arch=mips64el -filetype=obj -o=%t.o %s
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: Disassembly of section .text:
+# CHECK-NEXT: T0:
+# CHECK-NEXT: 120000250: 01 00 62 64 daddiu $2, $3, 1
+# CHECK-NEXT: 120000254: 00 00 62 64 daddiu $2, $3, 0
+#
+# CHECK: T1:
+# CHECK-NEXT: 120000258: 00 00 00 00 nop
+
+ .text
+ .globl T0
+T0:
+ daddiu $2, $3, %higher(T1+0x0000800100000000)
+ daddiu $2, $3, %highest(T1+0x4001000000000000)
+
+ .globl T1
+T1:
+ nop
diff --git a/test/old-elf/Mips/rel-jalr-01.test b/test/old-elf/Mips/rel-jalr-01.test
new file mode 100644
index 0000000000000..3c519056e1a93
--- /dev/null
+++ b/test/old-elf/Mips/rel-jalr-01.test
@@ -0,0 +1,101 @@
+# REQUIRES: mips
+
+# Check handling of the R_MIPS_JALR relocation.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mipsel -o %t.exe %t2.o %t.so
+# RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+# CHECK: __start:
+# CHECK-NEXT: {{[0-9a-f]+}}: 05 00 11 04 bal 24
+# CHECK-NEXT: {{[0-9a-f]+}}: 00 00 00 00 nop
+# CHECK-NEXT: {{[0-9a-f]+}}: 04 00 00 10 b 20
+# CHECK-NEXT: {{[0-9a-f]+}}: 00 00 00 00 nop
+# CHECK-NEXT: {{[0-9a-f]+}}: 09 f8 20 03 jalr $25
+# CHECK-NEXT: {{[0-9a-f]+}}: 00 00 00 00 nop
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: T3
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "09f8200300000000080020030000000009f82003000000000000000000000000"
+# ^ jalr T1 ^ j T2 ^ jalr T3
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_JALR
+ - Offset: 8
+ Symbol: T2
+ Type: R_MIPS_JALR
+ - Offset: 16
+ Symbol: T3
+ Type: R_MIPS_JALR
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 16
+ Size: 0
+
+Symbols:
+ Local:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 24
+ Size: 4
+ Global:
+ - Name: __start
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 24
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Value: 28
+ Size: 4
+ - Name: T3
+...
diff --git a/test/old-elf/Mips/rel-jalr-02.test b/test/old-elf/Mips/rel-jalr-02.test
new file mode 100644
index 0000000000000..e9c74c4c3300e
--- /dev/null
+++ b/test/old-elf/Mips/rel-jalr-02.test
@@ -0,0 +1,68 @@
+# REQUIRES: mips
+
+# Check R_MIPS_JALR relocations do not affect the code
+# in case of relocatable targets.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t.o
+# RUN: llvm-objdump -d %t.so | FileCheck %s
+
+# CHECK: __start:
+# CHECK-NEXT: {{[0-9a-f]+}}: 09 f8 20 03 jalr $25
+# CHECK-NEXT: {{[0-9a-f]+}}: 00 00 00 00 nop
+# CHECK-NEXT: {{[0-9a-f]+}}: 08 00 20 03 jr $25
+# CHECK-NEXT: {{[0-9a-f]+}}: 00 00 00 00 nop
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "09f820030000000008002003000000000000000000000000"
+# ^ jalr ^ jr ^ T1 ^ T2
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_JALR
+ - Offset: 8
+ Symbol: T2
+ Type: R_MIPS_JALR
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 16
+ Size: 0
+
+Symbols:
+ Global:
+ - Name: __start
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 16
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 16
+ Size: 4
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Value: 20
+ Size: 4
+...
diff --git a/test/old-elf/Mips/rel-lit-micro.test b/test/old-elf/Mips/rel-lit-micro.test
new file mode 100644
index 0000000000000..783b24f838136
--- /dev/null
+++ b/test/old-elf/Mips/rel-lit-micro.test
@@ -0,0 +1,59 @@
+# Check handling of R_MICROMIPS_LITERAL relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 400130 00000f10
+# ^ 0x402000 + 0x7fff - 0x408ff0 = 0x100f
+
+# CHECK: 00402000 g .data 00000004 D0
+# CHECK: 00408ff0 g *ABS* 00000000 _gp_disp
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32,
+ EF_MIPS_ARCH_32, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "0000ff7f"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: D0
+ Type: R_MICROMIPS_LITERAL
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: D0
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/rel-lit.test b/test/old-elf/Mips/rel-lit.test
new file mode 100644
index 0000000000000..19aa687216913
--- /dev/null
+++ b/test/old-elf/Mips/rel-lit.test
@@ -0,0 +1,57 @@
+# Check handling of R_MIPS_LITERAL relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 400130 0f100000
+# ^ 0x402000 + 0x7fff - 0x408ff0 = 0x100f
+
+# CHECK: 00402000 g .data 00000004 D0
+# CHECK: 00408ff0 g *ABS* 00000000 _gp_disp
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "ff7f0000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: D0
+ Type: R_MIPS_LITERAL
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: D0
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0
+ Size: 4
+...
diff --git a/test/old-elf/Mips/rel-pc-hilo.test b/test/old-elf/Mips/rel-pc-hilo.test
new file mode 100644
index 0000000000000..6791926762b27
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc-hilo.test
@@ -0,0 +1,70 @@
+# Check handling of R_MIPS_PCHI16 / R_MIPS_PCLO16 relocations.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 01000000 02000000 03000000 00000000
+# ^
+# A = 0x10000 - 1 == 0xffff
+# V = (T1 + 0xffff - T0) >> 16 =>
+# V => 0x1000b >> 16 = 1
+# ^
+# A = 0x20000 - 1 == 0x1ffff
+# V = (T1 + 0x1ffff - T0 - 4) >> 16 =>
+# V => 0x20007 >> 16 = 2
+# ^
+# A = 0xffff == -1
+# V = T1 - 1 - T0 - 8 = 3
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9a-f]+}} g F .text 0000000c T0
+# CHECK: {{[0-9a-f]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0100000002000000ffff000000000000"
+# ^ T0
+# ^ A := 0x1 == 0x10000
+# ^ A := 0x2 == 0x20000
+# ^ A := 0xffff == -1
+# ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PCHI16
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_PCHI16
+ - Offset: 8
+ Symbol: T1
+ Type: R_MIPS_PCLO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 12
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 12
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc16-align.test b/test/old-elf/Mips/rel-pc16-align.test
new file mode 100644
index 0000000000000..6366a4d67e923
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc16-align.test
@@ -0,0 +1,43 @@
+# Check incorrect alignment handling for R_MIPS_PC16 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T0+0 to T1+0 of type 10 (R_MIPS_PC16)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 6
+ Size: 2
diff --git a/test/old-elf/Mips/rel-pc16-overflow.test b/test/old-elf/Mips/rel-pc16-overflow.test
new file mode 100644
index 0000000000000..910482ee61549
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc16-overflow.test
@@ -0,0 +1,45 @@
+# Check R_MIPS_PC16 relocation overflow handling.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}} reference from T0+0 to T1+131068 of type 10 (R_MIPS_PC16)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "ff7f00000000000000000000"
+# ^ T1
+# ^ T0 A := 0x7fff << 2 = 0x1fffc
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc16.test b/test/old-elf/Mips/rel-pc16.test
new file mode 100644
index 0000000000000..f298afd81cd6c
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc16.test
@@ -0,0 +1,53 @@
+# Check handling of R_MIPS_PC16 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} feff0000 00000000 00000000
+# ^ V
+# A = -16 =>
+# V = (T1 - 16 - T0) >> 2 = -2
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000008 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "fcff00000000000000000000"
+# ^ T1
+# ^ T0 A := 0xfffc << 2 = -16
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC16
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc18-s3-align.test b/test/old-elf/Mips/rel-pc18-s3-align.test
new file mode 100644
index 0000000000000..ca2fa18ecaa0c
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc18-s3-align.test
@@ -0,0 +1,44 @@
+# Check incorrect alignment handling for R_MIPS_PC18_S3 relocation target.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T1+0 to T1+0 of type 62 (R_MIPS_PC18_S3)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+# ^ T0 ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_PC18_S3
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc18-s3-micro.test b/test/old-elf/Mips/rel-pc18-s3-micro.test
new file mode 100644
index 0000000000000..fc143a75e5698
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc18-s3-micro.test
@@ -0,0 +1,56 @@
+# Check handling of R_MICROMIPS_PC18_S3 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 00000000 00000100 00000000 00000000
+# ^ V
+# A = -1 << 3 = -8 =>
+# V = (T1 - 8 - (T0|7)^7) >> 3 =>
+# V => 8 >> 3 = 1 (shuffled)
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000010 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "000000000300ffff000000000000000000000000"
+# ^ T1
+# ^ T0 ^ A := 0x3ffff == -1 (shuffled)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 4
+ Symbol: T1
+ Type: R_MICROMIPS_PC18_S3
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 16
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 16
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
diff --git a/test/old-elf/Mips/rel-pc18-s3.test b/test/old-elf/Mips/rel-pc18-s3.test
new file mode 100644
index 0000000000000..d61427448d530
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc18-s3.test
@@ -0,0 +1,54 @@
+# Check handling of R_MIPS_PC18_S3 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 00000000 01000000 00000000 00000000
+# ^ V
+# A = -1 << 3 = -8 =>
+# V = (T1 - 8 - (T0|7)^7) >> 3 =>
+# V => 8 >> 3 = 1
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000010 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "00000000ffff0300000000000000000000000000"
+# ^ T1
+# ^ T0 ^ A := 0x3ffff == -1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 4
+ Symbol: T1
+ Type: R_MIPS_PC18_S3
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 16
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 16
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc19-s2-align.test b/test/old-elf/Mips/rel-pc19-s2-align.test
new file mode 100644
index 0000000000000..19010a445578b
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc19-s2-align.test
@@ -0,0 +1,44 @@
+# Check incorrect alignment handling for R_MIPS_PC19_S2 relocation target.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T0+0 to T1+0 of type 63 (R_MIPS_PC19_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+# ^ T0 ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC19_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 6
+ Size: 2
diff --git a/test/old-elf/Mips/rel-pc19-s2-micro.test b/test/old-elf/Mips/rel-pc19-s2-micro.test
new file mode 100644
index 0000000000000..d9a930e41d888
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc19-s2-micro.test
@@ -0,0 +1,56 @@
+# Check handling of R_MICROMIPS_PC19_S2 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 00000100 00000000 00000000
+# ^ V
+# A = -1 << 2 = -4 =>
+# V = (T1 - 4 - T0) >> 2 =>
+# V => 4 >> 2 = 1 (shuffled)
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000008 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0700ffff0000000000000000"
+# ^ T1
+# ^ T0 A := 0x7ffff == -1 (shuffled)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MICROMIPS_PC19_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
diff --git a/test/old-elf/Mips/rel-pc19-s2.test b/test/old-elf/Mips/rel-pc19-s2.test
new file mode 100644
index 0000000000000..da21864a1214d
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc19-s2.test
@@ -0,0 +1,54 @@
+# Check handling of R_MIPS_PC19_S2 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 01000000 00000000 00000000
+# ^ V
+# A = -1 << 2 = -4 =>
+# V = (T1 - 4 - T0) >> 2 =>
+# V => 4 >> 2 = 1
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000008 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "ffff07000000000000000000"
+# ^ T1
+# ^ T0 A := 0x7ffff == -1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC19_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc21-s2-align.test b/test/old-elf/Mips/rel-pc21-s2-align.test
new file mode 100644
index 0000000000000..a79e1e2a46e0e
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc21-s2-align.test
@@ -0,0 +1,44 @@
+# Check incorrect alignment handling for R_MIPS_PC21_S2 relocation target.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T0+0 to T1+0 of type 60 (R_MIPS_PC21_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+# ^ T0 ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC21_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 6
+ Size: 2
diff --git a/test/old-elf/Mips/rel-pc21-s2-micro.test b/test/old-elf/Mips/rel-pc21-s2-micro.test
new file mode 100644
index 0000000000000..4aa0a7de94894
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc21-s2-micro.test
@@ -0,0 +1,56 @@
+# Check handling of R_MICROMIPS_PC21_S2 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 00000100 00000000 00000000
+# ^ V
+# A = -1 << 2 = -4 =>
+# V = (T1 - 4 - T0) >> 2 =>
+# V => 4 >> 2 = 1 (shuffled)
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000008 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "1f00ffff0000000000000000"
+# ^ T1
+# ^ T0 A := 0x1fffff (shuffled)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MICROMIPS_PC21_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
diff --git a/test/old-elf/Mips/rel-pc21-s2-overflow.test b/test/old-elf/Mips/rel-pc21-s2-overflow.test
new file mode 100644
index 0000000000000..ad88e0c14b44e
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc21-s2-overflow.test
@@ -0,0 +1,45 @@
+# Check R_MIPS_PC21_S2 relocation overflow handling.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation out of range in file {{.*}} reference from T0+0 to T1+4194300 of type 60 (R_MIPS_PC21_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "ffff0f000000000000000000"
+# ^ T1
+# ^ T0 A := 0xfffff
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC21_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc21-s2.test b/test/old-elf/Mips/rel-pc21-s2.test
new file mode 100644
index 0000000000000..c2b58c859af9f
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc21-s2.test
@@ -0,0 +1,54 @@
+# Check handling of R_MIPS_PC21_S2 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 01000000 00000000 00000000
+# ^ V
+# A = -1 << 2 = -4 =>
+# V = (T1 - 4 - T0) >> 2 =>
+# V => 4 >> 2 = 1
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000008 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "ffff1f000000000000000000"
+# ^ T1
+# ^ T0 A := 0x1fffff
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC21_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc26-s2-align.test b/test/old-elf/Mips/rel-pc26-s2-align.test
new file mode 100644
index 0000000000000..23e660848365c
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc26-s2-align.test
@@ -0,0 +1,44 @@
+# Check incorrect alignment handling for R_MIPS_PC26_S2 relocation target.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: Relocation not aligned in file {{.*}} reference from T0+0 to T1+0 of type 61 (R_MIPS_PC26_S2)
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "0000000000000000"
+# ^ T0 ^ T1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC26_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 6
+ Size: 2
diff --git a/test/old-elf/Mips/rel-pc26-s2-micro.test b/test/old-elf/Mips/rel-pc26-s2-micro.test
new file mode 100644
index 0000000000000..193c328be6876
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc26-s2-micro.test
@@ -0,0 +1,56 @@
+# Check handling of R_MICROMIPS_PC26_S2 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 00000100 00000000 00000000
+# ^ V
+# A = -1 << 2 = -4 =>
+# V = (T1 - 4 - T0) >> 2 =>
+# V => 4 >> 2 = 1 (shuffled)
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000008 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "ff03ffff0000000000000000"
+# ^ T1
+# ^ T0 A := 0x3ffffff == -1 (shuffled)
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MICROMIPS_PC26_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
diff --git a/test/old-elf/Mips/rel-pc26-s2.test b/test/old-elf/Mips/rel-pc26-s2.test
new file mode 100644
index 0000000000000..c500f00cb860a
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc26-s2.test
@@ -0,0 +1,54 @@
+# Check handling of R_MIPS_PC26_S2 relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 01000000 00000000 00000000
+# ^ V
+# A = -1 << 2 = -4 =>
+# V = (T1 - 4 - T0) >> 2 =>
+# V => 4 >> 2 = 1
+
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g F .text 00000008 T0
+# CHECK: {{[0-9A-F]+}} g F .text 00000004 T1
+
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "ffffff030000000000000000"
+# ^ T1
+# ^ T0 A := 0x3ffffff == -1
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_PC26_S2
+
+Symbols:
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 8
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc32.test b/test/old-elf/Mips/rel-pc32.test
new file mode 100644
index 0000000000000..9faa32efec7bd
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc32.test
@@ -0,0 +1,59 @@
+# Check handling of R_MIPS_PC32 relocation.
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel -o %t-exe %t-obj
+# RUN: llvm-objdump -s -t %t-exe | FileCheck %s
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: {{[0-9A-F]+}} 00000000 05000080 fdffff7f
+# ^^ data2 + 0x80000001 - data1
+# ^^ data1 + 0x80000001 - data2
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9A-F]+}} g .data 00000004 data1
+# CHECK: {{[0-9A-F]+}} g .data 00000004 data2
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Content: "00000000"
+ AddressAlign: 16
+ Flags: [SHF_ALLOC]
+- Name: .data
+ Type: SHT_PROGBITS
+ Content: "000000000100008001000080"
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rel.data
+ Type: SHT_REL
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x4
+ Symbol: data2
+ Type: R_MIPS_PC32
+ - Offset: 0x8
+ Symbol: data1
+ Type: R_MIPS_PC32
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Value: 0x0
+ Size: 4
+ - Name: data1
+ Section: .data
+ Value: 0x4
+ Size: 4
+ - Name: data2
+ Section: .data
+ Value: 0x8
+ Size: 4
diff --git a/test/old-elf/Mips/rel-pc7-10-16-23.test b/test/old-elf/Mips/rel-pc7-10-16-23.test
new file mode 100644
index 0000000000000..51c4c3a670f13
--- /dev/null
+++ b/test/old-elf/Mips/rel-pc7-10-16-23.test
@@ -0,0 +1,86 @@
+# Check handling of R_MICROMIPS_PC7_S1, R_MICROMIPS_PC10_S1,
+# R_MICROMIPS_PC16_S1, and R_MICROMIPS_PC23_S2 relocations.
+
+# RUN: yaml2obj -format=elf %s > %t-obj
+# RUN: lld -flavor old-gnu -target mipsel -o %t-exe %t-obj
+# RUN: llvm-objdump -s -t %t-exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: {{[0-9A-F]+}} 00000000 80780500 a240fcff 000c03cc
+# ^^ addiu s1,$pc,20
+# ^^ bnezc v0,400114 <__start+0x4>
+# ^^ b 400126 <L1>
+# CHECK-NEXT: {{[0-9A-F]+}} 000c03ad 00000000 00000000 00000000
+# ^^ bnez v0,40012a <L2>
+# CHECK: SYMBOL TABLE:
+# CHECK: {{[0-9a-f]+}} l F .text 00000002 L0
+# CHECK: {{[0-9a-f]+}} l F .text 00000004 L1
+# CHECK: {{[0-9a-f]+}} l F .text 00000004 L2
+# CHECK: {{[0-9a-f]+}} l F .text 00000002 L3
+# CHECK: {{[0-9a-f]+}} g F .text 00000014 __start
+
+!ELF
+FileHeader: !FileHeader
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2,
+ EF_MIPS_MICROMIPS ]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+# v nop v nop v L0
+ Content: "0000000080780100a240f5ff000cfdcf000c7dad000000000000000000000000"
+# ^ PC23 ^ PC16 ^ PC10 ^ PC7 ^ L1 ^ L2 ^ L3
+# 7d << 1 = -6 => L3 + 2 - 6 = L2
+# 3fd << 1 = -6 => L2 + 2 - 6 = L1
+# fff5 << 1 = -22 => L1 + 2 - 22 = __start
+# 1 << 2 = 4 => L0 + 4 - 4 = L0
+ AddressAlign: 16
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 4
+ Symbol: L0
+ Type: R_MICROMIPS_PC23_S2
+ - Offset: 8
+ Symbol: L1
+ Type: R_MICROMIPS_PC16_S1
+ - Offset: 14
+ Symbol: L2
+ Type: R_MICROMIPS_PC10_S1
+ - Offset: 18
+ Symbol: L3
+ Type: R_MICROMIPS_PC7_S1
+
+Symbols:
+ Local:
+ - Name: L0
+ Section: .text
+ Value: 20
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: L1
+ Section: .text
+ Value: 22
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: L2
+ Section: .text
+ Value: 26
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: L3
+ Section: .text
+ Value: 30
+ Other: [ STO_MIPS_MICROMIPS ]
+ Global:
+ - Name: __start
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 32
+ Other: [ STO_MIPS_MICROMIPS ]
diff --git a/test/old-elf/Mips/rel-sub-micro.test b/test/old-elf/Mips/rel-sub-micro.test
new file mode 100644
index 0000000000000..831a020ce2f90
--- /dev/null
+++ b/test/old-elf/Mips/rel-sub-micro.test
@@ -0,0 +1,62 @@
+# Check handling of R_MICROMIPS_SUB relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: 120002000 0020cc01 01000000 0020d001 0100ffff
+# ^^ __start - 4 = 0x1200001cc
+# ^^ __start - 0x1000000000000
+# = 0xffff0001200001d0
+# CHECK: SYMBOL TABLE:
+# CHECK: 00000001200001d0 g .rodata 00000008 __start
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_ALLOC]
+
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 16
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rela.data
+ Type: SHT_RELA
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: __start
+ Type: R_MICROMIPS_SUB
+ Addend: 4
+ - Offset: 8
+ Symbol: __start
+ Type: R_MICROMIPS_SUB
+ Addend: 0x1000000000000
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Value: 0
+ Size: 8
+ - Name: D1
+ Section: .data
+ Value: 0
+ Size: 8
+ - Name: D2
+ Section: .data
+ Value: 8
+ Size: 8
diff --git a/test/old-elf/Mips/rel-sub.test b/test/old-elf/Mips/rel-sub.test
new file mode 100644
index 0000000000000..5100406fd5d54
--- /dev/null
+++ b/test/old-elf/Mips/rel-sub.test
@@ -0,0 +1,61 @@
+# Check handling of R_MIPS_SUB relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .data:
+# CHECK-NEXT: 120002000 cf010020 01000000 d0010020 0100ffff ... ....... ....
+# ^^ __start - 1 = 0x1200001cf
+# ^^ __start - 0x1000000000000
+# = 0Xffff0001200001d0
+# CHECK: SYMBOL TABLE:
+# CHECK: 00000001200001d0 g .rodata 00000008 __start
+
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 0x08
+ AddressAlign: 16
+ Flags: [SHF_ALLOC]
+- Name: .data
+ Type: SHT_PROGBITS
+ Size: 0x10
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_WRITE]
+
+- Name: .rela.data
+ Type: SHT_RELA
+ Info: .data
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0x0
+ Symbol: __start
+ Type: R_MIPS_SUB
+ Addend: 1
+ - Offset: 0x8
+ Symbol: __start
+ Type: R_MIPS_SUB
+ Addend: 0x1000000000000
+
+Symbols:
+ Global:
+ - Name: __start
+ Section: .text
+ Value: 0x0
+ Size: 8
+ - Name: data1
+ Section: .data
+ Value: 0x0
+ Size: 8
+ - Name: data2
+ Section: .data
+ Value: 0x8
+ Size: 8
diff --git a/test/old-elf/Mips/rld_map.test b/test/old-elf/Mips/rld_map.test
new file mode 100644
index 0000000000000..ee063be1d7fc4
--- /dev/null
+++ b/test/old-elf/Mips/rld_map.test
@@ -0,0 +1,42 @@
+# REQUIRES: mips
+
+# Check definition of DT_MIPS_RLD_MAP and DT_MIPS_RLD_MAP_REL dynamic tags,
+# .rld_map section, and __RLD_MAP symbol.
+
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o
+# RUN: lld -flavor old-gnu -target mips %t.o -o %t.exe
+# RUN: llvm-readobj -dynamic-table -s -st %t.exe \
+# RUN: | FileCheck -check-prefix=EXE-DYN %s
+
+# EXE-DYN: Name: .rld_map
+# EXE-DYN-NEXT: Type: SHT_PROGBITS
+# EXE-DYN-NEXT: Flags [
+# EXE-DYN-NEXT: SHF_ALLOC
+# EXE-DYN-NEXT: SHF_WRITE
+# EXE-DYN-NEXT: ]
+# EXE-DYN-NEXT: Address: 0x[[ADDR:[0-9A-F]+]]
+# EXE-DYN: Size: 4
+# EXE-DYN: AddressAlignment: 4
+# EXE-DYN: Symbols [
+# EXE-DYN-NEXT: Symbol {
+# EXE-DYN-NEXT: Name: __RLD_MAP
+# EXE-DYN-NEXT: Value: 0x[[ADDR]]
+# EXE-DYN-NEXT: Size: 4
+# EXE-DYN-NEXT: Binding: Global
+# EXE-DYN-NEXT: Type: Object
+#
+# EXE-DYN: 0x70000016 MIPS_RLD_MAP 0x[[ADDR]]
+# EXE-DYN: 0x70000035 MIPS_RLD_MAP_REL 0x1E48
+
+# RUN: lld -flavor old-gnu -target mips -static %t.o -o %t.exe
+# RUN: llvm-nm -just-symbol-name %t.exe | FileCheck -check-prefix=EXE-STATIC %s
+
+# EXE-STATIC-NOT: __RLD_MAP
+
+# RUN: lld -flavor old-gnu -target mips -shared %t.o -o %t.so
+# RUN: llvm-nm -just-symbol-name %t.so | FileCheck -check-prefix=DYNLIB %s
+
+# DYNLIB-NOT: __RLD_MAP
+
+ .globl __start;
+__start:
diff --git a/test/old-elf/Mips/sign-rela.test b/test/old-elf/Mips/sign-rela.test
new file mode 100644
index 0000000000000..3e5341f2c230e
--- /dev/null
+++ b/test/old-elf/Mips/sign-rela.test
@@ -0,0 +1,54 @@
+# Check that relocation addend read from RELA record is not sign-extended.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor old-gnu -target mips64el -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: {{[0-9a-f]+}} 01000000 00000000 ........
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 0x20008
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0x20000
+ Symbol: __start
+ Type: R_MIPS_PC16
+ Addend: 0x20000
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 16
+ Size: 0
+
+Symbols:
+ Local:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ Global:
+ - Name: __start
+ Type: STT_FUNC
+ Section: .text
+ Value: 4
+ Size: 0x20004
+...
diff --git a/test/old-elf/Mips/st-other.test b/test/old-elf/Mips/st-other.test
new file mode 100644
index 0000000000000..2bb1f8b96e075
--- /dev/null
+++ b/test/old-elf/Mips/st-other.test
@@ -0,0 +1,90 @@
+# Check STO_MICROMIPS flag handling. microMIPS symbol records in a dynamic
+# symbol table should not have STO_MICROMIPS flag but their value field
+# must be odd. microMIPS symbol records in a regular symbol table should
+# have the STO_MICROMIPS flag.
+
+# RUN: yaml2obj -format=elf %s > %t-micro.o
+
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-micro.o
+# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck -check-prefix=SO %s
+
+# RUN: lld -flavor old-gnu -target mipsel -e S0 -o %t.exe %t-micro.o
+# RUN: llvm-readobj -symbols %t.exe | FileCheck -check-prefix=EXE-SYM %s
+# RUN: llvm-readobj -dyn-symbols %t.exe | FileCheck -check-prefix=EXE-DSYM %s
+
+# SO: Symbol {
+# SO: Name: S0@ (1)
+# SO-NEXT: Value: 0x{{[0-9A-F]+}}
+# SO-NEXT: Size: 4
+# SO-NEXT: Binding: Global (0x1)
+# SO-NEXT: Type: Function (0x2)
+# SO-NEXT: Other: 0
+# SO-NEXT: Section: .text (0x4)
+# SO-NEXT: }
+
+# SO: Symbol {
+# SO: Name: S1@ (4)
+# SO-NEXT: Value: 0x{{[0-9A-F]+}}
+# SO-NEXT: Size: 4
+# SO-NEXT: Binding: Global (0x1)
+# SO-NEXT: Type: Function (0x2)
+# SO-NEXT: Other: 0
+# SO-NEXT: Section: .text (0x4)
+# SO-NEXT: }
+
+# EXE-SYM: Symbol {
+# EXE-SYM: Name: S0 (1)
+# EXE-SYM-NEXT: Value: 0x{{[0-9A-F]+}}
+# EXE-SYM-NEXT: Size: 4
+# EXE-SYM-NEXT: Binding: Global (0x1)
+# EXE-SYM-NEXT: Type: Function (0x2)
+# EXE-SYM-NEXT: Other: 0
+# EXE-SYM-NEXT: Section: .text (0x5)
+# EXE-SYM-NEXT: }
+
+# EXE-SYM: Symbol {
+# EXE-SYM: Name: S1 (4)
+# EXE-SYM-NEXT: Value: 0x{{[0-9A-F]+}}
+# EXE-SYM-NEXT: Size: 4
+# EXE-SYM-NEXT: Binding: Global (0x1)
+# EXE-SYM-NEXT: Type: Function (0x2)
+# EXE-SYM-NEXT: Other: 128
+# EXE-SYM-NEXT: Section: .text (0x5)
+# EXE-SYM-NEXT: }
+
+# EXE-DSYM-NOT: Name: S1 (4)
+
+# micro.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+
+Symbols:
+ Global:
+ - Name: S0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ Value: 0x00
+ Visibility: STV_DEFAULT
+ Other: [ ]
+
+ - Name: S1
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ Value: 0x04
+ Visibility: STV_DEFAULT
+ Other: [ STO_MIPS_MICROMIPS ]
+...
diff --git a/test/old-elf/Mips/static-01.test b/test/old-elf/Mips/static-01.test
new file mode 100644
index 0000000000000..77a33469df3fa
--- /dev/null
+++ b/test/old-elf/Mips/static-01.test
@@ -0,0 +1,119 @@
+# Check handling relocations against _gp/__gnu_local_gp symbols
+# in case of "-static" linking.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.o
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -static -o %t.exe %t1.o %t2.o
+# RUN: llvm-nm %t.exe | FileCheck %s
+
+# CHECK: 00401000 N _GLOBAL_OFFSET_TABLE_
+# CHECK: 00408ff0 A __gnu_local_gp
+# CHECK: 00408ff0 A _gp
+# CHECK: 00408ff0 A _gp_disp
+
+# o1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 28
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: .data
+ Type: R_MIPS_HI16
+ - Offset: 4
+ Symbol: .data
+ Type: R_MIPS_LO16
+ - Offset: 8
+ Symbol: T1
+ Type: R_MIPS_26
+ - Offset: 12
+ Symbol: _gp
+ Type: R_MIPS_HI16
+ - Offset: 16
+ Symbol: _gp
+ Type: R_MIPS_LO16
+ - Offset: 20
+ Symbol: __gnu_local_gp
+ Type: R_MIPS_HI16
+ - Offset: 24
+ Symbol: __gnu_local_gp
+ Type: R_MIPS_LO16
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC ]
+ AddressAlign: 16
+ Size: 4
+
+ - Name: .pdr
+ Type: SHT_PROGBITS
+ AddressAlign: 4
+ Size: 4
+
+ - Name: .rel.pdr
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .pdr
+ Relocations:
+ - Offset: 0
+ Symbol: T0
+ Type: R_MIPS_32
+
+Symbols:
+ Local:
+ - Type: STT_SECTION
+ Section: .text
+ - Type: STT_SECTION
+ Section: .data
+ - Type: STT_SECTION
+ Section: .pdr
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 28
+ - Name: T1
+ - Name: _gp
+ - Name: __gnu_local_gp
+
+# o2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 20
+...
diff --git a/test/old-elf/Mips/tls-1-micro.test b/test/old-elf/Mips/tls-1-micro.test
new file mode 100644
index 0000000000000..f47592a5ab7d7
--- /dev/null
+++ b/test/old-elf/Mips/tls-1-micro.test
@@ -0,0 +1,65 @@
+# Check handling of R_MICROMIPS_TLS_TPREL_HI16 / R_MICROMIPS_TLS_TPREL_LO16
+# relocations.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e L0 -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK: {{[0-9A-F]+}} 00000000 00000100 00000380 00000480
+
+!ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Content: '00000100000002000000030000000400'
+ - Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: L1
+ Type: R_MICROMIPS_TLS_TPREL_HI16
+ - Offset: 0x04
+ Symbol: L2
+ Type: R_MICROMIPS_TLS_TPREL_HI16
+ - Offset: 0x08
+ Symbol: L2
+ Type: R_MICROMIPS_TLS_TPREL_LO16
+ - Offset: 0x0C
+ Symbol: L1
+ Type: R_MICROMIPS_TLS_TPREL_LO16
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Address: 0x1000
+ Size: 0x20000
+
+Symbols:
+ Global:
+ - Name: L0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x58
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: L1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0x00
+ Size: 0x04
+ - Name: L2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0x10000
+ Size: 0x04
diff --git a/test/old-elf/Mips/tls-1.test b/test/old-elf/Mips/tls-1.test
new file mode 100644
index 0000000000000..c25a06c1dee9b
--- /dev/null
+++ b/test/old-elf/Mips/tls-1.test
@@ -0,0 +1,63 @@
+# Check handling of R_MIPS_TLS_TPREL_HI16 / R_MIPS_TLS_TPREL_LO16 relocations.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e L0 -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK: {{[0-9A-F]+}} 00000000 01000000 03800000 04800000
+
+!ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Content: '01000000020000000300000004000000'
+ - Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: L1
+ Type: R_MIPS_TLS_TPREL_HI16
+ - Offset: 0x04
+ Symbol: L2
+ Type: R_MIPS_TLS_TPREL_HI16
+ - Offset: 0x08
+ Symbol: L2
+ Type: R_MIPS_TLS_TPREL_LO16
+ - Offset: 0x0C
+ Symbol: L1
+ Type: R_MIPS_TLS_TPREL_LO16
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Address: 0x1000
+ Size: 0x20000
+
+Symbols:
+ Global:
+ - Name: L0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x58
+ - Name: L1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0x00
+ Size: 0x04
+ - Name: L2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0x10000
+ Size: 0x04
diff --git a/test/old-elf/Mips/tls-2-64-static.test b/test/old-elf/Mips/tls-2-64-static.test
new file mode 100644
index 0000000000000..c8c30ea06c603
--- /dev/null
+++ b/test/old-elf/Mips/tls-2-64-static.test
@@ -0,0 +1,71 @@
+# Check handling of R_MIPS_TLS_GD relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 120000120 20800000 30800000
+# ^ -32736 ^ -32720
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 120001000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 120002000 00000000 00000000 00000000 00000080
+# CHECK-NEXT: 120002010 01000000 00000000 0480ffff ffffffff
+# CHECK-NEXT: 120002020 01000000 00000000 0c80ffff ffffffff
+# D1 0x120001000 + 4 - (0x120001000 + 0x8000) = 0xffff8004 => 0480ffff
+# D2 0x120001040 + 8 - (0x120001000 + 0x8000) = 0xffff800c => 0c80ffff
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GD
+ Addend: 4
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_TLS_GD
+ Addend: 8
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+...
diff --git a/test/old-elf/Mips/tls-2-64.test b/test/old-elf/Mips/tls-2-64.test
new file mode 100644
index 0000000000000..3a6f6b3bedea9
--- /dev/null
+++ b/test/old-elf/Mips/tls-2-64.test
@@ -0,0 +1,69 @@
+# Check handling of R_MIPS_TLS_GOTTPREL and R_MIPS_TLS_GD relocations
+# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL64,
+# R_MIPS_TLS_DTPMOD64 and R_MIPS_TLS_DTPREL64 in case of shared library.
+
+# Create a shared library with thread symbol D1.
+# RUN: yaml2obj -format=elf -o %t-so.o %s
+# RUN: lld -flavor old-gnu -target mips64el -shared -o %t.so %t-so.o
+
+# Check dynamic relocations and GOT in the shared library.
+# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s
+# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s
+# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s
+
+# REL: Section (4) .rel.dyn {
+# REL-NEXT: 0x2010 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE D1 0x0
+# REL-NEXT: 0x2018 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE D1 0x0
+# REL-NEXT: }
+
+# DYN: 0x000000007000000A MIPS_LOCAL_GOTNO 2
+# DYN: 0x0000000070000013 MIPS_GOTSYM 0x3
+
+# SYM: Name: T1@ (1)
+# SYM: Name: D1@ (4)
+
+# GOT: Contents of section .got:
+# GOT-NEXT: 2000 00000000 00000000 00000000 00000080 ................
+# GOT-NEXT: 2010 00000000 00000000 00000000 00000000 ................
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 4
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GD
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 4
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Size: 8
+...
diff --git a/test/old-elf/Mips/tls-2-micro.test b/test/old-elf/Mips/tls-2-micro.test
new file mode 100644
index 0000000000000..88d8797cd06a8
--- /dev/null
+++ b/test/old-elf/Mips/tls-2-micro.test
@@ -0,0 +1,70 @@
+# Check handling of R_MICROMIPS_TLS_GOTTPREL and R_MICROMIPS_TLS_GD relocations
+# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL32,
+# R_MIPS_TLS_DTPMOD32 and R_MIPS_TLS_DTPREL32 in case of shared library.
+
+# Create a shared library with thread symbol D1.
+# RUN: yaml2obj -format=elf -o %t-so.o %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Check dynamic relocations and GOT in the shared library.
+# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s
+# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s
+# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s
+
+# REL: Section (4) .rel.dyn {
+# REL-NEXT: 0x2008 R_MIPS_TLS_DTPMOD32 D1 0x0
+# REL-NEXT: 0x200C R_MIPS_TLS_DTPREL32 D1 0x0
+# REL-NEXT: }
+
+# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2
+# DYN: 0x70000013 MIPS_GOTSYM 0x3
+
+# SYM: Name: T1@ (1)
+# SYM: Name: D1@ (4)
+
+# GOT: Contents of section .got:
+# GOT-NEXT: 2000 00000000 00000080 00000000 00000000 ................
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MICROMIPS_TLS_GD
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/tls-2-static.test b/test/old-elf/Mips/tls-2-static.test
new file mode 100644
index 0000000000000..3ac2122628d6a
--- /dev/null
+++ b/test/old-elf/Mips/tls-2-static.test
@@ -0,0 +1,125 @@
+# Check handling of R_MIPS_TLS_GD relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -docnum 1 -o %t1.o %s
+# RUN: yaml2obj -format=elf -docnum 2 -o %t2.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -static -o %t.exe %t1.o %t2.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 4000b4 18800000 20800000 28800000 30800000
+# ^ -32744 ^ -32736 ^ -32728 ^ -32720
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 401000 00000000 00000000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 402000 00000000 00000080 01000000 0480ffff
+# CHECK-NEXT: 402010 01000000 0c80ffff 01000000 0c80ffff
+# CHECK-NEXT: 402020 01000000 1480ffff
+# D1 0x401000 + 4 - (0x401000 + 0x8000) = 0xffff8004 => 0480ffff
+# D2 0x401004 + 8 - (0x401000 + 0x8000) = 0xffff800c => 0c80ffff
+# D3 0x401008 + 4 - (0x401000 + 0x8000) = 0xffff800c => 0c80ffff
+# D4 0x40100c + 8 - (0x401000 + 0x8000) = 0xffff8014 => 1480ffff
+
+# t1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: "0400000008000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GD
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_TLS_GD
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+
+# t2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: "0400000008000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D3
+ Type: R_MIPS_TLS_GD
+ - Offset: 4
+ Symbol: D4
+ Type: R_MIPS_TLS_GD
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+ - Name: D3
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D4
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+...
diff --git a/test/old-elf/Mips/tls-2.test b/test/old-elf/Mips/tls-2.test
new file mode 100644
index 0000000000000..de8fc2a70861e
--- /dev/null
+++ b/test/old-elf/Mips/tls-2.test
@@ -0,0 +1,69 @@
+# Check handling of R_MIPS_TLS_GOTTPREL and R_MIPS_TLS_GD relocations
+# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL32,
+# R_MIPS_TLS_DTPMOD32 and R_MIPS_TLS_DTPREL32 in case of shared library.
+
+# Create a shared library with thread symbol D1.
+# RUN: yaml2obj -format=elf -o %t-so.o %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Check dynamic relocations and GOT in the shared library.
+# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s
+# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s
+# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s
+
+# REL: Section (4) .rel.dyn {
+# REL-NEXT: 0x2008 R_MIPS_TLS_DTPMOD32 D1 0x0
+# REL-NEXT: 0x200C R_MIPS_TLS_DTPREL32 D1 0x0
+# REL-NEXT: }
+
+# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2
+# DYN: 0x70000013 MIPS_GOTSYM 0x3
+
+# SYM: Name: T1@ (1)
+# SYM: Name: D1@ (4)
+
+# GOT: Contents of section .got:
+# GOT-NEXT: 2000 00000000 00000080 00000000 00000000 ................
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MIPS_TLS_GD
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/tls-3-64-static.test b/test/old-elf/Mips/tls-3-64-static.test
new file mode 100644
index 0000000000000..2183d1fd6833a
--- /dev/null
+++ b/test/old-elf/Mips/tls-3-64-static.test
@@ -0,0 +1,70 @@
+# Check handling of R_MIPS_TLS_GOTTPREL relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 120000120 20800000 28800000
+# ^ -32736 ^ -32728
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 120001000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 120002000 00000000 00000000 00000000 00000080
+# CHECK-NEXT: 120002010 0490ffff ffffffff 0c90ffff ffffffff
+# D1 0x120001000 + 4 - (0x120001000 + 0x7000) = 0xffff9004 => 0490ffff
+# D2 0x120001004 + 8 - (0x120001000 + 0x7000) = 0xffff900c => 0c90ffff
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_PIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GOTTPREL
+ Addend: 4
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_TLS_GOTTPREL
+ Addend: 8
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+...
diff --git a/test/old-elf/Mips/tls-3-micro.test b/test/old-elf/Mips/tls-3-micro.test
new file mode 100644
index 0000000000000..347332e6633ee
--- /dev/null
+++ b/test/old-elf/Mips/tls-3-micro.test
@@ -0,0 +1,183 @@
+# Check handling of R_MICROMIPS_TLS_GOTTPREL and R_MICROMIPS_TLS_GD relocations
+# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL32,
+# R_MIPS_TLS_DTPMOD32 and R_MIPS_TLS_DTPREL32 in case of executable linking.
+
+# Create a shared library with thread symbol D1.
+# RUN: yaml2obj -format=elf -docnum 1 -o %t-so.o %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Create executable file linked using two object files and the shared library.
+# The object files defines thread symbols D0 and D2.
+# RUN: yaml2obj -format=elf -docnum 2 -o %t-o1.o %s
+# RUN: yaml2obj -format=elf -docnum 3 -o %t-o2.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o1.o %t-o2.o %t.so
+
+# Check dynamic relocations and GOT in the executable file.
+# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s
+# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck -check-prefix=DYN %s
+# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=GOT %s
+
+# REL: Section (5) .rel.dyn {
+# REL-NEXT: 0x402008 R_MIPS_TLS_TPREL32 D1 0x0
+# REL-NEXT: 0x40200C R_MIPS_TLS_TPREL32 D2 0x0
+# REL-NEXT: }
+
+# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2
+# DYN: 0x70000013 MIPS_GOTSYM 0x3
+
+# SYM: Name: D2@ (1)
+# SYM: Name: D1@ (4)
+
+# GOT: Contents of section .got:
+# GOT-NEXT: 402000 00000000 00000080 00000000 00000000 ................
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MICROMIPS_TLS_GD
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+
+# o1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: D2
+ Type: R_MICROMIPS_TLS_TPREL_HI16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MICROMIPS_TLS_TPREL_LO16
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+
+# o2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x10
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MICROMIPS_TLS_GOTTPREL
+ Addend: 0
+ - Offset: 0x04
+ Symbol: D0
+ Type: R_MICROMIPS_TLS_TPREL_HI16
+ Addend: 0
+ - Offset: 0x08
+ Symbol: D0
+ Type: R_MICROMIPS_TLS_TPREL_LO16
+ Addend: 0
+ - Offset: 0x0C
+ Symbol: D2
+ Type: R_MICROMIPS_TLS_GOTTPREL
+ Addend: 0
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: D0
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x10
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: D1
+ Type: STT_TLS
+ - Name: D2
+ Type: STT_TLS
+...
diff --git a/test/old-elf/Mips/tls-3-static.test b/test/old-elf/Mips/tls-3-static.test
new file mode 100644
index 0000000000000..5d3a7b8bfd6a3
--- /dev/null
+++ b/test/old-elf/Mips/tls-3-static.test
@@ -0,0 +1,67 @@
+# Check handling of R_MIPS_TLS_GOTTPREL relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 4000b4 18800000 1c800000
+# ^ -32744 ^ -32740
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 401000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 402000 00000000 00000080 0490ffff 0c90ffff
+# D1 0x401000 + 4 - (0x401000 + 0x7000) = 0xffff9004 => 0490ffff
+# D2 0x401004 + 8 - (0x401000 + 0x7000) = 0xffff900c => 0c90ffff
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: "0400000008000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: D1
+ Type: R_MIPS_TLS_GOTTPREL
+ - Offset: 4
+ Symbol: D2
+ Type: R_MIPS_TLS_GOTTPREL
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+...
diff --git a/test/old-elf/Mips/tls-3.test b/test/old-elf/Mips/tls-3.test
new file mode 100644
index 0000000000000..eb9750fee28de
--- /dev/null
+++ b/test/old-elf/Mips/tls-3.test
@@ -0,0 +1,180 @@
+# Check handling of R_MIPS_TLS_GOTTPREL and R_MIPS_TLS_GD relocations
+# and generation of corresponding dynamic relocations R_MIPS_TLS_TPREL32,
+# R_MIPS_TLS_DTPMOD32 and R_MIPS_TLS_DTPREL32 in case of executable linking.
+
+# Create a shared library with thread symbol D1.
+# RUN: yaml2obj -format=elf -docnum 1 -o %t-so.o %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o
+
+# Create executable file linked using two object files and the shared library.
+# The object files defines thread symbols D0 and D2.
+# RUN: yaml2obj -format=elf -docnum 2 -o %t-o1.o %s
+# RUN: yaml2obj -format=elf -docnum 3 -o %t-o2.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o1.o %t-o2.o %t.so
+
+# Check dynamic relocations and GOT in the executable file.
+# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s
+# RUN: llvm-readobj -dynamic-table %t.exe | FileCheck -check-prefix=DYN %s
+# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=GOT %s
+
+# REL: Section (5) .rel.dyn {
+# REL-NEXT: 0x402008 R_MIPS_TLS_TPREL32 D1 0x0
+# REL-NEXT: 0x40200C R_MIPS_TLS_TPREL32 D2 0x0
+# REL-NEXT: }
+
+# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2
+# DYN: 0x70000013 MIPS_GOTSYM 0x3
+
+# SYM: Name: D2@ (1)
+# SYM: Name: D1@ (4)
+
+# GOT: Contents of section .got:
+# GOT-NEXT: 402000 00000000 00000080 00000000 00000000 ................
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MIPS_TLS_GD
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ - Name: D1
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+
+# o1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: D2
+ Type: R_MIPS_TLS_TPREL_HI16
+ - Offset: 0x04
+ Symbol: D2
+ Type: R_MIPS_TLS_TPREL_LO16
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x08
+ - Name: D2
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+
+# o2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x10
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x00
+ Symbol: D1
+ Type: R_MIPS_TLS_GOTTPREL
+ Addend: 0
+ - Offset: 0x04
+ Symbol: D0
+ Type: R_MIPS_TLS_TPREL_HI16
+ Addend: 0
+ - Offset: 0x08
+ Symbol: D0
+ Type: R_MIPS_TLS_TPREL_LO16
+ Addend: 0
+ - Offset: 0x0C
+ Symbol: D2
+ Type: R_MIPS_TLS_GOTTPREL
+ Addend: 0
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: D0
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x10
+ - Name: D1
+ Type: STT_TLS
+ - Name: D2
+ Type: STT_TLS
+...
diff --git a/test/old-elf/Mips/tls-4-64-static.test b/test/old-elf/Mips/tls-4-64-static.test
new file mode 100644
index 0000000000000..3aa37046d36b1
--- /dev/null
+++ b/test/old-elf/Mips/tls-4-64-static.test
@@ -0,0 +1,71 @@
+# Check handling of R_MIPS_TLS_LDM relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 120000120 20800000 20800000
+# ^ -32736 ^ -32736
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 120001000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 120002000 00000000 00000000 00000000 00000080
+# CHECK-NEXT: 120002010 01000000 00000000 00000000 00000000
+# ^ R_MIPS_TLS_DTPMOD64
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Size: 8
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: L1
+ Type: R_MIPS_TLS_LDM
+ Addend: 4
+ - Offset: 4
+ Symbol: L2
+ Type: R_MIPS_TLS_LDM
+ Addend: 8
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Local:
+ - Name: L1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: L2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+...
diff --git a/test/old-elf/Mips/tls-4-micro.test b/test/old-elf/Mips/tls-4-micro.test
new file mode 100644
index 0000000000000..23d8e0a1de313
--- /dev/null
+++ b/test/old-elf/Mips/tls-4-micro.test
@@ -0,0 +1,126 @@
+# Check handling of R_MICROMIPS_TLS_LDM relocation and generation
+# of corresponding dynamic relocation R_MICROMIPS_TLS_DTPMOD32.
+
+# RUN: yaml2obj -format=elf -docnum 1 -o %t-so1.o %s
+# RUN: yaml2obj -format=elf -docnum 2 -o %t-so2.o %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so1.o %t-so2.o
+
+# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s
+# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s
+# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s
+
+# REL: Section (4) .rel.dyn {
+# REL-NEXT: 0x2008 R_MIPS_TLS_DTPMOD32 - 0x0
+# REL-NEXT: }
+
+# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2
+# DYN: 0x70000013 MIPS_GOTSYM 0x4
+
+# SYM: Name: @ (0)
+# SYM: Name: T1@ (1)
+# SYM: Name: T2@ (4)
+# SYM: Name: T3@ (7)
+
+# GOT: Contents of section .got:
+# GOT-NEXT: 2000 00000000 00000080 00000000 00000000 ................
+# Two LDM entries --^--------^
+
+# so1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: L01
+ Type: R_MICROMIPS_TLS_LDM
+ - Offset: 0x04
+ Symbol: L01
+ Type: R_MICROMIPS_TLS_LDM
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Local:
+ - Name: L01
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x00
+ Size: 0x04
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x04
+ Size: 0x04
+ Other: [ STO_MIPS_MICROMIPS ]
+
+# so2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: L02
+ Type: R_MICROMIPS_TLS_LDM
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Local:
+ - Name: L02
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+ Global:
+ - Name: T3
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ Other: [ STO_MIPS_MICROMIPS ]
+...
diff --git a/test/old-elf/Mips/tls-4-static.test b/test/old-elf/Mips/tls-4-static.test
new file mode 100644
index 0000000000000..5fdb11df874b6
--- /dev/null
+++ b/test/old-elf/Mips/tls-4-static.test
@@ -0,0 +1,68 @@
+# Check handling of R_MIPS_TLS_LDM relocation in case of -static linking.
+
+# RUN: yaml2obj -format=elf -o %t.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -static -o %t.exe %t.o
+# RUN: llvm-objdump -s %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 4000b4 18800000 18800000
+# ^ -32744 ^ -32744
+# CHECK-NEXT: Contents of section .tdata:
+# CHECK-NEXT: 401000 00000000 00000000
+# CHECK-NEXT: Contents of section .got:
+# CHECK-NEXT: 402000 00000000 00000080 01000000 00000000
+# ^ R_MIPS_TLS_DTPMOD32
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 4
+ Content: "0400000008000000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: L1
+ Type: R_MIPS_TLS_LDM
+ - Offset: 4
+ Symbol: L2
+ Type: R_MIPS_TLS_LDM
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Local:
+ - Name: L1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 4
+ - Name: L2
+ Type: STT_TLS
+ Section: .tdata
+ Value: 4
+ Size: 4
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+...
diff --git a/test/old-elf/Mips/tls-4.test b/test/old-elf/Mips/tls-4.test
new file mode 100644
index 0000000000000..95df6d67151f1
--- /dev/null
+++ b/test/old-elf/Mips/tls-4.test
@@ -0,0 +1,123 @@
+# Check handling of R_MIPS_TLS_LDM relocation and generation of corresponding
+# dynamic relocation R_MIPS_TLS_DTPMOD32.
+
+# RUN: yaml2obj -format=elf -docnum 1 -o %t-so1.o %s
+# RUN: yaml2obj -format=elf -docnum 2 -o %t-so2.o %s
+# RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so1.o %t-so2.o
+
+# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=REL %s
+# RUN: llvm-readobj -dynamic-table %t.so | FileCheck -check-prefix=DYN %s
+# RUN: llvm-readobj -dt %t.so | FileCheck -check-prefix=SYM %s
+# RUN: llvm-objdump -s %t.so | FileCheck -check-prefix=GOT %s
+
+# REL: Section (4) .rel.dyn {
+# REL-NEXT: 0x2008 R_MIPS_TLS_DTPMOD32 - 0x0
+# REL-NEXT: }
+
+# DYN: 0x7000000A MIPS_LOCAL_GOTNO 2
+# DYN: 0x70000013 MIPS_GOTSYM 0x4
+
+# SYM: Name: @ (0)
+# SYM: Name: T1@ (1)
+# SYM: Name: T2@ (4)
+# SYM: Name: T3@ (7)
+
+# GOT: Contents of section .got:
+# GOT-NEXT: 2000 00000000 00000080 00000000 00000000 ................
+# Two LDM entries --^--------^
+
+# so1.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x08
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: L01
+ Type: R_MIPS_TLS_LDM
+ - Offset: 0x04
+ Symbol: L01
+ Type: R_MIPS_TLS_LDM
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Local:
+ - Name: L01
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x00
+ Size: 0x04
+ - Name: T2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x04
+ Size: 0x04
+
+# so2.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ OSABI: ELFOSABI_GNU
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x04
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: L02
+ Type: R_MIPS_TLS_LDM
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Local:
+ - Name: L02
+ Type: STT_TLS
+ Section: .tdata
+ Size: 0x04
+ Global:
+ - Name: T3
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/tls-5-64.test b/test/old-elf/Mips/tls-5-64.test
new file mode 100644
index 0000000000000..43e6e6c1cf30e
--- /dev/null
+++ b/test/old-elf/Mips/tls-5-64.test
@@ -0,0 +1,71 @@
+# Check that in case of an executable file linking symbol referred
+# by the R_MIPS_TLS_GD relocation gets an entry in the dynamic symbol table.
+
+# RUN: yaml2obj -format=elf -o %t-o.o %s
+# RUN: lld -flavor old-gnu -target mips64el -e T0 -o %t.exe %t-o.o
+
+# Check dynamic relocations:
+# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s
+# Check dynamic symbol table:
+# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s
+
+# REL: Relocations [
+# REL-NEXT: Section (5) .rel.dyn {
+# REL-NEXT: 0x120002010 R_MIPS_TLS_DTPMOD64/R_MIPS_NONE/R_MIPS_NONE T1 0x0
+# REL-NEXT: 0x120002018 R_MIPS_TLS_DTPREL64/R_MIPS_NONE/R_MIPS_NONE T1 0x0
+# REL-NEXT: }
+# REL-NEXT: ]
+
+# SYM: Symbol {
+# SYM: Name: T1@ (1)
+# SYM-NEXT: Value: 0x0
+# SYM-NEXT: Size: 8
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: TLS (0x6)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .tdata (0x7)
+# SYM-NEXT: }
+
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 8
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_TLS_GD
+
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 4
+ Size: 8
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 8
+ - Name: T1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0
+ Size: 8
+...
diff --git a/test/old-elf/Mips/tls-5-micro.test b/test/old-elf/Mips/tls-5-micro.test
new file mode 100644
index 0000000000000..412456417826d
--- /dev/null
+++ b/test/old-elf/Mips/tls-5-micro.test
@@ -0,0 +1,70 @@
+# Check that in case of an executable file linking symbol referred by
+# the R_MICROMIPS_TLS_GD relocation gets an entry in the dynamic symbol table.
+
+# RUN: yaml2obj -format=elf -o %t-o.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o
+
+# Check dynamic relocations:
+# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s
+# Check dynamic symbol table:
+# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s
+
+# REL: Relocations [
+# REL-NEXT: Section (5) .rel.dyn {
+# REL-NEXT: 0x402008 R_MIPS_TLS_DTPMOD32 T1 0x0
+# REL-NEXT: 0x40200C R_MIPS_TLS_DTPREL32 T1 0x0
+# REL-NEXT: }
+# REL-NEXT: ]
+
+# SYM: Symbol {
+# SYM: Name: T1@ (1)
+# SYM-NEXT: Value: 0x0
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: TLS (0x6)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .tdata (0x7)
+# SYM-NEXT: }
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2, EF_MIPS_MICROMIPS ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MICROMIPS_TLS_GD
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ Other: [ STO_MIPS_MICROMIPS ]
+ - Name: T1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0x00
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/tls-5.test b/test/old-elf/Mips/tls-5.test
new file mode 100644
index 0000000000000..cb71e3ac5f9ec
--- /dev/null
+++ b/test/old-elf/Mips/tls-5.test
@@ -0,0 +1,69 @@
+# Check that in case of an executable file linking symbol referred
+# by the R_MIPS_TLS_GD relocation gets an entry in the dynamic symbol table.
+
+# RUN: yaml2obj -format=elf -o %t-o.o %s
+# RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o
+
+# Check dynamic relocations:
+# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=REL %s
+# Check dynamic symbol table:
+# RUN: llvm-readobj -dt %t.exe | FileCheck -check-prefix=SYM %s
+
+# REL: Relocations [
+# REL-NEXT: Section (5) .rel.dyn {
+# REL-NEXT: 0x402008 R_MIPS_TLS_DTPMOD32 T1 0x0
+# REL-NEXT: 0x40200C R_MIPS_TLS_DTPREL32 T1 0x0
+# REL-NEXT: }
+# REL-NEXT: ]
+
+# SYM: Symbol {
+# SYM: Name: T1@ (1)
+# SYM-NEXT: Value: 0x0
+# SYM-NEXT: Size: 4
+# SYM-NEXT: Binding: Global (0x1)
+# SYM-NEXT: Type: TLS (0x6)
+# SYM-NEXT: Other: 0
+# SYM-NEXT: Section: .tdata (0x7)
+# SYM-NEXT: }
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [ EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2 ]
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x10
+ Size: 0x04
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 0x04
+ Info: .text
+ Relocations:
+ - Offset: 0x00
+ Symbol: T1
+ Type: R_MIPS_TLS_GD
+ - Name: .tdata
+ Type: SHT_PROGBITS
+ Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]
+ AddressAlign: 0x04
+ Size: 0x04
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x04
+ - Name: T1
+ Type: STT_TLS
+ Section: .tdata
+ Value: 0x00
+ Size: 0x04
+...
diff --git a/test/old-elf/Mips/validate-rel-01.test b/test/old-elf/Mips/validate-rel-01.test
new file mode 100644
index 0000000000000..0b8734c5429ec
--- /dev/null
+++ b/test/old-elf/Mips/validate-rel-01.test
@@ -0,0 +1,82 @@
+# Check that the linker does not accept position-dependent relocations
+# in case of shared library linking.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-hi.o
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so %t-hi.o 2>&1 \
+# RUN: | FileCheck -check-prefix=RHI %s
+
+# RHI: R_MIPS_HI16 (5) relocation cannot be used when making a shared object, recompile {{.*}}validate-rel-01.test.tmp-hi.o with -fPIC
+
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-26.o
+# RUN: not lld -flavor old-gnu -target mipsel -shared -o %t.so %t-26.o 2>&1 \
+# RUN: | FileCheck -check-prefix=R26 %s
+
+# R26: R_MIPS_26 (4) relocation cannot be used when making a shared object, recompile {{.*}}validate-rel-01.test.tmp-26.o with -fPIC
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 4
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T0
+ Type: R_MIPS_HI16
+ - Offset: 0
+ Symbol: T0
+ Type: R_MIPS_LO16
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 4
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 4
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MIPS_26
+
+Symbols:
+ Global:
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Size: 4
+...
diff --git a/test/old-elf/Mips/validate-rel-03.test b/test/old-elf/Mips/validate-rel-03.test
new file mode 100644
index 0000000000000..baf8516c63b08
--- /dev/null
+++ b/test/old-elf/Mips/validate-rel-03.test
@@ -0,0 +1,56 @@
+# Check that the linker does not accept R_MIPS_CALL16 relocation
+# against local symbol.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t.o
+# RUN: not lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t.o 2>&1 \
+# RUN: | FileCheck %s
+
+# CHECK: R_MIPS_CALL16 (11) relocation cannot be used against local symbol L0 in file {{.*}}validate-rel-03.test.tmp.o
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Size: 16
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 8
+ Symbol: T0
+ Type: R_MIPS_CALL16
+ - Offset: 4
+ Symbol: L0
+ Type: R_MIPS_CALL16
+
+Symbols:
+ Local:
+ - Name: L0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 4
+ Size: 4
+ - Name: T1
+ Type: STT_FUNC
+ Section: .text
+ Value: 8
+ Size: 8
+...