Move ELFObjHandler to TextAPI library

This change moves ELFObjHandler to llvm/TextAPI library so it can
be used by different llvm tools.
This commit is contained in:
Haowei Wu 2020-08-10 11:35:01 -07:00
parent 4514a3cfa4
commit e6f8ba12e6
5 changed files with 31 additions and 34 deletions

View File

@ -10,8 +10,8 @@
///
//===-----------------------------------------------------------------------===/
#ifndef LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H
#define LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H
#ifndef LLVM_TEXTAPI_ELF_ELFOBJHANDLER_H
#define LLVM_TEXTAPI_ELF_ELFOBJHANDLER_H
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/ELFTypes.h"
@ -29,4 +29,4 @@ Expected<std::unique_ptr<ELFStub>> readELFFile(MemoryBufferRef Buf);
} // end namespace elfabi
} // end namespace llvm
#endif // LLVM_TOOLS_ELFABI_ELFOBJHANDLER_H
#endif // LLVM_TEXTAPI_ELF_ELFOBJHANDLER_H

View File

@ -1,4 +1,5 @@
add_llvm_component_library(LLVMTextAPI
ELF/ELFObjHandler.cpp
ELF/ELFStub.cpp
ELF/TBEHandler.cpp
MachO/Architecture.cpp
@ -13,6 +14,6 @@ add_llvm_component_library(LLVMTextAPI
ADDITIONAL_HEADER_DIRS
"${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI"
"${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI/Elf"
"${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI/ELF"
"${LLVM_MAIN_INCLUDE_DIR}/llvm/TextAPI/MachO"
)

View File

@ -6,7 +6,7 @@
//
//===-----------------------------------------------------------------------===/
#include "ELFObjHandler.h"
#include "llvm/TextAPI/ELF/ELFObjHandler.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/ELFTypes.h"
@ -128,16 +128,14 @@ static Error populateDynamic(DynamicEntries &Dyn,
"Couldn't locate dynamic symbol table (no DT_SYMTAB entry)");
}
if (Dyn.SONameOffset.hasValue() && *Dyn.SONameOffset >= Dyn.StrSize) {
return createStringError(
object_error::parse_failed,
return createStringError(object_error::parse_failed,
"DT_SONAME string offset (0x%016" PRIx64
") outside of dynamic string table",
*Dyn.SONameOffset);
}
for (uint64_t Offset : Dyn.NeededLibNames) {
if (Offset >= Dyn.StrSize) {
return createStringError(
object_error::parse_failed,
return createStringError(object_error::parse_failed,
"DT_NEEDED string offset (0x%016" PRIx64
") outside of dynamic string table",
Offset);
@ -355,9 +353,8 @@ buildStub(const ELFObjectFile<ELFT> &ElfObj) {
if (!DynSymPtr)
return appendToError(DynSymPtr.takeError(),
"when locating .dynsym section contents");
Elf_Sym_Range DynSyms =
ArrayRef<Elf_Sym>(reinterpret_cast<const Elf_Sym *>(*DynSymPtr),
*SymCount);
Elf_Sym_Range DynSyms = ArrayRef<Elf_Sym>(
reinterpret_cast<const Elf_Sym *>(*DynSymPtr), *SymCount);
Error SymReadError = populateSymbols<ELFT>(*DestStub, DynSyms, DynStr);
if (SymReadError)
return appendToError(std::move(SymReadError),

View File

@ -5,7 +5,6 @@ set(LLVM_LINK_COMPONENTS
)
add_llvm_tool(llvm-elfabi
ELFObjHandler.cpp
ErrorCollector.cpp
llvm-elfabi.cpp
)

View File

@ -6,15 +6,15 @@
//
//===-----------------------------------------------------------------------===/
#include "ELFObjHandler.h"
#include "ErrorCollector.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TextAPI/ELF/ELFObjHandler.h"
#include "llvm/TextAPI/ELF/TBEHandler.h"
#include <string>