LLVM  14.0.0git
MachOUniversalWriter.h
Go to the documentation of this file.
1 //===- MachOUniversalWriter.h - MachO universal binary writer----*- 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 //===----------------------------------------------------------------------===//
8 //
9 // Declares the Slice class and writeUniversalBinary function for writing a
10 // MachO universal binary file.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_OBJECT_MACHOUNIVERSALWRITER_H
15 #define LLVM_OBJECT_MACHOUNIVERSALWRITER_H
16 
17 #include "llvm/Object/Archive.h"
18 #include "llvm/Object/Binary.h"
19 #include "llvm/Object/MachO.h"
20 
21 namespace llvm {
22 class LLVMContext;
23 
24 namespace object {
25 class IRObjectFile;
26 
27 class Slice {
28  const Binary *B;
29  uint32_t CPUType;
30  uint32_t CPUSubType;
31  std::string ArchName;
32 
33  // P2Alignment field stores slice alignment values from universal
34  // binaries. This is also needed to order the slices so the total
35  // file size can be calculated before creating the output buffer.
36  uint32_t P2Alignment;
37 
38  Slice(const IRObjectFile &IRO, uint32_t CPUType, uint32_t CPUSubType,
39  std::string ArchName, uint32_t Align);
40 
41 public:
42  explicit Slice(const MachOObjectFile &O);
43 
45 
46  /// This constructor takes pre-specified \param CPUType , \param CPUSubType ,
47  /// \param ArchName , \param Align instead of inferring them from the archive
48  /// members.
49  Slice(const Archive &A, uint32_t CPUType, uint32_t CPUSubType,
50  std::string ArchName, uint32_t Align);
51 
52  static Expected<Slice> create(const Archive &A,
53  LLVMContext *LLVMCtx = nullptr);
54 
55  static Expected<Slice> create(const IRObjectFile &IRO, uint32_t Align);
56 
57  void setP2Alignment(uint32_t Align) { P2Alignment = Align; }
58 
59  const Binary *getBinary() const { return B; }
60 
61  uint32_t getCPUType() const { return CPUType; }
62 
63  uint32_t getCPUSubType() const { return CPUSubType; }
64 
65  uint32_t getP2Alignment() const { return P2Alignment; }
66 
67  uint64_t getCPUID() const {
68  return static_cast<uint64_t>(CPUType) << 32 | CPUSubType;
69  }
70 
71  std::string getArchString() const {
72  if (!ArchName.empty())
73  return ArchName;
74  return ("unknown(" + Twine(CPUType) + "," +
75  Twine(CPUSubType & ~MachO::CPU_SUBTYPE_MASK) + ")")
76  .str();
77  }
78 
79  friend bool operator<(const Slice &Lhs, const Slice &Rhs) {
80  if (Lhs.CPUType == Rhs.CPUType)
81  return Lhs.CPUSubType < Rhs.CPUSubType;
82  // force arm64-family to follow after all other slices for
83  // compatibility with cctools lipo
84  if (Lhs.CPUType == MachO::CPU_TYPE_ARM64)
85  return false;
86  if (Rhs.CPUType == MachO::CPU_TYPE_ARM64)
87  return true;
88  // Sort by alignment to minimize file size
89  return Lhs.P2Alignment < Rhs.P2Alignment;
90  }
91 };
92 
93 Error writeUniversalBinary(ArrayRef<Slice> Slices, StringRef OutputFileName);
94 
96 
97 } // end namespace object
98 
99 } // end namespace llvm
100 
101 #endif // LLVM_OBJECT_MACHOUNIVERSALWRITER_H
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::object::Slice::getP2Alignment
uint32_t getP2Alignment() const
Definition: MachOUniversalWriter.h:65
llvm::MachO::CPU_SUBTYPE_MASK
@ CPU_SUBTYPE_MASK
Definition: MachO.h:1435
llvm::object::Slice::getCPUID
uint64_t getCPUID() const
Definition: MachOUniversalWriter.h:67
llvm::object::Slice::create
static Expected< Slice > create(const Archive &A, LLVMContext *LLVMCtx=nullptr)
llvm::object::Slice::setP2Alignment
void setP2Alignment(uint32_t Align)
Definition: MachOUniversalWriter.h:57
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
MachO.h
llvm::object::Archive
Definition: Archive.h:81
llvm::object::Slice::getCPUSubType
uint32_t getCPUSubType() const
Definition: MachOUniversalWriter.h:63
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::object::Slice::getBinary
const Binary * getBinary() const
Definition: MachOUniversalWriter.h:59
Align
uint64_t Align
Definition: ELFObjHandler.cpp:83
llvm::Align
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39
llvm::object::MachOObjectFile
Definition: MachO.h:262
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:179
object
bar al al movzbl eax ret Missed when stored in a memory object
Definition: README.txt:1411
llvm::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
Archive.h
llvm::MachO::CPU_TYPE_ARM64
@ CPU_TYPE_ARM64
Definition: MachO.h:1426
llvm::object::Slice
Definition: MachOUniversalWriter.h:27
llvm::object::Slice::getArchString
std::string getArchString() const
Definition: MachOUniversalWriter.h:71
llvm::object::IRObjectFile
Definition: IRObjectFile.h:31
B
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional ldr LCPI1_0 ldr ldr tst movne lsr ldr LCPI1_1 and r0 bx lr it saves an instruction and a register It might be profitable to cse MOVi16 if there are lots of bit immediates with the same bottom half Robert Muth started working on an alternate jump table implementation that does not put the tables in line in the text This is more like the llvm default jump table implementation This might be useful sometime Several revisions of patches are on the mailing beginning while CMP sets them like a subtract Therefore to be able to use CMN for comparisons other than the Z we ll need additional logic to reverse the conditionals associated with the comparison Perhaps a pseudo instruction for the with a post codegen pass to clean up and handle the condition codes See PR5694 for testcase Given the following on int B
Definition: README.txt:592
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::object::Binary
Definition: Binary.h:32
uint32_t
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::object::writeUniversalBinaryToStream
Error writeUniversalBinaryToStream(ArrayRef< Slice > Slices, raw_ostream &Out)
Definition: MachOUniversalWriter.cpp:266
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::object::Slice::operator<
friend bool operator<(const Slice &Lhs, const Slice &Rhs)
Definition: MachOUniversalWriter.h:79
Binary.h
llvm::object::writeUniversalBinary
Error writeUniversalBinary(ArrayRef< Slice > Slices, StringRef OutputFileName)
Definition: MachOUniversalWriter.cpp:307
llvm::object::Slice::getCPUType
uint32_t getCPUType() const
Definition: MachOUniversalWriter.h:61