[InstCombine] Signed saturation patterns
[llvm-complete.git] / tools / llvm-objcopy / MachO / MachOObjcopy.cpp
blob6d586e7d73f10879bff2dab13efb8b69a3b8595f
1 //===- MachOObjcopy.cpp -----------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "MachOObjcopy.h"
10 #include "../CopyConfig.h"
11 #include "MachOReader.h"
12 #include "MachOWriter.h"
13 #include "llvm/Support/Errc.h"
14 #include "llvm/Support/Error.h"
16 namespace llvm {
17 namespace objcopy {
18 namespace macho {
20 using namespace object;
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.NewSymbolVisibility || !Config.OnlySection.empty() ||
29 !Config.SymbolsToGlobalize.empty() || !Config.SymbolsToKeep.empty() ||
30 !Config.SymbolsToLocalize.empty() || !Config.SymbolsToWeaken.empty() ||
31 !Config.SymbolsToKeepGlobal.empty() || !Config.SectionsToRename.empty() ||
32 !Config.SymbolsToRename.empty() ||
33 !Config.UnneededSymbolsToRemove.empty() ||
34 !Config.SetSectionAlignment.empty() || !Config.SetSectionFlags.empty() ||
35 !Config.ToRemove.empty() || Config.ExtractDWO || Config.KeepFileSymbols ||
36 Config.LocalizeHidden || Config.PreserveDates || Config.StripDWO ||
37 Config.StripNonAlloc || Config.StripSections || Config.Weaken ||
38 Config.DecompressDebugSections || Config.StripDebug ||
39 Config.StripNonAlloc || Config.StripSections || Config.StripUnneeded ||
40 Config.DiscardMode != DiscardType::None || !Config.SymbolsToAdd.empty() ||
41 Config.EntryExpr) {
42 return createStringError(llvm::errc::invalid_argument,
43 "option not supported by llvm-objcopy for MachO");
46 return Error::success();
49 Error executeObjcopyOnBinary(const CopyConfig &Config,
50 object::MachOObjectFile &In, Buffer &Out) {
51 MachOReader Reader(In);
52 std::unique_ptr<Object> O = Reader.create();
53 if (!O)
54 return createFileError(
55 Config.InputFilename,
56 createStringError(object_error::parse_failed,
57 "unable to deserialize MachO object"));
59 if (Error E = handleArgs(Config, *O))
60 return createFileError(Config.InputFilename, std::move(E));
62 // TODO: Support 16KB pages which are employed in iOS arm64 binaries:
63 // https://github.com/llvm/llvm-project/commit/1bebb2832ee312d3b0316dacff457a7a29435edb
64 const uint64_t PageSize = 4096;
66 MachOWriter Writer(*O, In.is64Bit(), In.isLittleEndian(), PageSize, Out);
67 if (auto E = Writer.finalize())
68 return E;
69 return Writer.write();
72 } // end namespace macho
73 } // end namespace objcopy
74 } // end namespace llvm