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//===----------------------------------------------------------------------===//
19 #define DEBUG_TYPE "orc"
26 assert(!
I.InitSymbol &&
"I already has an init symbol");
30 std::string InitSymString;
32 <<
"$." << ObjFileName <<
".__inits." << Counter++;
33 I.InitSymbol = ES.
intern(InitSymString);
34 }
while (
I.SymbolFlags.count(
I.InitSymbol));
44 for (
auto &Sym : Obj.
symbols()) {
47 // TODO: Test this error.
50 // Skip symbols not defined in this object file.
54 // Skip symbols that are not global.
58 // Skip symbols that have type SF_File.
59 if (
auto SymType = Sym.getType()) {
63 return SymType.takeError();
65 auto Name = Sym.getName();
67 return Name.takeError();
70 return SymFlags.takeError();
72 // Strip the 'exported' flag from MachO linker-private symbols.
73 if (Name->starts_with(
"l"))
76 I.SymbolFlags[ES.
intern(*Name)] = std::move(*SymFlags);
101 for (
auto &Sym : Obj.
symbols()) {
104 // TODO: Test this error.
107 // Skip symbols not defined in this object file.
111 // Skip symbols that are not global.
115 // Skip symbols that have type SF_File.
116 if (
auto SymType = Sym.getType()) {
120 return SymType.takeError();
122 auto Name = Sym.getName();
124 return Name.takeError();
128 return SymFlags.takeError();
130 // ELF STB_GNU_UNIQUE should map to Weak for ORC.
134 I.SymbolFlags[ES.
intern(std::move(*Name))] = std::move(*SymFlags);
139 if (
auto SecName = Sec.getName()) {
154 std::vector<std::optional<object::coff_aux_section_definition>> ComdatDefs(
156 for (
auto &Sym : Obj.
symbols()) {
159 // TODO: Test this error.
162 // Handle comdat symbols
165 if (
auto *Def = COFFSym.getSectionDefinition()) {
166 auto Sec = Obj.
getSection(COFFSym.getSectionNumber());
168 return Sec.takeError();
171 ComdatDefs[COFFSym.getSectionNumber()] = *Def;
176 ComdatDefs[COFFSym.getSectionNumber()]) {
177 auto Def = ComdatDefs[COFFSym.getSectionNumber()];
181 ComdatDefs[COFFSym.getSectionNumber()] = std::nullopt;
183 // Skip symbols not defined in this object file.
188 // Skip symbols that are not global.
192 // Skip symbols that have type SF_File.
193 if (
auto SymType = Sym.getType()) {
197 return SymType.takeError();
199 auto Name = Sym.getName();
201 return Name.takeError();
205 return SymFlags.takeError();
208 // Weak external is always a function
209 if (COFFSym.isWeakExternal())
215 I.SymbolFlags[ES.
intern(*Name)] = std::move(*SymFlags);
220 if (
auto SecName = Sec.getName()) {
226 return SecName.takeError();
238 for (
auto &Sym : Obj.
symbols()) {
244 // Skip undefined, non global and ST_File
257 auto Name = Sym.getName();
259 return Name.takeError();
262 return SymFlags.takeError();
264 // TODO: Revisit symbol visibility
265 // On AIX, symbols with C_EXT and C_WEAKEXT symbols have no specified
266 // visibility are considered to have Default scope for LinkGraph. When the
267 // object is not a DSO, symbol visibility is not specified. In the absence
268 // of an Export List, its reasonable to minimic roughly the behaviour of
269 // -bexpall or CreateExportList.
272 I.SymbolFlags[ES.
intern(std::move(*Name))] = std::move(*SymFlags);
274 // TODO: Find all initialization symbols for c++ static initializers
283 for (
auto &Sym : Obj.
symbols()) {
286 // TODO: Test this error.
289 // Skip symbols not defined in this object file.
293 // Skip symbols that are not global.
297 // Skip symbols that have type SF_File.
298 if (
auto SymType = Sym.getType()) {
302 return SymType.takeError();
304 auto Name = Sym.getName();
306 return Name.takeError();
310 return SymFlags.takeError();
312 I.SymbolFlags[ES.
intern(*Name)] = std::move(*SymFlags);
323 return Obj.takeError();
337}
// End namespace orc.
338}
// End namespace llvm.
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
Flags for symbols in the JIT.
static LLVM_ABI 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.
LLVM_ABI 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)
Expected< MaterializationUnit::Interface > getXCOFFObjectFileSymbolInfo(ExecutionSession &ES, const object::ObjectFile &Obj)
LLVM_ABI bool isMachOInitializerSection(StringRef SegName, StringRef SecName)
LLVM_ABI Expected< MaterializationUnit::Interface > getObjectFileInterface(ExecutionSession &ES, MemoryBufferRef ObjBuffer)
Returns a MaterializationUnit::Interface for the object file contained in the given buffer,...
LLVM_ABI bool isCOFFInitializerSection(StringRef Name)
static Expected< MaterializationUnit::Interface > getCOFFObjectFileSymbolInfo(ExecutionSession &ES, const object::COFFObjectFile &Obj)
LLVM_ABI bool isELFInitializerSection(StringRef SecName)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.