diff options
Diffstat (limited to 'unittests/ObjectFile/ELF')
-rw-r--r-- | unittests/ObjectFile/ELF/CMakeLists.txt | 19 | ||||
-rw-r--r-- | unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml | 183 | ||||
-rw-r--r-- | unittests/ObjectFile/ELF/Inputs/early-section-headers.so | bin | 581 -> 0 bytes | |||
-rw-r--r-- | unittests/ObjectFile/ELF/Inputs/sections-resolve-consistently.yaml | 50 | ||||
-rw-r--r-- | unittests/ObjectFile/ELF/TestObjectFileELF.cpp | 212 |
5 files changed, 0 insertions, 464 deletions
diff --git a/unittests/ObjectFile/ELF/CMakeLists.txt b/unittests/ObjectFile/ELF/CMakeLists.txt deleted file mode 100644 index d16dc2d58eb0..000000000000 --- a/unittests/ObjectFile/ELF/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -add_lldb_unittest(ObjectFileELFTests - TestObjectFileELF.cpp - - LINK_LIBS - lldbPluginObjectFileELF - lldbPluginSymbolVendorELF - lldbCore - lldbUtilityHelpers - ) - -add_dependencies(ObjectFileELFTests yaml2obj) -add_definitions(-DYAML2OBJ="$<TARGET_FILE:yaml2obj>") - -set(test_inputs - early-section-headers.so - debug-info-relocations.pcm.yaml - sections-resolve-consistently.yaml - ) -add_unittest_inputs(ObjectFileELFTests "${test_inputs}") diff --git a/unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml b/unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml deleted file mode 100644 index 10bf9c2d177d..000000000000 --- a/unittests/ObjectFile/ELF/Inputs/debug-info-relocations.pcm.yaml +++ /dev/null @@ -1,183 +0,0 @@ ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_REL - Machine: EM_AARCH64 -Sections: - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - AddressAlign: 0x0000000000000004 - Content: E0031B32C0035FD6 - - Name: .debug_str - Type: SHT_PROGBITS - Flags: [ SHF_MERGE, SHF_STRINGS ] - AddressAlign: 0x0000000000000001 - Content: 636C616E672076657273696F6E20362E302E312028746167732F52454C454153455F3630312F66696E616C2900726564756365642E68002F746D702F617364666173646673646661006600696E7400 - - Name: .debug_abbrev - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000001 - Content: 011101250E1305030E10171B0EB44219110112060000022E00110112064018030E3A0B3B0B271949133F190000032400030E3E0B0B0B000000 - - Name: .debug_info - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000001 - Content: 470000000400000000000801000000000C0000000000000000000000000000000000000000000800000002000000000000000008000000016F000000000102430000000300000000050400 - - Name: .rela.debug_info - Type: SHT_RELA - Link: .symtab - AddressAlign: 0x0000000000000008 - Info: .debug_info - Relocations: - - Offset: 0x0000000000000006 - Symbol: .debug_abbrev - Type: R_AARCH64_ABS32 - - Offset: 0x000000000000000C - Symbol: .debug_str - Type: R_AARCH64_ABS32 - - Offset: 0x0000000000000012 - Symbol: .debug_str - Type: R_AARCH64_ABS32 - Addend: 45 - - Offset: 0x0000000000000016 - Symbol: .debug_line - Type: R_AARCH64_ABS32 - - Offset: 0x000000000000001A - Symbol: .debug_str - Type: R_AARCH64_ABS32 - Addend: 55 - - Offset: 0x000000000000001E - Symbol: .text - Type: R_AARCH64_ABS64 - - Offset: 0x000000000000002B - Symbol: .text - Type: R_AARCH64_ABS64 - - Offset: 0x0000000000000039 - Symbol: .debug_str - Type: R_AARCH64_ABS32 - Addend: 73 - - Offset: 0x0000000000000044 - Symbol: .debug_str - Type: R_AARCH64_ABS32 - Addend: 75 - - Name: .debug_ranges - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000001 - Content: '' - - Name: .debug_macinfo - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000001 - Content: '00' - - Name: .debug_pubnames - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000001 - Content: 140000000200000000004B0000002A000000660000000000 - - Name: .rela.debug_pubnames - Type: SHT_RELA - Link: .symtab - AddressAlign: 0x0000000000000008 - Info: .debug_pubnames - Relocations: - - Offset: 0x0000000000000006 - Symbol: .debug_info - Type: R_AARCH64_ABS32 - - Name: .debug_pubtypes - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000001 - Content: 160000000200000000004B00000043000000696E740000000000 - - Name: .rela.debug_pubtypes - Type: SHT_RELA - Link: .symtab - AddressAlign: 0x0000000000000008 - Info: .debug_pubtypes - Relocations: - - Offset: 0x0000000000000006 - Symbol: .debug_info - Type: R_AARCH64_ABS32 - - Name: .comment - Type: SHT_PROGBITS - Flags: [ SHF_MERGE, SHF_STRINGS ] - AddressAlign: 0x0000000000000001 - Content: 00636C616E672076657273696F6E20362E302E312028746167732F52454C454153455F3630312F66696E616C2900 - - Name: .note.GNU-stack - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000001 - Content: '' - - Name: .debug_frame - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000008 - Content: 14000000FFFFFFFF04000800017C1E0C1F00000000000000140000000000000000000000000000000800000000000000 - - Name: .rela.debug_frame - Type: SHT_RELA - Link: .symtab - AddressAlign: 0x0000000000000008 - Info: .debug_frame - Relocations: - - Offset: 0x000000000000001C - Symbol: .debug_frame - Type: R_AARCH64_ABS32 - - Offset: 0x0000000000000020 - Symbol: .text - Type: R_AARCH64_ABS64 - - Name: .debug_line - Type: SHT_PROGBITS - AddressAlign: 0x0000000000000001 - Content: 3C000000040021000000010101FB0E0D00010101010000000100000100726564756365642E68000000000000090200000000000000001305030A4B0204000101 - - Name: .rela.debug_line - Type: SHT_RELA - Link: .symtab - AddressAlign: 0x0000000000000008 - Info: .debug_line - Relocations: - - Offset: 0x000000000000002E - Symbol: .text - Type: R_AARCH64_ABS64 -Symbols: - Local: - - Name: reduced.h - Type: STT_FILE - - Name: '$d.1' - Section: .debug_str - - Name: '$d.2' - Section: .debug_abbrev - - Name: '$d.3' - Section: .debug_info - - Name: '$d.4' - Section: .debug_macinfo - - Name: '$d.5' - Section: .debug_pubnames - - Name: '$d.6' - Section: .debug_pubtypes - - Name: '$d.7' - Section: .comment - - Name: '$d.8' - Section: .debug_frame - - Name: '$d.9' - Section: .debug_line - - Name: '$x.0' - Section: .text - - Name: .text - Type: STT_SECTION - Section: .text - - Name: .debug_str - Type: STT_SECTION - Section: .debug_str - - Name: .debug_abbrev - Type: STT_SECTION - Section: .debug_abbrev - - Name: .debug_info - Type: STT_SECTION - Section: .debug_info - - Name: .debug_frame - Type: STT_SECTION - Section: .debug_frame - - Name: .debug_line - Type: STT_SECTION - Section: .debug_line - Global: - - Name: f - Type: STT_FUNC - Section: .text - Size: 0x0000000000000008 -DynamicSymbols: -... diff --git a/unittests/ObjectFile/ELF/Inputs/early-section-headers.so b/unittests/ObjectFile/ELF/Inputs/early-section-headers.so Binary files differdeleted file mode 100644 index b4c4b2f9a4a7..000000000000 --- a/unittests/ObjectFile/ELF/Inputs/early-section-headers.so +++ /dev/null diff --git a/unittests/ObjectFile/ELF/Inputs/sections-resolve-consistently.yaml b/unittests/ObjectFile/ELF/Inputs/sections-resolve-consistently.yaml deleted file mode 100644 index 98b68bd2773c..000000000000 --- a/unittests/ObjectFile/ELF/Inputs/sections-resolve-consistently.yaml +++ /dev/null @@ -1,50 +0,0 @@ ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 - Entry: 0x0000000000400180 -Sections: - - Name: .note.gnu.build-id - Type: SHT_NOTE - Flags: [ SHF_ALLOC ] - Address: 0x0000000000400158 - AddressAlign: 0x0000000000000004 - Content: 040000001400000003000000474E55003F3EC29E3FD83E49D18C4D49CD8A730CC13117B6 - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Address: 0x0000000000400180 - AddressAlign: 0x0000000000000010 - Content: 554889E58B042500106000890425041060005DC3 - - Name: .data - Type: SHT_PROGBITS - Flags: [ SHF_WRITE, SHF_ALLOC ] - Address: 0x0000000000601000 - AddressAlign: 0x0000000000000004 - Content: 2F000000 - - Name: .bss - Type: SHT_NOBITS - Flags: [ SHF_WRITE, SHF_ALLOC ] - Address: 0x0000000000601004 - AddressAlign: 0x0000000000000004 - Size: 0x0000000000000004 -Symbols: - Global: - - Name: Y - Type: STT_OBJECT - Section: .data - Value: 0x0000000000601000 - Size: 0x0000000000000004 - - Name: _start - Type: STT_FUNC - Section: .text - Value: 0x0000000000400180 - Size: 0x0000000000000014 - - Name: X - Type: STT_OBJECT - Section: .bss - Value: 0x0000000000601004 - Size: 0x0000000000000004 -... diff --git a/unittests/ObjectFile/ELF/TestObjectFileELF.cpp b/unittests/ObjectFile/ELF/TestObjectFileELF.cpp deleted file mode 100644 index 9d3b84514ce9..000000000000 --- a/unittests/ObjectFile/ELF/TestObjectFileELF.cpp +++ /dev/null @@ -1,212 +0,0 @@ -//===-- TestObjectFileELF.cpp -----------------------------------*- C++ -*-===// -// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "Plugins/ObjectFile/ELF/ObjectFileELF.h" -#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h" -#include "TestingSupport/TestUtilities.h" -#include "lldb/Core/Module.h" -#include "lldb/Core/ModuleSpec.h" -#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" -#include "llvm/Support/Path.h" -#include "llvm/Support/Program.h" -#include "llvm/Support/raw_ostream.h" -#include "gtest/gtest.h" - -using namespace lldb_private; -using namespace lldb; - -class ObjectFileELFTest : public testing::Test { -public: - void SetUp() override { - FileSystem::Initialize(); - HostInfo::Initialize(); - ObjectFileELF::Initialize(); - SymbolVendorELF::Initialize(); - } - - void TearDown() override { - SymbolVendorELF::Terminate(); - ObjectFileELF::Terminate(); - HostInfo::Terminate(); - FileSystem::Terminate(); - } - -protected: -}; - -#define ASSERT_NO_ERROR(x) \ - if (std::error_code ASSERT_NO_ERROR_ec = x) { \ - llvm::SmallString<128> MessageStorage; \ - llvm::raw_svector_ostream Message(MessageStorage); \ - Message << #x ": did not return errc::success.\n" \ - << "error number: " << ASSERT_NO_ERROR_ec.value() << "\n" \ - << "error message: " << ASSERT_NO_ERROR_ec.message() << "\n"; \ - GTEST_FATAL_FAILURE_(MessageStorage.c_str()); \ - } else { \ - } - -TEST_F(ObjectFileELFTest, SectionsResolveConsistently) { - std::string yaml = GetInputFilePath("sections-resolve-consistently.yaml"); - llvm::SmallString<128> obj; - ASSERT_NO_ERROR(llvm::sys::fs::createTemporaryFile( - "sections-resolve-consistently-%%%%%%", "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); - SectionList *list = module_sp->GetSectionList(); - ASSERT_NE(nullptr, list); - - auto bss_sp = list->FindSectionByName(ConstString(".bss")); - ASSERT_NE(nullptr, bss_sp); - auto data_sp = list->FindSectionByName(ConstString(".data")); - ASSERT_NE(nullptr, data_sp); - auto text_sp = list->FindSectionByName(ConstString(".text")); - ASSERT_NE(nullptr, text_sp); - - const Symbol *X = module_sp->FindFirstSymbolWithNameAndType(ConstString("X"), - eSymbolTypeAny); - ASSERT_NE(nullptr, X); - EXPECT_EQ(bss_sp, X->GetAddress().GetSection()); - - const Symbol *Y = module_sp->FindFirstSymbolWithNameAndType(ConstString("Y"), - eSymbolTypeAny); - ASSERT_NE(nullptr, Y); - EXPECT_EQ(data_sp, Y->GetAddress().GetSection()); - - const Symbol *start = module_sp->FindFirstSymbolWithNameAndType( - ConstString("_start"), eSymbolTypeAny); - ASSERT_NE(nullptr, start); - EXPECT_EQ(text_sp, start->GetAddress().GetSection()); -} - -// Test that GetModuleSpecifications works on an "atypical" object file which -// has section headers right after the ELF header (instead of the more common -// layout where the section headers are at the very end of the object file). -// -// Test file generated with yaml2obj (@svn rev 324254) from the following input: -/* ---- !ELF -FileHeader: - Class: ELFCLASS64 - Data: ELFDATA2LSB - Type: ET_EXEC - Machine: EM_X86_64 - Entry: 0x00000000004003D0 -Sections: - - Name: .note.gnu.build-id - Type: SHT_NOTE - Flags: [ SHF_ALLOC ] - Address: 0x0000000000400274 - AddressAlign: 0x0000000000000004 - Content: 040000001400000003000000474E55001B8A73AC238390E32A7FF4AC8EBE4D6A41ECF5C9 - - Name: .text - Type: SHT_PROGBITS - Flags: [ SHF_ALLOC, SHF_EXECINSTR ] - Address: 0x00000000004003D0 - AddressAlign: 0x0000000000000010 - Content: DEADBEEFBAADF00D -... -*/ -TEST_F(ObjectFileELFTest, GetModuleSpecifications_EarlySectionHeaders) { - std::string SO = GetInputFilePath("early-section-headers.so"); - ModuleSpecList Specs; - ASSERT_EQ(1u, ObjectFile::GetModuleSpecifications(FileSpec(SO), 0, 0, Specs)); - ModuleSpec Spec; - ASSERT_TRUE(Specs.GetModuleSpecAtIndex(0, Spec)) ; - UUID Uuid; - Uuid.SetFromStringRef("1b8a73ac238390e32a7ff4ac8ebe4d6a41ecf5c9", 20); - EXPECT_EQ(Spec.GetUUID(), Uuid); -} - -static void CHECK_ABS32(uint8_t *bytes, uint32_t offset, uint32_t addend) { - uint32_t res; - memcpy(&res, reinterpret_cast<uint32_t *>(bytes + offset), sizeof(uint32_t)); - ASSERT_EQ(addend, res); -} - -static void CHECK_ABS64(uint8_t *bytes, uint64_t offset, uint64_t addend) { - uint64_t res; - memcpy(&res, reinterpret_cast<uint64_t *>(bytes + offset), sizeof(uint64_t)); - ASSERT_EQ(addend, res); -} - -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(bytes, 0x6, 0); - CHECK_ABS32(bytes, 0xC, 0); - CHECK_ABS32(bytes, 0x12, 45); - CHECK_ABS32(bytes, 0x16, 0); - CHECK_ABS32(bytes, 0x1A, 55); - CHECK_ABS64(bytes, 0x1E, 0); - CHECK_ABS64(bytes, 0x2B, 0); - CHECK_ABS32(bytes, 0x39, 73); - CHECK_ABS32(bytes, 0x44, 75); -} |