40 return FlagsOrErr.takeError();
45 Result.SymFlags |=
Weak;
59 return static_cast<std::string
>(Path);
63static std::optional<std::string>
67 if (std::optional<std::string> File =
findFile(Dir, Root, Name))
74static std::optional<std::string>
77 if (
Input.starts_with(
":"))
80 (
"lib" +
Input +
".a").toVector(LibName);
90 bool Extracted = !IsLazy;
92 for (
unsigned I = 0;
I != IRSymtabOrErr->Mods.size(); ++
I) {
93 for (
const auto &IRSym : IRSymtabOrErr->TheReader.module_symbols(
I)) {
94 if (IRSym.isFormatSpecific() || !IRSym.isGlobal())
98 (IsLazy && !SymTab.
count(IRSym.getName())) ? PendingSymbols : SymTab;
104 bool ResolvesReference =
108 Extracted |= ResolvesReference;
111 if (ResolvesReference)
116 for (
const auto &[Name,
Symbol] : PendingSymbols)
124 bool Extracted = !IsLazy;
127 auto NameOrErr = ObjSym.getName();
129 return NameOrErr.takeError();
132 (IsLazy && !SymTab.
count(*NameOrErr)) ? PendingSymbols : SymTab;
138 return SymOrErr.takeError();
145 (!OldSym.
isWeak() || !IsLazy);
146 Extracted |= ResolvesReference;
148 if (ResolvesReference)
153 for (
const auto &[Name,
Symbol] : PendingSymbols)
164 if (DeviceArchs.
empty())
207 std::optional<std::string>
Filename;
213 Desc.Value.str().c_str());
236 InputFiles.
emplace_back(std::move(*BufferOrErr),
false);
244 for (
auto Child : (*LibFile)->children(Err)) {
245 auto ChildBufferOrErr = Child.getMemoryBufferRef();
246 if (!ChildBufferOrErr)
247 return ChildBufferOrErr.takeError();
249 std::string BufferIdentifier =
250 (*
Filename +
"(" + ChildBufferOrErr->getBufferIdentifier() +
")")
252 std::unique_ptr<MemoryBuffer> ChildBuffer =
271 bool Extracted =
true;
274 for (
auto &[
Input, IsLazy] : InputFiles) {
280 Result.Buffers.emplace_back(std::move(
Input));
289 Extracted |= *ExtractOrErr;
293 Result.Buffers.emplace_back(std::move(
Input));
297 return std::move(Result);
static constexpr StringLiteral Filename
Represent a constant reference to an array (0 or more elements consecutively in memory),...
bool empty() const
Check if the array is empty.
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.
StringRef getBufferIdentifier() const
StringRef getBuffer() const
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
size_type count(StringRef Key) const
count - Return 1 if the element is in the map, 0 otherwise.
Represent a constant reference to a string, i.e.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Target - Wrapper for Target specific information.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static Expected< std::unique_ptr< Archive > > create(MemoryBufferRef Source)
Expected< uint32_t > getFlags() const
Get symbol flags (bitwise OR of SymbolRef::Flags)
MemoryBufferRef getMemoryBufferRef() const
This class is the base class for all object file types.
symbol_iterator_range symbols() const
This is a value type class that represents a single symbol in the list of symbols in the object file.
LLVM_ABI Expected< IRSymtabFile > readIRSymtab(MemoryBufferRef MBRef)
Reads a bitcode file, creating its irsymtab if necessary.
Expected< ResolvedInputs > resolveArchiveMembers(ArrayRef< InputDesc > Order, ArrayRef< StringRef > SearchPaths, ArrayRef< StringRef > ForcedUndefs={}, StringRef Root="", ArrayRef< Triple::ArchType > DeviceArchs={})
Resolve archive members from the given inputs using a symbol-driven fixed-point algorithm.
static std::optional< std::string > findFromSearchPaths(StringRef Name, StringRef Root, ArrayRef< StringRef > SearchPaths)
static std::optional< std::string > findFile(StringRef Dir, StringRef Root, const Twine &Name)
static Expected< bool > getSymbols(MemoryBufferRef Buffer, StringMap< Symbol > &SymTab, bool IsLazy)
static bool isFatBinary(MemoryBufferRef Buffer, ArrayRef< Triple::ArchType > DeviceArchs)
Identify "fat binary" inputs that should be passed through to the linker without symbol-driven extrac...
static Expected< bool > getSymbolsFromBitcode(MemoryBufferRef Buffer, StringMap< Symbol > &SymTab, bool IsLazy)
static std::optional< std::string > searchLibrary(StringRef Input, StringRef Root, ArrayRef< StringRef > SearchPaths)
Search for static libraries in the linker's library path given input like -lfoo or -l:libfoo....
static Expected< bool > getSymbolsFromObject(ObjectFile &ObjFile, StringMap< Symbol > &SymTab, bool IsLazy)
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
LLVM_ABI bool is_directory(const basic_file_status &status)
Does status represent a directory?
LLVM_ABI void append(SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
Append to path.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
Error createFileError(const Twine &F, Error E)
Concatenate a source file path and/or name with an Error.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Expected< T > errorOrToExpected(ErrorOr< T > &&EO)
Convert an ErrorOr<T> to an Expected<T>.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
void consumeError(Error Err)
Consume a Error without doing anything.
@ elf_relocatable
ELF Relocatable object file.
@ archive
ar style archive file
A minimum symbol interface that provides the necessary information to extract archive members and res...
static Expected< Symbol > createFromObject(MemoryBufferRef File, const object::SymbolRef &Sym)
Create a Symbol from an object file symbol reference.