diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-03-24 21:31:36 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-03-24 21:31:36 +0000 |
commit | fb911942f1434f3d1750f83f25f5e42c80e60638 (patch) | |
tree | 1678c4a4f0182e4029a86d135aa4a1b7d09e3c41 /test/elf/Mips |
Notes
Diffstat (limited to 'test/elf/Mips')
133 files changed, 13643 insertions, 0 deletions
diff --git a/test/elf/Mips/base-address-64.test b/test/elf/Mips/base-address-64.test new file mode 100644 index 0000000000000..07110e7f918f8 --- /dev/null +++ b/test/elf/Mips/base-address-64.test @@ -0,0 +1,78 @@ +# 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 gnu -target mips64el --noinhibit-exec -o %t.exe %t.o +# RUN: llvm-readobj -dynamic-table -program-headers %t.exe | FileCheck %s + +# CHECK: DynamicSection [ (13 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: 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/elf/Mips/base-address.test b/test/elf/Mips/base-address.test new file mode 100644 index 0000000000000..f55091f84c33d --- /dev/null +++ b/test/elf/Mips/base-address.test @@ -0,0 +1,109 @@ +# 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 gnu -target mipsel --noinhibit-exec -o %t.exe %t.o +# RUN: llvm-readobj -dynamic-table -program-headers %t.exe | FileCheck %s + +# 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 1 (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 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 + - Name: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Size: 0x18 + - Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x08 + Content: '000020010101000100000000000000000000000000000000' +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .data + Type: STT_SECTION + Section: .data + - Name: .bss + Type: STT_SECTION + Section: .bss + - Name: .reginfo + Type: STT_SECTION + Section: .reginfo + - Name: .MIPS.abiflags + Type: STT_SECTION + Section: .MIPS.abiflags + Global: + - Name: main + Section: .text diff --git a/test/elf/Mips/ctors-order.test b/test/elf/Mips/ctors-order.test new file mode 100644 index 0000000000000..344dcd5fc516c --- /dev/null +++ b/test/elf/Mips/ctors-order.test @@ -0,0 +1,163 @@ +# 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 gnu -target mipsel -shared --output-filetype=yaml \ +# RUN: %t-crtbeginS.o %t-obj.o %t-crtendS.o | FileCheck %s +# RUN: lld -flavor 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# CHECK-NEXT: section-choice: custom-required +# CHECK-NEXT: section-name: .ctors.2 +# CHECK-NEXT: - ref-name: L003 +# CHECK-NEXT: type: data +# CHECK-NEXT: alignment: 2^2 +# 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: 2^2 +# 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_HI16 + - Offset: 0x04 + Symbol: .ctors + Type: R_MIPS_LO16 + - Offset: 0x08 + Symbol: .ctors + Type: R_MIPS_HI16 + - 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/elf/Mips/dt-textrel-64.test b/test/elf/Mips/dt-textrel-64.test new file mode 100644 index 0000000000000..32cc99e54b2fd --- /dev/null +++ b/test/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 gnu -target mips64el -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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/elf/Mips/dt-textrel.test b/test/elf/Mips/dt-textrel.test new file mode 100644 index 0000000000000..ca854dff8e583 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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/elf/Mips/dynlib-dynamic.test b/test/elf/Mips/dynlib-dynamic.test new file mode 100644 index 0000000000000..54afdec263a63 --- /dev/null +++ b/test/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 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/elf/Mips/dynlib-dynsym-micro.test b/test/elf/Mips/dynlib-dynsym-micro.test new file mode 100644 index 0000000000000..4d75945af7b04 --- /dev/null +++ b/test/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 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 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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/elf/Mips/dynlib-dynsym.test b/test/elf/Mips/dynlib-dynsym.test new file mode 100644 index 0000000000000..d480c3cbbe417 --- /dev/null +++ b/test/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 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 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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/elf/Mips/dynlib-fileheader-64.test b/test/elf/Mips/dynlib-fileheader-64.test new file mode 100644 index 0000000000000..206f4fa7794d7 --- /dev/null +++ b/test/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 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: 0x170 +# CHECK: ProgramHeaderOffset: 0x40 +# CHECK: SectionHeaderOffset: 0x2140 +# 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: 4 +# CHECK: SectionHeaderEntrySize: 64 +# CHECK: SectionHeaderCount: 11 +# CHECK: StringTableSectionIndex: 8 +# 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/elf/Mips/dynlib-fileheader-micro-64.test b/test/elf/Mips/dynlib-fileheader-micro-64.test new file mode 100644 index 0000000000000..c03a951671eac --- /dev/null +++ b/test/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 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: 0x170 +# CHECK-NEXT: ProgramHeaderOffset: 0x40 +# CHECK-NEXT: SectionHeaderOffset: 0x2140 +# 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: 4 +# CHECK-NEXT: SectionHeaderEntrySize: 64 +# CHECK-NEXT: SectionHeaderCount: 11 +# CHECK-NEXT: StringTableSectionIndex: 8 +# 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/elf/Mips/dynlib-fileheader-micro.test b/test/elf/Mips/dynlib-fileheader-micro.test new file mode 100644 index 0000000000000..139b3aa626c90 --- /dev/null +++ b/test/elf/Mips/dynlib-fileheader-micro.test @@ -0,0 +1,82 @@ +# Check ELF Header for shared library in case of microMIPS symbols. + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor 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: 0x100 +# CHECK-NEXT: ProgramHeaderOffset: 0x34 +# CHECK-NEXT: SectionHeaderOffset: 0x2100 +# 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: 4 +# CHECK-NEXT: SectionHeaderEntrySize: 40 +# CHECK-NEXT: SectionHeaderCount: 11 +# CHECK-NEXT: StringTableSectionIndex: 8 +# 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: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Size: 0x18 + - Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x08 + Size: 0x18 + +Symbols: + Global: + - Name: glob + Section: .text + Other: [ STO_MIPS_MICROMIPS ] diff --git a/test/elf/Mips/dynlib-fileheader.test b/test/elf/Mips/dynlib-fileheader.test new file mode 100644 index 0000000000000..5dd9d6a64a713 --- /dev/null +++ b/test/elf/Mips/dynlib-fileheader.test @@ -0,0 +1,80 @@ +# Check ELF Header for shared library. + +# Build shared library +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor 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: 0x100 +# CHECK: ProgramHeaderOffset: 0x34 +# CHECK: SectionHeaderOffset: 0x2100 +# 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: 4 +# CHECK: SectionHeaderEntrySize: 40 +# CHECK: SectionHeaderCount: 11 +# CHECK: StringTableSectionIndex: 8 +# 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: .reginfo + Type: SHT_MIPS_REGINFO + Flags: [ SHF_ALLOC ] + AddressAlign: 0x01 + Size: 0x18 + - Name: .MIPS.abiflags + Type: SHT_MIPS_ABIFLAGS + Flags: [ SHF_ALLOC ] + AddressAlign: 0x08 + Size: 0x18 + +Symbols: + Global: + - Name: glob + Section: .text diff --git a/test/elf/Mips/dynsym-table-1.test b/test/elf/Mips/dynsym-table-1.test new file mode 100644 index 0000000000000..43c48e7304058 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t-bar.so %t-bar.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t-foo.so %t-foo.o %t-bar.so +# RUN: lld -flavor 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 0x401000 +# 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/elf/Mips/dynsym-table-2.test b/test/elf/Mips/dynsym-table-2.test new file mode 100644 index 0000000000000..538aa758910e0 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t-bar.so %t-bar.o +# RUN: lld -flavor 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 0x1000 +# 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/elf/Mips/e-flags-merge-1-64.test b/test/elf/Mips/e-flags-merge-1-64.test new file mode 100644 index 0000000000000..d5719539baaa5 --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-1.test b/test/elf/Mips/e-flags-merge-1.test new file mode 100644 index 0000000000000..1f1d7aca6c41d --- /dev/null +++ b/test/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 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 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/elf/Mips/e-flags-merge-10.test b/test/elf/Mips/e-flags-merge-10.test new file mode 100644 index 0000000000000..a0aa45d5f2c89 --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-11.test b/test/elf/Mips/e-flags-merge-11.test new file mode 100644 index 0000000000000..b4c0039bd1989 --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-2-64.test b/test/elf/Mips/e-flags-merge-2-64.test new file mode 100644 index 0000000000000..a169e7ea1645b --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-2.test b/test/elf/Mips/e-flags-merge-2.test new file mode 100644 index 0000000000000..41d4a0b0c45e1 --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-3-64.test b/test/elf/Mips/e-flags-merge-3-64.test new file mode 100644 index 0000000000000..54065a63fb949 --- /dev/null +++ b/test/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 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 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 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 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/elf/Mips/e-flags-merge-3.test b/test/elf/Mips/e-flags-merge-3.test new file mode 100644 index 0000000000000..e2d9f6c2e2fc6 --- /dev/null +++ b/test/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 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 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 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 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/elf/Mips/e-flags-merge-4-64.test b/test/elf/Mips/e-flags-merge-4-64.test new file mode 100644 index 0000000000000..9ffa613437111 --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-4.test b/test/elf/Mips/e-flags-merge-4.test new file mode 100644 index 0000000000000..096b04d676e9e --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-5-64.test b/test/elf/Mips/e-flags-merge-5-64.test new file mode 100644 index 0000000000000..e629aedbc154f --- /dev/null +++ b/test/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 gnu -target mips64el -shared -o %t.so \ +# RUN: %t-32.o %t-64.o 2>&1 | FileCheck %s + +# CHECK: Bitness is incompatible with that of the selected target + +# 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/elf/Mips/e-flags-merge-5.test b/test/elf/Mips/e-flags-merge-5.test new file mode 100644 index 0000000000000..3b5b397ab7808 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so \ +# RUN: %t-32.o %t-64.o 2>&1 | FileCheck %s + +# CHECK: Bitness is incompatible with that of the selected target + +# 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/elf/Mips/e-flags-merge-6-64.test b/test/elf/Mips/e-flags-merge-6-64.test new file mode 100644 index 0000000000000..fbc32b7135b20 --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-6.test b/test/elf/Mips/e-flags-merge-6.test new file mode 100644 index 0000000000000..759c8b63c97db --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-7-64.test b/test/elf/Mips/e-flags-merge-7-64.test new file mode 100644 index 0000000000000..07ed6bb548366 --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-7.test b/test/elf/Mips/e-flags-merge-7.test new file mode 100644 index 0000000000000..7e114ff968fec --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-8.test b/test/elf/Mips/e-flags-merge-8.test new file mode 100644 index 0000000000000..57af77d70260a --- /dev/null +++ b/test/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 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/elf/Mips/e-flags-merge-9.test b/test/elf/Mips/e-flags-merge-9.test new file mode 100644 index 0000000000000..dea32f07cb9e6 --- /dev/null +++ b/test/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 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/elf/Mips/entry-name.test b/test/elf/Mips/entry-name.test new file mode 100644 index 0000000000000..b10adc68bde89 --- /dev/null +++ b/test/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 gnu -target mipsel --noinhibit-exec -o %t.exe %t.o +# RUN: llvm-nm %t.exe | FileCheck %s + +# CHECK: U __start +# CHECK: 00400108 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/elf/Mips/exe-dynamic.test b/test/elf/Mips/exe-dynamic.test new file mode 100644 index 0000000000000..28d2b13fbce87 --- /dev/null +++ b/test/elf/Mips/exe-dynamic.test @@ -0,0 +1,108 @@ +# 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 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 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 [ (18 entries) +# CHECK: Tag Type Name/Value +# CHECK-NEXT: 0x00000004 HASH 0x400104 +# CHECK-NEXT: 0x00000005 STRTAB 0x400138 +# CHECK-NEXT: 0x00000006 SYMTAB 0x400118 +# CHECK-NEXT: 0x0000000A STRSZ 28 (bytes) +# CHECK-NEXT: 0x0000000B SYMENT 16 (bytes) +# CHECK-NEXT: 0x00000002 PLTRELSZ 8 (bytes) +# CHECK-NEXT: 0x70000032 MIPS_PLTGOT 0x402000 +# CHECK-NEXT: 0x00000014 PLTREL REL +# CHECK-NEXT: 0x00000017 JMPREL 0x400154 +# CHECK-NEXT: 0x70000001 MIPS_RLD_VERSION 1 +# 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 0x401000 +# 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/elf/Mips/exe-dynsym-micro.test b/test/elf/Mips/exe-dynsym-micro.test new file mode 100644 index 0000000000000..e3b00277ef6a9 --- /dev/null +++ b/test/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 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 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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/elf/Mips/exe-dynsym.test b/test/elf/Mips/exe-dynsym.test new file mode 100644 index 0000000000000..a59916c4be4c4 --- /dev/null +++ b/test/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 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 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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/elf/Mips/exe-fileheader-64.test b/test/elf/Mips/exe-fileheader-64.test new file mode 100644 index 0000000000000..63baff53e6782 --- /dev/null +++ b/test/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 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: 0x1200001A0 +# CHECK: ProgramHeaderOffset: 0x40 +# CHECK: SectionHeaderOffset: 0x1300 +# 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: 5 +# CHECK: SectionHeaderEntrySize: 64 +# CHECK: SectionHeaderCount: 11 +# CHECK: StringTableSectionIndex: 8 +# 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/elf/Mips/exe-fileheader-micro-64.test b/test/elf/Mips/exe-fileheader-micro-64.test new file mode 100644 index 0000000000000..044c2f729f388 --- /dev/null +++ b/test/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 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: 0x1200001A1 +# CHECK: ProgramHeaderOffset: 0x40 +# CHECK: SectionHeaderOffset: 0x1300 +# 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: 5 +# CHECK: SectionHeaderEntrySize: 64 +# CHECK: SectionHeaderCount: 11 +# CHECK: StringTableSectionIndex: 8 +# 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/elf/Mips/exe-fileheader-micro.test b/test/elf/Mips/exe-fileheader-micro.test new file mode 100644 index 0000000000000..351f299b04cdc --- /dev/null +++ b/test/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 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: 0 +# 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: 0x400109 +# CHECK-NEXT: ProgramHeaderOffset: 0x34 +# CHECK-NEXT: SectionHeaderOffset: 0x1268 +# 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: 5 +# CHECK-NEXT: SectionHeaderEntrySize: 40 +# CHECK-NEXT: SectionHeaderCount: 11 +# CHECK-NEXT: StringTableSectionIndex: 8 +# 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/elf/Mips/exe-fileheader.test b/test/elf/Mips/exe-fileheader.test new file mode 100644 index 0000000000000..ff0d38198c316 --- /dev/null +++ b/test/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 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 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: 0x400190 +# CHECK: ProgramHeaderOffset: 0x34 +# CHECK: SectionHeaderOffset: 0x2280 +# CHECK: Flags [ (0x70001005) +# CHECK: EF_MIPS_ABI_O32 (0x1000) +# CHECK: EF_MIPS_ARCH_32R2 (0x70000000) +# CHECK: EF_MIPS_CPIC (0x4) +# CHECK: EF_MIPS_NOREORDER (0x1) +# CHECK: ] +# CHECK: HeaderSize: 52 +# CHECK: ProgramHeaderEntrySize: 32 +# CHECK: ProgramHeaderCount: 6 +# CHECK: SectionHeaderEntrySize: 40 +# CHECK: SectionHeaderCount: 14 +# CHECK: StringTableSectionIndex: 11 +# 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/elf/Mips/exe-got-micro.test b/test/elf/Mips/exe-got-micro.test new file mode 100644 index 0000000000000..d2d1588ab964b --- /dev/null +++ b/test/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 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 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: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# GOT: - type: got +# GOT: content: [ 00, 00, 00, 80 ] +# GOT: alignment: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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/elf/Mips/exe-got.test b/test/elf/Mips/exe-got.test new file mode 100644 index 0000000000000..7254c87530bcb --- /dev/null +++ b/test/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 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 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: 2^2 +# GOT: section-choice: custom-required +# GOT: section-name: .got +# GOT: permissions: rw- +# GOT: - type: got +# GOT: content: [ 00, 00, 00, 80 ] +# GOT: alignment: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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/elf/Mips/got-page-32.test b/test/elf/Mips/got-page-32.test new file mode 100644 index 0000000000000..00376da786633 --- /dev/null +++ b/test/elf/Mips/got-page-32.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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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: T0 (1) +# GOT-NEXT: Value: 0x400154 +# GOT: Symbol { +# GOT: Name: LT1 (4) +# GOT-NEXT: Value: 0x40017C +# GOT: Symbol { +# GOT: Name: LT2 (8) +# GOT-NEXT: Value: 0x400180 +# 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: 0x40017C +# 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: ] +# GOT-NEXT: Global entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401014 +# 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@ (1) +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401018 +# 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@ (4) +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Number of TLS and multi-GOT entries: 0 +# GOT-NEXT: } + +# RAW: Contents of section .text: +# RAW-NEXT: 400154 24800000 18800000 24800000 28800000 $.......$...(... +# ^ = -32732 (T1) +# ^ = -32744 (LT1) +# ^ -32732 (T1) +# ^ -32728 (T2) +# RAW-NEXT: 400164 1c800000 20800000 00000000 00000000 .... ........... +# ^ -32740 (PAGE) +# ^ -32736 (PAGE) +# ^ T1 OFST +# ^ T2 OFST +# RAW-NEXT: 400174 7c010000 80010000 00000000 00000000 |............... +# ^ LT1 OFST +# ^ LT2 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: 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/elf/Mips/got-page-64.test b/test/elf/Mips/got-page-64.test new file mode 100644 index 0000000000000..21bece5d32420 --- /dev/null +++ b/test/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 gnu -target mips64el -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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: 0x1200001F0 +# GOT: Symbol { +# GOT: Name: LT1 (4) +# GOT-NEXT: Value: 0x120000218 +# GOT: Symbol { +# GOT: Name: LT2 (8) +# GOT-NEXT: Value: 0x12000021C +# 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: 0x120000218 +# 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: 1200001f0 38800000 20800000 38800000 40800000 8... ...8...@... +# ^ = -32712 (T1) +# ^ = -32736 (LT1) +# ^ -32712 (T1) +# ^ -32704 (T2) +# RAW-NEXT: 120000200 28800000 30800000 00000000 00000000 (...0........... +# ^ -32728 (PAGE) +# ^ -32720 (PAGE) +# ^ T1 OFST +# ^ T2 OFST +# RAW-NEXT: 120000210 18020000 1c020000 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/elf/Mips/got16-2.test b/test/elf/Mips/got16-2.test new file mode 100644 index 0000000000000..6f576536c5410 --- /dev/null +++ b/test/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 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/elf/Mips/got16-micro.test b/test/elf/Mips/got16-micro.test new file mode 100644 index 0000000000000..6b77613581ec5 --- /dev/null +++ b/test/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 gnu -target mipsel -shared --noinhibit-exec \ +# RUN: --output-filetype=yaml %t.o \ +# RUN: | FileCheck -check-prefix YAML %s +# RUN: lld -flavor 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 2^4 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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 00000000 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/elf/Mips/got16.test b/test/elf/Mips/got16.test new file mode 100644 index 0000000000000..9090d3003c142 --- /dev/null +++ b/test/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 gnu -target mipsel -shared --noinhibit-exec \ +# RUN: --output-filetype=yaml %t.o \ +# RUN: | FileCheck -check-prefix YAML %s +# RUN: lld -flavor 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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: 2^2 +# 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/elf/Mips/gotsym.test b/test/elf/Mips/gotsym.test new file mode 100644 index 0000000000000..4581901958aae --- /dev/null +++ b/test/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 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 g *ABS* 00000000 _GLOBAL_OFFSET_TABLE_ +# SHARED: 00008ff0 g *ABS* 00000000 _gp +# SHARED: 00008ff0 g *ABS* 00000000 _gp_disp + +# RUN: lld -flavor 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 g *ABS* 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/elf/Mips/gp-sym-1-micro.test b/test/elf/Mips/gp-sym-1-micro.test new file mode 100644 index 0000000000000..76274eaaa8ac9 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 (203) +# 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/elf/Mips/gp-sym-1.test b/test/elf/Mips/gp-sym-1.test new file mode 100644 index 0000000000000..6c2ffb62629d6 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 (203) +# 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/elf/Mips/gp-sym-2.test b/test/elf/Mips/gp-sym-2.test new file mode 100644 index 0000000000000..6b9e5a5e52d93 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t-1.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 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/elf/Mips/hilo16-1.test b/test/elf/Mips/hilo16-1.test new file mode 100644 index 0000000000000..c2863408c888d --- /dev/null +++ b/test/elf/Mips/hilo16-1.test @@ -0,0 +1,44 @@ +# REQUIRES: mips + +# Check handling multiple HI16 relocation followed by a single LO16 relocation. +# +# RUN: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s +# RUN: lld -flavor 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: {{[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]+}}: 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]+}}: 55 01 08 85 lh $8, 341($8) + +# CHECK: SYMBOL TABLE: +# CHECK: {{[0-9a-f]+}} g F .text 00000024 glob1 +# CHECK: {{[0-9a-f]+}} g F .text 00000004 glob2 + + .global glob1 + .ent glob1 +glob1: + lui $t0,%hi(glob2+0x1) + lui $t0,%hi(glob2+(-0x1)) + lui $t0,%hi(glob2+0x1ff) + lui $t0,%hi(glob2+(-0x1ff)) + lui $t0,%hi(glob2+0x1ffff) + lui $t0,%hi(glob2+(-0x1ffff)) + lui $t0,%hi(glob2+0x1ffffff) + lui $t0,%hi(glob2+(-0x1ffffff)) + + lh $t0,%lo(glob2+(-0x1ffffff))($t0) + .end glob1 + + .global glob2 + .ent glob2 +glob2: + nop + .end glob2 diff --git a/test/elf/Mips/hilo16-2.test b/test/elf/Mips/hilo16-2.test new file mode 100644 index 0000000000000..68cb26eec7881 --- /dev/null +++ b/test/elf/Mips/hilo16-2.test @@ -0,0 +1,68 @@ +# 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 -triple=mipsel -filetype=obj -o=%t-obj %s +# RUN: lld -flavor 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: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 71 01 08 85 lh $8, 369($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 6f 01 08 85 lh $8, 367($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 6f 03 08 85 lh $8, 879($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 00 08 3c lui $8, 64 +# CHECK-NEXT: {{[0-9a-f]+}}: 71 ff 08 85 lh $8, -143($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 42 00 08 3c lui $8, 66 +# CHECK-NEXT: {{[0-9a-f]+}}: 6f 01 08 85 lh $8, 367($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 3e 00 08 3c lui $8, 62 +# CHECK-NEXT: {{[0-9a-f]+}}: 71 01 08 85 lh $8, 369($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 02 08 3c lui $8, 576 +# CHECK-NEXT: {{[0-9a-f]+}}: 6f 01 08 85 lh $8, 367($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 40 fe 08 3c lui $8, 65088 +# CHECK-NEXT: {{[0-9a-f]+}}: 71 01 08 85 lh $8, 369($8) + +# CHECK: SYMBOL TABLE: +# CHECK: {{[0-9a-f]+}} g F .text 00000040 glob1 +# CHECK: {{[0-9a-f]+}} g F .text 00000004 glob2 + + .global glob1 + .ent glob1 +glob1: + lui $t0,%hi(glob2+0x1) + lh $t0,%lo(glob2+0x1)($t0) + + lui $t0,%hi(glob2+(-0x1)) + lh $t0,%lo(glob2+(-0x1))($t0) + + lui $t0,%hi(glob2+0x1ff) + lh $t0,%lo(glob2+0x1ff)($t0) + + lui $t0,%hi(glob2+(-0x1ff)) + lh $t0,%lo(glob2+(-0x1ff))($t0) + + lui $t0,%hi(glob2+0x1ffff) + lh $t0,%lo(glob2+0x1ffff)($t0) + + lui $t0,%hi(glob2+(-0x1ffff)) + lh $t0,%lo(glob2+(-0x1ffff))($t0) + + lui $t0,%hi(glob2+0x1ffffff) # truncate + lh $t0,%lo(glob2+0x1ffffff)($t0) + + lui $t0,%hi(glob2+(-0x1ffffff)) # truncate + lh $t0,%lo(glob2+(-0x1ffffff))($t0) + .end glob1 + + .global glob2 + .ent glob2 +glob2: + nop + .end glob2 diff --git a/test/elf/Mips/hilo16-3.test b/test/elf/Mips/hilo16-3.test new file mode 100644 index 0000000000000..daf4807d719a9 --- /dev/null +++ b/test/elf/Mips/hilo16-3.test @@ -0,0 +1,45 @@ +# REQUIRES: mips + +# 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: llvm-mc -triple=mipsel -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t-so %t-obj +# RUN: llvm-objdump -t -disassemble %t-so | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK: glob1: +# CHECK-NEXT: {{[0-9a-f]+}}: 01 00 08 3c lui $8, 1 +# CHECK-NEXT: {{[0-9a-f]+}}: 01 8f 08 85 lh $8, -28927($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 01 00 08 3c lui $8, 1 +# CHECK-NEXT: {{[0-9a-f]+}}: f7 8e 08 85 lh $8, -28937($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 01 00 08 3c lui $8, 1 +# CHECK-NEXT: {{[0-9a-f]+}}: ef 90 08 85 lh $8, -28433($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 01 00 08 3c lui $8, 1 +# CHECK-NEXT: {{[0-9a-f]+}}: e9 8c 08 85 lh $8, -29463($8) +# CHECK-NEXT: {{[0-9a-f]+}}: 03 00 08 3c lui $8, 3 +# CHECK-NEXT: {{[0-9a-f]+}}: df 8e 08 85 lh $8, -28961($8) + +# CHECK: SYMBOL TABLE: +# CHECK: {{[0-9a-f]+}} g F .text 00000028 glob1 +# CHECK: {{[0-9a-f]+}} g *ABS* 00000000 _gp_disp + + .global glob1 +glob1: + lui $t0,%hi(_gp_disp+0x1) + lh $t0,%lo(_gp_disp+0x1)($t0) + + lui $t0,%hi(_gp_disp+(-0x1)) + lh $t0,%lo(_gp_disp+(-0x1))($t0) + + lui $t0,%hi(_gp_disp+0x1ff) + lh $t0,%lo(_gp_disp+0x1ff)($t0) + + lui $t0,%hi(_gp_disp+(-0x1ff)) + lh $t0,%lo(_gp_disp+(-0x1ff))($t0) + + lui $t0,%hi(_gp_disp+0x1ffff) + lh $t0,%lo(_gp_disp+0x1ffff)($t0) diff --git a/test/elf/Mips/hilo16-4.test b/test/elf/Mips/hilo16-4.test new file mode 100644 index 0000000000000..8a13f7b131fd3 --- /dev/null +++ b/test/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 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/elf/Mips/hilo16-5.test b/test/elf/Mips/hilo16-5.test new file mode 100644 index 0000000000000..91aca8b1c3662 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -o %t-o.o -docnum 2 %s +# RUN: lld -flavor 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/elf/Mips/hilo16-8-micro.test b/test/elf/Mips/hilo16-8-micro.test new file mode 100644 index 0000000000000..3248804f8f540 --- /dev/null +++ b/test/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 -triple=mipsel -mattr=micromips -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -e glob1 -o %t-exe %t-obj +# RUN: llvm-objdump -t -d -mattr=micromips %t-exe | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: glob1: +# CHECK-NEXT: 400130: a8 41 40 00 lui $8, 64 +# CHECK-NEXT: 400134: 08 3d 6a 01 lh $8, 362($8) +# CHECK-NEXT: 400138: a8 41 41 00 lui $8, 65 +# CHECK-NEXT: 40013c: 08 3d 68 81 lh $8, -32408($8) +# CHECK-NEXT: 400140: a8 41 41 00 lui $8, 65 +# CHECK-NEXT: 400144: 08 3d e9 81 lh $8, -32279($8) +# CHECK-NEXT: 400148: a8 41 42 00 lui $8, 66 +# CHECK-NEXT: 40014c: 08 3d 69 81 lh $8, -32407($8) +# CHECK-NEXT: 400150: a8 41 40 40 lui $8, 16448 +# CHECK-NEXT: 400154: 08 3d 69 01 lh $8, 361($8) +# CHECK-NEXT: 400158: a8 41 40 80 lui $8, 32832 +# CHECK-NEXT: 40015c: 08 3d 69 01 lh $8, 361($8) +# CHECK-NEXT: 400160: a8 41 c1 80 lui $8, 32961 +# CHECK-NEXT: 400164: 08 3d e9 81 lh $8, -32279($8) + +# CHECK: glob2: +# CHECK-NEXT: 400168: a8 41 40 00 lui $8, 64 +# CHECK-NEXT: 40016c: a8 41 40 00 lui $8, 64 +# CHECK-NEXT: 400170: a8 41 41 00 lui $8, 65 +# CHECK-NEXT: 400174: a8 41 42 00 lui $8, 66 +# CHECK-NEXT: 400178: a8 41 40 40 lui $8, 16448 +# CHECK-NEXT: 40017c: a8 41 40 80 lui $8, 32832 +# CHECK-NEXT: 400180: a8 41 c1 80 lui $8, 32961 +# CHECK-NEXT: 400184: 08 3d b1 81 lh $8, -32335($8) + +# CHECK: SYMBOL TABLE: +# CHECK: 00400130 g F .text 00000038 glob1 +# CHECK: 00400168 g F .text 00000020 glob2 + + .globl glob1 + .type glob1, @function + .set micromips + .ent glob1 +glob1: + lui $t0,%hi(glob2+0x00000001) + lh $t0,%lo(glob2+0x00000001)($t0) + + lui $t0,%hi(glob2+0x00007fff) + lh $t0,%lo(glob2+0x00007fff)($t0) + + lui $t0,%hi(glob2+0x00008080) + lh $t0,%lo(glob2+0x00008080)($t0) + + lui $t0,%hi(glob2+0x00018000) + lh $t0,%lo(glob2+0x00018000)($t0) + + lui $t0,%hi(glob2+0x40000000) + lh $t0,%lo(glob2+0x40000000)($t0) + + lui $t0,%hi(glob2+0x80000000) + lh $t0,%lo(glob2+0x80000000)($t0) + + lui $t0,%hi(glob2+0x80808080) + lh $t0,%lo(glob2+0x80808080)($t0) + .end glob1 + + .globl glob2 + .type glob2, @function + .set micromips + .ent glob2 +glob2: + lui $t0,%hi(glob1+0x00000001) + lui $t0,%hi(glob1+0x00007fff) + lui $t0,%hi(glob1+0x00008080) + lui $t0,%hi(glob1+0x00018000) + lui $t0,%hi(glob1+0x40000000) + lui $t0,%hi(glob1+0x80000000) + lui $t0,%hi(glob1+0x80808080) + lh $t0,%lo(glob1+0x80808080)($t0) + .end glob2 diff --git a/test/elf/Mips/hilo16-9-micro.test b/test/elf/Mips/hilo16-9-micro.test new file mode 100644 index 0000000000000..30ad10ce0dd4a --- /dev/null +++ b/test/elf/Mips/hilo16-9-micro.test @@ -0,0 +1,68 @@ +# REQUIRES: mips + +# Check calculation of AHL addendums for R_MICROMIPS_HI16 / R_MICROMIPS_LO16 +# relocations for the _gp_disp symbol. +# +# RUN: llvm-mc -triple=mipsel -mattr=micromips -filetype=obj -o=%t-obj %s +# RUN: lld -flavor gnu -target mipsel -shared -o %t-so %t-obj +# RUN: llvm-objdump -t -d -mattr=micromips %t-so | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: glob1: +# CHECK-NEXT: 130: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 134: 08 3d c0 9e lh $8, -24896($8) +# CHECK-NEXT: 138: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 13c: 08 3d b6 1e lh $8, 7862($8) +# CHECK-NEXT: 140: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 144: 08 3d 2f 1f lh $8, 7983($8) +# CHECK-NEXT: 148: a8 41 02 00 lui $8, 2 +# CHECK-NEXT: 14c: 08 3d a7 1e lh $8, 7847($8) +# CHECK-NEXT: 150: a8 41 01 40 lui $8, 16385 +# CHECK-NEXT: 154: 08 3d 9f 9e lh $8, -24929($8) + +# CHECK: glob2: +# CHECK-NEXT: 158: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 15c: a8 41 01 00 lui $8, 1 +# CHECK-NEXT: 160: a8 41 02 00 lui $8, 2 +# CHECK-NEXT: 164: a8 41 03 00 lui $8, 3 +# CHECK-NEXT: 168: a8 41 01 40 lui $8, 16385 +# CHECK-NEXT: 16c: 08 3d 87 9e lh $8, -24953($8) + +# CHECK: SYMBOL TABLE: +# CHECK: 00000130 g F .text 00000028 glob1 +# CHECK: 00000158 g F .text 00000018 glob2 +# CHECK: 00009ff0 g *ABS* 00000000 _gp_disp + + .globl glob1 + .type glob1, @function + .set micromips + .ent glob1 +glob1: + lui $t0,%hi(_gp_disp+0x00000001) + lh $t0,%lo(_gp_disp+0x00000001)($t0) + + lui $t0,%hi(_gp_disp+0x00007fff) + lh $t0,%lo(_gp_disp+0x00007fff)($t0) + + lui $t0,%hi(_gp_disp+0x00008080) + lh $t0,%lo(_gp_disp+0x00008080)($t0) + + lui $t0,%hi(_gp_disp+0x00018000) + lh $t0,%lo(_gp_disp+0x00018000)($t0) + + lui $t0,%hi(_gp_disp+0x40000000) + lh $t0,%lo(_gp_disp+0x40000000)($t0) + .end glob1 + + .globl glob2 + .type glob2, @function + .set micromips + .ent glob2 +glob2: + lui $t0,%hi(_gp_disp+0x00000001) + lui $t0,%hi(_gp_disp+0x00007fff) + lui $t0,%hi(_gp_disp+0x00008080) + lui $t0,%hi(_gp_disp+0x00018000) + lui $t0,%hi(_gp_disp+0x40000000) + lh $t0,%lo(_gp_disp+0x40000000)($t0) + .end glob2 diff --git a/test/elf/Mips/initfini-micro.test b/test/elf/Mips/initfini-micro.test new file mode 100644 index 0000000000000..ba30e89ade215 --- /dev/null +++ b/test/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 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/elf/Mips/interpreter-64.test b/test/elf/Mips/interpreter-64.test new file mode 100644 index 0000000000000..3ece3e6a467a8 --- /dev/null +++ b/test/elf/Mips/interpreter-64.test @@ -0,0 +1,26 @@ +# Check program interpreter setup. +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor 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/elf/Mips/interpreter.test b/test/elf/Mips/interpreter.test new file mode 100644 index 0000000000000..5355f7709fbdf --- /dev/null +++ b/test/elf/Mips/interpreter.test @@ -0,0 +1,26 @@ +# Check program interpreter setup. +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor 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/elf/Mips/invalid-reginfo.test b/test/elf/Mips/invalid-reginfo.test new file mode 100644 index 0000000000000..d56223bf2e046 --- /dev/null +++ b/test/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 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/elf/Mips/jalx-align-err.test b/test/elf/Mips/jalx-align-err.test new file mode 100644 index 0000000000000..3db18fc98fac7 --- /dev/null +++ b/test/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 gnu -target mipsel -e T0 -o %t-exe %t-obj 2>&1 \ +# RUN: | FileCheck %s + +# CHECK: The jalx target 0x400116 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/elf/Mips/jump-fix-err.test b/test/elf/Mips/jump-fix-err.test new file mode 100644 index 0000000000000..9811799383978 --- /dev/null +++ b/test/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 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/elf/Mips/la25-stub-micro.test b/test/elf/Mips/la25-stub-micro.test new file mode 100644 index 0000000000000..d41297a0ddc3c --- /dev/null +++ b/test/elf/Mips/la25-stub-micro.test @@ -0,0 +1,140 @@ +# 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 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: 0x400135 +# SYM: Name: T1N (1) +# SYM-NEXT: Value: 0x400111 +# SYM: Name: T1 (5) +# SYM-NEXT: Value: 0x400121 +# SYM: Name: glob (8) +# SYM-NEXT: Value: 0x400125 + +# ASM: Contents of section .text: +# ASM-NEXT: 400110 00000000 00000000 00000000 00000000 +# ASM-NEXT: 400120 00000000 00000000 00000000 10f04900 +# 0x100049 << 2 == 0x400125 (jalx glob) --^ +# ASM-NEXT: 400130 00000000 20f49200 00000000 20f48800 +# ^-- 0x100049 << 2 == 0x400124 (jal glob) +# 0x100044 << 2 == 0x400110 (jal T1N) --^ +# ASM-NEXT: 400140 00000000 20f4a800 00000000 00000000 +# ^-- 0x100054 << 2 == 0x400150 (jal T1 stub) +# ASM-NEXT: 400150 b9414000 20d49000 39332101 00000000 +# ^-- j 0x400120 (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/elf/Mips/la25-stub.test b/test/elf/Mips/la25-stub.test new file mode 100644 index 0000000000000..2c4b26452cecb --- /dev/null +++ b/test/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 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: 0x400134 +# SYM: Name: T1N (1) +# SYM-NEXT: Value: 0x400110 +# SYM: Name: T1 (5) +# SYM-NEXT: Value: 0x400120 +# SYM: Name: glob (8) +# SYM-NEXT: Value: 0x400124 + +# ASM: Contents of section .text: +# ASM-NEXT: 400110 00000000 00000000 00000000 00000000 +# ASM-NEXT: 400120 00000000 00000000 00000000 49001000 +# 0x100049 << 2 == 0x400124 (glob) --^ +# ASM-NEXT: 400130 00000000 49001000 00000000 44001000 +# ^-- 0x100049 << 2 == 0x400124 (glob) +# 0x100044 << 2 == 0x400110 (T1N) --^ +# ASM-NEXT: 400140 00000000 54001000 00000000 00000000 +# ^-- 0x100054 << 2 == 0x400150 (T1 stub) +# ASM-NEXT: 400150 4000193c 48001008 20013927 00000000 +# ^-- j 0x400120 (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/elf/Mips/mips-options-gp0.test b/test/elf/Mips/mips-options-gp0.test new file mode 100644 index 0000000000000..339ab97253b63 --- /dev/null +++ b/test/elf/Mips/mips-options-gp0.test @@ -0,0 +1,78 @@ +# Check reading GP0 value from .MIPS.options section +# +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mipsel -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 (1) +# SYM-NEXT: Value: 0xCC +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Local (0x0) +# SYM-NEXT: Type: Function (0x2) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .text (0x4) + +# SYM: Name: _gp (34) +# 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) + +# 0xffff80dc == 0x0 (addend) + 0x00cc (L1) + 0x1000 (GP0) - 0x8ff0 (_gp) +# SEC: Contents of section .rodata: +# SEC-NEXT: 00d4 dc80ffff 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: +- 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_REL + 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: "0128000000000000000000000000000000000000000000000000000000100000" + +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/elf/Mips/n64-rel-chain.test b/test/elf/Mips/n64-rel-chain.test new file mode 100644 index 0000000000000..0ae7af73ae833 --- /dev/null +++ b/test/elf/Mips/n64-rel-chain.test @@ -0,0 +1,134 @@ +# Check handling MIPS N64 ABI relocation "chains". + +# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o +# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 1200001d0 01000000 00000000 208e0000 00000000 ........ ....... +# CHECK-NEXT: 1200001e0 20800000 f8010000 28800000 00000000 .......(....... +# CHECK: Contents of section .pdr: +# CHECK-NEXT: 0000 d0010020 e0010020 ... ... + +--- +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/elf/Mips/opt-emulation.test b/test/elf/Mips/opt-emulation.test new file mode 100644 index 0000000000000..2d1e7142c3867 --- /dev/null +++ b/test/elf/Mips/opt-emulation.test @@ -0,0 +1,41 @@ +# Check MIPS specific arguments of the -m command line option. + +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -m elf32ltsmip -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: 0 +# 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/elf/Mips/pc23-range.test b/test/elf/Mips/pc23-range.test new file mode 100644 index 0000000000000..7166176c46288 --- /dev/null +++ b/test/elf/Mips/pc23-range.test @@ -0,0 +1,56 @@ +# Check that LLD shows an error if ADDIUPC immediate is out of range. + +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj 2>&1 | FileCheck %s + +# CHECK: The addiupc instruction immediate 0x02000008 is out of range + +!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: "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/elf/Mips/plt-entry-mixed-1.test b/test/elf/Mips/plt-entry-mixed-1.test new file mode 100644 index 0000000000000..bc45763fa16d9 --- /dev/null +++ b/test/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 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 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: 21 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/elf/Mips/plt-entry-mixed-2.test b/test/elf/Mips/plt-entry-mixed-2.test new file mode 100644 index 0000000000000..5aec7d7a328a0 --- /dev/null +++ b/test/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 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 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 2178e003 82c01800 09f82003 feff1827 !x........ ....' +# CHECK-NEXT: 400190 40000f3c 0820f98d 08002003 0820f825 @..<. .... .. .% +# CHECK-NEXT: 4001a0 00799a07 22ff0000 9945020f .y.."....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: 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/elf/Mips/plt-entry-mixed-3.test b/test/elf/Mips/plt-entry-mixed-3.test new file mode 100644 index 0000000000000..c61991b4b1395 --- /dev/null +++ b/test/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 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 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/elf/Mips/plt-entry-mixed-4.test b/test/elf/Mips/plt-entry-mixed-4.test new file mode 100644 index 0000000000000..acf5060621f6c --- /dev/null +++ b/test/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 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 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 2178e003 82c01800 09f82003 feff1827 !x........ ....' +# 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/elf/Mips/plt-entry-r6.test b/test/elf/Mips/plt-entry-r6.test new file mode 100644 index 0000000000000..bb05531487ff5 --- /dev/null +++ b/test/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 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 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: 21 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/elf/Mips/plt-header-micro.test b/test/elf/Mips/plt-header-micro.test new file mode 100644 index 0000000000000..ce042741cd326 --- /dev/null +++ b/test/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 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 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/elf/Mips/plt-header-mixed.test b/test/elf/Mips/plt-header-mixed.test new file mode 100644 index 0000000000000..0d3af19ee5939 --- /dev/null +++ b/test/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 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 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: 21 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/elf/Mips/plt-header.test b/test/elf/Mips/plt-header.test new file mode 100644 index 0000000000000..caf7e83ea5e24 --- /dev/null +++ b/test/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 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 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: 21 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/elf/Mips/r26-1-micro.test b/test/elf/Mips/r26-1-micro.test new file mode 100644 index 0000000000000..629754febc7e3 --- /dev/null +++ b/test/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 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 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/elf/Mips/r26-1.test b/test/elf/Mips/r26-1.test new file mode 100644 index 0000000000000..abc0a7ce5a811 --- /dev/null +++ b/test/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 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 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/elf/Mips/r26-2-micro.test b/test/elf/Mips/r26-2-micro.test new file mode 100644 index 0000000000000..b92b9acf4c842 --- /dev/null +++ b/test/elf/Mips/r26-2-micro.test @@ -0,0 +1,88 @@ +# REQUIRES: mips + +# Check reading addendum for R_MICROMIPS_26_S1 relocation. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -d -mattr=micromips %t-exe | FileCheck -check-prefix=DIS %s +# RUN: llvm-objdump -t %t-exe | FileCheck %s + +# DIS: Disassembly of section .text: +# DIS-NEXT: loc0: +# DIS-NEXT: 400110: 00 00 00 00 nop + +# DIS: __start: +# DIS-NEXT: 400114: 20 f4 8e e0 jal 4309276 +# DIS-NEXT: 400118: 00 00 00 00 nop +# DIS-NEXT: 40011c: 20 f4 9a e0 jal 4309300 +# DIS-NEXT: 400120: 00 00 00 00 nop + +# DIS: loc1: +# DIS-NEXT: 400124: 20 f4 89 00 jal 4194578 +# DIS-NEXT: 400128: 00 00 00 00 nop +# DIS-NEXT: 40012c: 20 f4 91 00 jal 4194594 +# DIS-NEXT: 400130: 00 00 00 00 nop + +# CHECK: SYMBOL TABLE: +# CHECK: 00400124 l F .text 00000010 loc1 +# CHECK: 00400114 g F .text 00000010 __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 +# nop +# jal __start + 0x1C000 +# nop +# jal loc + 0x1C000 +# nop +# jal __start + 7FFFFE2 +# nop +# jal loc + 7FFFFEA +# nop + Content: "0000000000f404e00000000000f408e000000000FFF7FFFF00000000FFF7FFFF00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x4 + Symbol: __start + Type: R_MICROMIPS_26_S1 + - Offset: 0xC + Symbol: loc1 + Type: R_MICROMIPS_26_S1 + - Offset: 0x14 + Symbol: __start + Type: R_MICROMIPS_26_S1 + - Offset: 0x1C + Symbol: loc1 + Type: R_MICROMIPS_26_S1 + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x4 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] + Local: + - Name: loc0 + Section: .text + Value: 0 + Size: 4 + Other: [ STO_MIPS_MICROMIPS ] + - Name: loc1 + Section: .text + Value: 0x14 + Size: 8 + Other: [ STO_MIPS_MICROMIPS ] diff --git a/test/elf/Mips/r26-2.test b/test/elf/Mips/r26-2.test new file mode 100644 index 0000000000000..0f0063ae13349 --- /dev/null +++ b/test/elf/Mips/r26-2.test @@ -0,0 +1,82 @@ +# REQUIRES: mips + +# Check reading addendum for R_MIPS_26 relocation. +# RUN: yaml2obj -format=elf %s > %t-obj +# RUN: lld -flavor gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -t -disassemble %t-exe | FileCheck %s + +# CHECK: Disassembly of section .text: +# CHECK-NEXT: __start: +# CHECK-NEXT: 400110: 00 00 00 00 nop +# CHECK-NEXT: 400114: 44 70 10 0c jal 4309264 +# 0x107044 << 2 = 0x41C110 = _start + (0x7000 << 2) +# CHECK-NEXT: 400118: 00 00 00 00 nop +# +# CHECK: loc: +# CHECK-NEXT: 40011c: 47 70 10 0c jal 4309276 +# 0x107047 << 2 = 0x41C11C = loc + (0x7000 << 2) +# CHECK-NEXT: 400120: 00 00 00 00 nop +# CHECK-NEXT: 400124: 43 00 10 0c jal 4194572 +# 0x100043 << 2 = 0x40010C = _start - 4 +# CHECK-NEXT: 400128: 00 00 00 00 nop +# CHECK-NEXT: 40012c: 46 00 10 0c jal 4194584 +# 0x100046 << 2 = 0x400118 = loc - 4 +# CHECK-NEXT: 400130: 00 00 00 00 nop + +# CHECK: SYMBOL TABLE: +# CHECK: 0040011c l F .text 00000018 loc +# CHECK: 00400110 g F .text 0000000c __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_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS +# nop +# jal __start + 0x1C000 +# nop +# jal loc + 0x1C000 +# nop +# jal __start - 1 +# nop +# jal loc - 1 +# nop + Content: "000000000070000C000000000070000C00000000FFFFFF0F00000000FFFFFF0F00000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x4 + Symbol: __start + Type: R_MIPS_26 + - Offset: 0xC + Symbol: loc + Type: R_MIPS_26 + - Offset: 0x14 + Symbol: __start + Type: R_MIPS_26 + - Offset: 0x1C + Symbol: loc + Type: R_MIPS_26 + +Symbols: + Global: + - Name: __start + Section: .text + Value: 0x0 + Size: 4 + Local: + - Name: loc + Section: .text + Value: 0xc + Size: 4 diff --git a/test/elf/Mips/rel-32.test b/test/elf/Mips/rel-32.test new file mode 100644 index 0000000000000..beefde59b7b1c --- /dev/null +++ b/test/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 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/elf/Mips/rel-64.test b/test/elf/Mips/rel-64.test new file mode 100644 index 0000000000000..e05b75687038e --- /dev/null +++ b/test/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 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/elf/Mips/rel-copy-micro.test b/test/elf/Mips/rel-copy-micro.test new file mode 100644 index 0000000000000..afa99198e37f5 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t1.so %t-so1.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-so2.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t2.so %t-so2.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-o.o +# RUN: lld -flavor 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 (0xA) +# 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 (0xA) +# 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/elf/Mips/rel-copy-pc.test b/test/elf/Mips/rel-copy-pc.test new file mode 100644 index 0000000000000..2dd702334fed8 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 (0xA) +# 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/elf/Mips/rel-copy.test b/test/elf/Mips/rel-copy.test new file mode 100644 index 0000000000000..648a25e22ae78 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t1.so %t-so1.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-so2.o +# RUN: lld -flavor gnu -target mipsel -shared -o %t2.so %t-so2.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t-o.o +# RUN: lld -flavor 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: 0x402010 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Object (0x1) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .bss (0xA) +# CHECK-NEXT: } +# CHECK-NEXT: Symbol { +# CHECK-NEXT: Name: D3@ (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 (0xA) +# 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/elf/Mips/rel-dynamic-01-micro.test b/test/elf/Mips/rel-dynamic-01-micro.test new file mode 100644 index 0000000000000..6e0a41bf26063 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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: 0x402018 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: 0x402018 +# 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 (0xD) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T1@ (4) +# PLT-SYM-NEXT: Value: 0x4001D5 +# 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/elf/Mips/rel-dynamic-01.test b/test/elf/Mips/rel-dynamic-01.test new file mode 100644 index 0000000000000..ca4619668bd20 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-01.test @@ -0,0 +1,237 @@ +# 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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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: 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: 21 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: 0x402018 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: 0x402018 +# 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 (0xD) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T1@ (4) +# PLT-SYM-NEXT: Value: 0x400220 +# 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: ] + +# 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/elf/Mips/rel-dynamic-02.test b/test/elf/Mips/rel-dynamic-02.test new file mode 100644 index 0000000000000..4de86383482cb --- /dev/null +++ b/test/elf/Mips/rel-dynamic-02.test @@ -0,0 +1,82 @@ +# 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-obj +# RUN: lld -flavor gnu -target mipsel -shared --noinhibit-exec -o %t1-so %t-obj +# RUN: llvm-readobj -dt -r -s %t1-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: 0x140 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: None (0x0) +# PLT-SYM-NEXT: Other: 0 +# PLT-SYM-NEXT: Section: Undefined (0x0) + +!ELF +FileHeader: !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: "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: 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/elf/Mips/rel-dynamic-03-micro.test b/test/elf/Mips/rel-dynamic-03-micro.test new file mode 100644 index 0000000000000..5de2cdcdc131d --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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/elf/Mips/rel-dynamic-03.test b/test/elf/Mips/rel-dynamic-03.test new file mode 100644 index 0000000000000..cc791b051748a --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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: 21 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/elf/Mips/rel-dynamic-04-micro.test b/test/elf/Mips/rel-dynamic-04-micro.test new file mode 100644 index 0000000000000..1c58efdf5f70d --- /dev/null +++ b/test/elf/Mips/rel-dynamic-04-micro.test @@ -0,0 +1,211 @@ +# 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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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.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: ] + +# 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/elf/Mips/rel-dynamic-04.test b/test/elf/Mips/rel-dynamic-04.test new file mode 100644 index 0000000000000..5b5bcce01cd83 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-04.test @@ -0,0 +1,206 @@ +# 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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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.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: ] + +# 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/elf/Mips/rel-dynamic-05-micro.test b/test/elf/Mips/rel-dynamic-05-micro.test new file mode 100644 index 0000000000000..d1c87076b596c --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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/elf/Mips/rel-dynamic-05.test b/test/elf/Mips/rel-dynamic-05.test new file mode 100644 index 0000000000000..3bfbd3f6efdbc --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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: 0x400190 +# PLT-NEXT: Offset: 0x190 +# 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: 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: 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: 0x4001D0 +# 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: 0x4001E0 +# 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: 0x4001F0 +# 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/elf/Mips/rel-dynamic-06-64.test b/test/elf/Mips/rel-dynamic-06-64.test new file mode 100644 index 0000000000000..c153eb22af4c5 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-06-64.test @@ -0,0 +1,101 @@ +# 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 gnu -target mips64el -shared -o %t.so %t.o +# RUN: llvm-readobj -dt -r -s %t.so | FileCheck -check-prefix=CHECK %s + +# CHECK: Sections [ +# CHECK: Section { +# CHECK-NOT: Name: .plt ({{[0-9]+}}) + +# CHECK: Relocations [ +# CHECK-NEXT: Section (4) .rel.dyn { +# CHECK-NEXT: 0x170 R_MIPS_REL32/R_MIPS_64/R_MIPS_NONE T0 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: T1@ (4) +# CHECK-NEXT: Value: 0x174 +# CHECK-NEXT: Size: 4 +# 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: T0@ (1) +# CHECK-NEXT: Value: 0x170 +# CHECK-NEXT: Size: 4 +# CHECK-NEXT: Binding: Global (0x1) +# CHECK-NEXT: Type: Function (0x2) +# CHECK-NEXT: Other: 0 +# CHECK-NEXT: Section: .text (0x5) +# CHECK-NEXT: } +# 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_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/elf/Mips/rel-dynamic-06.test b/test/elf/Mips/rel-dynamic-06.test new file mode 100644 index 0000000000000..433eb5fadf59f --- /dev/null +++ b/test/elf/Mips/rel-dynamic-06.test @@ -0,0 +1,103 @@ +# 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-obj +# RUN: lld -flavor gnu -target mipsel -shared -o %t1-so %t-obj +# RUN: llvm-readobj -dt -r -s %t1-so | FileCheck -check-prefix=PLT1 %s + +# PLT1-SYM: Sections [ +# PLT1-SYM: Section { +# PLT1-SYM-NOT: Name: .plt ({{[0-9]+}}) + +# PLT1: Relocations [ +# PLT1-NEXT: Section (4) .rel.dyn { +# PLT1-NEXT: 0x100 R_MIPS_REL32 T0 0x0 +# PLT1-NEXT: } +# PLT1-NEXT: ] + +# PLT1: DynamicSymbols [ +# PLT1-NEXT: Symbol { +# PLT1-NEXT: Name: @ (0) +# PLT1-NEXT: Value: 0x0 +# PLT1-NEXT: Size: 0 +# PLT1-NEXT: Binding: Local (0x0) +# PLT1-NEXT: Type: None (0x0) +# PLT1-NEXT: Other: 0 +# PLT1-NEXT: Section: Undefined (0x0) +# PLT1-NEXT: } +# PLT1-NEXT: Symbol { +# PLT1-NEXT: Name: T1@ (4) +# PLT1-NEXT: Value: 0x104 +# PLT1-NEXT: Size: 4 +# PLT1-NEXT: Binding: Global (0x1) +# PLT1-NEXT: Type: Function (0x2) +# PLT1-NEXT: Other: 0 +# PLT1-NEXT: Section: .text (0x5) +# PLT1-NEXT: } +# PLT1-NEXT: Symbol { +# PLT1-NEXT: Name: T0@ (1) +# PLT1-NEXT: Value: 0x100 +# PLT1-NEXT: Size: 4 +# PLT1-NEXT: Binding: Global (0x1) +# PLT1-NEXT: Type: Function (0x2) +# PLT1-NEXT: Other: 0 +# PLT1-NEXT: Section: .text (0x5) +# PLT1-NEXT: } +# PLT1-NEXT: ] + +!ELF +FileHeader: !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: "0000000000000000" + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0x00 + Symbol: T0 + Type: R_MIPS_32 + +- Name: .pdr + Type: SHT_PROGBITS + Content: "0000000000000000" + AddressAlign: 16 + Flags: [] + +- Name: .rel.pdr + Type: SHT_REL + Info: .pdr + 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 + Section: .text + Type: STT_FUNC + Value: 0x4 + Size: 4 diff --git a/test/elf/Mips/rel-dynamic-07-64.test b/test/elf/Mips/rel-dynamic-07-64.test new file mode 100644 index 0000000000000..f7a1c44258234 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-07-64.test @@ -0,0 +1,261 @@ +# 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 gnu -target mips64el -shared -o %t1.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 + +# 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: ] + +# 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/elf/Mips/rel-dynamic-07.test b/test/elf/Mips/rel-dynamic-07.test new file mode 100644 index 0000000000000..fc163b9a12f7e --- /dev/null +++ b/test/elf/Mips/rel-dynamic-07.test @@ -0,0 +1,276 @@ +# 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 gnu -target mipsel -shared -o %t1.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 + +# 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: ] + +# 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/elf/Mips/rel-dynamic-08-64.test b/test/elf/Mips/rel-dynamic-08-64.test new file mode 100644 index 0000000000000..d845d7407c1c4 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-08-64.test @@ -0,0 +1,233 @@ +# 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 gnu -target mips64el -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 + +# 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: ] + +# 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/elf/Mips/rel-dynamic-08-micro.test b/test/elf/Mips/rel-dynamic-08-micro.test new file mode 100644 index 0000000000000..de0038956086e --- /dev/null +++ b/test/elf/Mips/rel-dynamic-08-micro.test @@ -0,0 +1,236 @@ +# 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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 + +# 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: ] + +# 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/elf/Mips/rel-dynamic-08.test b/test/elf/Mips/rel-dynamic-08.test new file mode 100644 index 0000000000000..62f4dc278b051 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-08.test @@ -0,0 +1,233 @@ +# 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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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 + +# 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: ] + +# 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/elf/Mips/rel-dynamic-09-micro.test b/test/elf/Mips/rel-dynamic-09-micro.test new file mode 100644 index 0000000000000..07ffce9eb0744 --- /dev/null +++ b/test/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 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/elf/Mips/rel-dynamic-09.test b/test/elf/Mips/rel-dynamic-09.test new file mode 100644 index 0000000000000..18eeb9dd33d8c --- /dev/null +++ b/test/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 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/elf/Mips/rel-dynamic-10-micro.test b/test/elf/Mips/rel-dynamic-10-micro.test new file mode 100644 index 0000000000000..6b3f2af3db322 --- /dev/null +++ b/test/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 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/elf/Mips/rel-dynamic-10.test b/test/elf/Mips/rel-dynamic-10.test new file mode 100644 index 0000000000000..4df558167fc79 --- /dev/null +++ b/test/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 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/elf/Mips/rel-dynamic-11.test b/test/elf/Mips/rel-dynamic-11.test new file mode 100644 index 0000000000000..20295396cd083 --- /dev/null +++ b/test/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 gnu -target mipsel -shared -o %t1.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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/elf/Mips/rel-dynamic-12.test b/test/elf/Mips/rel-dynamic-12.test new file mode 100644 index 0000000000000..2a4061ab40359 --- /dev/null +++ b/test/elf/Mips/rel-dynamic-12.test @@ -0,0 +1,213 @@ +# 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 gnu -target mipsel -shared -o %t.so %t-so.o +# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o +# RUN: lld -flavor 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: 0x402014 R_MIPS_REL32 T2 0x0 +# PLT-SYM-NEXT: 0x402014 R_MIPS_REL32 D2 0x0 +# PLT-SYM-NEXT: 0x402018 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: 0x402018 +# 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 (0xD) +# PLT-SYM-NEXT: } +# PLT-SYM-NEXT: Symbol { +# PLT-SYM-NEXT: Name: T1@ (4) +# PLT-SYM-NEXT: Value: 0x400220 +# 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: ] + +# 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/elf/Mips/rel-gprel16.test b/test/elf/Mips/rel-gprel16.test new file mode 100644 index 0000000000000..dc188ea6825a7 --- /dev/null +++ b/test/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 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 (1) +# SYM-NEXT: Value: 0xCC +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Local (0x0) +# SYM-NEXT: Type: Function (0x2) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .text (0x4) + +# SYM: Name: G1 (4) +# SYM-NEXT: Value: 0xD0 +# SYM-NEXT: Size: 4 +# SYM-NEXT: Binding: Global (0x1) +# SYM-NEXT: Type: Function (0x2) +# SYM-NEXT: Other: 0 +# SYM-NEXT: Section: .text (0x4) + +# SYM: Name: _gp (34) +# 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) + +# 0x160db == 0xffff (addend) + 0x00cc (L1) + 0x01f000 (GP0) - 0x8ff0 (_gp) +# SEC: Contents of section .rodata: +# SEC-NEXT: 00d4 db600008 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: ffff0008000000000000000000000000 + +- 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: 000000000000000000000000000000000000000000f00100 + +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/elf/Mips/rel-gprel32-64.test b/test/elf/Mips/rel-gprel32-64.test new file mode 100644 index 0000000000000..723c8e1ee7386 --- /dev/null +++ b/test/elf/Mips/rel-gprel32-64.test @@ -0,0 +1,70 @@ +# Check R_MIPS_GPREL32/R_MIPS_64 relocations handling. + +# RUN: yaml2obj -format=elf %s > %t.o +# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 1200001a0 c871ffff ffffffff c871ffff c871ffff .q.......q...q.. +# CHECK-NEXT: 1200001b0 c871ffff ffffffff 00000000 00000000 .q.............. + +--- +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 + + Global: + - Name: LT1 + Type: STT_FUNC + Section: .text + Value: 0x18 + Size: 0x8 + - Name: T0 + Type: STT_FUNC + Section: .text + Value: 0x0 + Size: 0x18 +... diff --git a/test/elf/Mips/rel-gprel32.test b/test/elf/Mips/rel-gprel32.test new file mode 100644 index 0000000000000..73ae6f161979c --- /dev/null +++ b/test/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 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 (1) +# SYM-NEXT: Value: 0x400108 +# 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 (212) +# 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) + +# 0x08FF711B == 0x8000001 (addend) + 0x400108 ($L1) + +# 0x1000002 (GP0) - 0x408FF0 (_gp) +# SEC: Contents of section .rodata: +# SEC-NEXT: 400118 1b71ff08 00000000 00000000 00000000 .q.............. + +!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/elf/Mips/rel-pc-hilo.test b/test/elf/Mips/rel-pc-hilo.test new file mode 100644 index 0000000000000..89cd2b121797a --- /dev/null +++ b/test/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 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: 400110 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: 00400110 g F .text 0000000c T0 +# CHECK: 0040011c 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/elf/Mips/rel-pc18-s3.test b/test/elf/Mips/rel-pc18-s3.test new file mode 100644 index 0000000000000..5d5d5c7ce658e --- /dev/null +++ b/test/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 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: 400110 00000000 01000000 00000000 00000000 +# ^ V +# A = -1 << 3 = -8 => +# V = (T1 - 8 - (T0|7)^7) >> 3 => +# V => 8 >> 3 = 1 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 00000010 T0 +# CHECK: 00400120 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/elf/Mips/rel-pc19-s2.test b/test/elf/Mips/rel-pc19-s2.test new file mode 100644 index 0000000000000..479965df814fa --- /dev/null +++ b/test/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 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: 400110 01000000 00000000 00000000 +# ^ V +# A = -1 << 2 = -4 => +# V = (T1 - 4 - T0) >> 2 => +# V => 4 >> 2 = 1 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 00000008 T0 +# CHECK: 00400118 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/elf/Mips/rel-pc21-s2.test b/test/elf/Mips/rel-pc21-s2.test new file mode 100644 index 0000000000000..44d840e94c32c --- /dev/null +++ b/test/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 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: 400110 01000000 00000000 00000000 +# ^ V +# A = -1 << 2 = -4 => +# V = (T1 - 4 - T0) >> 2 => +# V => 4 >> 2 = 1 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 00000008 T0 +# CHECK: 00400118 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/elf/Mips/rel-pc26-s2.test b/test/elf/Mips/rel-pc26-s2.test new file mode 100644 index 0000000000000..abd05040f0c34 --- /dev/null +++ b/test/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 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: 400110 01000000 00000000 00000000 +# ^ V +# A = -1 << 2 = -4 => +# V = (T1 - 4 - T0) >> 2 => +# V => 4 >> 2 = 1 + +# CHECK: SYMBOL TABLE: +# CHECK: 00400110 g F .text 00000008 T0 +# CHECK: 00400118 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/elf/Mips/rel-pc32.test b/test/elf/Mips/rel-pc32.test new file mode 100644 index 0000000000000..e448e8afc30e5 --- /dev/null +++ b/test/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 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 05000080 fdffff7f ............ +# ^^ data2 + 0x80000001 - data1 +# ^^ data1 + 0x80000001 - data2 +# 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_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/elf/Mips/rel-pc7-10-16-23.test b/test/elf/Mips/rel-pc7-10-16-23.test new file mode 100644 index 0000000000000..c38b9eed2a5ee --- /dev/null +++ b/test/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 gnu -target mipsel -o %t-exe %t-obj +# RUN: llvm-objdump -s -t %t-exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK-NEXT: 400110 00000000 80780500 a240fcff 000c03cc .....x...@...... +# ^^ addiu s1,$pc,20 +# ^^ bnezc v0,400114 <__start+0x4> +# ^^ b 400126 <L1> +# CHECK-NEXT: 400120 000c03ad 00000000 00000000 00000000 ................ +# ^^ bnez v0,40012a <L2> +# CHECK: SYMBOL TABLE: +# CHECK: 00400124 l F .text 00000002 L0 +# CHECK: 00400126 l F .text 00000004 L1 +# CHECK: 0040012a l F .text 00000004 L2 +# CHECK: 0040012e l F .text 00000002 L3 +# CHECK: 00400110 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/elf/Mips/rel-sub.test b/test/elf/Mips/rel-sub.test new file mode 100644 index 0000000000000..93e569a22035f --- /dev/null +++ b/test/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 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/elf/Mips/st-other.test b/test/elf/Mips/st-other.test new file mode 100644 index 0000000000000..8d15e75676b0b --- /dev/null +++ b/test/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 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 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: 0xEC +# 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: 0xF1 +# 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: 0x400108 +# 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: 0x40010D +# 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/elf/Mips/tls-1-micro.test b/test/elf/Mips/tls-1-micro.test new file mode 100644 index 0000000000000..bd962b4e9e804 --- /dev/null +++ b/test/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 gnu -target mipsel -e L0 -o %t.exe %t.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400150 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/elf/Mips/tls-1.test b/test/elf/Mips/tls-1.test new file mode 100644 index 0000000000000..99176e69171d5 --- /dev/null +++ b/test/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 gnu -target mipsel -e L0 -o %t.exe %t.o +# RUN: llvm-objdump -s %t.exe | FileCheck %s + +# CHECK: Contents of section .text: +# CHECK: 400150 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/elf/Mips/tls-2-64.test b/test/elf/Mips/tls-2-64.test new file mode 100644 index 0000000000000..a068934aeafa5 --- /dev/null +++ b/test/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 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/elf/Mips/tls-2-micro.test b/test/elf/Mips/tls-2-micro.test new file mode 100644 index 0000000000000..5a1fe2904ac96 --- /dev/null +++ b/test/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 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/elf/Mips/tls-2.test b/test/elf/Mips/tls-2.test new file mode 100644 index 0000000000000..32b2bc1051122 --- /dev/null +++ b/test/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 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/elf/Mips/tls-3-micro.test b/test/elf/Mips/tls-3-micro.test new file mode 100644 index 0000000000000..0e0f3d556f8f3 --- /dev/null +++ b/test/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 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 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/elf/Mips/tls-3.test b/test/elf/Mips/tls-3.test new file mode 100644 index 0000000000000..7e54724fade5a --- /dev/null +++ b/test/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 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 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/elf/Mips/tls-4-micro.test b/test/elf/Mips/tls-4-micro.test new file mode 100644 index 0000000000000..1b0d03fa88753 --- /dev/null +++ b/test/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 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/elf/Mips/tls-4.test b/test/elf/Mips/tls-4.test new file mode 100644 index 0000000000000..fb42f0d93378c --- /dev/null +++ b/test/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 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/elf/Mips/tls-5-64.test b/test/elf/Mips/tls-5-64.test new file mode 100644 index 0000000000000..784d71efc48f4 --- /dev/null +++ b/test/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 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/elf/Mips/tls-5-micro.test b/test/elf/Mips/tls-5-micro.test new file mode 100644 index 0000000000000..89d1d98a6877f --- /dev/null +++ b/test/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 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/elf/Mips/tls-5.test b/test/elf/Mips/tls-5.test new file mode 100644 index 0000000000000..378ce321b8c92 --- /dev/null +++ b/test/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 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 +... |