Skip to content

Commit e9f9027

Browse files
author
Alexander Shaposhnikov
committed
[llvm-install-name-tool] Validate -id value early
The code which validates the value of -id is moved into the function parseInstallNameToolOptions. Test plan: make check-all Differential revision: https://reviews.llvm.org/D87855
1 parent 2ac0624 commit e9f9027

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

llvm/tools/llvm-objcopy/CopyConfig.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,15 @@ parseInstallNameToolOptions(ArrayRef<const char *> ArgsArr) {
902902
Config.RPathsToUpdate.insert({Old, New});
903903
}
904904

905-
if (auto *Arg = InputArgs.getLastArg(INSTALL_NAME_TOOL_id))
905+
if (auto *Arg = InputArgs.getLastArg(INSTALL_NAME_TOOL_id)) {
906906
Config.SharedLibId = Arg->getValue();
907+
if (Config.SharedLibId->empty())
908+
return createStringError(errc::invalid_argument,
909+
"cannot specify an empty id");
910+
}
907911

908-
for (auto *Arg : InputArgs.filtered(INSTALL_NAME_TOOL_change)) {
912+
for (auto *Arg : InputArgs.filtered(INSTALL_NAME_TOOL_change))
909913
Config.InstallNamesToUpdate.insert({Arg->getValue(0), Arg->getValue(1)});
910-
}
911914

912915
SmallVector<StringRef, 2> Positional;
913916
for (auto Arg : InputArgs.filtered(INSTALL_NAME_TOOL_UNKNOWN))

llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,9 @@ static Error processLoadCommands(const CopyConfig &Config, Object &Obj) {
181181
for (LoadCommand &LC : Obj.LoadCommands) {
182182
switch (LC.MachOLoadCommand.load_command_data.cmd) {
183183
case MachO::LC_ID_DYLIB:
184-
if (Config.SharedLibId) {
185-
StringRef Id = Config.SharedLibId.getValue();
186-
if (Id.empty())
187-
return createStringError(errc::invalid_argument,
188-
"cannot specify an empty id");
189-
updateLoadCommandPayloadString<MachO::dylib_command>(LC, Id);
190-
}
184+
if (Config.SharedLibId)
185+
updateLoadCommandPayloadString<MachO::dylib_command>(
186+
LC, *Config.SharedLibId);
191187
break;
192188

193189
case MachO::LC_RPATH: {

0 commit comments

Comments
 (0)