1//===- ObjectFileTransformer.cpp --------------------------------*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 25// Extract the UUID from the object file 26 std::vector<uint8_t>
UUID;
27if (
auto *MachO = dyn_cast<object::MachOObjectFile>(&Obj)) {
31 }
elseif (isa<object::ELFObjectFileBase>(&Obj)) {
32constStringRef GNUBuildID(
".note.gnu.build-id");
40if (SectName != GNUBuildID)
59if (!UUIDBytes.
empty()) {
74constbool IsMachO = isa<MachOObjectFile>(&Obj);
75constbool IsELF = isa<ELFObjectFileBase>(&Obj);
80// Parse the symbol table. 90// TODO: Test this error. 93if (SymType.
get() != SymbolRef::Type::ST_Function ||
96// Function size for MachO files will be 0 97constexprbool NoCopy =
false;
103"ObjectFileTransformer: ");
108// Remove the leading '_' character in any symbol names if there is one 111Name->consume_front(
"_");
117 *Out.
GetOS() <<
"Loaded " << FunctionsAddedCount
118 <<
" functions from symbol table.\n";
static std::vector< uint8_t > getUUID(const object::ObjectFile &Obj)
constexpr uint32_t NT_GNU_BUILD_ID_TAG
std::pair< llvm::MachO::Target, std::string > UUID
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
StringRef getFixedLengthString(uint64_t *OffsetPtr, uint64_t Length, StringRef TrimChars={"\0", 1}) const
Extract a fixed length string from *OffsetPtr and consume Length bytes.
uint32_t getU32(uint64_t *offset_ptr, Error *Err=nullptr) const
Extract a uint32_t value from *offset_ptr.
StringRef getBytes(uint64_t *OffsetPtr, uint64_t Length, Error *Err=nullptr) const
Extract a fixed number of bytes from the specified offset.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
reference get()
Returns a reference to the stored T value.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
constexpr const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
bool isLittleEndian() const
Tests whether the target triple is little endian.
GsymCreator is used to emit GSYM data to a stand alone file or section within a file.
void addFunctionInfo(FunctionInfo &&FI)
Add a function info to this GSYM creator.
uint32_t insertString(StringRef S, bool Copy=true)
Insert a string into the GSYM string table.
void setUUID(llvm::ArrayRef< uint8_t > UUIDBytes)
Set the UUID value.
size_t getNumFunctionInfos() const
Get the current number of FunctionInfo objects contained in this object.
bool IsValidTextAddress(uint64_t Addr) const
Check if an address is a valid code address.
static llvm::Error convert(const object::ObjectFile &Obj, OutputAggregator &Output, GsymCreator &Gsym)
Extract any object file data that is needed by the GsymCreator.
raw_ostream * GetOS() const
This class is the base class for all object file types.
Triple makeTriple() const
Create a triple from the data in this object file.
section_iterator_range sections() const
symbol_iterator_range symbols() const
This is a value type class that represents a single section in the list of sections in the object fil...
This is a value type class that represents a single symbol in the list of symbols in the object file.
constexpr size_t NameSize
This is an optimization pass for GlobalISel generic memory operations.
void logAllUnhandledErrors(Error E, raw_ostream &OS, Twine ErrorBanner={})
Log all errors (if any) in E to OS.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
void consumeError(Error Err)
Consume a Error without doing anything.
Function information in GSYM files encodes information for one contiguous address range.