Add a relocation to ObjectFileELF::ApplyRelocations and a test
Summary: pcm files can end up being processed by lldb with relocations to be made for the .debug_info section. When a R_AARCH64_ABS64 relocation was required lldb would hit an `assert(false)` and die. Add R_AARCH64_ABS64 relocations to the S+A 64 bit width code path. Add a test for R_AARCH64_ABS64 and R_AARCH64_ABS32 .rela.debug_info relocations in a pcm file. Reviewers: sas, xiaobai, davide, javed.absar, espindola Reviewed By: davide Subscribers: labath, zturner, emaste, mgorny, arichardson, kristof.beyls Differential Revision: https://reviews.llvm.org/D51566 llvm-svn: 346171
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "lldb/Core/Section.h"
|
||||
#include "lldb/Host/FileSystem.h"
|
||||
#include "lldb/Host/HostInfo.h"
|
||||
#include "lldb/Utility/DataBufferHeap.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/Support/Compression.h"
|
||||
#include "llvm/Support/FileUtilities.h"
|
||||
@@ -141,3 +142,64 @@ TEST_F(ObjectFileELFTest, GetModuleSpecifications_EarlySectionHeaders) {
|
||||
Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20);
|
||||
EXPECT_EQ(Spec.GetUUID(), Uuid);
|
||||
}
|
||||
|
||||
#define CHECK_ABS32(offset, addend) \
|
||||
ASSERT_EQ((uint32_t)addend, *(uint32_t *)(bytes + offset))
|
||||
#define CHECK_ABS64(offset, addend) \
|
||||
ASSERT_EQ((uint64_t)addend, *(uint64_t *)(bytes + offset))
|
||||
|
||||
TEST_F(ObjectFileELFTest, TestAARCH64Relocations) {
|
||||
std::string yaml = GetInputFilePath("debug-info-relocations.pcm.yaml");
|
||||
llvm::SmallString<128> obj;
|
||||
ASSERT_NO_ERROR(llvm::sys::fs::createTemporaryFile(
|
||||
"debug-info-relocations-%%%%%%", "obj", obj));
|
||||
|
||||
llvm::FileRemover remover(obj);
|
||||
llvm::StringRef args[] = {YAML2OBJ, yaml};
|
||||
llvm::StringRef obj_ref = obj;
|
||||
const llvm::Optional<llvm::StringRef> redirects[] = {llvm::None, obj_ref,
|
||||
llvm::None};
|
||||
ASSERT_EQ(0,
|
||||
llvm::sys::ExecuteAndWait(YAML2OBJ, args, llvm::None, redirects));
|
||||
uint64_t size;
|
||||
ASSERT_NO_ERROR(llvm::sys::fs::file_size(obj, size));
|
||||
ASSERT_GT(size, 0u);
|
||||
|
||||
ModuleSpec spec{FileSpec(obj)};
|
||||
spec.GetSymbolFileSpec().SetFile(obj, FileSpec::Style::native);
|
||||
auto module_sp = std::make_shared<Module>(spec);
|
||||
|
||||
auto objfile = static_cast<ObjectFileELF *>(module_sp->GetObjectFile());
|
||||
SectionList *section_list = objfile->GetSectionList();
|
||||
ASSERT_NE(nullptr, section_list);
|
||||
|
||||
auto debug_info_sp =
|
||||
section_list->FindSectionByName(ConstString(".debug_info"));
|
||||
ASSERT_NE(nullptr, debug_info_sp);
|
||||
objfile->RelocateSection(debug_info_sp.get());
|
||||
|
||||
DataExtractor data;
|
||||
// length of 0x10 is not needed but length 0x0 crashes
|
||||
objfile->GetData(0x00, 0x10, data);
|
||||
DataBufferSP &data_buffer_sp = data.GetSharedDataBuffer();
|
||||
uint8_t *bytes = data_buffer_sp->GetBytes();
|
||||
|
||||
addr_t debug_info_offset = debug_info_sp->GetFileOffset();
|
||||
bytes += debug_info_offset;
|
||||
|
||||
// Sanity check - The first byte from the yaml file is 0x47
|
||||
ASSERT_EQ(0x47, *bytes);
|
||||
|
||||
// .rela.debug_info contains 9 relocations:
|
||||
// 7 R_AARCH64_ABS32 - 2 R_AARCH64_ABS64
|
||||
// None have a value. Four have addends.
|
||||
CHECK_ABS32(0x6, 0);
|
||||
CHECK_ABS32(0xC, 0);
|
||||
CHECK_ABS32(0x12, 45);
|
||||
CHECK_ABS32(0x16, 0);
|
||||
CHECK_ABS32(0x1A, 55);
|
||||
CHECK_ABS64(0x1E, 0);
|
||||
CHECK_ABS64(0x2B, 0);
|
||||
CHECK_ABS32(0x39, 73);
|
||||
CHECK_ABS32(0x44, 75);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user