From: Alexander Shaposhnikov Date: Thu, 7 Nov 2019 01:04:04 +0000 (-0800) Subject: Revert "Introduce llvm-install-name-tool" X-Git-Tag: llvmorg-11-init~4840 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7d83c2989092fbfc4afb41bed43848dbc69e35d6;p=platform%2Fupstream%2Fllvm.git Revert "Introduce llvm-install-name-tool" This reverts commit b5913e6d2f6d13fb753df701619731ca11936316. --- diff --git a/llvm/test/tools/llvm-objcopy/MachO/Inputs/i386.yaml b/llvm/test/tools/llvm-objcopy/MachO/Inputs/i386.yaml deleted file mode 100644 index 15e6220..0000000 --- a/llvm/test/tools/llvm-objcopy/MachO/Inputs/i386.yaml +++ /dev/null @@ -1,88 +0,0 @@ ---- !mach-o -FileHeader: - magic: 0xFEEDFACE - cputype: 0x00000007 - cpusubtype: 0x00000003 - filetype: 0x00000001 - ncmds: 4 - sizeofcmds: 312 - flags: 0x00002000 -LoadCommands: - - cmd: LC_SEGMENT - cmdsize: 192 - segname: '' - vmaddr: 0 - vmsize: 72 - fileoff: 340 - filesize: 72 - maxprot: 7 - initprot: 7 - nsects: 2 - flags: 0 - Sections: - - sectname: __text - segname: __TEXT - addr: 0x0000000000000000 - size: 18 - offset: 0x00000154 - align: 4 - reloff: 0x00000000 - nreloc: 0 - flags: 0x80000400 - reserved1: 0x00000000 - reserved2: 0x00000000 - reserved3: 0x00000000 - - sectname: __eh_frame - segname: __TEXT - addr: 0x0000000000000014 - size: 52 - offset: 0x00000168 - align: 2 - reloff: 0x00000000 - nreloc: 0 - flags: 0x6800000B - reserved1: 0x00000000 - reserved2: 0x00000000 - reserved3: 0x00000000 - - cmd: LC_VERSION_MIN_MACOSX - cmdsize: 16 - version: 656384 - sdk: 0 - - cmd: LC_SYMTAB - cmdsize: 24 - symoff: 412 - nsyms: 1 - stroff: 424 - strsize: 8 - - cmd: LC_DYSYMTAB - cmdsize: 80 - ilocalsym: 0 - nlocalsym: 0 - iextdefsym: 0 - nextdefsym: 1 - iundefsym: 1 - nundefsym: 0 - tocoff: 0 - ntoc: 0 - modtaboff: 0 - nmodtab: 0 - extrefsymoff: 0 - nextrefsyms: 0 - indirectsymoff: 0 - nindirectsyms: 0 - extreloff: 0 - nextrel: 0 - locreloff: 0 - nlocrel: 0 -LinkEditData: - NameList: - - n_strx: 1 - n_type: 0x0F - n_sect: 1 - n_desc: 0 - n_value: 0 - StringTable: - - '' - - _main - - '' -... diff --git a/llvm/test/tools/llvm-objcopy/MachO/Inputs/x86_64.yaml b/llvm/test/tools/llvm-objcopy/MachO/Inputs/x86_64.yaml deleted file mode 100644 index 5b059bb..0000000 --- a/llvm/test/tools/llvm-objcopy/MachO/Inputs/x86_64.yaml +++ /dev/null @@ -1,89 +0,0 @@ ---- !mach-o -FileHeader: - magic: 0xFEEDFACF - cputype: 0x01000007 - cpusubtype: 0x00000003 - filetype: 0x00000001 - ncmds: 4 - sizeofcmds: 352 - flags: 0x00002000 - reserved: 0x00000000 -LoadCommands: - - cmd: LC_SEGMENT_64 - cmdsize: 232 - segname: '' - vmaddr: 0 - vmsize: 80 - fileoff: 384 - filesize: 80 - maxprot: 7 - initprot: 7 - nsects: 2 - flags: 0 - Sections: - - sectname: __text - segname: __TEXT - addr: 0x0000000000000000 - size: 15 - offset: 0x00000180 - align: 4 - reloff: 0x00000000 - nreloc: 0 - flags: 0x80000400 - reserved1: 0x00000000 - reserved2: 0x00000000 - reserved3: 0x00000000 - - sectname: __eh_frame - segname: __TEXT - addr: 0x0000000000000010 - size: 64 - offset: 0x00000190 - align: 3 - reloff: 0x00000000 - nreloc: 0 - flags: 0x6800000B - reserved1: 0x00000000 - reserved2: 0x00000000 - reserved3: 0x00000000 - - cmd: LC_VERSION_MIN_MACOSX - cmdsize: 16 - version: 656384 - sdk: 0 - - cmd: LC_SYMTAB - cmdsize: 24 - symoff: 464 - nsyms: 1 - stroff: 480 - strsize: 8 - - cmd: LC_DYSYMTAB - cmdsize: 80 - ilocalsym: 0 - nlocalsym: 0 - iextdefsym: 0 - nextdefsym: 1 - iundefsym: 1 - nundefsym: 0 - tocoff: 0 - ntoc: 0 - modtaboff: 0 - nmodtab: 0 - extrefsymoff: 0 - nextrefsyms: 0 - indirectsymoff: 0 - nindirectsyms: 0 - extreloff: 0 - nextrel: 0 - locreloff: 0 - nlocrel: 0 -LinkEditData: - NameList: - - n_strx: 1 - n_type: 0x0F - n_sect: 1 - n_desc: 0 - n_value: 0 - StringTable: - - '' - - _main - - '' -... diff --git a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-add-rpath.test b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-add-rpath.test deleted file mode 100644 index 6d26201..0000000 --- a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-add-rpath.test +++ /dev/null @@ -1,23 +0,0 @@ -## This test checks adding a new LC_RPATH load command to a MachO binary. - -# RUN: yaml2obj %p/Inputs/i386.yaml > %t.i386 -# RUN: llvm-install-name-tool -add_rpath @executable_path/. %t.i386 -# RUN: llvm-objdump -p %t.i386 | FileCheck --check-prefix=NEW-RPATH %s - -# RUN: yaml2obj %p/Inputs/x86_64.yaml > %t.x86_64 -# RUN: llvm-install-name-tool -add_rpath @executable_path/. %t.x86_64 -# RUN: llvm-objdump -p %t.x86_64 | FileCheck --check-prefix=NEW-RPATH %s - -# NEW-RPATH: cmd LC_RPATH -# NEW-RPATH-NEXT: cmdsize -# NEW-RPATH-NEXT: @executable_path/. - -# RUN: not llvm-install-name-tool -add_rpath @executable_path/. %t.i386 2>&1 \ -# RUN: | FileCheck --check-prefix=DUPLICATE-RPATH %s - -# DUPLICATE-RPATH: duplicate load command - -# RUN: not llvm-install-name-tool -add_rpath @executable_path/. 2>&1 \ -# RUN: | FileCheck --check-prefix=NO-INPUT %s - -# NO-INPUT: no input file specified diff --git a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test deleted file mode 100644 index 43e5290..0000000 --- a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-help-message.test +++ /dev/null @@ -1,10 +0,0 @@ -# RUN: llvm-install-name-tool -h | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s -# RUN: llvm-install-name-tool --help | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s -# RUN: not llvm-install-name-tool 2>&1 | FileCheck --check-prefix=INSTALL-NAME-TOOL-USAGE %s -# RUN: not llvm-install-name-tool -abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s -# RUN: not llvm-install-name-tool --abcabc 2>&1 | FileCheck --check-prefix=UNKNOWN-ARG %s - -# INSTALL-NAME-TOOL-USAGE: USAGE: llvm-install-name-tool -# INSTALL-NAME-TOOL-USAGE: @FILE - -# UNKNOWN-ARG: unknown argument '{{-+}}abcabc' diff --git a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-version.test b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-version.test deleted file mode 100644 index 295e573..0000000 --- a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-version.test +++ /dev/null @@ -1,2 +0,0 @@ -# RUN: llvm-install-name-tool --version | FileCheck %s -# CHECK: {{ version }} diff --git a/llvm/tools/llvm-objcopy/CMakeLists.txt b/llvm/tools/llvm-objcopy/CMakeLists.txt index 6d4048f..50c890b 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 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 -parseInstallNameToolOptions(ArrayRef 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 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 AddSection; std::vector DumpSection; std::vector SymbolsToAdd; - std::vector RPathToAdd; // Section matchers NameMatcher KeepSection; @@ -252,12 +251,6 @@ Expected parseObjcopyOptions(ArrayRef ArgsArr, llvm::function_ref 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 -parseInstallNameToolOptions(ArrayRef 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 ArgsArr); Expected parseStripOptions(ArrayRef ArgsArr, llvm::function_ref 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; - -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(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 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 Payload; + ArrayRef 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 FunctionStartsCommandIndex; void removeSections(function_ref 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(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 = - (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));