Index: lib/Object/ELF.cpp =================================================================== --- lib/Object/ELF.cpp +++ lib/Object/ELF.cpp @@ -393,20 +393,17 @@ 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) Index: test/tools/llvm-readobj/Inputs/elf-packed-relocs3.s =================================================================== --- test/tools/llvm-readobj/Inputs/elf-packed-relocs3.s +++ test/tools/llvm-readobj/Inputs/elf-packed-relocs3.s @@ -0,0 +1,31 @@ +.ascii "APS2" +.sleb128 6 // Number of relocations +.sleb128 4096 // Initial offset + +.sleb128 2 // Number of relocations in group +.sleb128 8 // RELOCATION_GROUP_HAS_ADDEND_FLAG + +.sleb128 256 // Reloc 1: r_offset delta +.sleb128 8 // Reloc 1: r_info R_X86_RELATIVE +.sleb128 0 // Reloc 1: r_addend delta +.sleb128 128 // Reloc 2: r_offset delta +.sleb128 8 // Reloc 2: r_info R_X86_RELATIVE +.sleb128 8 // Reloc 2: r_addend delta + +.sleb128 2 // Number of relocations in group +.sleb128 0 // No RELOCATION_GROUP_HAS_ADDEND_FLAG + +.sleb128 128 // reloc 1: r_offset delta +.sleb128 (1 << 32) | 1 // r_x86_64_64 (sym index 1) +.sleb128 8 // reloc 2: r_offset delta +.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 8 // reloc 1: r_offset delta +.sleb128 (1 << 32) | 1 // r_x86_64_64 (sym index 1) +.sleb128 0 // reloc 1: r_addend delta +.sleb128 8 // reloc 2: r_offset delta +.sleb128 (2 << 32) | 1 // r_x86_64_64 (sym index 2) +.sleb128 8 // reloc 2: r_addend delta Index: test/tools/llvm-readobj/elf-packed-relocs.test =================================================================== --- test/tools/llvm-readobj/elf-packed-relocs.test +++ test/tools/llvm-readobj/elf-packed-relocs.test @@ -94,3 +94,45 @@ - 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 +...