llvm/llvm/tools/llvm-ar/llvm-ar.cpp

//===-- llvm-ar.cpp - LLVM archive librarian utility ----------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// Builds up (relatively) standard unix archive files (.a) containing LLVM
// bitcode or other files.
//
//===----------------------------------------------------------------------===//

#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/ArchiveWriter.h"
#include "llvm/Object/SymbolicFile.h"
#include "llvm/Support/Chrono.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ConvertUTF.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/FormatVariadic.h"
#include "llvm/Support/LLVMDriver.h"
#include "llvm/Support/LineIterator.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/StringSaver.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/ToolOutputFile.h"
#include "llvm/Support/WithColor.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/TargetParser/Triple.h"
#include "llvm/ToolDrivers/llvm-dlltool/DlltoolDriver.h"
#include "llvm/ToolDrivers/llvm-lib/LibDriver.h"

#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
#else
#include <io.h>
#endif

#ifdef _WIN32
#include "llvm/Support/Windows/WindowsSupport.h"
#endif

usingnamespacellvm;
usingnamespacellvm::object;

// The name this program was invoked as.
static StringRef ToolName;

// The basename of this program.
static StringRef Stem;

static void printRanLibHelp(StringRef ToolName) {}

static void printArHelp(StringRef ToolName) {}

static void printHelpMessage() {}

static unsigned MRILineNumber;
static bool ParsingMRIScript;

// Show the error plus the usage message, and exit.
[[noreturn]] static void badUsage(Twine Error) {}

// Show the error message and exit.
[[noreturn]] static void fail(Twine Error) {}

static void failIfError(std::error_code EC, Twine Context = "") {}

static void failIfError(Error E, Twine Context = "") {}

static void warn(Twine Message) {}

static SmallVector<const char *, 256> PositionalArgs;

static bool MRI;

namespace {
enum Format {};
}

static Format FormatType =;

static std::string Options;

// This enumeration delineates the kinds of operations on an archive
// that are permitted.
enum ArchiveOperation {};

enum class BitModeTy {};

static BitModeTy BitMode =;

// Modifiers to follow operation to vary behavior
static bool AddAfter =;             ///< 'a' modifier
static bool AddBefore =;            ///< 'b' modifier
static bool Create =;               ///< 'c' modifier
static bool OriginalDates =;        ///< 'o' modifier
static bool DisplayMemberOffsets =; ///< 'O' modifier
static bool CompareFullPath =;      ///< 'P' modifier
static bool OnlyUpdate =;           ///< 'u' modifier
static bool Verbose =;              ///< 'v' modifier
static SymtabWritingMode Symtab =;      ///< 's' modifier
static bool Deterministic =;         ///< 'D' and 'U' modifiers
static bool Thin =;                 ///< 'T' modifier
static bool AddLibrary =;           ///< 'L' modifier

// Relative Positional Argument (for insert/move). This variable holds
// the name of the archive member to which the 'a', 'b' or 'i' modifier
// refers. Only one of 'a', 'b' or 'i' can be specified so we only need
// one variable.
static std::string RelPos;

// Count parameter for 'N' modifier. This variable specifies which file should
// match for extract/delete operations when there are multiple matches. This is
// 1-indexed. A value of 0 is invalid, and implies 'N' is not used.
static int CountParam =;

// This variable holds the name of the archive file as given on the
// command line.
static std::string ArchiveName;

// Output directory specified by --output.
static std::string OutputDir;

static std::vector<std::unique_ptr<MemoryBuffer>> ArchiveBuffers;
static std::vector<std::unique_ptr<object::Archive>> Archives;

// This variable holds the list of member files to proecess, as given
// on the command line.
static std::vector<StringRef> Members;

// Static buffer to hold StringRefs.
static BumpPtrAllocator Alloc;

// Extract the member filename from the command line for the [relpos] argument
// associated with a, b, and i modifiers
static void getRelPos() {}

// Extract the parameter from the command line for the [count] argument
// associated with the N modifier
static void getCountParam() {}

// Get the archive file name from the command line
static void getArchive() {}

static object::Archive &readLibrary(const Twine &Library) {}

static void runMRIScript();

// Parse the command line options as presented and return the operation
// specified. Process all modifiers and check to make sure that constraints on
// modifier/operation pairs have not been violated.
static ArchiveOperation parseCommandLine() {}

// Implements the 'p' operation. This function traverses the archive
// looking for members that match the path list.
static void doPrint(StringRef Name, const object::Archive::Child &C) {}

// Utility function for printing out the file mode when the 't' operation is in
// verbose mode.
static void printMode(unsigned mode) {}

// Implement the 't' operation. This function prints out just
// the file names of each of the members. However, if verbose mode is requested
// ('v' modifier) then the file type, permission mode, user, group, size, and
// modification time are also printed.
static void doDisplayTable(StringRef Name, const object::Archive::Child &C) {}

static std::string normalizePath(StringRef Path) {}

static bool comparePaths(StringRef Path1, StringRef Path2) {}

// Implement the 'x' operation. This function extracts files back to the file
// system.
static void doExtract(StringRef Name, const object::Archive::Child &C) {}

static bool shouldCreateArchive(ArchiveOperation Op) {}

static bool isValidInBitMode(Binary &Bin) {}

Expected<std::unique_ptr<Binary>> getAsBinary(const NewArchiveMember &NM,
                                              LLVMContext *Context) {}

Expected<std::unique_ptr<Binary>> getAsBinary(const Archive::Child &C,
                                              LLVMContext *Context) {}

template <class A> static bool isValidInBitMode(const A &Member) {}

static void warnInvalidObjectForFileMode(Twine Name) {}

static void performReadOperation(ArchiveOperation Operation,
                                 object::Archive *OldArchive) {}

static void addChildMember(std::vector<NewArchiveMember> &Members,
                           const object::Archive::Child &M,
                           bool FlattenArchive = false) {}

static NewArchiveMember getArchiveMember(StringRef FileName) {}

static void addMember(std::vector<NewArchiveMember> &Members,
                      NewArchiveMember &NM) {}

static void addMember(std::vector<NewArchiveMember> &Members,
                      StringRef FileName, bool FlattenArchive = false) {}

enum InsertAction {};

static InsertAction computeInsertAction(ArchiveOperation Operation,
                                        const object::Archive::Child &Member,
                                        StringRef Name,
                                        std::vector<StringRef>::iterator &Pos,
                                        StringMap<int> &MemberCount) {}

// We have to walk this twice and computing it is not trivial, so creating an
// explicit std::vector is actually fairly efficient.
static std::vector<NewArchiveMember>
computeNewArchiveMembers(ArchiveOperation Operation,
                         object::Archive *OldArchive) {}

static void performWriteOperation(ArchiveOperation Operation,
                                  object::Archive *OldArchive,
                                  std::unique_ptr<MemoryBuffer> OldArchiveBuf,
                                  std::vector<NewArchiveMember> *NewMembersP) {}

static void createSymbolTable(object::Archive *OldArchive) {}

static void performOperation(ArchiveOperation Operation,
                             object::Archive *OldArchive,
                             std::unique_ptr<MemoryBuffer> OldArchiveBuf,
                             std::vector<NewArchiveMember> *NewMembers) {}

static int performOperation(ArchiveOperation Operation) {}

static void runMRIScript() {}

static bool handleGenericOption(StringRef arg) {}

static BitModeTy getBitMode(const char *RawBitMode) {}

static const char *matchFlagWithArg(StringRef Expected,
                                    ArrayRef<const char *>::iterator &ArgIt,
                                    ArrayRef<const char *> Args) {}

static cl::TokenizerCallback getRspQuoting(ArrayRef<const char *> ArgsArr) {}

static int ar_main(int argc, char **argv) {}

static int ranlib_main(int argc, char **argv) {}

int llvm_ar_main(int argc, char **argv, const llvm::ToolContext &) {}