You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
clang-tools-extra
compiler-rt
libcxx
libcxxabi
libunwind
lld
COFF
Common
ELF
MinGW
cmake
docs
include
lib
Core
Driver
ReaderWriter
MachO
ArchHandler.cpp
ArchHandler.h
ArchHandler_arm.cpp
ArchHandler_arm64.cpp
ArchHandler_x86.cpp
ArchHandler_x86_64.cpp
Atoms.h
CMakeLists.txt
CompactUnwindPass.cpp
DebugInfo.h
ExecutableAtoms.h
File.h
FlatNamespaceFile.h
GOTPass.cpp
LayoutPass.cpp
LayoutPass.h
MachOLinkingContext.cpp
MachONormalizedFile.h
MachONormalizedFileBinaryReader.cpp
MachONormalizedFileBinaryUtils.h
MachONormalizedFileBinaryWriter.cpp
MachONormalizedFileFromAtoms.cpp
MachONormalizedFileToAtoms.cpp
MachONormalizedFileYAML.cpp
MachOPasses.h
ObjCPass.cpp
SectCreateFile.h
ShimPass.cpp
StubsPass.cpp
TLVPass.cpp
WriterMachO.cpp
YAML
CMakeLists.txt
FileArchive.cpp
CMakeLists.txt
test
tools
unittests
utils
wasm
.arcconfig
.clang-format
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
LICENSE.TXT
README.md
lldb
llvm
openmp
polly
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mk
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
133 lines
3.5 KiB
C++
133 lines
3.5 KiB
C++
![]() |
//===- lib/ReaderWriter/MachO/ObjCPass.cpp -------------------------------===//
|
||
|
//
|
||
|
// The LLVM Linker
|
||
|
//
|
||
|
// This file is distributed under the University of Illinois Open Source
|
||
|
// License. See LICENSE.TXT for details.
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
//
|
||
|
//===----------------------------------------------------------------------===//
|
||
|
|
||
|
#include "ArchHandler.h"
|
||
|
#include "File.h"
|
||
|
#include "MachONormalizedFileBinaryUtils.h"
|
||
|
#include "MachOPasses.h"
|
||
|
#include "lld/Common/LLVM.h"
|
||
|
#include "lld/Core/DefinedAtom.h"
|
||
|
#include "lld/Core/File.h"
|
||
|
#include "lld/Core/Reference.h"
|
||
|
#include "lld/Core/Simple.h"
|
||
|
#include "lld/ReaderWriter/MachOLinkingContext.h"
|
||
|
#include "llvm/ADT/DenseMap.h"
|
||
|
#include "llvm/ADT/STLExtras.h"
|
||
|
|
||
|
namespace lld {
|
||
|
namespace mach_o {
|
||
|
|
||
|
///
|
||
|
/// ObjC Image Info Atom created by the ObjC pass.
|
||
|
///
|
||
|
class ObjCImageInfoAtom : public SimpleDefinedAtom {
|
||
|
public:
|
||
|
ObjCImageInfoAtom(const File &file, bool isBig,
|
||
|
MachOLinkingContext::ObjCConstraint objCConstraint,
|
||
|
uint32_t swiftVersion)
|
||
|
: SimpleDefinedAtom(file) {
|
||
|
|
||
|
Data.info.version = 0;
|
||
|
|
||
|
switch (objCConstraint) {
|
||
|
case MachOLinkingContext::objc_unknown:
|
||
|
llvm_unreachable("Shouldn't run the objc pass without a constraint");
|
||
|
case MachOLinkingContext::objc_supports_gc:
|
||
|
case MachOLinkingContext::objc_gc_only:
|
||
|
llvm_unreachable("GC is not supported");
|
||
|
case MachOLinkingContext::objc_retainReleaseForSimulator:
|
||
|
// The retain/release for simulator flag is already the correct
|
||
|
// encoded value for the data so just set it here.
|
||
|
Data.info.flags = (uint32_t)objCConstraint;
|
||
|
break;
|
||
|
case MachOLinkingContext::objc_retainRelease:
|
||
|
// We don't need to encode this flag, so just leave the flags as 0.
|
||
|
Data.info.flags = 0;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
Data.info.flags |= (swiftVersion << 8);
|
||
|
|
||
|
normalized::write32(Data.bytes + 4, Data.info.flags, isBig);
|
||
|
}
|
||
|
|
||
|
~ObjCImageInfoAtom() override = default;
|
||
|
|
||
|
ContentType contentType() const override {
|
||
|
return DefinedAtom::typeObjCImageInfo;
|
||
|
}
|
||
|
|
||
|
Alignment alignment() const override {
|
||
|
return 4;
|
||
|
}
|
||
|
|
||
|
uint64_t size() const override {
|
||
|
return 8;
|
||
|
}
|
||
|
|
||
|
ContentPermissions permissions() const override {
|
||
|
return DefinedAtom::permR__;
|
||
|
}
|
||
|
|
||
|
ArrayRef<uint8_t> rawContent() const override {
|
||
|
return llvm::makeArrayRef(Data.bytes, size());
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
|
||
|
struct objc_image_info {
|
||
|
uint32_t version;
|
||
|
uint32_t flags;
|
||
|
};
|
||
|
|
||
|
union {
|
||
|
objc_image_info info;
|
||
|
uint8_t bytes[8];
|
||
|
} Data;
|
||
|
};
|
||
|
|
||
|
class ObjCPass : public Pass {
|
||
|
public:
|
||
|
ObjCPass(const MachOLinkingContext &context)
|
||
|
: _ctx(context),
|
||
|
_file(*_ctx.make_file<MachOFile>("<mach-o objc pass>")) {
|
||
|
_file.setOrdinal(_ctx.getNextOrdinalAndIncrement());
|
||
|
}
|
||
|
|
||
|
llvm::Error perform(SimpleFile &mergedFile) override {
|
||
|
// Add the image info.
|
||
|
mergedFile.addAtom(*getImageInfo());
|
||
|
|
||
|
return llvm::Error::success();
|
||
|
}
|
||
|
|
||
|
private:
|
||
|
|
||
|
const DefinedAtom* getImageInfo() {
|
||
|
bool IsBig = MachOLinkingContext::isBigEndian(_ctx.arch());
|
||
|
return new (_file.allocator()) ObjCImageInfoAtom(_file, IsBig,
|
||
|
_ctx.objcConstraint(),
|
||
|
_ctx.swiftVersion());
|
||
|
}
|
||
|
|
||
|
const MachOLinkingContext &_ctx;
|
||
|
MachOFile &_file;
|
||
|
};
|
||
|
|
||
|
|
||
|
|
||
|
void addObjCPass(PassManager &pm, const MachOLinkingContext &ctx) {
|
||
|
pm.add(llvm::make_unique<ObjCPass>(ctx));
|
||
|
}
|
||
|
|
||
|
} // end namespace mach_o
|
||
|
} // end namespace lld
|