Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
llvm-readobj: Add support for reading relocations in the Android pack…
…ed format. This is in preparation for testing lld's upcoming relocation packing feature (D39152). I have verified that this implementation correctly unpacks the relocations from a Chromium DSO built with gold and the Android relocation packer for ARM32 and ARM64. Differential Revision: https://reviews.llvm.org/D39272 llvm-svn: 316543
- Loading branch information
Showing
14 changed files
with
338 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.ascii "APS2" | ||
.sleb128 8 // Number of relocations | ||
.sleb128 4096 // Initial offset | ||
|
||
.sleb128 2 // Number of relocations in group | ||
.sleb128 1 // RELOCATION_GROUPED_BY_INFO_FLAG | ||
.sleb128 8 // R_X86_RELATIVE | ||
|
||
.sleb128 256 // Reloc 1: r_offset delta | ||
.sleb128 128 // Reloc 2: r_offset delta | ||
|
||
.sleb128 2 // Number of relocations in group | ||
.sleb128 2 // RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG | ||
.sleb128 8 // offset delta | ||
|
||
.sleb128 (1 << 32) | 1 // R_X86_64_64 (sym index 1) | ||
.sleb128 (2 << 32) | 1 // R_X86_64_64 (sym index 2) | ||
|
||
.sleb128 2 // Number of relocations in group | ||
.sleb128 8 // RELOCATION_GROUP_HAS_ADDEND_FLAG | ||
|
||
.sleb128 1 // offset delta | ||
.sleb128 (1 << 32) | 1 // R_X86_64_64 (sym index 1) | ||
.sleb128 8 // addend delta | ||
|
||
.sleb128 2 // offset delta | ||
.sleb128 (2 << 32) | 1 // R_X86_64_64 (sym index 2) | ||
.sleb128 4 // addend delta | ||
|
||
.sleb128 2 // Number of relocations in group | ||
.sleb128 12 // RELOCATION_GROUP_HAS_ADDEND_FLAG | RELOCATION_GROUPED_BY_ADDEND_FLAG | ||
.sleb128 -2 // addend delta | ||
|
||
.sleb128 4 // offset delta | ||
.sleb128 (1 << 32) | 1 // R_X86_64_64 (sym index 1) | ||
.sleb128 8 // offset delta | ||
.sleb128 (2 << 32) | 1 // R_X86_64_64 (sym index 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.ascii "APS2" | ||
.sleb128 10 // Number of relocations | ||
.sleb128 4096 // Initial offset | ||
|
||
.sleb128 2 // Number of relocations in group | ||
.sleb128 2 // RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG | ||
.sleb128 8 // offset delta | ||
|
||
.sleb128 (1 << 8) | 1 // R_386_32 (sym index 1) | ||
.sleb128 (2 << 8) | 3 // R_386_GOT32 (sym index 2) | ||
|
||
.sleb128 8 // Number of relocations in group | ||
.sleb128 3 // RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG | RELOCATION_GROUPED_BY_INFO_FLAG | ||
.sleb128 -4 // offset delta | ||
.sleb128 8 // R_386_RELATIVE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | llvm-readobj -relocations - | FileCheck %s | ||
|
||
// CHECK: Relocations [ | ||
// CHECK-NEXT: Section (3) .rela.dyn { | ||
// CHECK-NEXT: } | ||
// CHECK-NEXT: ] | ||
|
||
.section .rela.dyn, "a", @0x60000001 | ||
.ascii "APS2" | ||
.sleb128 0 | ||
.sleb128 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s | ||
|
||
// CHECK: Error reading file: invalid packed relocation header | ||
|
||
.section .rela.dyn, "a", @0x60000001 | ||
.ascii "APS9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s | ||
|
||
// CHECK: Error reading file: malformed sleb128, extends past end | ||
|
||
.section .rela.dyn, "a", @0x60000001 | ||
.ascii "APS2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s | ||
|
||
// CHECK: Error reading file: malformed sleb128, extends past end | ||
|
||
.section .rela.dyn, "a", @0x60000001 | ||
.ascii "APS2" | ||
.sleb128 4 // Number of relocations | ||
.sleb128 0 // Initial offset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s | ||
|
||
// CHECK: Error reading file: malformed sleb128, extends past end | ||
|
||
.section .rela.dyn, "a", @0x60000001 | ||
.ascii "APS2" | ||
.sleb128 4 // Number of relocations | ||
.sleb128 0 // Initial offset | ||
|
||
.sleb128 2 // Number of relocations in group | ||
.sleb128 2 // RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG | ||
.sleb128 8 // offset delta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// RUN: llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu %s -o - | not llvm-readobj -relocations - 2>&1 | FileCheck %s | ||
|
||
// CHECK: Error reading file: relocation group unexpectedly large | ||
|
||
.section .rela.dyn, "a", @0x60000001 | ||
.ascii "APS2" | ||
.sleb128 4 // Number of relocations | ||
.sleb128 0 // Initial offset | ||
|
||
.sleb128 5 // Number of relocations in group | ||
.sleb128 2 // RELOCATION_GROUPED_BY_OFFSET_DELTA_FLAG | ||
.sleb128 8 // offset delta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# The binary blobs in this file were created like this: | ||
# llvm-mc -filetype=obj -triple x86_64-pc-linux-gnu Inputs/elf-packed-relocs1.s -o - | obj2yaml | grep Content: | ||
|
||
# RUN: yaml2obj -docnum 1 %s | llvm-readobj -elf-output-style=LLVM -relocations - | FileCheck --check-prefix=LLVM1 %s | ||
# LLVM1: Section (1) .rela.dyn { | ||
# LLVM1-NEXT: 0x1100 R_X86_64_RELATIVE - 0x0 | ||
# LLVM1-NEXT: 0x1180 R_X86_64_RELATIVE - 0x0 | ||
# LLVM1-NEXT: 0x1188 R_X86_64_64 sym1 0x0 | ||
# LLVM1-NEXT: 0x1190 R_X86_64_64 sym2 0x0 | ||
# LLVM1-NEXT: 0x1191 R_X86_64_64 sym1 0x8 | ||
# LLVM1-NEXT: 0x1193 R_X86_64_64 sym2 0xC | ||
# LLVM1-NEXT: 0x1197 R_X86_64_64 sym1 0xA | ||
# LLVM1-NEXT: 0x119F R_X86_64_64 sym2 0xA | ||
# LLVM1-NEXT: } | ||
|
||
# RUN: yaml2obj -docnum 1 %s | llvm-readobj -elf-output-style=GNU -relocations - | FileCheck --check-prefix=GNU1 %s | ||
# GNU1: 0000000000001100 0000000000000008 R_X86_64_RELATIVE 0 | ||
# GNU1-NEXT: 0000000000001180 0000000000000008 R_X86_64_RELATIVE 0 | ||
# GNU1-NEXT: 0000000000001188 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 0 | ||
# GNU1-NEXT: 0000000000001190 0000000200000001 R_X86_64_64 0000000000000000 sym2 + 0 | ||
# GNU1-NEXT: 0000000000001191 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 8 | ||
# GNU1-NEXT: 0000000000001193 0000000200000001 R_X86_64_64 0000000000000000 sym2 + c | ||
# GNU1-NEXT: 0000000000001197 0000000100000001 R_X86_64_64 0000000000000000 sym1 + a | ||
# GNU1-NEXT: 000000000000119f 0000000200000001 R_X86_64_64 0000000000000000 sym2 + a | ||
|
||
# elf-packed-relocs1.s | ||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS64 | ||
Data: ELFDATA2LSB | ||
Type: ET_DYN | ||
Machine: EM_X86_64 | ||
Entry: 0x0000000000001000 | ||
Sections: | ||
- Name: .rela.dyn | ||
Type: SHT_ANDROID_RELA | ||
Flags: [ SHF_ALLOC ] | ||
Address: 0x00000000000001C8 | ||
Link: .symtab | ||
AddressAlign: 0x0000000000000001 | ||
Content: 41505332088020020108800280010202088180808010818080802002080181808080100802818080802004020C7E048180808010088180808020 | ||
Symbols: | ||
Global: | ||
- Name: sym1 | ||
- Name: sym2 | ||
... | ||
|
||
# RUN: yaml2obj -docnum 2 %s | llvm-readobj -elf-output-style=LLVM -relocations - | FileCheck --check-prefix=LLVM2 %s | ||
# LLVM2: Section (1) .rel.dyn { | ||
# LLVM2-NEXT: 0x1008 R_386_32 sym1 0x0 | ||
# LLVM2-NEXT: 0x1010 R_386_GOT32 sym2 0x0 | ||
# LLVM2-NEXT: 0x100C R_386_RELATIVE - 0x0 | ||
# LLVM2-NEXT: 0x1008 R_386_RELATIVE - 0x0 | ||
# LLVM2-NEXT: 0x1004 R_386_RELATIVE - 0x0 | ||
# LLVM2-NEXT: 0x1000 R_386_RELATIVE - 0x0 | ||
# LLVM2-NEXT: 0xFFC R_386_RELATIVE - 0x0 | ||
# LLVM2-NEXT: 0xFF8 R_386_RELATIVE - 0x0 | ||
# LLVM2-NEXT: 0xFF4 R_386_RELATIVE - 0x0 | ||
# LLVM2-NEXT: 0xFF0 R_386_RELATIVE - 0x0 | ||
# LLVM2-NEXT: } | ||
|
||
# RUN: yaml2obj -docnum 2 %s | llvm-readobj -elf-output-style=GNU -relocations - | FileCheck --check-prefix=GNU2 %s | ||
# GNU2: 00001008 00000101 R_386_32 00000000 sym1 | ||
# GNU2-NEXT: 00001010 00000203 R_386_GOT32 00000000 sym2 | ||
# GNU2-NEXT: 0000100c 00000008 R_386_RELATIVE | ||
# GNU2-NEXT: 00001008 00000008 R_386_RELATIVE | ||
# GNU2-NEXT: 00001004 00000008 R_386_RELATIVE | ||
# GNU2-NEXT: 00001000 00000008 R_386_RELATIVE | ||
# GNU2-NEXT: 00000ffc 00000008 R_386_RELATIVE | ||
# GNU2-NEXT: 00000ff8 00000008 R_386_RELATIVE | ||
# GNU2-NEXT: 00000ff4 00000008 R_386_RELATIVE | ||
# GNU2-NEXT: 00000ff0 00000008 R_386_RELATIVE | ||
|
||
# elf-packed-relocs2.s | ||
--- !ELF | ||
FileHeader: | ||
Class: ELFCLASS32 | ||
Data: ELFDATA2LSB | ||
Type: ET_DYN | ||
Machine: EM_386 | ||
Entry: 0x0000000000001000 | ||
Sections: | ||
- Name: .rel.dyn | ||
Type: SHT_ANDROID_REL | ||
Flags: [ SHF_ALLOC ] | ||
Address: 0x00000000000001C8 | ||
Link: .symtab | ||
AddressAlign: 0x0000000000000001 | ||
Content: 415053320A80200202088102830408037C08 | ||
Symbols: | ||
Global: | ||
- Name: sym1 | ||
- Name: sym2 | ||
... |
Oops, something went wrong.