Skip to content

Commit 4bc7101

Browse files
committed
[llvm-objcopy][MachO] Print an error message on use of unsupported options
Summary: It is better to print an error message instead of silently ignoring unsupported options. As mentioned in https://reviews.llvm.org/D57045, this is not the best solution and we should print which flag is not supported at some time. Reviewers: alexshap, rupprecht, jhenderson, jakehehrlich Reviewed By: alexshap, rupprecht, jakehehrlich Subscribers: jakehehrlich, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62578 llvm-svn: 362040
1 parent b9b6446 commit 4bc7101

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,53 @@
1010
#include "../CopyConfig.h"
1111
#include "MachOReader.h"
1212
#include "MachOWriter.h"
13+
#include "llvm/Support/Errc.h"
1314
#include "llvm/Support/Error.h"
1415

1516
namespace llvm {
1617
namespace objcopy {
1718
namespace macho {
1819

20+
using namespace object;
21+
22+
static Error handleArgs(const CopyConfig &Config, Object &Obj) {
23+
if (Config.AllowBrokenLinks || !Config.BuildIdLinkDir.empty() ||
24+
Config.BuildIdLinkInput || Config.BuildIdLinkOutput ||
25+
!Config.SplitDWO.empty() || !Config.SymbolsPrefix.empty() ||
26+
!Config.AllocSectionsPrefix.empty() || !Config.AddSection.empty() ||
27+
!Config.DumpSection.empty() || !Config.KeepSection.empty() ||
28+
!Config.OnlySection.empty() || !Config.SymbolsToGlobalize.empty() ||
29+
!Config.SymbolsToKeep.empty() || !Config.SymbolsToLocalize.empty() ||
30+
!Config.SymbolsToWeaken.empty() || !Config.SymbolsToKeepGlobal.empty() ||
31+
!Config.SectionsToRename.empty() || !Config.SymbolsToRename.empty() ||
32+
!Config.UnneededSymbolsToRemove.empty() ||
33+
!Config.SetSectionFlags.empty() || !Config.ToRemove.empty() ||
34+
Config.ExtractDWO || Config.KeepFileSymbols || Config.LocalizeHidden ||
35+
Config.PreserveDates || Config.StripDWO || Config.StripNonAlloc ||
36+
Config.StripSections || Config.Weaken || Config.DecompressDebugSections ||
37+
Config.StripDebug || Config.StripNonAlloc || Config.StripSections ||
38+
Config.StripUnneeded || Config.DiscardMode != DiscardType::None ||
39+
!Config.SymbolsToAdd.empty() || Config.EntryExpr) {
40+
return createStringError(llvm::errc::invalid_argument,
41+
"option not supported by llvm-objcopy for MachO");
42+
}
43+
44+
return Error::success();
45+
}
46+
1947
Error executeObjcopyOnBinary(const CopyConfig &Config,
2048
object::MachOObjectFile &In, Buffer &Out) {
2149
MachOReader Reader(In);
2250
std::unique_ptr<Object> O = Reader.create();
23-
assert(O && "Unable to deserialize MachO object");
51+
if (!O)
52+
return createFileError(
53+
Config.InputFilename,
54+
createStringError(object_error::parse_failed,
55+
"unable to deserialize MachO object"));
56+
57+
if (Error E = handleArgs(Config, *O))
58+
return createFileError(Config.InputFilename, std::move(E));
59+
2460
MachOWriter Writer(*O, In.is64Bit(), In.isLittleEndian(), Out);
2561
return Writer.write();
2662
}

0 commit comments

Comments
 (0)