diff options
author | vitalyisaev <vitalyisaev@yandex-team.com> | 2023-06-29 10:00:50 +0300 |
---|---|---|
committer | vitalyisaev <vitalyisaev@yandex-team.com> | 2023-06-29 10:00:50 +0300 |
commit | 6ffe9e53658409f212834330e13564e4952558f6 (patch) | |
tree | 85b1e00183517648b228aafa7c8fb07f5276f419 /contrib/libs/llvm14/lib/ToolDrivers | |
parent | 726057070f9c5a91fc10fde0d5024913d10f1ab9 (diff) | |
download | ydb-6ffe9e53658409f212834330e13564e4952558f6.tar.gz |
YQ Connector: support managed ClickHouse
Со стороны dqrun можно обратиться к инстансу коннектора, который работает на streaming стенде, и извлечь данные из облачного CH.
Diffstat (limited to 'contrib/libs/llvm14/lib/ToolDrivers')
6 files changed, 731 insertions, 0 deletions
diff --git a/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp b/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp new file mode 100644 index 0000000000..de1634ebed --- /dev/null +++ b/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp @@ -0,0 +1,218 @@ +//===- DlltoolDriver.cpp - dlltool.exe-compatible driver ------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Defines an interface to a dlltool.exe-compatible driver. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h" +#include "llvm/ADT/Optional.h" +#include "llvm/ADT/StringSwitch.h" +#include "llvm/Object/COFF.h" +#include "llvm/Object/COFFImportFile.h" +#include "llvm/Object/COFFModuleDefinition.h" +#include "llvm/Option/Arg.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/Option.h" +#include "llvm/Support/Host.h" +#include "llvm/Support/Path.h" + +#include <vector> + +using namespace llvm; +using namespace llvm::object; +using namespace llvm::COFF; + +namespace { + +enum { + OPT_INVALID = 0, +#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID, +#include "Options.inc" +#undef OPTION +}; + +#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#include "Options.inc" +#undef PREFIX + +static const llvm::opt::OptTable::Info InfoTable[] = { +#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \ + {X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \ + X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12}, +#include "Options.inc" +#undef OPTION +}; + +class DllOptTable : public llvm::opt::OptTable { +public: + DllOptTable() : OptTable(InfoTable, false) {} +}; + +// Opens a file. Path has to be resolved already. +std::unique_ptr<MemoryBuffer> openFile(const Twine &Path) { + ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MB = MemoryBuffer::getFile(Path); + + if (std::error_code EC = MB.getError()) { + llvm::errs() << "cannot open file " << Path << ": " << EC.message() << "\n"; + return nullptr; + } + + return std::move(*MB); +} + +MachineTypes getEmulation(StringRef S) { + return StringSwitch<MachineTypes>(S) + .Case("i386", IMAGE_FILE_MACHINE_I386) + .Case("i386:x86-64", IMAGE_FILE_MACHINE_AMD64) + .Case("arm", IMAGE_FILE_MACHINE_ARMNT) + .Case("arm64", IMAGE_FILE_MACHINE_ARM64) + .Default(IMAGE_FILE_MACHINE_UNKNOWN); +} + +MachineTypes getMachine(Triple T) { + switch (T.getArch()) { + case Triple::x86: + return COFF::IMAGE_FILE_MACHINE_I386; + case Triple::x86_64: + return COFF::IMAGE_FILE_MACHINE_AMD64; + case Triple::arm: + return COFF::IMAGE_FILE_MACHINE_ARMNT; + case Triple::aarch64: + return COFF::IMAGE_FILE_MACHINE_ARM64; + default: + return COFF::IMAGE_FILE_MACHINE_UNKNOWN; + } +} + +MachineTypes getDefaultMachine() { + return getMachine(Triple(sys::getDefaultTargetTriple())); +} + +Optional<std::string> getPrefix(StringRef Argv0) { + StringRef ProgName = llvm::sys::path::stem(Argv0); + // x86_64-w64-mingw32-dlltool -> x86_64-w64-mingw32 + // llvm-dlltool -> None + // aarch64-w64-mingw32-llvm-dlltool-10.exe -> aarch64-w64-mingw32 + ProgName = ProgName.rtrim("0123456789.-"); + if (!ProgName.consume_back_insensitive("dlltool")) + return None; + ProgName.consume_back_insensitive("llvm-"); + ProgName.consume_back_insensitive("-"); + return ProgName.str(); +} + +} // namespace + +int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) { + DllOptTable Table; + unsigned MissingIndex; + unsigned MissingCount; + llvm::opt::InputArgList Args = + Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount); + if (MissingCount) { + llvm::errs() << Args.getArgString(MissingIndex) << ": missing argument\n"; + return 1; + } + + // Handle when no input or output is specified + if (Args.hasArgNoClaim(OPT_INPUT) || + (!Args.hasArgNoClaim(OPT_d) && !Args.hasArgNoClaim(OPT_l))) { + Table.printHelp(outs(), "llvm-dlltool [options] file...", "llvm-dlltool", + false); + llvm::outs() << "\nTARGETS: i386, i386:x86-64, arm, arm64\n"; + return 1; + } + + for (auto *Arg : Args.filtered(OPT_UNKNOWN)) + llvm::errs() << "ignoring unknown argument: " << Arg->getAsString(Args) + << "\n"; + + if (!Args.hasArg(OPT_d)) { + llvm::errs() << "no definition file specified\n"; + return 1; + } + + std::unique_ptr<MemoryBuffer> MB = + openFile(Args.getLastArg(OPT_d)->getValue()); + if (!MB) + return 1; + + if (!MB->getBufferSize()) { + llvm::errs() << "definition file empty\n"; + return 1; + } + + COFF::MachineTypes Machine = getDefaultMachine(); + if (Optional<std::string> Prefix = getPrefix(ArgsArr[0])) { + Triple T(*Prefix); + if (T.getArch() != Triple::UnknownArch) + Machine = getMachine(T); + } + if (auto *Arg = Args.getLastArg(OPT_m)) + Machine = getEmulation(Arg->getValue()); + + if (Machine == IMAGE_FILE_MACHINE_UNKNOWN) { + llvm::errs() << "unknown target\n"; + return 1; + } + + Expected<COFFModuleDefinition> Def = + parseCOFFModuleDefinition(*MB, Machine, true); + + if (!Def) { + llvm::errs() << "error parsing definition\n" + << errorToErrorCode(Def.takeError()).message(); + return 1; + } + + // Do this after the parser because parseCOFFModuleDefinition sets OutputFile. + if (auto *Arg = Args.getLastArg(OPT_D)) + Def->OutputFile = Arg->getValue(); + + if (Def->OutputFile.empty()) { + llvm::errs() << "no DLL name specified\n"; + return 1; + } + + std::string Path = std::string(Args.getLastArgValue(OPT_l)); + + // If ExtName is set (if the "ExtName = Name" syntax was used), overwrite + // Name with ExtName and clear ExtName. When only creating an import + // library and not linking, the internal name is irrelevant. This avoids + // cases where writeImportLibrary tries to transplant decoration from + // symbol decoration onto ExtName. + for (COFFShortExport& E : Def->Exports) { + if (!E.ExtName.empty()) { + E.Name = E.ExtName; + E.ExtName.clear(); + } + } + + if (Machine == IMAGE_FILE_MACHINE_I386 && Args.getLastArg(OPT_k)) { + for (COFFShortExport& E : Def->Exports) { + if (!E.AliasTarget.empty() || (!E.Name.empty() && E.Name[0] == '?')) + continue; + E.SymbolName = E.Name; + // Trim off the trailing decoration. Symbols will always have a + // starting prefix here (either _ for cdecl/stdcall, @ for fastcall + // or ? for C++ functions). Vectorcall functions won't have any + // fixed prefix, but the function base name will still be at least + // one char. + E.Name = E.Name.substr(0, E.Name.find('@', 1)); + // By making sure E.SymbolName != E.Name for decorated symbols, + // writeImportLibrary writes these symbols with the type + // IMPORT_NAME_UNDECORATE. + } + } + + if (!Path.empty() && + writeImportLibrary(Def->OutputFile, Path, Def->Exports, Machine, true)) + return 1; + return 0; +} diff --git a/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/Options.td b/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/Options.td new file mode 100644 index 0000000000..e78182ab81 --- /dev/null +++ b/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/Options.td @@ -0,0 +1,26 @@ +include "llvm/Option/OptParser.td" + +def m: JoinedOrSeparate<["-"], "m">, HelpText<"Set target machine">; +def m_long : JoinedOrSeparate<["--"], "machine">, Alias<m>; + +def l: JoinedOrSeparate<["-"], "l">, HelpText<"Generate an import lib">; +def l_long : JoinedOrSeparate<["--"], "output-lib">, Alias<l>; + +def D: JoinedOrSeparate<["-"], "D">, HelpText<"Specify the input DLL Name">; +def D_long : JoinedOrSeparate<["--"], "dllname">, Alias<D>; + +def d: JoinedOrSeparate<["-"], "d">, HelpText<"Input .def File">; +def d_long : JoinedOrSeparate<["--"], "input-def">, Alias<d>; + +def k: Flag<["-"], "k">, HelpText<"Kill @n Symbol from export">; +def k_alias: Flag<["--"], "kill-at">, Alias<k>; + +//============================================================================== +// The flags below do nothing. They are defined only for dlltool compatibility. +//============================================================================== + +def S: JoinedOrSeparate<["-"], "S">, HelpText<"Assembler">; +def S_alias: JoinedOrSeparate<["--"], "as">, Alias<S>; + +def f: JoinedOrSeparate<["-"], "f">, HelpText<"Assembler Flags">; +def f_alias: JoinedOrSeparate<["--"], "as-flags">, Alias<f>; diff --git a/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/ya.make b/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/ya.make new file mode 100644 index 0000000000..09d134b953 --- /dev/null +++ b/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool/ya.make @@ -0,0 +1,30 @@ +# Generated by devtools/yamaker. + +LIBRARY() + +LICENSE(Apache-2.0 WITH LLVM-exception) + +LICENSE_TEXTS(.yandex_meta/licenses.list.txt) + +PEERDIR( + contrib/libs/llvm14 + contrib/libs/llvm14/include + contrib/libs/llvm14/lib/Object + contrib/libs/llvm14/lib/Option + contrib/libs/llvm14/lib/Support +) + +ADDINCL( + ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool + contrib/libs/llvm14/lib/ToolDrivers/llvm-dlltool +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + DlltoolDriver.cpp +) + +END() diff --git a/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/LibDriver.cpp b/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/LibDriver.cpp new file mode 100644 index 0000000000..8f69282d34 --- /dev/null +++ b/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/LibDriver.cpp @@ -0,0 +1,387 @@ +//===- LibDriver.cpp - lib.exe-compatible driver --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// Defines an interface to a lib.exe-compatible driver that also understands +// bitcode files. Used by llvm-lib and lld-link /lib. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ToolDrivers/llvm-lib/LibDriver.h" +#include "llvm/ADT/STLExtras.h" +#include "llvm/ADT/StringSet.h" +#include "llvm/BinaryFormat/COFF.h" +#include "llvm/BinaryFormat/Magic.h" +#include "llvm/Bitcode/BitcodeReader.h" +#include "llvm/Object/ArchiveWriter.h" +#include "llvm/Object/COFF.h" +#include "llvm/Object/WindowsMachineFlag.h" +#include "llvm/Option/Arg.h" +#include "llvm/Option/ArgList.h" +#include "llvm/Option/Option.h" +#include "llvm/Support/CommandLine.h" +#include "llvm/Support/Path.h" +#include "llvm/Support/Process.h" +#include "llvm/Support/StringSaver.h" +#include "llvm/Support/raw_ostream.h" + +using namespace llvm; + +namespace { + +enum { + OPT_INVALID = 0, +#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID, +#include "Options.inc" +#undef OPTION +}; + +#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE; +#include "Options.inc" +#undef PREFIX + +static const opt::OptTable::Info InfoTable[] = { +#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \ + {X1, X2, X10, X11, OPT_##ID, opt::Option::KIND##Class, \ + X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12}, +#include "Options.inc" +#undef OPTION +}; + +class LibOptTable : public opt::OptTable { +public: + LibOptTable() : OptTable(InfoTable, true) {} +}; + +} + +static std::string getDefaultOutputPath(const NewArchiveMember &FirstMember) { + SmallString<128> Val = StringRef(FirstMember.Buf->getBufferIdentifier()); + sys::path::replace_extension(Val, ".lib"); + return std::string(Val.str()); +} + +static std::vector<StringRef> getSearchPaths(opt::InputArgList *Args, + StringSaver &Saver) { + std::vector<StringRef> Ret; + // Add current directory as first item of the search path. + Ret.push_back(""); + + // Add /libpath flags. + for (auto *Arg : Args->filtered(OPT_libpath)) + Ret.push_back(Arg->getValue()); + + // Add $LIB. + Optional<std::string> EnvOpt = sys::Process::GetEnv("LIB"); + if (!EnvOpt.hasValue()) + return Ret; + StringRef Env = Saver.save(*EnvOpt); + while (!Env.empty()) { + StringRef Path; + std::tie(Path, Env) = Env.split(';'); + Ret.push_back(Path); + } + return Ret; +} + +static std::string findInputFile(StringRef File, ArrayRef<StringRef> Paths) { + for (StringRef Dir : Paths) { + SmallString<128> Path = Dir; + sys::path::append(Path, File); + if (sys::fs::exists(Path)) + return std::string(Path); + } + return ""; +} + +static void fatalOpenError(llvm::Error E, Twine File) { + if (!E) + return; + handleAllErrors(std::move(E), [&](const llvm::ErrorInfoBase &EIB) { + llvm::errs() << "error opening '" << File << "': " << EIB.message() << '\n'; + exit(1); + }); +} + +static void doList(opt::InputArgList& Args) { + // lib.exe prints the contents of the first archive file. + std::unique_ptr<MemoryBuffer> B; + for (auto *Arg : Args.filtered(OPT_INPUT)) { + // Create or open the archive object. + ErrorOr<std::unique_ptr<MemoryBuffer>> MaybeBuf = MemoryBuffer::getFile( + Arg->getValue(), /*IsText=*/false, /*RequiresNullTerminator=*/false); + fatalOpenError(errorCodeToError(MaybeBuf.getError()), Arg->getValue()); + + if (identify_magic(MaybeBuf.get()->getBuffer()) == file_magic::archive) { + B = std::move(MaybeBuf.get()); + break; + } + } + + // lib.exe doesn't print an error if no .lib files are passed. + if (!B) + return; + + Error Err = Error::success(); + object::Archive Archive(B.get()->getMemBufferRef(), Err); + fatalOpenError(std::move(Err), B->getBufferIdentifier()); + + for (auto &C : Archive.children(Err)) { + Expected<StringRef> NameOrErr = C.getName(); + fatalOpenError(NameOrErr.takeError(), B->getBufferIdentifier()); + StringRef Name = NameOrErr.get(); + llvm::outs() << Name << '\n'; + } + fatalOpenError(std::move(Err), B->getBufferIdentifier()); +} + +static Expected<COFF::MachineTypes> getCOFFFileMachine(MemoryBufferRef MB) { + std::error_code EC; + auto Obj = object::COFFObjectFile::create(MB); + if (!Obj) + return Obj.takeError(); + + uint16_t Machine = (*Obj)->getMachine(); + if (Machine != COFF::IMAGE_FILE_MACHINE_I386 && + Machine != COFF::IMAGE_FILE_MACHINE_AMD64 && + Machine != COFF::IMAGE_FILE_MACHINE_ARMNT && + Machine != COFF::IMAGE_FILE_MACHINE_ARM64) { + return createStringError(inconvertibleErrorCode(), + "unknown machine: " + std::to_string(Machine)); + } + + return static_cast<COFF::MachineTypes>(Machine); +} + +static Expected<COFF::MachineTypes> getBitcodeFileMachine(MemoryBufferRef MB) { + Expected<std::string> TripleStr = getBitcodeTargetTriple(MB); + if (!TripleStr) + return TripleStr.takeError(); + + switch (Triple(*TripleStr).getArch()) { + case Triple::x86: + return COFF::IMAGE_FILE_MACHINE_I386; + case Triple::x86_64: + return COFF::IMAGE_FILE_MACHINE_AMD64; + case Triple::arm: + return COFF::IMAGE_FILE_MACHINE_ARMNT; + case Triple::aarch64: + return COFF::IMAGE_FILE_MACHINE_ARM64; + default: + return createStringError(inconvertibleErrorCode(), + "unknown arch in target triple: " + *TripleStr); + } +} + +static void appendFile(std::vector<NewArchiveMember> &Members, + COFF::MachineTypes &LibMachine, + std::string &LibMachineSource, MemoryBufferRef MB) { + file_magic Magic = identify_magic(MB.getBuffer()); + + if (Magic != file_magic::coff_object && Magic != file_magic::bitcode && + Magic != file_magic::archive && Magic != file_magic::windows_resource && + Magic != file_magic::coff_import_library) { + llvm::errs() << MB.getBufferIdentifier() + << ": not a COFF object, bitcode, archive, import library or " + "resource file\n"; + exit(1); + } + + // If a user attempts to add an archive to another archive, llvm-lib doesn't + // handle the first archive file as a single file. Instead, it extracts all + // members from the archive and add them to the second archive. This behavior + // is for compatibility with Microsoft's lib command. + if (Magic == file_magic::archive) { + Error Err = Error::success(); + object::Archive Archive(MB, Err); + fatalOpenError(std::move(Err), MB.getBufferIdentifier()); + + for (auto &C : Archive.children(Err)) { + Expected<MemoryBufferRef> ChildMB = C.getMemoryBufferRef(); + if (!ChildMB) { + handleAllErrors(ChildMB.takeError(), [&](const ErrorInfoBase &EIB) { + llvm::errs() << MB.getBufferIdentifier() << ": " << EIB.message() + << "\n"; + }); + exit(1); + } + + appendFile(Members, LibMachine, LibMachineSource, *ChildMB); + } + + fatalOpenError(std::move(Err), MB.getBufferIdentifier()); + return; + } + + // Check that all input files have the same machine type. + // Mixing normal objects and LTO bitcode files is fine as long as they + // have the same machine type. + // Doing this here duplicates the header parsing work that writeArchive() + // below does, but it's not a lot of work and it's a bit awkward to do + // in writeArchive() which needs to support many tools, can't assume the + // input is COFF, and doesn't have a good way to report errors. + if (Magic == file_magic::coff_object || Magic == file_magic::bitcode) { + Expected<COFF::MachineTypes> MaybeFileMachine = + (Magic == file_magic::coff_object) ? getCOFFFileMachine(MB) + : getBitcodeFileMachine(MB); + if (!MaybeFileMachine) { + handleAllErrors(MaybeFileMachine.takeError(), [&](const ErrorInfoBase &EIB) { + llvm::errs() << MB.getBufferIdentifier() << ": " << EIB.message() + << "\n"; + }); + exit(1); + } + COFF::MachineTypes FileMachine = *MaybeFileMachine; + + // FIXME: Once lld-link rejects multiple resource .obj files: + // Call convertResToCOFF() on .res files and add the resulting + // COFF file to the .lib output instead of adding the .res file, and remove + // this check. See PR42180. + if (FileMachine != COFF::IMAGE_FILE_MACHINE_UNKNOWN) { + if (LibMachine == COFF::IMAGE_FILE_MACHINE_UNKNOWN) { + LibMachine = FileMachine; + LibMachineSource = + (" (inferred from earlier file '" + MB.getBufferIdentifier() + "')") + .str(); + } else if (LibMachine != FileMachine) { + llvm::errs() << MB.getBufferIdentifier() << ": file machine type " + << machineToStr(FileMachine) + << " conflicts with library machine type " + << machineToStr(LibMachine) << LibMachineSource << '\n'; + exit(1); + } + } + } + + Members.emplace_back(MB); +} + +int llvm::libDriverMain(ArrayRef<const char *> ArgsArr) { + BumpPtrAllocator Alloc; + StringSaver Saver(Alloc); + + // Parse command line arguments. + SmallVector<const char *, 20> NewArgs(ArgsArr.begin(), ArgsArr.end()); + cl::ExpandResponseFiles(Saver, cl::TokenizeWindowsCommandLine, NewArgs); + ArgsArr = NewArgs; + + LibOptTable Table; + unsigned MissingIndex; + unsigned MissingCount; + opt::InputArgList Args = + Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount); + if (MissingCount) { + llvm::errs() << "missing arg value for \"" + << Args.getArgString(MissingIndex) << "\", expected " + << MissingCount + << (MissingCount == 1 ? " argument.\n" : " arguments.\n"); + return 1; + } + for (auto *Arg : Args.filtered(OPT_UNKNOWN)) + llvm::errs() << "ignoring unknown argument: " << Arg->getAsString(Args) + << "\n"; + + // Handle /help + if (Args.hasArg(OPT_help)) { + Table.printHelp(outs(), "llvm-lib [options] file...", "LLVM Lib"); + return 0; + } + + // If no input files and not told otherwise, silently do nothing to match + // lib.exe + if (!Args.hasArgNoClaim(OPT_INPUT) && !Args.hasArg(OPT_llvmlibempty)) + return 0; + + if (Args.hasArg(OPT_lst)) { + doList(Args); + return 0; + } + + std::vector<StringRef> SearchPaths = getSearchPaths(&Args, Saver); + + COFF::MachineTypes LibMachine = COFF::IMAGE_FILE_MACHINE_UNKNOWN; + std::string LibMachineSource; + if (auto *Arg = Args.getLastArg(OPT_machine)) { + LibMachine = getMachineType(Arg->getValue()); + if (LibMachine == COFF::IMAGE_FILE_MACHINE_UNKNOWN) { + llvm::errs() << "unknown /machine: arg " << Arg->getValue() << '\n'; + return 1; + } + LibMachineSource = + std::string(" (from '/machine:") + Arg->getValue() + "' flag)"; + } + + std::vector<std::unique_ptr<MemoryBuffer>> MBs; + StringSet<> Seen; + std::vector<NewArchiveMember> Members; + + // Create a NewArchiveMember for each input file. + for (auto *Arg : Args.filtered(OPT_INPUT)) { + // Find a file + std::string Path = findInputFile(Arg->getValue(), SearchPaths); + if (Path.empty()) { + llvm::errs() << Arg->getValue() << ": no such file or directory\n"; + return 1; + } + + // Input files are uniquified by pathname. If you specify the exact same + // path more than once, all but the first one are ignored. + // + // Note that there's a loophole in the rule; you can prepend `.\` or + // something like that to a path to make it look different, and they are + // handled as if they were different files. This behavior is compatible with + // Microsoft lib.exe. + if (!Seen.insert(Path).second) + continue; + + // Open a file. + ErrorOr<std::unique_ptr<MemoryBuffer>> MOrErr = MemoryBuffer::getFile( + Path, /*IsText=*/false, /*RequiresNullTerminator=*/false); + fatalOpenError(errorCodeToError(MOrErr.getError()), Path); + MemoryBufferRef MBRef = (*MOrErr)->getMemBufferRef(); + + // Append a file. + appendFile(Members, LibMachine, LibMachineSource, MBRef); + + // Take the ownership of the file buffer to keep the file open. + MBs.push_back(std::move(*MOrErr)); + } + + // Create an archive file. + std::string OutputPath; + if (auto *Arg = Args.getLastArg(OPT_out)) { + OutputPath = Arg->getValue(); + } else if (!Members.empty()) { + OutputPath = getDefaultOutputPath(Members[0]); + } else { + llvm::errs() << "no output path given, and cannot infer with no inputs\n"; + return 1; + } + // llvm-lib uses relative paths for both regular and thin archives, unlike + // standard GNU ar, which only uses relative paths for thin archives and + // basenames for regular archives. + for (NewArchiveMember &Member : Members) { + if (sys::path::is_relative(Member.MemberName)) { + Expected<std::string> PathOrErr = + computeArchiveRelativePath(OutputPath, Member.MemberName); + if (PathOrErr) + Member.MemberName = Saver.save(*PathOrErr); + } + } + + if (Error E = + writeArchive(OutputPath, Members, + /*WriteSymtab=*/true, object::Archive::K_GNU, + /*Deterministic*/ true, Args.hasArg(OPT_llvmlibthin))) { + handleAllErrors(std::move(E), [&](const ErrorInfoBase &EI) { + llvm::errs() << OutputPath << ": " << EI.message() << "\n"; + }); + return 1; + } + + return 0; +} diff --git a/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/Options.td b/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/Options.td new file mode 100644 index 0000000000..5891e238a3 --- /dev/null +++ b/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/Options.td @@ -0,0 +1,38 @@ +include "llvm/Option/OptParser.td" + +// lib.exe accepts options starting with either a dash or a slash. + +// Flag that takes no arguments. +class F<string name> : Flag<["/", "-", "/?", "-?"], name>; + +// Flag that takes one argument after ":". +class P<string name, string help> : + Joined<["/", "-", "/?", "-?"], name#":">, HelpText<help>; + +def libpath: P<"libpath", "Object file search path">; + +// Can't be called "list" since that's a keyword. +def lst : F<"list">, HelpText<"List contents of .lib file on stdout">; +def out : P<"out", "Path to file to write output">; + +def llvmlibthin : F<"llvmlibthin">, + HelpText<"Make .lib point to .obj files instead of copying their contents">; + +def llvmlibempty : F<"llvmlibempty">, + HelpText<"When given no contents, produce an empty .lib file">; + +def machine: P<"machine", "Specify target platform">; + +def help : F<"help">; + +// /?? and -?? must be before /? and -? to not confuse lib/Options. +def help_q : Flag<["/??", "-??", "/?", "-?"], "">, Alias<help>; + +//============================================================================== +// The flags below do nothing. They are defined only for lib.exe compatibility. +//============================================================================== + +class QF<string name> : Joined<["/", "-", "/?", "-?"], name#":">; + +def ignore : QF<"ignore">; +def nologo : F<"nologo">; diff --git a/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/ya.make b/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/ya.make new file mode 100644 index 0000000000..29a1a57513 --- /dev/null +++ b/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib/ya.make @@ -0,0 +1,32 @@ +# Generated by devtools/yamaker. + +LIBRARY() + +LICENSE(Apache-2.0 WITH LLVM-exception) + +LICENSE_TEXTS(.yandex_meta/licenses.list.txt) + +PEERDIR( + contrib/libs/llvm14 + contrib/libs/llvm14/include + contrib/libs/llvm14/lib/BinaryFormat + contrib/libs/llvm14/lib/Bitcode/Reader + contrib/libs/llvm14/lib/Object + contrib/libs/llvm14/lib/Option + contrib/libs/llvm14/lib/Support +) + +ADDINCL( + ${ARCADIA_BUILD_ROOT}/contrib/libs/llvm14/lib/ToolDrivers/llvm-lib + contrib/libs/llvm14/lib/ToolDrivers/llvm-lib +) + +NO_COMPILER_WARNINGS() + +NO_UTIL() + +SRCS( + LibDriver.cpp +) + +END() |