[llvm] 61133e0 - [llvm-install-name-tool] Add -delete_all_rpaths option
Alexander Shaposhnikov via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 13 01:01:38 PDT 2020
Author: Tobias Hieta
Date: 2020-10-13T00:45:57-07:00
New Revision: 61133e0b1110d03e35d0acc9ccfda2b6d9fb03cd
URL: https://github.com/llvm/llvm-project/commit/61133e0b1110d03e35d0acc9ccfda2b6d9fb03cd
DIFF: https://github.com/llvm/llvm-project/commit/61133e0b1110d03e35d0acc9ccfda2b6d9fb03cd.diff
LOG: [llvm-install-name-tool] Add -delete_all_rpaths option
This diff adds an option to remove all rpaths from a Mach-O binary.
Test plan: make check-all
Differential revision: https://reviews.llvm.org/D88674
Added:
Modified:
llvm/docs/CommandGuide/llvm-install-name-tool.rst
llvm/test/tools/llvm-objcopy/MachO/install-name-tool-delete-rpath.test
llvm/tools/llvm-objcopy/CopyConfig.cpp
llvm/tools/llvm-objcopy/CopyConfig.h
llvm/tools/llvm-objcopy/InstallNameToolOpts.td
llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-install-name-tool.rst b/llvm/docs/CommandGuide/llvm-install-name-tool.rst
index 87775d4f20d0..33eb998ab655 100644
--- a/llvm/docs/CommandGuide/llvm-install-name-tool.rst
+++ b/llvm/docs/CommandGuide/llvm-install-name-tool.rst
@@ -43,6 +43,10 @@ the same `<rpath>` value.
times to delete multiple rpaths. Throws an error if ``<rpath>`` is not listed in
the binary.
+.. option:: -delete_all_rpaths
+
+ Deletes all rpaths from the binary.
+
.. option:: --help, -h
Print a summary of command line options.
diff --git a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-delete-rpath.test b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-delete-rpath.test
index b5e6abb77752..77dd6d5eb9c4 100644
--- a/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-delete-rpath.test
+++ b/llvm/test/tools/llvm-objcopy/MachO/install-name-tool-delete-rpath.test
@@ -42,6 +42,21 @@
# COMBINED: cannot specify both -add_rpath @executable_b/. and -delete_rpath @executable_b/.
+## Remove all RPATHS
+# RUN: yaml2obj %s -o %t2
+# RUN: llvm-install-name-tool -delete_all_rpaths %t2
+# RUN: llvm-objdump -p %t2 | FileCheck %s
+
+# CHECK-NOT: LC_RPATH
+
+## Remove all RPATHS and add a new one.
+# RUN: yaml2obj %s -o %t3
+# RUN: llvm-install-name-tool --delete_all_rpaths -add_rpath @executable_b/. %t3
+# RUN: llvm-objdump -p %t3 | \
+# RUN: FileCheck %s --check-prefix=DELETE_AND_ADD --implicit-check-not=@executable
+
+# DELETE_AND_ADD: @executable_b/.
+
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp
index a98c16e6fc62..cdd9147f7613 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.cpp
+++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp
@@ -953,6 +953,9 @@ parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr) {
for (auto *Arg : InputArgs.filtered(INSTALL_NAME_TOOL_change))
Config.InstallNamesToUpdate.insert({Arg->getValue(0), Arg->getValue(1)});
+ Config.RemoveAllRpaths =
+ InputArgs.hasArg(INSTALL_NAME_TOOL_delete_all_rpaths);
+
SmallVector<StringRef, 2> Positional;
for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_UNKNOWN))
return createStringError(errc::invalid_argument, "unknown argument '%s'",
diff --git a/llvm/tools/llvm-objcopy/CopyConfig.h b/llvm/tools/llvm-objcopy/CopyConfig.h
index 666d0d450f61..af763f24d1cc 100644
--- a/llvm/tools/llvm-objcopy/CopyConfig.h
+++ b/llvm/tools/llvm-objcopy/CopyConfig.h
@@ -230,6 +230,9 @@ struct CopyConfig {
bool StripUnneeded = false;
bool Weaken = false;
bool DecompressDebugSections = false;
+ // install-name-tool's --delete_all_rpaths
+ bool RemoveAllRpaths = false;
+
DebugCompressionType CompressionType = DebugCompressionType::None;
// parseELFConfig performs ELF-specific command-line parsing. Fills `ELF` on
diff --git a/llvm/tools/llvm-objcopy/InstallNameToolOpts.td b/llvm/tools/llvm-objcopy/InstallNameToolOpts.td
index 7998041513cb..1c4e37f8b2ad 100644
--- a/llvm/tools/llvm-objcopy/InstallNameToolOpts.td
+++ b/llvm/tools/llvm-objcopy/InstallNameToolOpts.td
@@ -21,6 +21,9 @@ def add_rpath : Option<["-", "--"], "add_rpath", KIND_SEPARATE>,
def delete_rpath: Option<["-", "--"], "delete_rpath", KIND_SEPARATE>,
HelpText<"Delete specified rpath">;
+def delete_all_rpaths: Flag<["-", "--"], "delete_all_rpaths">,
+ HelpText<"Delete all rpath directives">;
+
def rpath: MultiArg<["-", "--"], "rpath", 2>,
HelpText<"Change rpath path name">;
diff --git a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
index 337c448f6dfd..4dbf1dabf9f3 100644
--- a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
+++ b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp
@@ -137,8 +137,14 @@ static Error processLoadCommands(const CopyConfig &Config, Object &Obj) {
DenseSet<StringRef> RPathsToRemove(Config.RPathsToRemove.begin(),
Config.RPathsToRemove.end());
- LoadCommandPred RemovePred = [&RPathsToRemove](const LoadCommand &LC) {
+ LoadCommandPred RemovePred = [&RPathsToRemove,
+ &Config](const LoadCommand &LC) {
if (LC.MachOLoadCommand.load_command_data.cmd == MachO::LC_RPATH) {
+ // When removing all RPaths we don't need to care
+ // about what it contains
+ if (Config.RemoveAllRpaths)
+ return true;
+
StringRef RPath = getPayloadString(LC);
if (RPathsToRemove.count(RPath)) {
RPathsToRemove.erase(RPath);
More information about the llvm-commits
mailing list