diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp --- a/llvm/tools/llvm-objcopy/CopyConfig.cpp +++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp @@ -902,12 +902,15 @@ Config.RPathsToUpdate.insert({Old, New}); } - if (auto *Arg = InputArgs.getLastArg(INSTALL_NAME_TOOL_id)) + if (auto *Arg = InputArgs.getLastArg(INSTALL_NAME_TOOL_id)) { Config.SharedLibId = Arg->getValue(); + if (Config.SharedLibId->empty()) + return createStringError(errc::invalid_argument, + "cannot specify an empty id"); + } - 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)}); - } SmallVector Positional; for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_UNKNOWN)) diff --git a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp --- a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp @@ -181,13 +181,8 @@ for (LoadCommand &LC : Obj.LoadCommands) { switch (LC.MachOLoadCommand.load_command_data.cmd) { case MachO::LC_ID_DYLIB: - if (Config.SharedLibId) { - StringRef Id = Config.SharedLibId.getValue(); - if (Id.empty()) - return createStringError(errc::invalid_argument, - "cannot specify an empty id"); - updateLoadCommandPayloadString(LC, Id); - } + if (Config.SharedLibId) + updateLoadCommandPayloadString(LC, *Config.SharedLibId); break; case MachO::LC_RPATH: {