diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2026-01-16 22:54:33 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2026-01-16 22:54:33 +0100 |
| commit | 112b49ab7d2af6edea6bad97f2eea98e96ed5428 (patch) | |
| tree | 80e7590c4851efafa6813f6f6adf483b1d5180de /include/CompilerKit/MachO.h | |
| parent | d4d91d5ffe7b02478a5ed14adcdad931dec95fd1 (diff) | |
feat: implement Mach-O linker and massive improvements on Assembler and Linkers.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'include/CompilerKit/MachO.h')
| -rw-r--r-- | include/CompilerKit/MachO.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/include/CompilerKit/MachO.h b/include/CompilerKit/MachO.h new file mode 100644 index 0000000..a22fa9d --- /dev/null +++ b/include/CompilerKit/MachO.h @@ -0,0 +1,48 @@ +// Copyright 2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (See accompanying +// file LICENSE or copy at http://www.apache.org/licenses/LICENSE-2.0) +// Official repository: https://github.com/nekernel-org/nectar + +#ifndef _NECTAR_MACHO_H_ +#define _NECTAR_MACHO_H_ + +#include <CompilerKit/Detail/Config.h> + +#include <mach-o/loader.h> +#include <mach-o/nlist.h> + +namespace CompilerKit { +namespace MachO { + + /// @brief Mach-O segment names + constexpr const char* kSegmentText = "__TEXT"; + constexpr const char* kSegmentData = "__DATA"; + constexpr const char* kSegmentLinkedit = "__LINKEDIT"; + + /// @brief Mach-O section names + constexpr const char* kSectionText = "__text"; + constexpr const char* kSectionData = "__data"; + constexpr const char* kSectionBss = "__bss"; + + /// @brief Default base address for Mach-O executables + constexpr uint64_t kDefaultBaseAddress = 0x100000000ULL; + + /// @brief Page size for alignment + constexpr uint64_t kPageSize = 0x4000ULL; // 16KB for arm64, also works for x86_64 + + /// @brief Section alignment (2^4 = 16 bytes) + constexpr uint32_t kSectionAlign = 4; + + /// @brief Helper to align a value to page boundary + inline uint64_t AlignToPage(uint64_t value) { return (value + kPageSize - 1) & ~(kPageSize - 1); } + + /// @brief Helper to copy segment/section name safely + inline void CopySegmentName(char* dest, const char* src) { + std::memset(dest, 0, 16); + std::strncpy(dest, src, 16); + } + +} // namespace MachO +} // namespace CompilerKit + +#endif // ifndef _NECTAR_MACHO_H_ |
