42#define OPTION(...) LLVM_MAKE_OPT_ID(__VA_ARGS__),
60 return std::string(Val);
65 std::vector<StringRef> Ret;
70 for (
auto *
Arg : Args->filtered(OPT_libpath))
78 while (!Env.
empty()) {
80 std::tie(Path, Env) = Env.
split(
';');
91 if (std::error_code EC = MB.
getError()) {
92 llvm::errs() <<
"cannot open file " << Path <<
": " << EC.message() <<
"\n";
96 return std::move(*MB);
104 return std::string(Path);
120 std::unique_ptr<MemoryBuffer>
B;
121 for (
auto *
Arg : Args.filtered(OPT_INPUT)) {
128 B = std::move(MaybeBuf.
get());
141 std::vector<StringRef> Names;
145 Names.push_back(NameOrErr.
get());
147 for (
auto Name :
reverse(Names))
156 return Obj.takeError();
164 "unknown machine: " + std::to_string(
Machine));
176 switch (
T.getArch()) {
190 "unknown arch in target triple: " + *TripleStr);
196 if (LibMachine == FileMachine)
200 switch (LibMachine) {
212static void appendFile(std::vector<NewArchiveMember> &Members,
221 <<
": not a COFF object, bitcode, archive, import library or "
239 llvm::errs() << MB.getBufferIdentifier() <<
": " << EIB.message()
245 appendFile(Members, LibMachine, LibMachineSource, *ChildMB);
263 if (!MaybeFileMachine) {
266 llvm::errs() << MB.getBufferIdentifier() <<
": "
267 << EIB.message() <<
"\n";
282 <<
" conflicts with inferred library machine type,"
283 <<
" use /machine:arm64ec or /machine:arm64x\n";
286 LibMachine = FileMachine;
293 <<
" conflicts with library machine type "
294 <<
machineToStr(LibMachine) << LibMachineSource <<
'\n';
300 Members.emplace_back(MB);
313 unsigned MissingIndex;
314 unsigned MissingCount;
316 Table.ParseArgs(ArgsArr.
slice(1), MissingIndex, MissingCount);
319 << Args.getArgString(MissingIndex) <<
"\", expected "
321 << (MissingCount == 1 ?
" argument.\n" :
" arguments.\n");
324 for (
auto *
Arg : Args.filtered(OPT_UNKNOWN))
329 if (Args.hasArg(OPT_help)) {
330 Table.printHelp(
outs(),
"llvm-lib [options] file...",
"LLVM Lib");
336 for (
auto *
Arg : Args.filtered(OPT_ignore))
340 std::string OutputPath;
341 if (
auto *
Arg = Args.getLastArg(OPT_out)) {
346 std::string LibMachineSource;
347 if (
auto *
Arg = Args.getLastArg(OPT_machine)) {
354 std::string(
" (from '/machine:") +
Arg->
getValue() +
"' flag)";
358 if (Args.hasArg(OPT_deffile)) {
360 if (OutputPath.empty()) {
366 llvm::errs() <<
"/def option requires /machine to be specified" <<
'\n';
370 std::unique_ptr<MemoryBuffer> MB =
371 openFile(Args.getLastArg(OPT_deffile)->getValue());
375 if (!MB->getBufferSize()) {
389 std::vector<COFFShortExport> NativeExports;
390 std::string OutputFile = Def->OutputFile;
392 if (isArm64EC(LibMachine) && Args.hasArg(OPT_nativedeffile)) {
393 std::unique_ptr<MemoryBuffer> NativeMB =
394 openFile(Args.getLastArg(OPT_nativedeffile)->getValue());
398 if (!NativeMB->getBufferSize()) {
399 llvm::errs() <<
"native definition file empty\n";
407 llvm::errs() <<
"error parsing native definition\n"
411 NativeExports = std::move(NativeDef->Exports);
412 OutputFile = std::move(NativeDef->OutputFile);
417 false, NativeExports)) {
428 if (!Args.hasArgNoClaim(OPT_INPUT) && !Args.hasArg(OPT_llvmlibempty)) {
429 if (!IgnoredWarnings.
contains(
"emptyoutput")) {
430 llvm::errs() <<
"warning: no input files, not writing output file\n";
431 llvm::errs() <<
" pass /llvmlibempty to write empty .lib file,\n";
432 llvm::errs() <<
" pass /ignore:emptyoutput to suppress warning\n";
433 if (Args.hasFlag(OPT_WX, OPT_WX_no,
false)) {
434 llvm::errs() <<
"treating warning as error due to /WX\n";
441 if (Args.hasArg(OPT_lst)) {
446 std::vector<StringRef> SearchPaths =
getSearchPaths(&Args, Saver);
448 std::vector<std::unique_ptr<MemoryBuffer>> MBs;
450 std::vector<NewArchiveMember> Members;
453 for (
auto *
Arg : Args.filtered(OPT_INPUT)) {
468 if (!Seen.
insert(Path).second)
478 appendFile(Members, LibMachine, LibMachineSource, MBRef);
481 MBs.push_back(std::move(*MOrErr));
485 if (OutputPath.empty()) {
486 if (!Members.empty()) {
489 llvm::errs() <<
"no output path given, and cannot infer with no inputs\n";
494 bool Thin = Args.hasArg(OPT_llvmlibthin);
501 Member.MemberName = Saver.
save(*PathOrErr);
507 std::reverse(Members.begin(), Members.end());
509 auto Symtab = Args.hasFlag(OPT_llvmlibindex, OPT_llvmlibindex_no,
515 OutputPath, Members, Symtab,
Defines the llvm::Arg class for parsed arguments.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static bool machineMatches(COFF::MachineTypes LibMachine, COFF::MachineTypes FileMachine)
static Expected< COFF::MachineTypes > getBitcodeFileMachine(MemoryBufferRef MB)
static Expected< COFF::MachineTypes > getCOFFFileMachine(MemoryBufferRef MB)
static std::string getDefaultOutputPath(const NewArchiveMember &FirstMember)
static std::string findInputFile(StringRef File, ArrayRef< StringRef > Paths)
static void doList(opt::InputArgList &Args)
static std::vector< StringRef > getSearchPaths(opt::InputArgList *Args, StringSaver &Saver)
std::unique_ptr< MemoryBuffer > openFile(const Twine &Path)
static void appendFile(std::vector< NewArchiveMember > &Members, COFF::MachineTypes &LibMachine, std::string &LibMachineSource, MemoryBufferRef MB)
static void fatalOpenError(llvm::Error E, Twine File)
Function const char TargetMachine * Machine
Provides a library for accessing information about this process and other processes on the operating ...
StringSet - A set-like wrapper for the StringMap.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Base class for error info classes.
virtual std::string message() const
Return the error message as a string.
Represents either an error or a value T.
std::error_code getError() const
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 getBufferIdentifier() const
StringRef getBuffer() const
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr bool empty() const
Check if the string is empty.
Saves strings in the provided stable storage and returns a StringRef with a stable character pointer.
StringRef save(const char *S)
StringSet - A wrapper for StringMap that provides set-like functionality.
bool contains(StringRef key) const
Check if the set contains the given key.
std::pair< typename Base::iterator, bool > insert(StringRef key)
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
iterator_range< child_iterator > children(Error &Err, bool SkipInternal=true) const
static Expected< std::unique_ptr< COFFObjectFile > > create(MemoryBufferRef Object)
A concrete instance of a particular driver option.
LLVM_ABI std::string getAsString(const ArgList &Args) const
Return a formatted version of the argument and its values, for diagnostics.
const char * getValue(unsigned N=0) const
Provide access to the Option info table.
static LLVM_ABI std::optional< std::string > GetEnv(StringRef name)
@ IMAGE_FILE_MACHINE_ARM64
@ IMAGE_FILE_MACHINE_UNKNOWN
@ IMAGE_FILE_MACHINE_AMD64
@ IMAGE_FILE_MACHINE_ARM64EC
@ IMAGE_FILE_MACHINE_R4000
@ IMAGE_FILE_MACHINE_I386
@ IMAGE_FILE_MACHINE_ARM64X
@ IMAGE_FILE_MACHINE_ARMNT
bool isAnyArm64(T Machine)
bool isArm64EC(T Machine)
LLVM_ABI bool ExpandResponseFiles(StringSaver &Saver, TokenizerCallback Tokenizer, SmallVectorImpl< const char * > &Argv)
A convenience helper which supports the typical use case of expansion function call.
LLVM_ABI void TokenizeWindowsCommandLine(StringRef Source, StringSaver &Saver, SmallVectorImpl< const char * > &NewArgv, bool MarkEOLs=false)
Tokenizes a string of Windows command line arguments, which may contain quotes and escaped quotes.
LLVM_ABI Expected< COFFModuleDefinition > parseCOFFModuleDefinition(MemoryBufferRef MB, COFF::MachineTypes Machine, bool MingwDef=false, bool AddUnderscores=true)
LLVM_ABI Error writeImportLibrary(StringRef ImportName, StringRef Path, ArrayRef< COFFShortExport > Exports, COFF::MachineTypes Machine, bool MinGW, ArrayRef< COFFShortExport > NativeExports={})
Writes a COFF import library containing entries described by the Exports array.
LLVM_ABI bool exists(const basic_file_status &status)
Does file exist?
LLVM_ABI void replace_extension(SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
Replace the file extension of path with extension.
LLVM_ABI bool is_relative(const Twine &path, Style style=Style::native)
Is path relative?
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.
LLVM_ABI Error writeArchive(StringRef ArcName, ArrayRef< NewArchiveMember > NewMembers, SymtabWritingMode WriteSymtab, object::Archive::Kind Kind, bool Deterministic, bool Thin, std::unique_ptr< MemoryBuffer > OldArchiveBuf=nullptr, std::optional< bool > IsEC=std::nullopt, function_ref< void(Error)> Warn=warnToStderr)
LLVM_ABI int libDriverMain(ArrayRef< const char * > ARgs)
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
LLVM_ABI raw_fd_ostream & outs()
This returns a reference to a raw_fd_ostream for standard output.
LLVM_ABI Expected< std::string > getBitcodeTargetTriple(MemoryBufferRef Buffer)
Read the header of the specified bitcode buffer and extract just the triple information.
LLVM_ABI COFF::MachineTypes getMachineType(StringRef S)
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
auto reverse(ContainerTy &&C)
LLVM_ABI StringRef machineToStr(COFF::MachineTypes MT)
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
LLVM_ABI Expected< std::string > computeArchiveRelativePath(StringRef From, StringRef To)
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
LLVM_ABI std::error_code errorToErrorCode(Error Err)
Helper for converting an ECError to a std::error_code.
std::unique_ptr< MemoryBuffer > Buf
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
@ coff_import_library
COFF import library.
@ archive
ar style archive file
@ windows_resource
Windows compiled resource file (.res)
@ coff_object
COFF object file.