|
10 | 10 | #include "../CopyConfig.h"
|
11 | 11 | #include "MachOReader.h"
|
12 | 12 | #include "MachOWriter.h"
|
| 13 | +#include "llvm/Support/Errc.h" |
13 | 14 | #include "llvm/Support/Error.h"
|
14 | 15 |
|
15 | 16 | namespace llvm {
|
16 | 17 | namespace objcopy {
|
17 | 18 | namespace macho {
|
18 | 19 |
|
| 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 | + |
19 | 47 | Error executeObjcopyOnBinary(const CopyConfig &Config,
|
20 | 48 | object::MachOObjectFile &In, Buffer &Out) {
|
21 | 49 | MachOReader Reader(In);
|
22 | 50 | 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 | + |
24 | 60 | MachOWriter Writer(*O, In.is64Bit(), In.isLittleEndian(), Out);
|
25 | 61 | return Writer.write();
|
26 | 62 | }
|
|
0 commit comments