1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 11:02:59 +02:00

llvm-readobj: Fix addend in relocations for android packed format

If a relocation group doesn't have the RELOCATION_GROUP_HAS_ADDEND_FLAG set, then this implies the group's addend equals zero.
In this case android packed format won't encode an explicit addend delta, instead we need to set Addend, the "previous addend" variable, to zero by ourself.

Patch by Yi-Yo Chiang!

Differential Revision: https://reviews.llvm.org/D50601

llvm-svn: 339799
This commit is contained in:
Peter Collingbourne 2018-08-15 17:58:22 +00:00
parent 7eea989e53
commit 69450b777d
2 changed files with 48 additions and 9 deletions

View File

@ -393,20 +393,17 @@ ELFFile<ELFT>::android_relas(const Elf_Shdr *Sec) const {
if (GroupedByAddend && GroupHasAddend)
Addend += ReadSLEB();
if (!GroupHasAddend)
Addend = 0;
for (uint64_t I = 0; I != NumRelocsInGroup; ++I) {
Elf_Rela R;
Offset += GroupedByOffsetDelta ? GroupOffsetDelta : ReadSLEB();
R.r_offset = Offset;
R.r_info = GroupedByInfo ? GroupRInfo : ReadSLEB();
if (GroupHasAddend) {
if (!GroupedByAddend)
Addend += ReadSLEB();
R.r_addend = Addend;
} else {
R.r_addend = 0;
}
if (GroupHasAddend && !GroupedByAddend)
Addend += ReadSLEB();
R.r_addend = Addend;
Relocs.push_back(R);
if (ErrStr)

View File

@ -94,3 +94,45 @@ Symbols:
- Name: sym1
- Name: sym2
...
# RUN: yaml2obj -docnum 3 %s | llvm-readobj -elf-output-style=LLVM -relocations - | FileCheck --check-prefix=LLVM3 %s
#
# LLVM3: Section (1) .rela.dyn {
# LLVM3-NEXT: 0x1100 R_X86_64_RELATIVE - 0x0
# LLVM3-NEXT: 0x1180 R_X86_64_RELATIVE - 0x8
# LLVM3-NEXT: 0x1200 R_X86_64_64 sym1 0x0
# LLVM3-NEXT: 0x1208 R_X86_64_64 sym2 0x0
# LLVM3-NEXT: 0x1210 R_X86_64_64 sym1 0x0
# LLVM3-NEXT: 0x1218 R_X86_64_64 sym2 0x8
# LLVM3-NEXT: }
# RUN: yaml2obj -docnum 3 %s | llvm-readobj -elf-output-style=GNU -relocations - | FileCheck --check-prefix=GNU3 %s
# GNU3: Relocation section '.rela.dyn' at offset 0x180 contains 6 entries:
# GNU3: 0000000000001100 0000000000000008 R_X86_64_RELATIVE 0
# GNU3-NEXT: 0000000000001180 0000000000000008 R_X86_64_RELATIVE 8
# GNU3-NEXT: 0000000000001200 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 0
# GNU3-NEXT: 0000000000001208 0000000200000001 R_X86_64_64 0000000000000000 sym2 + 0
# GNU3-NEXT: 0000000000001210 0000000100000001 R_X86_64_64 0000000000000000 sym1 + 0
# GNU3-NEXT: 0000000000001218 0000000200000001 R_X86_64_64 0000000000000000 sym2 + 8
# elf-packed-relocs3.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: 415053320680200208800208008001080802008001818080801008818080802002080881808080100008818080802008
Symbols:
Global:
- Name: sym1
- Name: sym2
...