Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@ -0,0 +1,18 @@
add_lldb_unittest(ObjectFileELFTests
TestELFHeader.cpp
TestObjectFileELF.cpp
LINK_LIBS
lldbPluginObjectFileELF
lldbPluginSymbolVendorELF
lldbCore
lldbUtilityHelpers
)
add_dependencies(ObjectFileELFTests yaml2obj)
add_definitions(-DYAML2OBJ="$<TARGET_FILE:yaml2obj>")
set(test_inputs
sections-resolve-consistently.yaml
)
add_unittest_inputs(ObjectFileELFTests "${test_inputs}")

View File

@ -0,0 +1,50 @@
--- !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
...

View File

@ -0,0 +1,62 @@
//===-- TestELFHeader.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/ELFHeader.h"
#include "lldb/Utility/DataExtractor.h"
#include "gtest/gtest.h"
using namespace lldb;
using namespace lldb_private;
TEST(ELFHeader, ParseHeaderExtension) {
uint8_t data[] = {
// e_ident
0x7f, 0x45, 0x4c, 0x46, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
// e_type, e_machine, e_version, e_entry
0x03, 0x00, 0x3e, 0x00, 0x01, 0x00, 0x00, 0x00, 0x90, 0x48, 0x40, 0x00,
0x00, 0x00, 0x00, 0x00,
// e_phoff, e_shoff
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
// e_flags, e_ehsize, e_phentsize, e_phnum, e_shentsize, e_shnum,
// e_shstrndx
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x38, 0x00, 0xff, 0xff, 0x40, 0x00,
0x00, 0x00, 0xff, 0xff,
// sh_name, sh_type, sh_flags
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
// sh_addr, sh_offset
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
// sh_size, sh_link, sh_info
0x23, 0x45, 0x67, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x56, 0x78, 0x00,
0x12, 0x34, 0x56, 0x00,
// sh_addralign, sh_entsize
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
};
DataExtractor extractor(data, sizeof data, eByteOrderLittle, 8);
elf::ELFHeader header;
offset_t offset = 0;
ASSERT_TRUE(header.Parse(extractor, &offset));
EXPECT_EQ(0x563412u, header.e_phnum);
EXPECT_EQ(0x785634u, header.e_shstrndx);
EXPECT_EQ(0x674523u, header.e_shnum);
}

View File

@ -0,0 +1,100 @@
//===-- 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/HostInfo.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 {
HostInfo::Initialize();
ObjectFileELF::Initialize();
SymbolVendorELF::Initialize();
}
void TearDown() override {
SymbolVendorELF::Terminate();
ObjectFileELF::Terminate();
HostInfo::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);
const char *args[] = {YAML2OBJ, yaml.c_str(), nullptr};
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, nullptr, redirects));
uint64_t size;
ASSERT_NO_ERROR(llvm::sys::fs::file_size(obj, size));
ASSERT_GT(size, 0u);
ModuleSpec spec{FileSpec(obj, false)};
spec.GetSymbolFileSpec().SetFile(obj, false);
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());
}