| # Conditions: |
| # a) Linking a non-shared executable file. |
| # b) Relocations' targets are symbols defined in the shared object. |
| # c) Relocations modify a writable section. |
| # d) The first symbol is referenced by R_MIPS32 relocation only |
| # e) The second symbol is referenced by R_MIPS_32 and R_MIPS26 relocations. |
| # f) The third symbol is referenced by R_MIPS26 and R_MIPS_32 relocations. |
| # Check: |
| # a) There should be the only R_MIPS_REL32 relocation. |
| # b) Linker creates a couple of PLT entry for both symbols referenced |
| # by the R_MIPS_26 branch relocation. |
| # c) STO_MIPS_PLT flag in the dynamic symbol table for symbols require |
| # a pointer equality. |
| # |
| # RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o |
| # RUN: lld -flavor old-gnu -target mipsel -shared -o %t.so %t-so.o |
| # RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o |
| # RUN: lld -flavor old-gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so |
| # RUN: llvm-readobj -dt -r -s %t.exe | FileCheck -check-prefix=PLT %s |
| # RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s |
| |
| # PLT: Section { |
| # PLT: Index: 5 |
| # PLT-NEXT: Name: .rel.dyn (31) |
| # PLT-NEXT: Type: SHT_REL (0x9) |
| # PLT-NEXT: Flags [ (0x2) |
| # PLT-NEXT: SHF_ALLOC (0x2) |
| # PLT-NEXT: ] |
| # PLT-NEXT: Address: 0x40109C |
| # PLT-NEXT: Offset: 0x109C |
| # PLT-NEXT: Size: 8 |
| # PLT-NEXT: Link: 3 |
| # PLT-NEXT: Info: 0 |
| # PLT-NEXT: AddressAlignment: 4 |
| # PLT-NEXT: EntrySize: 8 |
| # PLT-NEXT: } |
| # PLT-NEXT: Section { |
| # PLT-NEXT: Index: 6 |
| # PLT-NEXT: Name: .rel.plt (40) |
| # PLT-NEXT: Type: SHT_REL (0x9) |
| # PLT-NEXT: Flags [ (0x2) |
| # PLT-NEXT: SHF_ALLOC (0x2) |
| # PLT-NEXT: ] |
| # PLT-NEXT: Address: 0x4010A4 |
| # PLT-NEXT: Offset: 0x10A4 |
| # PLT-NEXT: Size: 16 |
| # PLT-NEXT: Link: 3 |
| # PLT-NEXT: Info: 0 |
| # PLT-NEXT: AddressAlignment: 4 |
| # PLT-NEXT: EntrySize: 8 |
| # PLT-NEXT: } |
| # PLT-NEXT: Section { |
| # PLT-NEXT: Index: 7 |
| # PLT-NEXT: Name: .plt (49) |
| # PLT-NEXT: Type: SHT_PROGBITS (0x1) |
| # PLT-NEXT: Flags [ (0x6) |
| # PLT-NEXT: SHF_ALLOC (0x2) |
| # PLT-NEXT: SHF_EXECINSTR (0x4) |
| # PLT-NEXT: ] |
| # PLT-NEXT: Address: 0x4010C0 |
| # PLT-NEXT: Offset: 0x10C0 |
| # PLT-NEXT: Size: 64 |
| # PLT-NEXT: Link: 0 |
| # PLT-NEXT: Info: 0 |
| # PLT-NEXT: AddressAlignment: 16 |
| # PLT-NEXT: EntrySize: 0 |
| # PLT-NEXT: } |
| |
| # PLT: Relocations [ |
| # PLT-NEXT: Section (5) .rel.dyn { |
| # PLT-NEXT: 0x400120 R_MIPS_REL32 T1 0x0 |
| # PLT-NEXT: } |
| # PLT-NEXT: Section (6) .rel.plt { |
| # PLT-NEXT: 0x403008 R_MIPS_JUMP_SLOT T2 0x0 |
| # PLT-NEXT: 0x40300C R_MIPS_JUMP_SLOT T3 0x0 |
| # PLT-NEXT: } |
| # PLT-NEXT: ] |
| |
| # PLT: DynamicSymbols [ |
| # PLT-NEXT: Symbol { |
| # PLT-NEXT: Name: @ (0) |
| # PLT-NEXT: Value: 0x0 |
| # PLT-NEXT: Size: 0 |
| # PLT-NEXT: Binding: Local (0x0) |
| # PLT-NEXT: Type: None (0x0) |
| # PLT-NEXT: Other: 0 |
| # PLT-NEXT: Section: Undefined (0x0) |
| # PLT-NEXT: } |
| # PLT-NEXT: Symbol { |
| # PLT-NEXT: Name: T2@ (4) |
| # PLT-NEXT: Value: 0x4010E0 |
| # PLT-NEXT: Size: 0 |
| # PLT-NEXT: Binding: Global (0x1) |
| # PLT-NEXT: Type: Function (0x2) |
| # PLT-NEXT: Other: 8 |
| # PLT-NEXT: Section: Undefined (0x0) |
| # PLT-NEXT: } |
| # PLT-NEXT: Symbol { |
| # PLT-NEXT: Name: T3@ (7) |
| # PLT-NEXT: Value: 0x4010F0 |
| # PLT-NEXT: Size: 0 |
| # PLT-NEXT: Binding: Global (0x1) |
| # PLT-NEXT: Type: Function (0x2) |
| # PLT-NEXT: Other: 8 |
| # PLT-NEXT: Section: Undefined (0x0) |
| # PLT-NEXT: } |
| # PLT-NEXT: Symbol { |
| # PLT-NEXT: Name: T1@ (1) |
| # PLT-NEXT: Value: 0x0 |
| # PLT-NEXT: Size: 0 |
| # PLT-NEXT: Binding: Global (0x1) |
| # PLT-NEXT: Type: Function (0x2) |
| # PLT-NEXT: Other: 0 |
| # PLT-NEXT: Section: Undefined (0x0) |
| # PLT-NEXT: } |
| # PLT-NEXT: ] |
| |
| # GOT: Local entries [ |
| # GOT-NEXT: ] |
| # GOT-NEXT: Global entries [ |
| # GOT-NEXT: Entry { |
| # GOT-NEXT: Address: 0x402008 |
| # GOT-NEXT: Access: -32744 |
| # GOT-NEXT: Initial: 0x0 |
| # GOT-NEXT: Value: 0x0 |
| # GOT-NEXT: Type: Function (0x2) |
| # GOT-NEXT: Section: Undefined (0x0) |
| # GOT-NEXT: Name: T1@ (1) |
| # GOT-NEXT: } |
| # GOT-NEXT: ] |
| |
| # so.o |
| --- |
| FileHeader: |
| Class: ELFCLASS32 |
| Data: ELFDATA2LSB |
| Type: ET_REL |
| Machine: EM_MIPS |
| Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] |
| |
| Sections: |
| - Name: .text |
| Type: SHT_PROGBITS |
| Size: 0x0C |
| AddressAlign: 16 |
| Flags: [SHF_EXECINSTR, SHF_ALLOC] |
| |
| Symbols: |
| Global: |
| - Name: T1 |
| Section: .text |
| Type: STT_FUNC |
| Value: 0x0 |
| Size: 4 |
| - Name: T2 |
| Section: .text |
| Type: STT_FUNC |
| Value: 0x4 |
| Size: 4 |
| - Name: T3 |
| Section: .text |
| Type: STT_FUNC |
| Value: 0x8 |
| Size: 4 |
| |
| # o.o |
| --- |
| FileHeader: !FileHeader |
| Class: ELFCLASS32 |
| Data: ELFDATA2LSB |
| Type: ET_REL |
| Machine: EM_MIPS |
| Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] |
| |
| Sections: |
| - Name: .text |
| Type: SHT_PROGBITS |
| Size: 0x08 |
| AddressAlign: 16 |
| Flags: [SHF_WRITE, SHF_EXECINSTR, SHF_ALLOC] |
| |
| - Name: .rel.text |
| Type: SHT_REL |
| Info: .text |
| AddressAlign: 4 |
| Relocations: |
| # There is no branch relocation for T1. |
| - Offset: 0x00 |
| Symbol: T1 |
| Type: R_MIPS_32 |
| # The R_MIPS_32 relocation for T2 might produce R_MIPS_REL32 ... |
| - Offset: 0x00 |
| Symbol: T2 |
| Type: R_MIPS_32 |
| # ... but R_MIPS_26 creates PLT entry and makes R_MIPS_REL32 redundant. |
| - Offset: 0x04 |
| Symbol: T2 |
| Type: R_MIPS_26 |
| # Create PLT entry for T3 symbol. |
| - Offset: 0x00 |
| Symbol: T3 |
| Type: R_MIPS_26 |
| # Take in account existing PLT entry and do not create R_MIPS_REL32. |
| - Offset: 0x04 |
| Symbol: T3 |
| Type: R_MIPS_32 |
| |
| Symbols: |
| Global: |
| - Name: T0 |
| Section: .text |
| Type: STT_FUNC |
| Value: 0x0 |
| Size: 8 |
| - Name: T1 |
| Type: STT_FUNC |
| - Name: T2 |
| Type: STT_FUNC |
| - Name: T3 |
| Type: STT_FUNC |
| ... |