[llvm] ab244b6 - [ORC] Specialize MachOBuilder support for the LC_ID_DYLIB command.
Ben Langmuir via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 18 09:14:26 PST 2024
Author: Lang Hames
Date: 2024-01-18T09:14:15-08:00
New Revision: ab244b64dfa6a35458693d4dea6223ff3fe7f7a9
URL: https://github.com/llvm/llvm-project/commit/ab244b64dfa6a35458693d4dea6223ff3fe7f7a9
DIFF: https://github.com/llvm/llvm-project/commit/ab244b64dfa6a35458693d4dea6223ff3fe7f7a9.diff
LOG: [ORC] Specialize MachOBuilder support for the LC_ID_DYLIB command.
Provides a natural API for adding LC_ID_DYLIB commands, including the arbitrary
install name.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h b/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h
index 2bc66b11e2704fd..d6dcdabab0e59fb 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/MachOBuilder.h
@@ -43,20 +43,20 @@ struct MachOBuilderLoadCommandBase {
};
/// MachOBuilder load command wrapper type.
-template <MachO::LoadCommandType LCType> struct MachOBuilderLoadCommand;
+template <MachO::LoadCommandType LCType> struct MachOBuilderLoadCommandImplBase;
#define HANDLE_LOAD_COMMAND(Name, Value, LCStruct) \
template <> \
- struct MachOBuilderLoadCommand<MachO::Name> \
+ struct MachOBuilderLoadCommandImplBase<MachO::Name> \
: public MachO::LCStruct, public MachOBuilderLoadCommandBase { \
using CmdStruct = LCStruct; \
- MachOBuilderLoadCommand() { \
+ MachOBuilderLoadCommandImplBase() { \
memset(&rawStruct(), 0, sizeof(CmdStruct)); \
cmd = Value; \
cmdsize = sizeof(CmdStruct); \
} \
template <typename... ArgTs> \
- MachOBuilderLoadCommand(ArgTs &&...Args) \
+ MachOBuilderLoadCommandImplBase(ArgTs &&...Args) \
: CmdStruct{Value, sizeof(CmdStruct), std::forward<ArgTs>(Args)...} {} \
CmdStruct &rawStruct() { return static_cast<CmdStruct &>(*this); } \
size_t size() const override { return cmdsize; } \
@@ -70,6 +70,40 @@ template <MachO::LoadCommandType LCType> struct MachOBuilderLoadCommand;
#undef HANDLE_LOAD_COMMAND
+template <MachO::LoadCommandType LCType>
+struct MachOBuilderLoadCommand
+ : public MachOBuilderLoadCommandImplBase<LCType> {
+public:
+ MachOBuilderLoadCommand() = default;
+
+ template <typename... ArgTs>
+ MachOBuilderLoadCommand(ArgTs &&...Args)
+ : MachOBuilderLoadCommand(std::forward<ArgTs>(Args)...) {}
+};
+
+template <>
+struct MachOBuilderLoadCommand<MachO::LC_ID_DYLIB>
+ : public MachOBuilderLoadCommandImplBase<MachO::LC_ID_DYLIB> {
+
+ MachOBuilderLoadCommand(std::string Name, uint32_t Timestamp,
+ uint32_t CurrentVersion,
+ uint32_t CompatibilityVersion)
+ : MachOBuilderLoadCommandImplBase(
+ MachO::dylib{24, Timestamp, CurrentVersion, CompatibilityVersion}),
+ Name(std::move(Name)) {
+ cmdsize += (this->Name.size() + 1 + 3) & ~0x3;
+ }
+
+ size_t write(MutableArrayRef<char> Buf, size_t Offset,
+ bool SwapStruct) override {
+ Offset = writeMachOStruct(Buf, Offset, rawStruct(), SwapStruct);
+ strcpy(Buf.data() + Offset, Name.data());
+ return Offset + ((Name.size() + 1 + 3) & ~0x3);
+ }
+
+ std::string Name;
+};
+
// Builds MachO objects.
template <typename MachOTraits> class MachOBuilder {
private:
More information about the llvm-commits
mailing list