1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 03:02:36 +01:00

[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
This commit is contained in:
Tobias Hieta 2020-10-13 00:45:14 -07:00 committed by Alexander Shaposhnikov
parent 0120cd1285
commit 34a683def6
6 changed files with 35 additions and 1 deletions

View File

@ -43,6 +43,10 @@ the same `<rpath>` value.
times to delete multiple rpaths. Throws an error if ``<rpath>`` is not listed in times to delete multiple rpaths. Throws an error if ``<rpath>`` is not listed in
the binary. the binary.
.. option:: -delete_all_rpaths
Deletes all rpaths from the binary.
.. option:: --help, -h .. option:: --help, -h
Print a summary of command line options. Print a summary of command line options.

View File

@ -42,6 +42,21 @@
# COMBINED: cannot specify both -add_rpath @executable_b/. and -delete_rpath @executable_b/. # 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 --- !mach-o
FileHeader: FileHeader:
magic: 0xFEEDFACF magic: 0xFEEDFACF

View File

@ -953,6 +953,9 @@ parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr) {
for (auto *Arg : InputArgs.filtered(INSTALL_NAME_TOOL_change)) for (auto *Arg : InputArgs.filtered(INSTALL_NAME_TOOL_change))
Config.InstallNamesToUpdate.insert({Arg->getValue(0), Arg->getValue(1)}); Config.InstallNamesToUpdate.insert({Arg->getValue(0), Arg->getValue(1)});
Config.RemoveAllRpaths =
InputArgs.hasArg(INSTALL_NAME_TOOL_delete_all_rpaths);
SmallVector<StringRef, 2> Positional; SmallVector<StringRef, 2> Positional;
for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_UNKNOWN)) for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_UNKNOWN))
return createStringError(errc::invalid_argument, "unknown argument '%s'", return createStringError(errc::invalid_argument, "unknown argument '%s'",

View File

@ -230,6 +230,9 @@ struct CopyConfig {
bool StripUnneeded = false; bool StripUnneeded = false;
bool Weaken = false; bool Weaken = false;
bool DecompressDebugSections = false; bool DecompressDebugSections = false;
// install-name-tool's --delete_all_rpaths
bool RemoveAllRpaths = false;
DebugCompressionType CompressionType = DebugCompressionType::None; DebugCompressionType CompressionType = DebugCompressionType::None;
// parseELFConfig performs ELF-specific command-line parsing. Fills `ELF` on // parseELFConfig performs ELF-specific command-line parsing. Fills `ELF` on

View File

@ -21,6 +21,9 @@ def add_rpath : Option<["-", "--"], "add_rpath", KIND_SEPARATE>,
def delete_rpath: Option<["-", "--"], "delete_rpath", KIND_SEPARATE>, def delete_rpath: Option<["-", "--"], "delete_rpath", KIND_SEPARATE>,
HelpText<"Delete specified rpath">; HelpText<"Delete specified rpath">;
def delete_all_rpaths: Flag<["-", "--"], "delete_all_rpaths">,
HelpText<"Delete all rpath directives">;
def rpath: MultiArg<["-", "--"], "rpath", 2>, def rpath: MultiArg<["-", "--"], "rpath", 2>,
HelpText<"Change rpath path name">; HelpText<"Change rpath path name">;

View File

@ -137,8 +137,14 @@ static Error processLoadCommands(const CopyConfig &Config, Object &Obj) {
DenseSet<StringRef> RPathsToRemove(Config.RPathsToRemove.begin(), DenseSet<StringRef> RPathsToRemove(Config.RPathsToRemove.begin(),
Config.RPathsToRemove.end()); 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) { 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); StringRef RPath = getPayloadString(LC);
if (RPathsToRemove.count(RPath)) { if (RPathsToRemove.count(RPath)) {
RPathsToRemove.erase(RPath); RPathsToRemove.erase(RPath);