ELF: Fix the section that relocations apply to. Add test to verify. Patch by Danil Malyshev!

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@141901 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer 2011-10-13 22:30:10 +00:00
parent 942eb00911
commit 63b2f8c710
2 changed files with 7 additions and 3 deletions

View File

@ -762,7 +762,7 @@ relocation_iterator ELFObjectFile<target_endianness, is64Bits>
const Elf_Shdr *sec = reinterpret_cast<const Elf_Shdr *>(Sec.p); const Elf_Shdr *sec = reinterpret_cast<const Elf_Shdr *>(Sec.p);
typename RelocMap_t::const_iterator ittr = SectionRelocMap.find(sec); typename RelocMap_t::const_iterator ittr = SectionRelocMap.find(sec);
if (sec != 0 && ittr != SectionRelocMap.end()) { if (sec != 0 && ittr != SectionRelocMap.end()) {
RelData.w.a = getSection(ittr->second[0])->sh_link; RelData.w.a = getSection(ittr->second[0])->sh_info;
RelData.w.b = ittr->second[0]; RelData.w.b = ittr->second[0];
RelData.w.c = 0; RelData.w.c = 0;
} }
@ -780,7 +780,7 @@ relocation_iterator ELFObjectFile<target_endianness, is64Bits>
// Get the index of the last relocation section for this section. // Get the index of the last relocation section for this section.
std::size_t relocsecindex = ittr->second[ittr->second.size() - 1]; std::size_t relocsecindex = ittr->second[ittr->second.size() - 1];
const Elf_Shdr *relocsec = getSection(relocsecindex); const Elf_Shdr *relocsec = getSection(relocsecindex);
RelData.w.a = relocsec->sh_link; RelData.w.a = relocsec->sh_info;
RelData.w.b = relocsecindex; RelData.w.b = relocsecindex;
RelData.w.c = relocsec->sh_size / relocsec->sh_entsize; RelData.w.c = relocsec->sh_size / relocsec->sh_entsize;
} }
@ -1114,7 +1114,7 @@ ELFObjectFile<target_endianness, is64Bits>::ELFObjectFile(MemoryBuffer *Object
SymbolTableSections.push_back(sh); SymbolTableSections.push_back(sh);
} }
if (sh->sh_type == ELF::SHT_REL || sh->sh_type == ELF::SHT_RELA) { if (sh->sh_type == ELF::SHT_REL || sh->sh_type == ELF::SHT_RELA) {
SectionRelocMap[getSection(sh->sh_link)].push_back(i); SectionRelocMap[getSection(sh->sh_info)].push_back(i);
} }
++sh; ++sh;
} }

View File

@ -7,18 +7,22 @@ RUN: | FileCheck %s -check-prefix ELF-i386
RUN: llvm-objdump -r %p/TestObjectFiles/trivial-object-test.elf-x86-64 \ RUN: llvm-objdump -r %p/TestObjectFiles/trivial-object-test.elf-x86-64 \
RUN: | FileCheck %s -check-prefix ELF-x86-64 RUN: | FileCheck %s -check-prefix ELF-x86-64
COFF-i386: .text
COFF-i386: IMAGE_REL_I386_DIR32 L_.str COFF-i386: IMAGE_REL_I386_DIR32 L_.str
COFF-i386: IMAGE_REL_I386_REL32 _puts COFF-i386: IMAGE_REL_I386_REL32 _puts
COFF-i386: IMAGE_REL_I386_REL32 _SomeOtherFunction COFF-i386: IMAGE_REL_I386_REL32 _SomeOtherFunction
COFF-x86-64: .text
COFF-x86-64: IMAGE_REL_AMD64_REL32 L.str COFF-x86-64: IMAGE_REL_AMD64_REL32 L.str
COFF-x86-64: IMAGE_REL_AMD64_REL32 puts COFF-x86-64: IMAGE_REL_AMD64_REL32 puts
COFF-x86-64: IMAGE_REL_AMD64_REL32 SomeOtherFunction COFF-x86-64: IMAGE_REL_AMD64_REL32 SomeOtherFunction
ELF-i386: .text
ELF-i386: R_386_32 ELF-i386: R_386_32
ELF-i386: R_386_PC32 ELF-i386: R_386_PC32
ELF-i386: R_386_PC32 ELF-i386: R_386_PC32
ELF-x86-64: .text
ELF-x86-64: R_X86_64_32S .rodata.str1.1 ELF-x86-64: R_X86_64_32S .rodata.str1.1
ELF-x86-64: R_X86_64_PC32 puts ELF-x86-64: R_X86_64_PC32 puts
ELF-x86-64: R_X86_64_PC32 SomeOtherFunction ELF-x86-64: R_X86_64_PC32 SomeOtherFunction