[Mips] Handle relocations against __gnu_local_gp symbol.

llvm-svn: 209644
This commit is contained in:
Simon Atanasyan 2014-05-27 05:23:16 +00:00
parent 82ac07c283
commit 1c04babce3
9 changed files with 161 additions and 29 deletions

View File

@ -52,6 +52,7 @@ public:
setAtomValue("_GLOBAL_OFFSET_TABLE_", got);
setAtomValue("_gp", gp);
setAtomValue("_gp_disp", gp);
setAtomValue("__gnu_local_gp", gp);
}
bool hasGlobalGOTEntry(const Atom *a) const {
@ -64,6 +65,7 @@ public:
file->addAbsoluteAtom("_GLOBAL_OFFSET_TABLE_");
file->addAbsoluteAtom("_gp");
file->addAbsoluteAtom("_gp_disp");
file->addAbsoluteAtom("__gnu_local_gp");
}
return file;
}

View File

@ -26,7 +26,7 @@
# CHECK: Version: 1
# CHECK: Entry: 0xF0
# CHECK: ProgramHeaderOffset: 0x34
# CHECK: SectionHeaderOffset: 0x20E0
# CHECK: SectionHeaderOffset: 0x2100
# CHECK: Flags [ (0x70001007)
# CHECK: EF_MIPS_ABI_O32 (0x1000)
# CHECK: EF_MIPS_ARCH_32R2 (0x70000000)

View File

@ -31,7 +31,7 @@
# CHECK: Version: 1
# CHECK: Entry: 0x4001A0
# CHECK: ProgramHeaderOffset: 0x34
# CHECK: SectionHeaderOffset: 0x2268
# CHECK: SectionHeaderOffset: 0x2288
# CHECK: Flags [ (0x70001005)
# CHECK: EF_MIPS_ABI_O32 (0x1000)
# CHECK: EF_MIPS_ARCH_32R2 (0x70000000)

View File

@ -0,0 +1,59 @@
# Check that relocations against __gnu_local_gp use "gp" value as target.
# RUN: yaml2obj -format=elf %S/Inputs/pic-obj.yaml > %t-pic.o
# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-pic.o
# RUN: yaml2obj -format=elf %s > %t.o
# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.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: 4001a0 41000000 f08f0000 64001000 A.......d...
# SEC: Contents of section .got:
# SEC-NEXT: 401000 00000000 00000080 ........
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

View File

@ -0,0 +1,71 @@
# 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 %S/Inputs/pic-obj.yaml > %t-pic.o
# RUN: lld -flavor gnu -target mipsel -shared -o %t-ext.so %t-pic.o
# RUN: yaml2obj -format=elf %s > %t.o
# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o %t-ext.so
# RUN: llvm-readobj -r %t.exe | FileCheck -check-prefix=EXE %s
# RUN: lld -flavor gnu -target mipsel -shared -o %t.exe %t.o %t-ext.so
# RUN: llvm-readobj -r %t.exe | 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: ]
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

View File

@ -69,7 +69,7 @@
# PLT-SYM-NEXT: Section: .bss (0xD)
# PLT-SYM-NEXT: }
# PLT-SYM-NEXT: Symbol {
# PLT-SYM-NEXT: Name: T3@ (7)
# PLT-SYM-NEXT: Name: T3@ (4)
# PLT-SYM-NEXT: Value: 0x0
# PLT-SYM-NEXT: Size: 0
# PLT-SYM-NEXT: Binding: Global (0x1)
@ -78,7 +78,7 @@
# PLT-SYM-NEXT: Section: Undefined (0x0)
# PLT-SYM-NEXT: }
# PLT-SYM-NEXT: Symbol {
# PLT-SYM-NEXT: Name: T1@ (10)
# PLT-SYM-NEXT: Name: T1@ (7)
# PLT-SYM-NEXT: Value: 0x400240
# PLT-SYM-NEXT: Size: 0
# PLT-SYM-NEXT: Binding: Global (0x1)
@ -96,7 +96,7 @@
# PLT-SYM-NEXT: Section: Undefined (0x0)
# PLT-SYM-NEXT: }
# PLT-SYM-NEXT: Symbol {
# PLT-SYM-NEXT: Name: T2@ (4)
# PLT-SYM-NEXT: Name: T2@ (10)
# PLT-SYM-NEXT: Value: 0x0
# PLT-SYM-NEXT: Size: 0
# PLT-SYM-NEXT: Binding: Global (0x1)

View File

@ -86,16 +86,7 @@
# PLT-NEXT: Section: Undefined (0x0)
# PLT-NEXT: }
# PLT-NEXT: Symbol {
# PLT-NEXT: Name: T2@ (1)
# 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@ (4)
# PLT-NEXT: Name: T3@ (1)
# PLT-NEXT: Value: 0x4010F0
# PLT-NEXT: Size: 0
# PLT-NEXT: Binding: Global (0x1)
@ -104,7 +95,16 @@
# PLT-NEXT: Section: Undefined (0x0)
# PLT-NEXT: }
# PLT-NEXT: Symbol {
# PLT-NEXT: Name: T1@ (7)
# PLT-NEXT: Name: T2@ (7)
# 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: T1@ (4)
# PLT-NEXT: Value: 0x0
# PLT-NEXT: Size: 0
# PLT-NEXT: Binding: Global (0x1)

View File

@ -68,16 +68,7 @@
# PLT-NEXT: Section: Undefined (0x0)
# PLT-NEXT: }
# PLT-NEXT: Symbol {
# PLT-NEXT: Name: T2@ (1)
# 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: Symbol {
# PLT-NEXT: Name: T3@ (4)
# PLT-NEXT: Name: T3@ (1)
# PLT-NEXT: Value: 0x400200
# PLT-NEXT: Size: 0
# PLT-NEXT: Binding: Global (0x1)
@ -86,7 +77,7 @@
# PLT-NEXT: Section: Undefined (0x0)
# PLT-NEXT: }
# PLT-NEXT: Symbol {
# PLT-NEXT: Name: T1@ (7)
# PLT-NEXT: Name: T1@ (4)
# PLT-NEXT: Value: 0x4001E0
# PLT-NEXT: Size: 0
# PLT-NEXT: Binding: Global (0x1)
@ -94,6 +85,15 @@
# PLT-NEXT: Other: 8
# PLT-NEXT: Section: Undefined (0x0)
# PLT-NEXT: }
# PLT-NEXT: Symbol {
# PLT-NEXT: Name: T2@ (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: ]
!ELF

View File

@ -45,7 +45,7 @@
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: T1@ (4)
# CHECK-NEXT: Name: T1@ (1)
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Binding: Global (0x1)
@ -54,7 +54,7 @@
# CHECK-NEXT: Section: Undefined (0x0)
# CHECK-NEXT: }
# CHECK-NEXT: Symbol {
# CHECK-NEXT: Name: T2@ (1)
# CHECK-NEXT: Name: T2@ (4)
# CHECK-NEXT: Value: 0x0
# CHECK-NEXT: Size: 0
# CHECK-NEXT: Binding: Global (0x1)