1//===------ ObjectFileInterface.cpp - MU interface utils for objects ------===// 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//===----------------------------------------------------------------------===// 17#define DEBUG_TYPE "orc" 24assert(!
I.InitSymbol &&
"I already has an init symbol");
28 std::string InitSymString;
30 <<
"$." << ObjFileName <<
".__inits." << Counter++;
31I.InitSymbol = ES.
intern(InitSymString);
32 }
while (
I.SymbolFlags.count(
I.InitSymbol));
45// TODO: Test this error. 48// Skip symbols not defined in this object file. 52// Skip symbols that are not global. 56// Skip symbols that have type SF_File. 57if (
auto SymType =
Sym.getType()) {
61return SymType.takeError();
65returnName.takeError();
68return SymFlags.takeError();
70// Strip the 'exported' flag from MachO linker-private symbols. 71if (
Name->starts_with(
"l"))
74I.SymbolFlags[ES.
intern(*
Name)] = std::move(*SymFlags);
102// TODO: Test this error. 105// Skip symbols not defined in this object file. 109// Skip symbols that are not global. 113// Skip symbols that have type SF_File. 114if (
auto SymType =
Sym.getType()) {
118return SymType.takeError();
122returnName.takeError();
126return SymFlags.takeError();
128// ELF STB_GNU_UNIQUE should map to Weak for ORC. 132I.SymbolFlags[ES.
intern(std::move(*
Name))] = std::move(*SymFlags);
137if (
auto SecName = Sec.getName()) {
152 std::vector<std::optional<object::coff_aux_section_definition>> ComdatDefs(
157// TODO: Test this error. 160// Handle comdat symbols 163if (
auto *Def = COFFSym.getSectionDefinition()) {
164auto Sec = Obj.
getSection(COFFSym.getSectionNumber());
166return Sec.takeError();
169 ComdatDefs[COFFSym.getSectionNumber()] = *Def;
174 ComdatDefs[COFFSym.getSectionNumber()]) {
175auto Def = ComdatDefs[COFFSym.getSectionNumber()];
179 ComdatDefs[COFFSym.getSectionNumber()] = std::nullopt;
181// Skip symbols not defined in this object file. 186// Skip symbols that are not global. 190// Skip symbols that have type SF_File. 191if (
auto SymType =
Sym.getType()) {
195return SymType.takeError();
199returnName.takeError();
203return SymFlags.takeError();
206// Weak external is always a function 207if (COFFSym.isWeakExternal())
213I.SymbolFlags[ES.
intern(*
Name)] = std::move(*SymFlags);
218if (
auto SecName = Sec.getName()) {
224return SecName.takeError();
238// TODO: Test this error. 241// Skip symbols not defined in this object file. 245// Skip symbols that are not global. 249// Skip symbols that have type SF_File. 250if (
auto SymType =
Sym.getType()) {
254return SymType.takeError();
258returnName.takeError();
262return SymFlags.takeError();
264I.SymbolFlags[ES.
intern(*
Name)] = std::move(*SymFlags);
275return Obj.takeError();
277if (
auto *MachOObj = dyn_cast<object::MachOObjectFile>(Obj->get()))
279elseif (
auto *ELFObj = dyn_cast<object::ELFObjectFileBase>(Obj->get()))
281elseif (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(Obj->get()))
287}
// End namespace orc. 288}
// End namespace llvm. assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
Flags for symbols in the JIT.
static Expected< JITSymbolFlags > fromObjectSymbol(const object::SymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
@ MaterializationSideEffectsOnly
StringRef - Represent a constant reference to a string, i.e.
StringRef getFileName() const
uint32_t getNumberOfSections() const
Expected< const coff_section * > getSection(int32_t index) const
COFFSymbolRef getCOFFSymbol(const DataRefImpl &Ref) const
elf_symbol_iterator_range symbols() const
unsigned getSectionType(SectionRef Sec) const
StringRef getSectionFinalSegmentName(DataRefImpl Sec) const
Expected< StringRef > getSectionName(DataRefImpl Sec) const override
This class is the base class for all object file types.
section_iterator_range sections() const
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
symbol_iterator_range symbols() const
An ExecutionSession represents a running JIT program.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
Pointer to a pooled string representing a symbol name.
A raw_ostream that writes to an std::string.
@ IMAGE_COMDAT_SELECT_NODUPLICATES
@ IMAGE_COMDAT_SELECT_ASSOCIATIVE
bool isReservedSectionNumber(int32_t SectionNumber)
@ S_MOD_INIT_FUNC_POINTERS
S_MOD_INIT_FUNC_POINTERS - Section with only function pointers for initialization.
void addInitSymbol(MaterializationUnit::Interface &I, ExecutionSession &ES, StringRef ObjFileName)
Adds an initializer symbol to the given MU interface.
static Expected< MaterializationUnit::Interface > getMachOObjectFileSymbolInfo(ExecutionSession &ES, const object::MachOObjectFile &Obj)
Expected< MaterializationUnit::Interface > getGenericObjectFileSymbolInfo(ExecutionSession &ES, const object::ObjectFile &Obj)
static Expected< MaterializationUnit::Interface > getELFObjectFileSymbolInfo(ExecutionSession &ES, const object::ELFObjectFileBase &Obj)
bool isMachOInitializerSection(StringRef SegName, StringRef SecName)
Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
bool isCOFFInitializerSection(StringRef Name)
static Expected< MaterializationUnit::Interface > getCOFFObjectFileSymbolInfo(ExecutionSession &ES, const object::COFFObjectFile &Obj)
bool isELFInitializerSection(StringRef SecName)
This is an optimization pass for GlobalISel generic memory operations.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.