diff options
Diffstat (limited to 'llvm/tools/llvm-objcopy')
-rw-r--r-- | llvm/tools/llvm-objcopy/CMakeLists.txt | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/CopyConfig.cpp | 89 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/CopyConfig.h | 8 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/InstallNameToolOpts.td | 22 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp | 26 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/MachO/Object.cpp | 4 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/MachO/Object.h | 3 | ||||
-rw-r--r-- | llvm/tools/llvm-objcopy/llvm-objcopy.cpp | 20 |
8 files changed, 8 insertions, 170 deletions
diff --git a/llvm/tools/llvm-objcopy/CMakeLists.txt b/llvm/tools/llvm-objcopy/CMakeLists.txt index 6d4048f..50c890b5 100644 --- a/llvm/tools/llvm-objcopy/CMakeLists.txt +++ b/llvm/tools/llvm-objcopy/CMakeLists.txt @@ -9,10 +9,6 @@ set(LLVM_TARGET_DEFINITIONS ObjcopyOpts.td) tablegen(LLVM ObjcopyOpts.inc -gen-opt-parser-defs) add_public_tablegen_target(ObjcopyOptsTableGen) -set(LLVM_TARGET_DEFINITIONS InstallNameToolOpts.td) -tablegen(LLVM InstallNameToolOpts.inc -gen-opt-parser-defs) -add_public_tablegen_target(InstallNameToolOptsTableGen) - set(LLVM_TARGET_DEFINITIONS StripOpts.td) tablegen(LLVM StripOpts.inc -gen-opt-parser-defs) add_public_tablegen_target(StripOptsTableGen) @@ -35,11 +31,9 @@ add_llvm_tool(llvm-objcopy MachO/Object.cpp DEPENDS ObjcopyOptsTableGen - InstallNameToolOptsTableGen StripOptsTableGen ) -add_llvm_tool_symlink(llvm-install-name-tool llvm-objcopy) add_llvm_tool_symlink(llvm-strip llvm-objcopy) if(LLVM_INSTALL_BINUTILS_SYMLINKS) diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp index 73ed00b..d707bec 100644 --- a/llvm/tools/llvm-objcopy/CopyConfig.cpp +++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp @@ -63,44 +63,6 @@ public: ObjcopyOptTable() : OptTable(ObjcopyInfoTable) {} }; -enum InstallNameToolID { - INSTALL_NAME_TOOL_INVALID = 0, // This is not an option ID. -#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR, VALUES) \ - INSTALL_NAME_TOOL_##ID, -#include "InstallNameToolOpts.inc" -#undef OPTION -}; - -#define PREFIX(NAME, VALUE) \ - const char *const INSTALL_NAME_TOOL_##NAME[] = VALUE; -#include "InstallNameToolOpts.inc" -#undef PREFIX - -static const opt::OptTable::Info InstallNameToolInfoTable[] = { -#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ - HELPTEXT, METAVAR, VALUES) \ - {INSTALL_NAME_TOOL_##PREFIX, \ - NAME, \ - HELPTEXT, \ - METAVAR, \ - INSTALL_NAME_TOOL_##ID, \ - opt::Option::KIND##Class, \ - PARAM, \ - FLAGS, \ - INSTALL_NAME_TOOL_##GROUP, \ - INSTALL_NAME_TOOL_##ALIAS, \ - ALIASARGS, \ - VALUES}, -#include "InstallNameToolOpts.inc" -#undef OPTION -}; - -class InstallNameToolOptTable : public opt::OptTable { -public: - InstallNameToolOptTable() : OptTable(InstallNameToolInfoTable) {} -}; - enum StripID { STRIP_INVALID = 0, // This is not an option ID. #define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \ @@ -790,57 +752,6 @@ parseObjcopyOptions(ArrayRef<const char *> ArgsArr, return std::move(DC); } -// ParseInstallNameToolOptions returns the config and sets the input arguments. -// If a help flag is set then ParseInstallNameToolOptions will print the help -// messege and exit. -Expected<DriverConfig> -parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr) { - DriverConfig DC; - CopyConfig Config; - InstallNameToolOptTable T; - unsigned MissingArgumentIndex, MissingArgumentCount; - llvm::opt::InputArgList InputArgs = - T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount); - - if (InputArgs.size() == 0) { - printHelp(T, errs(), "llvm-install-name-tool"); - exit(1); - } - - if (InputArgs.hasArg(INSTALL_NAME_TOOL_help)) { - printHelp(T, outs(), "llvm-install-name-tool"); - exit(0); - } - - if (InputArgs.hasArg(INSTALL_NAME_TOOL_version)) { - outs() << "llvm-install-name-tool, compatible with cctools " - "install_name_tool\n"; - cl::PrintVersionMessage(); - exit(0); - } - - for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_add_rpath)) - Config.RPathToAdd.push_back(Arg->getValue()); - - SmallVector<StringRef, 2> Positional; - for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_UNKNOWN)) - return createStringError(errc::invalid_argument, "unknown argument '%s'", - Arg->getAsString(InputArgs).c_str()); - for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_INPUT)) - Positional.push_back(Arg->getValue()); - if (Positional.empty()) - return createStringError(errc::invalid_argument, "no input file specified"); - if (Positional.size() > 1) - return createStringError( - errc::invalid_argument, - "llvm-install-name-tool expects a single input file"); - Config.InputFilename = Positional[0]; - Config.OutputFilename = Positional[0]; - - DC.CopyConfigs.push_back(std::move(Config)); - return std::move(DC); -} - // ParseStripOptions returns the config and sets the input arguments. If a // help flag is set then ParseStripOptions will print the help messege and // exit. diff --git a/llvm/tools/llvm-objcopy/CopyConfig.h b/llvm/tools/llvm-objcopy/CopyConfig.h index c83f688..55a55d3 100644 --- a/llvm/tools/llvm-objcopy/CopyConfig.h +++ b/llvm/tools/llvm-objcopy/CopyConfig.h @@ -175,7 +175,6 @@ struct CopyConfig { std::vector<StringRef> AddSection; std::vector<StringRef> DumpSection; std::vector<StringRef> SymbolsToAdd; - std::vector<StringRef> RPathToAdd; // Section matchers NameMatcher KeepSection; @@ -252,12 +251,6 @@ Expected<DriverConfig> parseObjcopyOptions(ArrayRef<const char *> ArgsArr, llvm::function_ref<Error(Error)> ErrorCallback); -// ParseInstallNameToolOptions returns the config and sets the input arguments. -// If a help flag is set then ParseInstallNameToolOptions will print the help -// messege and exit. -Expected<DriverConfig> -parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr); - // ParseStripOptions returns the config and sets the input arguments. If a // help flag is set then ParseStripOptions will print the help messege and // exit. ErrorCallback is used to handle recoverable errors. An Error returned @@ -265,6 +258,7 @@ parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr); Expected<DriverConfig> parseStripOptions(ArrayRef<const char *> ArgsArr, llvm::function_ref<Error(Error)> ErrorCallback); + } // namespace objcopy } // namespace llvm diff --git a/llvm/tools/llvm-objcopy/InstallNameToolOpts.td b/llvm/tools/llvm-objcopy/InstallNameToolOpts.td deleted file mode 100644 index 35047a5..0000000 --- a/llvm/tools/llvm-objcopy/InstallNameToolOpts.td +++ /dev/null @@ -1,22 +0,0 @@ -//===-- InstallNameToolOpts.td - llvm-install-name-tool options --------*-===// -// -// 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 -// -//===----------------------------------------------------------------------===// -// -// This file describes the command line options of llvm-install-name. -// -//===----------------------------------------------------------------------===// - -include "llvm/Option/OptParser.td" - -def help : Flag<["--"], "help">; -def h : Flag<["-"], "h">, Alias<help>; - -def add_rpath : Option<["-", "--"], "add_rpath", KIND_SEPARATE>, - HelpText<"Add new rpath">; - -def version : Flag<["--"], "version">, - HelpText<"Print the version and exit.">; diff --git a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp index 652c0ac..d14354e 100644 --- a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp @@ -59,18 +59,6 @@ static void removeSymbols(const CopyConfig &Config, Object &Obj) { Obj.SymTable.removeSymbols(RemovePred); } -static LoadCommand buildRPathLoadCommand(StringRef Path) { - LoadCommand LC; - MachO::rpath_command RPathLC; - RPathLC.cmd = MachO::LC_RPATH; - RPathLC.path = sizeof(MachO::rpath_command); - RPathLC.cmdsize = alignTo(sizeof(MachO::rpath_command) + Path.size(), 8); - LC.MachOLoadCommand.rpath_command_data = RPathLC; - LC.Payload.assign(RPathLC.cmdsize - sizeof(MachO::rpath_command), 0); - std::copy(Path.begin(), Path.end(), LC.Payload.begin()); - return LC; -} - static Error handleArgs(const CopyConfig &Config, Object &Obj) { if (Config.AllowBrokenLinks || !Config.BuildIdLinkDir.empty() || Config.BuildIdLinkInput || Config.BuildIdLinkOutput || @@ -93,6 +81,7 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) { return createStringError(llvm::errc::invalid_argument, "option not supported by llvm-objcopy for MachO"); } + removeSections(Config, Obj); // Mark symbols to determine which symbols are still needed. @@ -106,19 +95,6 @@ static Error handleArgs(const CopyConfig &Config, Object &Obj) { for (Section &Sec : LC.Sections) Sec.Relocations.clear(); - for (StringRef RPath : Config.RPathToAdd) { - for (LoadCommand &LC : Obj.LoadCommands) { - if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH && - RPath == StringRef(reinterpret_cast<char *>(LC.Payload.data()), - LC.Payload.size()) - .trim(0)) { - return createStringError(errc::invalid_argument, - "rpath " + RPath + - " would create a duplicate load command"); - } - } - Obj.addLoadCommand(buildRPathLoadCommand(RPath)); - } return Error::success(); } diff --git a/llvm/tools/llvm-objcopy/MachO/Object.cpp b/llvm/tools/llvm-objcopy/MachO/Object.cpp index 812853e..5626782 100644 --- a/llvm/tools/llvm-objcopy/MachO/Object.cpp +++ b/llvm/tools/llvm-objcopy/MachO/Object.cpp @@ -29,10 +29,6 @@ void Object::removeSections(function_ref<bool(const Section &)> ToRemove) { std::end(LC.Sections)); } -void Object::addLoadCommand(LoadCommand LC) { - LoadCommands.push_back(std::move(LC)); -} - } // end namespace macho } // end namespace objcopy } // end namespace llvm diff --git a/llvm/tools/llvm-objcopy/MachO/Object.h b/llvm/tools/llvm-objcopy/MachO/Object.h index 098556d..8642ce3 100644 --- a/llvm/tools/llvm-objcopy/MachO/Object.h +++ b/llvm/tools/llvm-objcopy/MachO/Object.h @@ -74,7 +74,7 @@ struct LoadCommand { // The raw content of the payload of the load command (located right after the // corresponding struct). In some cases it is either empty or can be // copied-over without digging into its structure. - std::vector<uint8_t> Payload; + ArrayRef<uint8_t> Payload; // Some load commands can contain (inside the payload) an array of sections, // though the contents of the sections are stored separately. The struct @@ -270,7 +270,6 @@ struct Object { Optional<size_t> FunctionStartsCommandIndex; void removeSections(function_ref<bool(const Section &)> ToRemove); - void addLoadCommand(LoadCommand LC); }; } // end namespace macho diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp index e662f35..a68210f 100644 --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp @@ -313,20 +313,11 @@ static Error executeObjcopy(CopyConfig &Config) { return Error::success(); } -namespace { - -enum class ToolType { Objcopy, Strip, InstallNameTool }; - -} // anonymous namespace - int main(int argc, char **argv) { InitLLVM X(argc, argv); ToolName = argv[0]; - ToolType Tool = StringSwitch<ToolType>(sys::path::stem(ToolName)) - .EndsWith("strip", ToolType::Strip) - .EndsWith("install-name-tool", ToolType::InstallNameTool) - .EndsWith("install_name_tool", ToolType::InstallNameTool) - .Default(ToolType::Objcopy); + bool IsStrip = sys::path::stem(ToolName).contains("strip"); + // Expand response files. // TODO: Move these lines, which are copied from lib/Support/CommandLine.cpp, // into a separate function in the CommandLine library and call that function @@ -341,11 +332,10 @@ int main(int argc, char **argv) { NewArgv); auto Args = makeArrayRef(NewArgv).drop_front(); + Expected<DriverConfig> DriverConfig = - (Tool == ToolType::Strip) ? parseStripOptions(Args, reportWarning) - : ((Tool == ToolType::InstallNameTool) - ? parseInstallNameToolOptions(Args) - : parseObjcopyOptions(Args, reportWarning)); + IsStrip ? parseStripOptions(Args, reportWarning) + : parseObjcopyOptions(Args, reportWarning); if (!DriverConfig) { logAllUnhandledErrors(DriverConfig.takeError(), WithColor::error(errs(), ToolName)); |