summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-01-24 17:11:15 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-01-24 17:25:33 +0100
commit34e82c2ecbbdc0aa3e9bc9937b8187580952ed11 (patch)
treefe17e055c7d6cc8016dcd722fd3f244362153b83
parent97868f338a02ad5acd8049f0ba0474d330e11877 (diff)
chore: wip: Inner calls (aka stubs in Nectar)
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
-rw-r--r--.gitignore2
-rw-r--r--include/CompilerKit/Detail/PreConfig.h5
-rw-r--r--include/CompilerKit/MachO.h4
-rw-r--r--include/CompilerKit/UUID.h2
-rw-r--r--include/ThirdParty/Dialogs/Dialogs.h43
-rw-r--r--include/mach-o/arm_reloc.h31
-rw-r--r--include/mach-o/fat.h24
-rw-r--r--include/mach-o/ldsyms.h48
-rw-r--r--include/mach-o/loader.h1500
-rw-r--r--include/mach-o/nlist.h107
-rw-r--r--include/mach-o/reloc.h85
-rw-r--r--include/mach-o/stab.h70
-rw-r--r--src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc82
-rw-r--r--test/test_samples/inner.nc13
14 files changed, 1065 insertions, 951 deletions
diff --git a/.gitignore b/.gitignore
index e3dc29c..f0418ef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -21,6 +21,8 @@ src/*/pef-*-necdrv
src/*/pef-*-cxxdrv
src/*/pef-*-cdrv
+*~
+
*.pp
*.masm
*.creator.user
diff --git a/include/CompilerKit/Detail/PreConfig.h b/include/CompilerKit/Detail/PreConfig.h
index a3d14a5..acc094f 100644
--- a/include/CompilerKit/Detail/PreConfig.h
+++ b/include/CompilerKit/Detail/PreConfig.h
@@ -48,9 +48,9 @@
#include <time.h>
#include <unistd.h>
#include <cassert>
+#include <filesystem>
#include <fstream>
#include <string>
-#include <filesystem>
#ifdef __linux__
#define isnumber isdigit
@@ -89,8 +89,7 @@
#define kObjectFileExt ".obj"
#define kBinaryFileExt ".bin"
-#define kAsmFileExts \
- { ".64x", ".32x", ".masm", ".s", ".S", ".asm", ".x64" }
+#define kAsmFileExts {".64x", ".32x", ".masm", ".s", ".S", ".asm", ".x64"}
#define kAsmFileExtsMax (7U)
diff --git a/include/CompilerKit/MachO.h b/include/CompilerKit/MachO.h
index 1b6282d..a9276f1 100644
--- a/include/CompilerKit/MachO.h
+++ b/include/CompilerKit/MachO.h
@@ -35,7 +35,9 @@ namespace MachO {
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); }
+ 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) {
diff --git a/include/CompilerKit/UUID.h b/include/CompilerKit/UUID.h
index 98733fd..2993b8b 100644
--- a/include/CompilerKit/UUID.h
+++ b/include/CompilerKit/UUID.h
@@ -165,7 +165,7 @@ namespace Detail {
process_byte(static_cast<unsigned char>((bitCount >> 24) & 0xFF));
process_byte(static_cast<unsigned char>((bitCount >> 16) & 0xFF));
process_byte(static_cast<unsigned char>((bitCount >> 8) & 0xFF));
- process_byte(static_cast<unsigned char>((bitCount) &0xFF));
+ process_byte(static_cast<unsigned char>((bitCount) & 0xFF));
memcpy(digest, m_digest, 5 * sizeof(uint32_t));
return digest;
diff --git a/include/ThirdParty/Dialogs/Dialogs.h b/include/ThirdParty/Dialogs/Dialogs.h
index f370719..8168dd2 100644
--- a/include/ThirdParty/Dialogs/Dialogs.h
+++ b/include/ThirdParty/Dialogs/Dialogs.h
@@ -176,7 +176,7 @@ namespace internal {
#elif __EMSCRIPTEN__
void start(int exit_code);
#else
- void start_process(std::vector<std::string> const& command);
+ void start_process(std::vector<std::string> const& command);
#endif
~executor();
@@ -219,7 +219,7 @@ namespace internal {
: m_proc(reinterpret_cast<T*>((void*) ::GetProcAddress(lib.handle, sym.c_str()))) {}
explicit operator bool() const { return m_proc != nullptr; }
- operator T*() const { return m_proc; }
+ operator T*() const { return m_proc; }
private:
T* m_proc;
@@ -491,10 +491,10 @@ inline settings::settings(bool resync) {
#if _WIN32
flags(flag::is_vista) = internal::is_vista();
#elif !__APPLE__
- flags(flag::has_zenity) = check_program("zenity");
+ flags(flag::has_zenity) = check_program("zenity");
flags(flag::has_matedialog) = check_program("matedialog");
- flags(flag::has_qarma) = check_program("qarma");
- flags(flag::has_kdialog) = check_program("kdialog");
+ flags(flag::has_qarma) = check_program("qarma");
+ flags(flag::has_kdialog) = check_program("kdialog");
// If multiple helpers are available, try to default to the best one
if (flags(flag::has_zenity) && flags(flag::has_kdialog)) {
@@ -541,7 +541,7 @@ inline bool settings::check_program(std::string const& program) {
(void) program;
return false;
#else
- int exit_code = -1;
+ int exit_code = -1;
internal::executor async;
async.start_process({"/bin/sh", "-c", "which " + program});
async.result(&exit_code);
@@ -605,7 +605,7 @@ inline std::string path::home() {
if (size_max != -1) len = size_t(size_max);
#endif
std::vector<char> buf(len);
- struct passwd pwd, *result;
+ struct passwd pwd, *result;
if (getpwuid_r(getuid(), &pwd, buf.data(), buf.size(), &result) == 0) return result->pw_dir;
#endif
return "/";
@@ -718,7 +718,7 @@ inline void internal::executor::start_process(std::vector<std::string> const& co
}
close(in[1]);
- m_fd = out[0];
+ m_fd = out[0];
auto flags = fcntl(m_fd, F_GETFL);
fcntl(m_fd, F_SETFL, flags | O_NONBLOCK);
@@ -754,7 +754,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */)
// FIXME: do something
(void) timeout;
#else
- char buf[BUFSIZ];
+ char buf[BUFSIZ];
ssize_t received = read(m_fd, buf, BUFSIZ); // Flawfinder: ignore
if (received > 0) {
m_stdout += std::string(buf, received);
@@ -765,7 +765,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */)
// (this happens when the calling application handles or ignores SIG_CHLD) and results in
// waitpid() failing with ECHILD. Otherwise we assume the child is running and we sleep for
// a little while.
- int status;
+ int status;
pid_t child = waitpid(m_pid, &status, WNOHANG);
if (child != m_pid && (child >= 0 || errno != ECHILD)) {
// FIXME: this happens almost always at first iteration
@@ -783,8 +783,7 @@ inline bool internal::executor::ready(int timeout /* = default_wait_timeout */)
inline void internal::executor::stop() {
// Loop until the user closes the dialog
- while (!ready())
- ;
+ while (!ready());
}
// dll implementation
@@ -880,11 +879,11 @@ inline std::vector<std::string> internal::dialog::desktop_helper() const {
#if __APPLE__
return {"osascript"};
#else
- return {flags(flag::has_zenity) ? "zenity"
+ return {flags(flag::has_zenity) ? "zenity"
: flags(flag::has_matedialog) ? "matedialog"
- : flags(flag::has_qarma) ? "qarma"
- : flags(flag::has_kdialog) ? "kdialog"
- : "echo"};
+ : flags(flag::has_qarma) ? "qarma"
+ : flags(flag::has_kdialog) ? "kdialog"
+ : "echo"};
#endif
}
@@ -1126,9 +1125,9 @@ inline internal::file_dialog::file_dialog(type in_type, std::string const& title
// Split the pattern list to check whether "*" is in there; if it
// is, we have to disable filters because there is no mechanism in
// OS X for the user to override the filter.
- std::regex sep("\\s+");
- std::string filter_list;
- bool has_filter = true;
+ std::regex sep("\\s+");
+ std::string filter_list;
+ bool has_filter = true;
std::sregex_token_iterator iter(patterns.begin(), patterns.end(), sep, -1);
std::sregex_token_iterator end;
for (; iter != end; ++iter) {
@@ -1237,7 +1236,7 @@ inline std::vector<std::string> internal::file_dialog::vector_result() {
return m_vector_result;
#else
std::vector<std::string> ret;
- auto result = m_async->result();
+ auto result = m_async->result();
for (;;) {
// Split result along newline characters
auto i = result.find('\n');
@@ -1570,7 +1569,7 @@ inline message::message(std::string const& title, std::string const& text,
if_cancel = button::ok;
break;
}
- m_mappings[1] = if_cancel;
+ m_mappings[1] = if_cancel;
m_mappings[256] = if_cancel; // XXX: I think this was never correct
script += " with icon ";
switch (_icon) {
@@ -1657,7 +1656,7 @@ inline message::message(std::string const& title, std::string const& text,
if (_choice == choice::yes_no_cancel) flag += "cancel";
command.push_back(flag);
if (_choice == choice::yes_no || _choice == choice::yes_no_cancel) {
- m_mappings[0] = button::yes;
+ m_mappings[0] = button::yes;
m_mappings[256] = button::no;
}
}
diff --git a/include/mach-o/arm_reloc.h b/include/mach-o/arm_reloc.h
index 2638d30..fa08a86 100644
--- a/include/mach-o/arm_reloc.h
+++ b/include/mach-o/arm_reloc.h
@@ -2,14 +2,14 @@
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -17,7 +17,7 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
/*
@@ -28,17 +28,16 @@
* for instructions. Since they are for instructions the r_address field
* indicates the 32 bit instruction that the relocation is to be preformed on.
*/
-enum reloc_type_arm
-{
- ARM_RELOC_VANILLA, /* generic relocation as discribed above */
- ARM_RELOC_PAIR, /* the second relocation entry of a pair */
- ARM_RELOC_SECTDIFF, /* a PAIR follows with subtract symbol value */
- ARM_RELOC_LOCAL_SECTDIFF, /* like ARM_RELOC_SECTDIFF, but the symbol
- referenced was local. */
- ARM_RELOC_PB_LA_PTR,/* prebound lazy pointer */
- ARM_RELOC_BR24, /* 24 bit branch displacement (to a word address) */
- ARM_THUMB_RELOC_BR22, /* 22 bit branch displacement (to a half-word
- address) */
- ARM_THUMB_32BIT_BRANCH, /* obsolete - a thumb 32-bit branch instruction
- possibly needing page-spanning branch workaround */
+enum reloc_type_arm {
+ ARM_RELOC_VANILLA, /* generic relocation as discribed above */
+ ARM_RELOC_PAIR, /* the second relocation entry of a pair */
+ ARM_RELOC_SECTDIFF, /* a PAIR follows with subtract symbol value */
+ ARM_RELOC_LOCAL_SECTDIFF, /* like ARM_RELOC_SECTDIFF, but the symbol
+ referenced was local. */
+ ARM_RELOC_PB_LA_PTR, /* prebound lazy pointer */
+ ARM_RELOC_BR24, /* 24 bit branch displacement (to a word address) */
+ ARM_THUMB_RELOC_BR22, /* 22 bit branch displacement (to a half-word
+ address) */
+ ARM_THUMB_32BIT_BRANCH, /* obsolete - a thumb 32-bit branch instruction
+ possibly needing page-spanning branch workaround */
};
diff --git a/include/mach-o/fat.h b/include/mach-o/fat.h
index e0d4e48..2275e58 100644
--- a/include/mach-o/fat.h
+++ b/include/mach-o/fat.h
@@ -2,14 +2,14 @@
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -17,7 +17,7 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _MACH_O_FAT_H_
@@ -44,20 +44,20 @@
#include <stdint.h>
-#define FAT_MAGIC 0xcafebabe
-#define FAT_CIGAM 0xbebafeca /* NXSwapLong(FAT_MAGIC) */
+#define FAT_MAGIC 0xcafebabe
+#define FAT_CIGAM 0xbebafeca /* NXSwapLong(FAT_MAGIC) */
struct fat_header {
- uint32_t magic; /* FAT_MAGIC */
- uint32_t nfat_arch; /* number of structs that follow */
+ uint32_t magic; /* FAT_MAGIC */
+ uint32_t nfat_arch; /* number of structs that follow */
};
struct fat_arch {
- int cputype; /* cpu specifier (int) */
- int cpusubtype; /* machine specifier (int) */
- uint32_t offset; /* file offset to this object file */
- uint32_t size; /* size of this object file */
- uint32_t align; /* alignment as a power of 2 */
+ int cputype; /* cpu specifier (int) */
+ int cpusubtype; /* machine specifier (int) */
+ uint32_t offset; /* file offset to this object file */
+ uint32_t size; /* size of this object file */
+ uint32_t align; /* alignment as a power of 2 */
};
#endif /* _MACH_O_FAT_H_ */
diff --git a/include/mach-o/ldsyms.h b/include/mach-o/ldsyms.h
index 1fbb783..05aa7f1 100644
--- a/include/mach-o/ldsyms.h
+++ b/include/mach-o/ldsyms.h
@@ -2,14 +2,14 @@
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -17,7 +17,7 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
@@ -51,15 +51,15 @@
* any file type other than a MH_EXECUTE file type. The type of the symbol is
* absolute as the header is not part of any section.
*/
-#define _MH_EXECUTE_SYM "__mh_execute_header"
-#define MH_EXECUTE_SYM "_mh_execute_header"
+#define _MH_EXECUTE_SYM "__mh_execute_header"
+#define MH_EXECUTE_SYM "_mh_execute_header"
extern const struct
#ifdef __LP64__
-mach_header_64
+ mach_header_64
#else
-mach_header
+ mach_header
#endif
-_mh_execute_header;
+ _mh_execute_header;
/*
* The value of the link editor defined symbol _MH_BUNDLE_SYM is the address
@@ -68,15 +68,15 @@ _mh_execute_header;
* an N_SECT symbol even thought the header is not part of any section. This
* symbol is private to the code in the bundle it is a part of.
*/
-#define _MH_BUNDLE_SYM "__mh_bundle_header"
-#define MH_BUNDLE_SYM "_mh_bundle_header"
+#define _MH_BUNDLE_SYM "__mh_bundle_header"
+#define MH_BUNDLE_SYM "_mh_bundle_header"
extern const struct
#ifdef __LP64__
-mach_header_64
+ mach_header_64
#else
-mach_header
+ mach_header
#endif
-_mh_bundle_header;
+ _mh_bundle_header;
/*
* The value of the link editor defined symbol _MH_DYLIB_SYM is the address
@@ -85,15 +85,15 @@ _mh_bundle_header;
* an N_SECT symbol even thought the header is not part of any section. This
* symbol is private to the code in the library it is a part of.
*/
-#define _MH_DYLIB_SYM "__mh_dylib_header"
-#define MH_DYLIB_SYM "_mh_dylib_header"
+#define _MH_DYLIB_SYM "__mh_dylib_header"
+#define MH_DYLIB_SYM "_mh_dylib_header"
extern const struct
#ifdef __LP64__
-mach_header_64
+ mach_header_64
#else
-mach_header
+ mach_header
#endif
-_mh_dylib_header;
+ _mh_dylib_header;
/*
* The value of the link editor defined symbol _MH_DYLINKER_SYM is the address
@@ -102,15 +102,15 @@ _mh_dylib_header;
* an N_SECT symbol even thought the header is not part of any section. This
* symbol is private to the code in the dynamic linker it is a part of.
*/
-#define _MH_DYLINKER_SYM "__mh_dylinker_header"
-#define MH_DYLINKER_SYM "_mh_dylinker_header"
+#define _MH_DYLINKER_SYM "__mh_dylinker_header"
+#define MH_DYLINKER_SYM "_mh_dylinker_header"
extern const struct
#ifdef __LP64__
-mach_header_64
+ mach_header_64
#else
-mach_header
+ mach_header
#endif
-_mh_dylinker_header;
+ _mh_dylinker_header;
/*
* For the MH_PRELOAD file type the headers are not loaded as part of any
@@ -122,7 +122,7 @@ _mh_dylinker_header;
* have the form: __SEGNAME__sectname__begin and __SEGNAME__sectname__end
* where __sectname is the name of the section and __SEGNAME is the segment it
* is in.
- *
+ *
* The above symbols' types are those of the section they are referring to.
* This is true even for symbols who's values are end's of a section and
* that value is next address after that section and not really in that
diff --git a/include/mach-o/loader.h b/include/mach-o/loader.h
index 9551c59..7b5d206 100644
--- a/include/mach-o/loader.h
+++ b/include/mach-o/loader.h
@@ -48,32 +48,32 @@
* 32-bit architectures.
*/
struct mach_header {
- uint32_t magic; /* mach magic number identifier */
- int cputype; /* cpu specifier */
- int cpusubtype; /* machine specifier */
- uint32_t filetype; /* type of file */
- uint32_t ncmds; /* number of load commands */
- uint32_t sizeofcmds; /* the size of all the load commands */
- uint32_t flags; /* flags */
+ uint32_t magic; /* mach magic number identifier */
+ int cputype; /* cpu specifier */
+ int cpusubtype; /* machine specifier */
+ uint32_t filetype; /* type of file */
+ uint32_t ncmds; /* number of load commands */
+ uint32_t sizeofcmds; /* the size of all the load commands */
+ uint32_t flags; /* flags */
};
/* Constant for the magic field of the mach_header (32-bit architectures) */
-#define MH_MAGIC 0xfeedface /* the mach magic number */
-#define MH_CIGAM 0xcefaedfe /* NXSwapInt(MH_MAGIC) */
+#define MH_MAGIC 0xfeedface /* the mach magic number */
+#define MH_CIGAM 0xcefaedfe /* NXSwapInt(MH_MAGIC) */
/*
* The 64-bit mach header appears at the very beginning of object files for
* 64-bit architectures.
*/
struct mach_header_64 {
- uint32_t magic; /* mach magic number identifier */
- int cputype; /* cpu specifier */
- int cpusubtype; /* machine specifier */
- uint32_t filetype; /* type of file */
- uint32_t ncmds; /* number of load commands */
- uint32_t sizeofcmds; /* the size of all the load commands */
- uint32_t flags; /* flags */
- uint32_t reserved; /* reserved */
+ uint32_t magic; /* mach magic number identifier */
+ int cputype; /* cpu specifier */
+ int cpusubtype; /* machine specifier */
+ uint32_t filetype; /* type of file */
+ uint32_t ncmds; /* number of load commands */
+ uint32_t sizeofcmds; /* the size of all the load commands */
+ uint32_t flags; /* flags */
+ uint32_t reserved; /* reserved */
};
/* Constant for the magic field of the mach_header_64 (64-bit architectures) */
@@ -103,96 +103,119 @@ struct mach_header_64 {
*
* Constants for the filetype field of the mach_header
*/
-#define MH_OBJECT 0x1 /* relocatable object file */
-#define MH_EXECUTE 0x2 /* demand paged executable file */
-#define MH_FVMLIB 0x3 /* fixed VM shared library file */
-#define MH_CORE 0x4 /* core file */
-#define MH_PRELOAD 0x5 /* preloaded executable file */
-#define MH_DYLIB 0x6 /* dynamically bound shared library */
-#define MH_DYLINKER 0x7 /* dynamic link editor */
-#define MH_BUNDLE 0x8 /* dynamically bound bundle file */
-#define MH_DYLIB_STUB 0x9 /* shared library stub for static */
- /* linking only, no section contents */
-#define MH_DSYM 0xa /* companion file with only debug */
- /* sections */
-#define MH_KEXT_BUNDLE 0xb /* x86_64 kexts */
+#define MH_OBJECT 0x1 /* relocatable object file */
+#define MH_EXECUTE 0x2 /* demand paged executable file */
+#define MH_FVMLIB 0x3 /* fixed VM shared library file */
+#define MH_CORE 0x4 /* core file */
+#define MH_PRELOAD 0x5 /* preloaded executable file */
+#define MH_DYLIB 0x6 /* dynamically bound shared library */
+#define MH_DYLINKER 0x7 /* dynamic link editor */
+#define MH_BUNDLE 0x8 /* dynamically bound bundle file */
+#define MH_DYLIB_STUB 0x9 /* shared library stub for static */
+ /* linking only, no section contents */
+#define MH_DSYM 0xa /* companion file with only debug */
+ /* sections */
+#define MH_KEXT_BUNDLE 0xb /* x86_64 kexts */
/* Constants for the flags field of the mach_header */
-#define MH_NOUNDEFS 0x1 /* the object file has no undefined
- references */
-#define MH_INCRLINK 0x2 /* the object file is the output of an
- incremental link against a base file
- and can't be link edited again */
-#define MH_DYLDLINK 0x4 /* the object file is input for the
- dynamic linker and can't be staticly
- link edited again */
-#define MH_BINDATLOAD 0x8 /* the object file's undefined
- references are bound by the dynamic
- linker when loaded. */
-#define MH_PREBOUND 0x10 /* the file has its dynamic undefined
- references prebound. */
-#define MH_SPLIT_SEGS 0x20 /* the file has its read-only and
- read-write segments split */
-#define MH_LAZY_INIT 0x40 /* the shared library init routine is
- to be run lazily via catching memory
- faults to its writeable segments
- (obsolete) */
-#define MH_TWOLEVEL 0x80 /* the image is using two-level name
- space bindings */
-#define MH_FORCE_FLAT 0x100 /* the executable is forcing all images
- to use flat name space bindings */
-#define MH_NOMULTIDEFS 0x200 /* this umbrella guarantees no multiple
- defintions of symbols in its
- sub-images so the two-level namespace
- hints can always be used. */
-#define MH_NOFIXPREBINDING 0x400 /* do not have dyld notify the
- prebinding agent about this
- executable */
-#define MH_PREBINDABLE 0x800 /* the binary is not prebound but can
- have its prebinding redone. only used
- when MH_PREBOUND is not set. */
-#define MH_ALLMODSBOUND 0x1000 /* indicates that this binary binds to
- all two-level namespace modules of
- its dependent libraries. only used
- when MH_PREBINDABLE and MH_TWOLEVEL
- are both set. */
-#define MH_SUBSECTIONS_VIA_SYMBOLS 0x2000/* safe to divide up the sections into
- sub-sections via symbols for dead
- code stripping */
-#define MH_CANONICAL 0x4000 /* the binary has been canonicalized
- via the unprebind operation */
-#define MH_WEAK_DEFINES 0x8000 /* the final linked image contains
- external weak symbols */
-#define MH_BINDS_TO_WEAK 0x10000 /* the final linked image uses
- weak symbols */
-
-#define MH_ALLOW_STACK_EXECUTION 0x20000/* When this bit is set, all stacks
- in the task will be given stack
- execution privilege. Only used in
- MH_EXECUTE filetypes. */
-#define MH_DEAD_STRIPPABLE_DYLIB 0x400000 /* Only for use on dylibs. When
- linking against a dylib that
- has this bit set, the static linker
- will automatically not create a
- LC_LOAD_DYLIB load command to the
- dylib if no symbols are being
- referenced from the dylib. */
-#define MH_ROOT_SAFE 0x40000 /* When this bit is set, the binary
- declares it is safe for use in
- processes with uid zero */
-
-#define MH_SETUID_SAFE 0x80000 /* When this bit is set, the binary
- declares it is safe for use in
- processes when issetugid() is true */
-
-#define MH_NO_REEXPORTED_DYLIBS 0x100000 /* When this bit is set on a dylib,
- the static linker does not need to
- examine dependent dylibs to see
- if any are re-exported */
-#define MH_PIE 0x200000 /* When this bit is set, the OS will
- load the main executable at a
- random address. Only used in
- MH_EXECUTE filetypes. */
+#define MH_NOUNDEFS \
+ 0x1 /* the object file has no undefined \
+references */
+#define MH_INCRLINK \
+ 0x2 /* the object file is the output of an \
+incremental link against a base file \
+and can't be link edited again */
+#define MH_DYLDLINK \
+ 0x4 /* the object file is input for the \
+dynamic linker and can't be staticly \
+link edited again */
+#define MH_BINDATLOAD \
+ 0x8 /* the object file's undefined \
+references are bound by the dynamic \
+linker when loaded. */
+#define MH_PREBOUND \
+ 0x10 /* the file has its dynamic undefined \
+references prebound. */
+#define MH_SPLIT_SEGS \
+ 0x20 /* the file has its read-only and \
+read-write segments split */
+#define MH_LAZY_INIT \
+ 0x40 /* the shared library init routine is \
+to be run lazily via catching memory \
+faults to its writeable segments \
+(obsolete) */
+#define MH_TWOLEVEL \
+ 0x80 /* the image is using two-level name \
+space bindings */
+#define MH_FORCE_FLAT \
+ 0x100 /* the executable is forcing all images \
+to use flat name space bindings */
+#define MH_NOMULTIDEFS \
+ 0x200 /* this umbrella guarantees no multiple \
+defintions of symbols in its \
+sub-images so the two-level namespace \
+hints can always be used. */
+#define MH_NOFIXPREBINDING \
+ 0x400 /* do not have dyld notify the \
+prebinding agent about this \
+executable */
+#define MH_PREBINDABLE \
+ 0x800 /* the binary is not prebound but can \
+have its prebinding redone. only used \
+ when MH_PREBOUND is not set. */
+#define MH_ALLMODSBOUND \
+ 0x1000 /* indicates that this binary binds to \
+ all two-level namespace modules of \
+its dependent libraries. only used \
+when MH_PREBINDABLE and MH_TWOLEVEL \
+are both set. */
+#define MH_SUBSECTIONS_VIA_SYMBOLS \
+ 0x2000 /* safe to divide up the sections into \
+sub-sections via symbols for dead \
+code stripping */
+#define MH_CANONICAL \
+ 0x4000 /* the binary has been canonicalized \
+via the unprebind operation */
+#define MH_WEAK_DEFINES \
+ 0x8000 /* the final linked image contains \
+external weak symbols */
+#define MH_BINDS_TO_WEAK \
+ 0x10000 /* the final linked image uses \
+weak symbols */
+
+#define MH_ALLOW_STACK_EXECUTION \
+ 0x20000 /* When this bit is set, all stacks \
+in the task will be given stack \
+execution privilege. Only used in \
+MH_EXECUTE filetypes. */
+#define MH_DEAD_STRIPPABLE_DYLIB \
+ 0x400000 /* Only for use on dylibs. When \
+linking against a dylib that \
+has this bit set, the static linker \
+will automatically not create a \
+LC_LOAD_DYLIB load command to the \
+dylib if no symbols are being \
+referenced from the dylib. */
+#define MH_ROOT_SAFE \
+ 0x40000 /* When this bit is set, the binary \
+declares it is safe for use in \
+processes with uid zero */
+
+#define MH_SETUID_SAFE \
+ 0x80000 /* When this bit is set, the binary \
+declares it is safe for use in \
+processes when issetugid() is true */
+
+#define MH_NO_REEXPORTED_DYLIBS \
+ 0x100000 /* When this bit is set on a dylib, \
+the static linker does not need to \
+examine dependent dylibs to see \
+if any are re-exported */
+#define MH_PIE \
+ 0x200000 /* When this bit is set, the OS will \
+load the main executable at a \
+random address. Only used in \
+MH_EXECUTE filetypes. */
/*
* The load commands directly follow the mach_header. The total size of all
@@ -212,8 +235,8 @@ struct mach_header_64 {
* padding zeroed like objects will compare byte for byte.
*/
struct load_command {
- uint32_t cmd; /* type of load command */
- uint32_t cmdsize; /* total size of command in bytes */
+ uint32_t cmd; /* type of load command */
+ uint32_t cmdsize; /* total size of command in bytes */
};
/*
@@ -228,50 +251,51 @@ struct load_command {
#define LC_REQ_DYLD 0x80000000
/* Constants for the cmd field of all load commands, the type */
-#define LC_SEGMENT 0x1 /* segment of this file to be mapped */
-#define LC_SYMTAB 0x2 /* link-edit stab symbol table info */
-#define LC_SYMSEG 0x3 /* link-edit gdb symbol table info (obsolete) */
-#define LC_THREAD 0x4 /* thread */
-#define LC_UNIXTHREAD 0x5 /* unix thread (includes a stack) */
-#define LC_LOADFVMLIB 0x6 /* load a specified fixed VM shared library */
-#define LC_IDFVMLIB 0x7 /* fixed VM shared library identification */
-#define LC_IDENT 0x8 /* object identification info (obsolete) */
-#define LC_FVMFILE 0x9 /* fixed VM file inclusion (internal use) */
-#define LC_PREPAGE 0xa /* prepage command (internal use) */
-#define LC_DYSYMTAB 0xb /* dynamic link-edit symbol table info */
-#define LC_LOAD_DYLIB 0xc /* load a dynamically linked shared library */
-#define LC_ID_DYLIB 0xd /* dynamically linked shared lib ident */
-#define LC_LOAD_DYLINKER 0xe /* load a dynamic linker */
-#define LC_ID_DYLINKER 0xf /* dynamic linker identification */
-#define LC_PREBOUND_DYLIB 0x10 /* modules prebound for a dynamically */
- /* linked shared library */
-#define LC_ROUTINES 0x11 /* image routines */
-#define LC_SUB_FRAMEWORK 0x12 /* sub framework */
-#define LC_SUB_UMBRELLA 0x13 /* sub umbrella */
-#define LC_SUB_CLIENT 0x14 /* sub client */
-#define LC_SUB_LIBRARY 0x15 /* sub library */
-#define LC_TWOLEVEL_HINTS 0x16 /* two-level namespace lookup hints */
-#define LC_PREBIND_CKSUM 0x17 /* prebind checksum */
+#define LC_SEGMENT 0x1 /* segment of this file to be mapped */
+#define LC_SYMTAB 0x2 /* link-edit stab symbol table info */
+#define LC_SYMSEG 0x3 /* link-edit gdb symbol table info (obsolete) */
+#define LC_THREAD 0x4 /* thread */
+#define LC_UNIXTHREAD 0x5 /* unix thread (includes a stack) */
+#define LC_LOADFVMLIB 0x6 /* load a specified fixed VM shared library */
+#define LC_IDFVMLIB 0x7 /* fixed VM shared library identification */
+#define LC_IDENT 0x8 /* object identification info (obsolete) */
+#define LC_FVMFILE 0x9 /* fixed VM file inclusion (internal use) */
+#define LC_PREPAGE 0xa /* prepage command (internal use) */
+#define LC_DYSYMTAB 0xb /* dynamic link-edit symbol table info */
+#define LC_LOAD_DYLIB 0xc /* load a dynamically linked shared library */
+#define LC_ID_DYLIB 0xd /* dynamically linked shared lib ident */
+#define LC_LOAD_DYLINKER 0xe /* load a dynamic linker */
+#define LC_ID_DYLINKER 0xf /* dynamic linker identification */
+#define LC_PREBOUND_DYLIB 0x10 /* modules prebound for a dynamically */
+ /* linked shared library */
+#define LC_ROUTINES 0x11 /* image routines */
+#define LC_SUB_FRAMEWORK 0x12 /* sub framework */
+#define LC_SUB_UMBRELLA 0x13 /* sub umbrella */
+#define LC_SUB_CLIENT 0x14 /* sub client */
+#define LC_SUB_LIBRARY 0x15 /* sub library */
+#define LC_TWOLEVEL_HINTS 0x16 /* two-level namespace lookup hints */
+#define LC_PREBIND_CKSUM 0x17 /* prebind checksum */
/*
* load a dynamically linked shared library that is allowed to be missing
* (all symbols are weak imported).
*/
-#define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
-
-#define LC_SEGMENT_64 0x19 /* 64-bit segment of this file to be
- mapped */
-#define LC_ROUTINES_64 0x1a /* 64-bit image routines */
-#define LC_UUID 0x1b /* the uuid */
-#define LC_RPATH (0x1c | LC_REQ_DYLD) /* runpath additions */
-#define LC_CODE_SIGNATURE 0x1d /* local of code signature */
-#define LC_SEGMENT_SPLIT_INFO 0x1e /* local of info to split segments */
-#define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */
-#define LC_LAZY_LOAD_DYLIB 0x20 /* delay load of dylib until first use */
-#define LC_ENCRYPTION_INFO 0x21 /* encrypted segment information */
-#define LC_DYLD_INFO 0x22 /* compressed dyld information */
-#define LC_DYLD_INFO_ONLY (0x22|LC_REQ_DYLD) /* compressed dyld information only */
-#define LC_LOAD_UPWARD_DYLIB (0x23 | LC_REQ_DYLD) /* load upward dylib */
+#define LC_LOAD_WEAK_DYLIB (0x18 | LC_REQ_DYLD)
+
+#define LC_SEGMENT_64 \
+ 0x19 /* 64-bit segment of this file to be \
+ mapped */
+#define LC_ROUTINES_64 0x1a /* 64-bit image routines */
+#define LC_UUID 0x1b /* the uuid */
+#define LC_RPATH (0x1c | LC_REQ_DYLD) /* runpath additions */
+#define LC_CODE_SIGNATURE 0x1d /* local of code signature */
+#define LC_SEGMENT_SPLIT_INFO 0x1e /* local of info to split segments */
+#define LC_REEXPORT_DYLIB (0x1f | LC_REQ_DYLD) /* load and re-export dylib */
+#define LC_LAZY_LOAD_DYLIB 0x20 /* delay load of dylib until first use */
+#define LC_ENCRYPTION_INFO 0x21 /* encrypted segment information */
+#define LC_DYLD_INFO 0x22 /* compressed dyld information */
+#define LC_DYLD_INFO_ONLY (0x22 | LC_REQ_DYLD) /* compressed dyld information only */
+#define LC_LOAD_UPWARD_DYLIB (0x23 | LC_REQ_DYLD) /* load upward dylib */
/*
* A variable length string in a load command is represented by an lc_str
@@ -282,9 +306,9 @@ struct load_command {
* of 4 bytes must be zero.
*/
union lc_str {
- uint32_t offset; /* offset to the string */
+ uint32_t offset; /* offset to the string */
#ifndef __LP64__
- char *ptr; /* pointer to the string */
+ char* ptr; /* pointer to the string */
#endif
};
@@ -301,17 +325,17 @@ union lc_str {
* reflected in cmdsize.
*/
struct segment_command { /* for 32-bit architectures */
- uint32_t cmd; /* LC_SEGMENT */
- uint32_t cmdsize; /* includes sizeof section structs */
- char segname[16]; /* segment name */
- uint32_t vmaddr; /* memory address of this segment */
- uint32_t vmsize; /* memory size of this segment */
- uint32_t fileoff; /* file offset of this segment */
- uint32_t filesize; /* amount to map from the file */
- int maxprot; /* maximum VM protection */
- int initprot; /* initial VM protection */
- uint32_t nsects; /* number of sections in segment */
- uint32_t flags; /* flags */
+ uint32_t cmd; /* LC_SEGMENT */
+ uint32_t cmdsize; /* includes sizeof section structs */
+ char segname[16]; /* segment name */
+ uint32_t vmaddr; /* memory address of this segment */
+ uint32_t vmsize; /* memory size of this segment */
+ uint32_t fileoff; /* file offset of this segment */
+ uint32_t filesize; /* amount to map from the file */
+ int maxprot; /* maximum VM protection */
+ int initprot; /* initial VM protection */
+ uint32_t nsects; /* number of sections in segment */
+ uint32_t flags; /* flags */
};
/*
@@ -321,34 +345,38 @@ struct segment_command { /* for 32-bit architectures */
* command and their size is reflected in cmdsize.
*/
struct segment_command_64 { /* for 64-bit architectures */
- uint32_t cmd; /* LC_SEGMENT_64 */
- uint32_t cmdsize; /* includes sizeof section_64 structs */
- char segname[16]; /* segment name */
- uint64_t vmaddr; /* memory address of this segment */
- uint64_t vmsize; /* memory size of this segment */
- uint64_t fileoff; /* file offset of this segment */
- uint64_t filesize; /* amount to map from the file */
- int maxprot; /* maximum VM protection */
- int initprot; /* initial VM protection */
- uint32_t nsects; /* number of sections in segment */
- uint32_t flags; /* flags */
+ uint32_t cmd; /* LC_SEGMENT_64 */
+ uint32_t cmdsize; /* includes sizeof section_64 structs */
+ char segname[16]; /* segment name */
+ uint64_t vmaddr; /* memory address of this segment */
+ uint64_t vmsize; /* memory size of this segment */
+ uint64_t fileoff; /* file offset of this segment */
+ uint64_t filesize; /* amount to map from the file */
+ int maxprot; /* maximum VM protection */
+ int initprot; /* initial VM protection */
+ uint32_t nsects; /* number of sections in segment */
+ uint32_t flags; /* flags */
};
/* Constants for the flags field of the segment_command */
-#define SG_HIGHVM 0x1 /* the file contents for this segment is for
- the high part of the VM space, the low part
- is zero filled (for stacks in core files) */
-#define SG_FVMLIB 0x2 /* this segment is the VM that is allocated by
- a fixed VM library, for overlap checking in
- the link editor */
-#define SG_NORELOC 0x4 /* this segment has nothing that was relocated
- in it and nothing relocated to it, that is
- it maybe safely replaced without relocation*/
-#define SG_PROTECTED_VERSION_1 0x8 /* This segment is protected. If the
- segment starts at file offset 0, the
- first page of the segment is not
- protected. All other pages of the
- segment are protected. */
+#define SG_HIGHVM \
+ 0x1 /* the file contents for this segment is for \
+the high part of the VM space, the low part \
+is zero filled (for stacks in core files) */
+#define SG_FVMLIB \
+ 0x2 /* this segment is the VM that is allocated by \
+a fixed VM library, for overlap checking in \
+the link editor */
+#define SG_NORELOC \
+ 0x4 /* this segment has nothing that was relocated \
+in it and nothing relocated to it, that is \
+it maybe safely replaced without relocation*/
+#define SG_PROTECTED_VERSION_1 \
+ 0x8 /* This segment is protected. If the \
+segment starts at file offset 0, the \
+first page of the segment is not \
+protected. All other pages of the \
+segment are protected. */
/*
* A segment is made up of zero or more sections. Non-MH_OBJECT files have
@@ -377,33 +405,33 @@ struct segment_command_64 { /* for 64-bit architectures */
* fields of the section structure for mach object files is described in the
* header file <reloc.h>.
*/
-struct section { /* for 32-bit architectures */
- char sectname[16]; /* name of this section */
- char segname[16]; /* segment this section goes in */
- uint32_t addr; /* memory address of this section */
- uint32_t size; /* size in bytes of this section */
- uint32_t offset; /* file offset of this section */
- uint32_t align; /* section alignment (power of 2) */
- uint32_t reloff; /* file offset of relocation entries */
- uint32_t nreloc; /* number of relocation entries */
- uint32_t flags; /* flags (section type and attributes)*/
- uint32_t reserved1; /* reserved (for offset or index) */
- uint32_t reserved2; /* reserved (for count or sizeof) */
+struct section { /* for 32-bit architectures */
+ char sectname[16]; /* name of this section */
+ char segname[16]; /* segment this section goes in */
+ uint32_t addr; /* memory address of this section */
+ uint32_t size; /* size in bytes of this section */
+ uint32_t offset; /* file offset of this section */
+ uint32_t align; /* section alignment (power of 2) */
+ uint32_t reloff; /* file offset of relocation entries */
+ uint32_t nreloc; /* number of relocation entries */
+ uint32_t flags; /* flags (section type and attributes)*/
+ uint32_t reserved1; /* reserved (for offset or index) */
+ uint32_t reserved2; /* reserved (for count or sizeof) */
};
-struct section_64 { /* for 64-bit architectures */
- char sectname[16]; /* name of this section */
- char segname[16]; /* segment this section goes in */
- uint64_t addr; /* memory address of this section */
- uint64_t size; /* size in bytes of this section */
- uint32_t offset; /* file offset of this section */
- uint32_t align; /* section alignment (power of 2) */
- uint32_t reloff; /* file offset of relocation entries */
- uint32_t nreloc; /* number of relocation entries */
- uint32_t flags; /* flags (section type and attributes)*/
- uint32_t reserved1; /* reserved (for offset or index) */
- uint32_t reserved2; /* reserved (for count or sizeof) */
- uint32_t reserved3; /* reserved */
+struct section_64 { /* for 64-bit architectures */
+ char sectname[16]; /* name of this section */
+ char segname[16]; /* segment this section goes in */
+ uint64_t addr; /* memory address of this section */
+ uint64_t size; /* size in bytes of this section */
+ uint32_t offset; /* file offset of this section */
+ uint32_t align; /* section alignment (power of 2) */
+ uint32_t reloff; /* file offset of relocation entries */
+ uint32_t nreloc; /* number of relocation entries */
+ uint32_t flags; /* flags (section type and attributes)*/
+ uint32_t reserved1; /* reserved (for offset or index) */
+ uint32_t reserved2; /* reserved (for count or sizeof) */
+ uint32_t reserved3; /* reserved */
};
/*
@@ -412,17 +440,17 @@ struct section_64 { /* for 64-bit architectures */
* can only have one type) but the section attributes are not (it may have more
* than one attribute).
*/
-#define SECTION_TYPE 0x000000ff /* 256 section types */
-#define SECTION_ATTRIBUTES 0xffffff00 /* 24 section attributes */
+#define SECTION_TYPE 0x000000ff /* 256 section types */
+#define SECTION_ATTRIBUTES 0xffffff00 /* 24 section attributes */
/* Constants for the type of a section */
-#define S_REGULAR 0x0 /* regular section */
-#define S_ZEROFILL 0x1 /* zero fill on demand section */
-#define S_CSTRING_LITERALS 0x2 /* section with only literal C strings*/
-#define S_4BYTE_LITERALS 0x3 /* section with only 4 byte literals */
-#define S_8BYTE_LITERALS 0x4 /* section with only 8 byte literals */
-#define S_LITERAL_POINTERS 0x5 /* section with only pointers to */
- /* literals */
+#define S_REGULAR 0x0 /* regular section */
+#define S_ZEROFILL 0x1 /* zero fill on demand section */
+#define S_CSTRING_LITERALS 0x2 /* section with only literal C strings*/
+#define S_4BYTE_LITERALS 0x3 /* section with only 4 byte literals */
+#define S_8BYTE_LITERALS 0x4 /* section with only 8 byte literals */
+#define S_LITERAL_POINTERS 0x5 /* section with only pointers to */
+ /* literals */
/*
* For the two types of symbol pointers sections and the symbol stubs section
* they have indirect symbol table entries. For each of the entries in the
@@ -435,51 +463,67 @@ struct section_64 { /* for 64-bit architectures */
* in the section is 4 bytes and for symbol stubs sections the byte size of the
* stubs is stored in the reserved2 field of the section structure.
*/
-#define S_NON_LAZY_SYMBOL_POINTERS 0x6 /* section with only non-lazy
- symbol pointers */
-#define S_LAZY_SYMBOL_POINTERS 0x7 /* section with only lazy symbol
- pointers */
-#define S_SYMBOL_STUBS 0x8 /* section with only symbol
- stubs, byte size of stub in
- the reserved2 field */
-#define S_MOD_INIT_FUNC_POINTERS 0x9 /* section with only function
- pointers for initialization*/
-#define S_MOD_TERM_FUNC_POINTERS 0xa /* section with only function
- pointers for termination */
-#define S_COALESCED 0xb /* section contains symbols that
- are to be coalesced */
-#define S_GB_ZEROFILL 0xc /* zero fill on demand section
- (that can be larger than 4
- gigabytes) */
-#define S_INTERPOSING 0xd /* section with only pairs of
- function pointers for
- interposing */
-#define S_16BYTE_LITERALS 0xe /* section with only 16 byte
- literals */
-#define S_DTRACE_DOF 0xf /* section contains
- DTrace Object Format */
-#define S_LAZY_DYLIB_SYMBOL_POINTERS 0x10 /* section with only lazy
- symbol pointers to lazy
- loaded dylibs */
+#define S_NON_LAZY_SYMBOL_POINTERS \
+ 0x6 /* section with only non-lazy \
+symbol pointers */
+#define S_LAZY_SYMBOL_POINTERS \
+ 0x7 /* section with only lazy symbol \
+pointers */
+#define S_SYMBOL_STUBS \
+ 0x8 /* section with only symbol \
+stubs, byte size of stub in \
+the reserved2 field */
+#define S_MOD_INIT_FUNC_POINTERS \
+ 0x9 /* section with only function \
+pointers for initialization*/
+#define S_MOD_TERM_FUNC_POINTERS \
+ 0xa /* section with only function \
+pointers for termination */
+#define S_COALESCED \
+ 0xb /* section contains symbols that \
+are to be coalesced */
+#define S_GB_ZEROFILL \
+ 0xc /* zero fill on demand section \
+(that can be larger than 4 \
+gigabytes) */
+#define S_INTERPOSING \
+ 0xd /* section with only pairs of \
+function pointers for \
+interposing */
+#define S_16BYTE_LITERALS \
+ 0xe /* section with only 16 byte \
+literals */
+#define S_DTRACE_DOF \
+ 0xf /* section contains \
+DTrace Object Format */
+#define S_LAZY_DYLIB_SYMBOL_POINTERS \
+ 0x10 /* section with only lazy \
+symbol pointers to lazy \
+loaded dylibs */
/*
* Constants for the section attributes part of the flags field of a section
* structure.
*/
-#define SECTION_ATTRIBUTES_USR 0xff000000 /* User setable attributes */
-#define S_ATTR_PURE_INSTRUCTIONS 0x80000000 /* section contains only true
- machine instructions */
-#define S_ATTR_NO_TOC 0x40000000 /* section contains coalesced
- symbols that are not to be
- in a ranlib table of
- contents */
-#define S_ATTR_STRIP_STATIC_SYMS 0x20000000 /* ok to strip static symbols
- in this section in files
- with the MH_DYLDLINK flag */
-#define S_ATTR_NO_DEAD_STRIP 0x10000000 /* no dead stripping */
-#define S_ATTR_LIVE_SUPPORT 0x08000000 /* blocks are live if they
- reference live blocks */
-#define S_ATTR_SELF_MODIFYING_CODE 0x04000000 /* Used with i386 code stubs
- written on by dyld */
+#define SECTION_ATTRIBUTES_USR 0xff000000 /* User setable attributes */
+#define S_ATTR_PURE_INSTRUCTIONS \
+ 0x80000000 /* section contains only true \
+machine instructions */
+#define S_ATTR_NO_TOC \
+ 0x40000000 /* section contains coalesced \
+symbols that are not to be \
+in a ranlib table of \
+contents */
+#define S_ATTR_STRIP_STATIC_SYMS \
+ 0x20000000 /* ok to strip static symbols \
+ in this section in files \
+ with the MH_DYLDLINK flag */
+#define S_ATTR_NO_DEAD_STRIP 0x10000000 /* no dead stripping */
+#define S_ATTR_LIVE_SUPPORT \
+ 0x08000000 /* blocks are live if they \
+reference live blocks */
+#define S_ATTR_SELF_MODIFYING_CODE \
+ 0x04000000 /* Used with i386 code stubs \
+written on by dyld */
/*
* If a segment contains any sections marked with S_ATTR_DEBUG then all
* sections in that segment must have this attribute. No section other than
@@ -489,15 +533,17 @@ struct section_64 { /* for 64-bit architectures */
* from sections with this attribute into its output file. These sections
* generally contain DWARF debugging info.
*/
-#define S_ATTR_DEBUG 0x02000000 /* a debug section */
-#define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */
-#define S_ATTR_SOME_INSTRUCTIONS 0x00000400 /* section contains some
- machine instructions */
-#define S_ATTR_EXT_RELOC 0x00000200 /* section has external
- relocation entries */
-#define S_ATTR_LOC_RELOC 0x00000100 /* section has local
- relocation entries */
-
+#define S_ATTR_DEBUG 0x02000000 /* a debug section */
+#define SECTION_ATTRIBUTES_SYS 0x00ffff00 /* system setable attributes */
+#define S_ATTR_SOME_INSTRUCTIONS \
+ 0x00000400 /* section contains some \
+machine instructions */
+#define S_ATTR_EXT_RELOC \
+ 0x00000200 /* section has external \
+relocation entries */
+#define S_ATTR_LOC_RELOC \
+ 0x00000100 /* section has local \
+relocation entries */
/*
* The names of segments and sections in them are mostly meaningless to the
@@ -515,49 +561,48 @@ struct section_64 { /* for 64-bit architectures */
/* The currently known segment names and the section names in those segments */
-#define SEG_PAGEZERO "__PAGEZERO" /* the pagezero segment which has no */
- /* protections and catches NULL */
- /* references for MH_EXECUTE files */
-
-
-#define SEG_TEXT "__TEXT" /* the tradition UNIX text segment */
-#define SECT_TEXT "__text" /* the real text part of the text */
- /* section no headers, and no padding */
-#define SECT_FVMLIB_INIT0 "__fvmlib_init0" /* the fvmlib initialization */
- /* section */
-#define SECT_FVMLIB_INIT1 "__fvmlib_init1" /* the section following the */
- /* fvmlib initialization */
- /* section */
-
-#define SEG_DATA "__DATA" /* the tradition UNIX data segment */
-#define SECT_DATA "__data" /* the real initialized data section */
- /* no padding, no bss overlap */
-#define SECT_BSS "__bss" /* the real uninitialized data section*/
- /* no padding */
-#define SECT_COMMON "__common" /* the section common symbols are */
- /* allocated in by the link editor */
-
-#define SEG_OBJC "__OBJC" /* objective-C runtime segment */
-#define SECT_OBJC_SYMBOLS "__symbol_table" /* symbol table */
-#define SECT_OBJC_MODULES "__module_info" /* module information */
-#define SECT_OBJC_STRINGS "__selector_strs" /* string table */
-#define SECT_OBJC_REFS "__selector_refs" /* string table */
-
-#define SEG_ICON "__ICON" /* the icon segment */
-#define SECT_ICON_HEADER "__header" /* the icon headers */
-#define SECT_ICON_TIFF "__tiff" /* the icons in tiff format */
-
-#define SEG_LINKEDIT "__LINKEDIT" /* the segment containing all structs */
- /* created and maintained by the link */
- /* editor. Created with -seglinkedit */
- /* option to ld(1) for MH_EXECUTE and */
- /* FVMLIB file types only */
-
-#define SEG_UNIXSTACK "__UNIXSTACK" /* the unix stack segment */
-
-#define SEG_IMPORT "__IMPORT" /* the segment for the self (dyld) */
- /* modifing code stubs that has read, */
- /* write and execute permissions */
+#define SEG_PAGEZERO "__PAGEZERO" /* the pagezero segment which has no */
+ /* protections and catches NULL */
+ /* references for MH_EXECUTE files */
+
+#define SEG_TEXT "__TEXT" /* the tradition UNIX text segment */
+#define SECT_TEXT "__text" /* the real text part of the text */
+ /* section no headers, and no padding */
+#define SECT_FVMLIB_INIT0 "__fvmlib_init0" /* the fvmlib initialization */
+ /* section */
+#define SECT_FVMLIB_INIT1 "__fvmlib_init1" /* the section following the */
+ /* fvmlib initialization */
+ /* section */
+
+#define SEG_DATA "__DATA" /* the tradition UNIX data segment */
+#define SECT_DATA "__data" /* the real initialized data section */
+ /* no padding, no bss overlap */
+#define SECT_BSS "__bss" /* the real uninitialized data section*/
+ /* no padding */
+#define SECT_COMMON "__common" /* the section common symbols are */
+ /* allocated in by the link editor */
+
+#define SEG_OBJC "__OBJC" /* objective-C runtime segment */
+#define SECT_OBJC_SYMBOLS "__symbol_table" /* symbol table */
+#define SECT_OBJC_MODULES "__module_info" /* module information */
+#define SECT_OBJC_STRINGS "__selector_strs" /* string table */
+#define SECT_OBJC_REFS "__selector_refs" /* string table */
+
+#define SEG_ICON "__ICON" /* the icon segment */
+#define SECT_ICON_HEADER "__header" /* the icon headers */
+#define SECT_ICON_TIFF "__tiff" /* the icons in tiff format */
+
+#define SEG_LINKEDIT "__LINKEDIT" /* the segment containing all structs */
+ /* created and maintained by the link */
+ /* editor. Created with -seglinkedit */
+ /* option to ld(1) for MH_EXECUTE and */
+ /* FVMLIB file types only */
+
+#define SEG_UNIXSTACK "__UNIXSTACK" /* the unix stack segment */
+
+#define SEG_IMPORT "__IMPORT" /* the segment for the self (dyld) */
+ /* modifing code stubs that has read, */
+ /* write and execute permissions */
/*
* Fixed virtual memory shared libraries are identified by two things. The
@@ -566,9 +611,9 @@ struct section_64 { /* for 64-bit architectures */
* header_addr. (THIS IS OBSOLETE and no longer supported).
*/
struct fvmlib {
- union lc_str name; /* library's target pathname */
- uint32_t minor_version; /* library's minor version number */
- uint32_t header_addr; /* library's header address */
+ union lc_str name; /* library's target pathname */
+ uint32_t minor_version; /* library's minor version number */
+ uint32_t header_addr; /* library's header address */
};
/*
@@ -579,9 +624,9 @@ struct fvmlib {
* (THIS IS OBSOLETE and no longer supported).
*/
struct fvmlib_command {
- uint32_t cmd; /* LC_IDFVMLIB or LC_LOADFVMLIB */
- uint32_t cmdsize; /* includes pathname string */
- struct fvmlib fvmlib; /* the library identification */
+ uint32_t cmd; /* LC_IDFVMLIB or LC_LOADFVMLIB */
+ uint32_t cmdsize; /* includes pathname string */
+ struct fvmlib fvmlib; /* the library identification */
};
/*
@@ -594,10 +639,10 @@ struct fvmlib_command {
* at runtime is exactly the same as used to built the program.
*/
struct dylib {
- union lc_str name; /* library's path name */
- uint32_t timestamp; /* library's build time stamp */
- uint32_t current_version; /* library's current version number */
- uint32_t compatibility_version; /* library's compatibility vers number*/
+ union lc_str name; /* library's path name */
+ uint32_t timestamp; /* library's build time stamp */
+ uint32_t current_version; /* library's current version number */
+ uint32_t compatibility_version; /* library's compatibility vers number*/
};
/*
@@ -608,10 +653,10 @@ struct dylib {
* LC_REEXPORT_DYLIB) for each library it uses.
*/
struct dylib_command {
- uint32_t cmd; /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB,
- LC_REEXPORT_DYLIB */
- uint32_t cmdsize; /* includes pathname string */
- struct dylib dylib; /* the library identification */
+ uint32_t cmd; /* LC_ID_DYLIB, LC_LOAD_{,WEAK_}DYLIB,
+ LC_REEXPORT_DYLIB */
+ uint32_t cmdsize; /* includes pathname string */
+ struct dylib dylib; /* the library identification */
};
/*
@@ -625,9 +670,9 @@ struct dylib_command {
* following structure.
*/
struct sub_framework_command {
- uint32_t cmd; /* LC_SUB_FRAMEWORK */
- uint32_t cmdsize; /* includes umbrella string */
- union lc_str umbrella; /* the umbrella framework name */
+ uint32_t cmd; /* LC_SUB_FRAMEWORK */
+ uint32_t cmdsize; /* includes umbrella string */
+ union lc_str umbrella; /* the umbrella framework name */
};
/*
@@ -640,9 +685,9 @@ struct sub_framework_command {
* where the bundle is built with "-client_name client_name".
*/
struct sub_client_command {
- uint32_t cmd; /* LC_SUB_CLIENT */
- uint32_t cmdsize; /* includes client string */
- union lc_str client; /* the client name */
+ uint32_t cmd; /* LC_SUB_CLIENT */
+ uint32_t cmdsize; /* includes client string */
+ union lc_str client; /* the client name */
};
/*
@@ -659,9 +704,9 @@ struct sub_client_command {
* The name of a sub_umbrella framework is recorded in the following structure.
*/
struct sub_umbrella_command {
- uint32_t cmd; /* LC_SUB_UMBRELLA */
- uint32_t cmdsize; /* includes sub_umbrella string */
- union lc_str sub_umbrella; /* the sub_umbrella framework name */
+ uint32_t cmd; /* LC_SUB_UMBRELLA */
+ uint32_t cmdsize; /* includes sub_umbrella string */
+ union lc_str sub_umbrella; /* the sub_umbrella framework name */
};
/*
@@ -680,9 +725,9 @@ struct sub_umbrella_command {
* For example /usr/lib/libobjc_profile.A.dylib would be recorded as "libobjc".
*/
struct sub_library_command {
- uint32_t cmd; /* LC_SUB_LIBRARY */
- uint32_t cmdsize; /* includes sub_library string */
- union lc_str sub_library; /* the sub_library name */
+ uint32_t cmd; /* LC_SUB_LIBRARY */
+ uint32_t cmdsize; /* includes sub_library string */
+ union lc_str sub_library; /* the sub_library name */
};
/*
@@ -695,11 +740,11 @@ struct sub_library_command {
* (linked_modules[N/8] >> N%8) & 1
*/
struct prebound_dylib_command {
- uint32_t cmd; /* LC_PREBOUND_DYLIB */
- uint32_t cmdsize; /* includes strings */
- union lc_str name; /* library's path name */
- uint32_t nmodules; /* number of modules in library */
- union lc_str linked_modules; /* bit vector of linked modules */
+ uint32_t cmd; /* LC_PREBOUND_DYLIB */
+ uint32_t cmdsize; /* includes strings */
+ union lc_str name; /* library's path name */
+ uint32_t nmodules; /* number of modules in library */
+ union lc_str linked_modules; /* bit vector of linked modules */
};
/*
@@ -709,9 +754,9 @@ struct prebound_dylib_command {
* A file can have at most one of these.
*/
struct dylinker_command {
- uint32_t cmd; /* LC_ID_DYLINKER or LC_LOAD_DYLINKER */
- uint32_t cmdsize; /* includes pathname string */
- union lc_str name; /* dynamic linker's path name */
+ uint32_t cmd; /* LC_ID_DYLINKER or LC_LOAD_DYLINKER */
+ uint32_t cmdsize; /* includes pathname string */
+ union lc_str name; /* dynamic linker's path name */
};
/*
@@ -736,12 +781,12 @@ struct dylinker_command {
* and environment variables are copied onto that stack.
*/
struct thread_command {
- uint32_t cmd; /* LC_THREAD or LC_UNIXTHREAD */
- uint32_t cmdsize; /* total size of this command */
- /* uint32_t flavor flavor of thread state */
- /* uint32_t count count of longs in thread state */
- /* struct XXX_thread_state state thread state for this flavor */
- /* ... */
+ uint32_t cmd; /* LC_THREAD or LC_UNIXTHREAD */
+ uint32_t cmdsize; /* total size of this command */
+ /* uint32_t flavor flavor of thread state */
+ /* uint32_t count count of longs in thread state */
+ /* struct XXX_thread_state state thread state for this flavor */
+ /* ... */
};
/*
@@ -753,34 +798,34 @@ struct thread_command {
* routines (used for C++ static constructors) in the library.
*/
struct routines_command { /* for 32-bit architectures */
- uint32_t cmd; /* LC_ROUTINES */
- uint32_t cmdsize; /* total size of this command */
- uint32_t init_address; /* address of initialization routine */
- uint32_t init_module; /* index into the module table that */
- /* the init routine is defined in */
- uint32_t reserved1;
- uint32_t reserved2;
- uint32_t reserved3;
- uint32_t reserved4;
- uint32_t reserved5;
- uint32_t reserved6;
+ uint32_t cmd; /* LC_ROUTINES */
+ uint32_t cmdsize; /* total size of this command */
+ uint32_t init_address; /* address of initialization routine */
+ uint32_t init_module; /* index into the module table that */
+ /* the init routine is defined in */
+ uint32_t reserved1;
+ uint32_t reserved2;
+ uint32_t reserved3;
+ uint32_t reserved4;
+ uint32_t reserved5;
+ uint32_t reserved6;
};
/*
* The 64-bit routines command. Same use as above.
*/
struct routines_command_64 { /* for 64-bit architectures */
- uint32_t cmd; /* LC_ROUTINES_64 */
- uint32_t cmdsize; /* total size of this command */
- uint64_t init_address; /* address of initialization routine */
- uint64_t init_module; /* index into the module table that */
- /* the init routine is defined in */
- uint64_t reserved1;
- uint64_t reserved2;
- uint64_t reserved3;
- uint64_t reserved4;
- uint64_t reserved5;
- uint64_t reserved6;
+ uint32_t cmd; /* LC_ROUTINES_64 */
+ uint32_t cmdsize; /* total size of this command */
+ uint64_t init_address; /* address of initialization routine */
+ uint64_t init_module; /* index into the module table that */
+ /* the init routine is defined in */
+ uint64_t reserved1;
+ uint64_t reserved2;
+ uint64_t reserved3;
+ uint64_t reserved4;
+ uint64_t reserved5;
+ uint64_t reserved6;
};
/*
@@ -789,12 +834,12 @@ struct routines_command_64 { /* for 64-bit architectures */
* <nlist.h> and <stab.h>.
*/
struct symtab_command {
- uint32_t cmd; /* LC_SYMTAB */
- uint32_t cmdsize; /* sizeof(struct symtab_command) */
- uint32_t symoff; /* symbol table offset */
- uint32_t nsyms; /* number of symbol table entries */
- uint32_t stroff; /* string table offset */
- uint32_t strsize; /* string table size in bytes */
+ uint32_t cmd; /* LC_SYMTAB */
+ uint32_t cmdsize; /* sizeof(struct symtab_command) */
+ uint32_t symoff; /* symbol table offset */
+ uint32_t nsyms; /* number of symbol table entries */
+ uint32_t stroff; /* string table offset */
+ uint32_t strsize; /* string table size in bytes */
};
/*
@@ -838,120 +883,119 @@ struct symtab_command {
* off the section structures.
*/
struct dysymtab_command {
- uint32_t cmd; /* LC_DYSYMTAB */
- uint32_t cmdsize; /* sizeof(struct dysymtab_command) */
-
- /*
- * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
- * are grouped into the following three groups:
- * local symbols (further grouped by the module they are from)
- * defined external symbols (further grouped by the module they are from)
- * undefined symbols
- *
- * The local symbols are used only for debugging. The dynamic binding
- * process may have to use them to indicate to the debugger the local
- * symbols for a module that is being bound.
- *
- * The last two groups are used by the dynamic binding process to do the
- * binding (indirectly through the module table and the reference symbol
- * table when this is a dynamically linked shared library file).
- */
- uint32_t ilocalsym; /* index to local symbols */
- uint32_t nlocalsym; /* number of local symbols */
-
- uint32_t iextdefsym;/* index to externally defined symbols */
- uint32_t nextdefsym;/* number of externally defined symbols */
-
- uint32_t iundefsym; /* index to undefined symbols */
- uint32_t nundefsym; /* number of undefined symbols */
-
- /*
- * For the for the dynamic binding process to find which module a symbol
- * is defined in the table of contents is used (analogous to the ranlib
- * structure in an archive) which maps defined external symbols to modules
- * they are defined in. This exists only in a dynamically linked shared
- * library file. For executable and object modules the defined external
- * symbols are sorted by name and is use as the table of contents.
- */
- uint32_t tocoff; /* file offset to table of contents */
- uint32_t ntoc; /* number of entries in table of contents */
-
- /*
- * To support dynamic binding of "modules" (whole object files) the symbol
- * table must reflect the modules that the file was created from. This is
- * done by having a module table that has indexes and counts into the merged
- * tables for each module. The module structure that these two entries
- * refer to is described below. This exists only in a dynamically linked
- * shared library file. For executable and object modules the file only
- * contains one module so everything in the file belongs to the module.
- */
- uint32_t modtaboff; /* file offset to module table */
- uint32_t nmodtab; /* number of module table entries */
-
- /*
- * To support dynamic module binding the module structure for each module
- * indicates the external references (defined and undefined) each module
- * makes. For each module there is an offset and a count into the
- * reference symbol table for the symbols that the module references.
- * This exists only in a dynamically linked shared library file. For
- * executable and object modules the defined external symbols and the
- * undefined external symbols indicates the external references.
- */
- uint32_t extrefsymoff; /* offset to referenced symbol table */
- uint32_t nextrefsyms; /* number of referenced symbol table entries */
-
- /*
- * The sections that contain "symbol pointers" and "routine stubs" have
- * indexes and (implied counts based on the size of the section and fixed
- * size of the entry) into the "indirect symbol" table for each pointer
- * and stub. For every section of these two types the index into the
- * indirect symbol table is stored in the section header in the field
- * reserved1. An indirect symbol table entry is simply a 32bit index into
- * the symbol table to the symbol that the pointer or stub is referring to.
- * The indirect symbol table is ordered to match the entries in the section.
- */
- uint32_t indirectsymoff; /* file offset to the indirect symbol table */
- uint32_t nindirectsyms; /* number of indirect symbol table entries */
-
- /*
- * To support relocating an individual module in a library file quickly the
- * external relocation entries for each module in the library need to be
- * accessed efficiently. Since the relocation entries can't be accessed
- * through the section headers for a library file they are separated into
- * groups of local and external entries further grouped by module. In this
- * case the presents of this load command who's extreloff, nextrel,
- * locreloff and nlocrel fields are non-zero indicates that the relocation
- * entries of non-merged sections are not referenced through the section
- * structures (and the reloff and nreloc fields in the section headers are
- * set to zero).
- *
- * Since the relocation entries are not accessed through the section headers
- * this requires the r_address field to be something other than a section
- * offset to identify the item to be relocated. In this case r_address is
- * set to the offset from the vmaddr of the first LC_SEGMENT command.
- * For MH_SPLIT_SEGS images r_address is set to the the offset from the
- * vmaddr of the first read-write LC_SEGMENT command.
- *
- * The relocation entries are grouped by module and the module table
- * entries have indexes and counts into them for the group of external
- * relocation entries for that the module.
- *
- * For sections that are merged across modules there must not be any
- * remaining external relocation entries for them (for merged sections
- * remaining relocation entries must be local).
- */
- uint32_t extreloff; /* offset to external relocation entries */
- uint32_t nextrel; /* number of external relocation entries */
-
- /*
- * All the local relocation entries are grouped together (they are not
- * grouped by their module since they are only used if the object is moved
- * from it staticly link edited address).
- */
- uint32_t locreloff; /* offset to local relocation entries */
- uint32_t nlocrel; /* number of local relocation entries */
-
-};
+ uint32_t cmd; /* LC_DYSYMTAB */
+ uint32_t cmdsize; /* sizeof(struct dysymtab_command) */
+
+ /*
+ * The symbols indicated by symoff and nsyms of the LC_SYMTAB load command
+ * are grouped into the following three groups:
+ * local symbols (further grouped by the module they are from)
+ * defined external symbols (further grouped by the module they are from)
+ * undefined symbols
+ *
+ * The local symbols are used only for debugging. The dynamic binding
+ * process may have to use them to indicate to the debugger the local
+ * symbols for a module that is being bound.
+ *
+ * The last two groups are used by the dynamic binding process to do the
+ * binding (indirectly through the module table and the reference symbol
+ * table when this is a dynamically linked shared library file).
+ */
+ uint32_t ilocalsym; /* index to local symbols */
+ uint32_t nlocalsym; /* number of local symbols */
+
+ uint32_t iextdefsym; /* index to externally defined symbols */
+ uint32_t nextdefsym; /* number of externally defined symbols */
+
+ uint32_t iundefsym; /* index to undefined symbols */
+ uint32_t nundefsym; /* number of undefined symbols */
+
+ /*
+ * For the for the dynamic binding process to find which module a symbol
+ * is defined in the table of contents is used (analogous to the ranlib
+ * structure in an archive) which maps defined external symbols to modules
+ * they are defined in. This exists only in a dynamically linked shared
+ * library file. For executable and object modules the defined external
+ * symbols are sorted by name and is use as the table of contents.
+ */
+ uint32_t tocoff; /* file offset to table of contents */
+ uint32_t ntoc; /* number of entries in table of contents */
+
+ /*
+ * To support dynamic binding of "modules" (whole object files) the symbol
+ * table must reflect the modules that the file was created from. This is
+ * done by having a module table that has indexes and counts into the merged
+ * tables for each module. The module structure that these two entries
+ * refer to is described below. This exists only in a dynamically linked
+ * shared library file. For executable and object modules the file only
+ * contains one module so everything in the file belongs to the module.
+ */
+ uint32_t modtaboff; /* file offset to module table */
+ uint32_t nmodtab; /* number of module table entries */
+
+ /*
+ * To support dynamic module binding the module structure for each module
+ * indicates the external references (defined and undefined) each module
+ * makes. For each module there is an offset and a count into the
+ * reference symbol table for the symbols that the module references.
+ * This exists only in a dynamically linked shared library file. For
+ * executable and object modules the defined external symbols and the
+ * undefined external symbols indicates the external references.
+ */
+ uint32_t extrefsymoff; /* offset to referenced symbol table */
+ uint32_t nextrefsyms; /* number of referenced symbol table entries */
+
+ /*
+ * The sections that contain "symbol pointers" and "routine stubs" have
+ * indexes and (implied counts based on the size of the section and fixed
+ * size of the entry) into the "indirect symbol" table for each pointer
+ * and stub. For every section of these two types the index into the
+ * indirect symbol table is stored in the section header in the field
+ * reserved1. An indirect symbol table entry is simply a 32bit index into
+ * the symbol table to the symbol that the pointer or stub is referring to.
+ * The indirect symbol table is ordered to match the entries in the section.
+ */
+ uint32_t indirectsymoff; /* file offset to the indirect symbol table */
+ uint32_t nindirectsyms; /* number of indirect symbol table entries */
+
+ /*
+ * To support relocating an individual module in a library file quickly the
+ * external relocation entries for each module in the library need to be
+ * accessed efficiently. Since the relocation entries can't be accessed
+ * through the section headers for a library file they are separated into
+ * groups of local and external entries further grouped by module. In this
+ * case the presents of this load command who's extreloff, nextrel,
+ * locreloff and nlocrel fields are non-zero indicates that the relocation
+ * entries of non-merged sections are not referenced through the section
+ * structures (and the reloff and nreloc fields in the section headers are
+ * set to zero).
+ *
+ * Since the relocation entries are not accessed through the section headers
+ * this requires the r_address field to be something other than a section
+ * offset to identify the item to be relocated. In this case r_address is
+ * set to the offset from the vmaddr of the first LC_SEGMENT command.
+ * For MH_SPLIT_SEGS images r_address is set to the the offset from the
+ * vmaddr of the first read-write LC_SEGMENT command.
+ *
+ * The relocation entries are grouped by module and the module table
+ * entries have indexes and counts into them for the group of external
+ * relocation entries for that the module.
+ *
+ * For sections that are merged across modules there must not be any
+ * remaining external relocation entries for them (for merged sections
+ * remaining relocation entries must be local).
+ */
+ uint32_t extreloff; /* offset to external relocation entries */
+ uint32_t nextrel; /* number of external relocation entries */
+
+ /*
+ * All the local relocation entries are grouped together (they are not
+ * grouped by their module since they are only used if the object is moved
+ * from it staticly link edited address).
+ */
+ uint32_t locreloff; /* offset to local relocation entries */
+ uint32_t nlocrel; /* number of local relocation entries */
+};
/*
* An indirect symbol table entry is simply a 32bit index into the symbol table
@@ -960,70 +1004,69 @@ struct dysymtab_command {
* removed. In which case it has the value INDIRECT_SYMBOL_LOCAL. If the
* symbol was also absolute INDIRECT_SYMBOL_ABS is or'ed with that.
*/
-#define INDIRECT_SYMBOL_LOCAL 0x80000000
-#define INDIRECT_SYMBOL_ABS 0x40000000
-
+#define INDIRECT_SYMBOL_LOCAL 0x80000000
+#define INDIRECT_SYMBOL_ABS 0x40000000
/* a table of contents entry */
struct dylib_table_of_contents {
- uint32_t symbol_index; /* the defined external symbol
- (index into the symbol table) */
- uint32_t module_index; /* index into the module table this symbol
- is defined in */
-};
+ uint32_t symbol_index; /* the defined external symbol
+ (index into the symbol table) */
+ uint32_t module_index; /* index into the module table this symbol
+ is defined in */
+};
/* a module table entry */
struct dylib_module {
- uint32_t module_name; /* the module name (index into string table) */
-
- uint32_t iextdefsym; /* index into externally defined symbols */
- uint32_t nextdefsym; /* number of externally defined symbols */
- uint32_t irefsym; /* index into reference symbol table */
- uint32_t nrefsym; /* number of reference symbol table entries */
- uint32_t ilocalsym; /* index into symbols for local symbols */
- uint32_t nlocalsym; /* number of local symbols */
-
- uint32_t iextrel; /* index into external relocation entries */
- uint32_t nextrel; /* number of external relocation entries */
-
- uint32_t iinit_iterm; /* low 16 bits are the index into the init
- section, high 16 bits are the index into
- the term section */
- uint32_t ninit_nterm; /* low 16 bits are the number of init section
- entries, high 16 bits are the number of
- term section entries */
-
- uint32_t /* for this module address of the start of */
- objc_module_info_addr; /* the (__OBJC,__module_info) section */
- uint32_t /* for this module size of */
- objc_module_info_size; /* the (__OBJC,__module_info) section */
-};
+ uint32_t module_name; /* the module name (index into string table) */
+
+ uint32_t iextdefsym; /* index into externally defined symbols */
+ uint32_t nextdefsym; /* number of externally defined symbols */
+ uint32_t irefsym; /* index into reference symbol table */
+ uint32_t nrefsym; /* number of reference symbol table entries */
+ uint32_t ilocalsym; /* index into symbols for local symbols */
+ uint32_t nlocalsym; /* number of local symbols */
+
+ uint32_t iextrel; /* index into external relocation entries */
+ uint32_t nextrel; /* number of external relocation entries */
+
+ uint32_t iinit_iterm; /* low 16 bits are the index into the init
+ section, high 16 bits are the index into
+ the term section */
+ uint32_t ninit_nterm; /* low 16 bits are the number of init section
+ entries, high 16 bits are the number of
+ term section entries */
+
+ uint32_t /* for this module address of the start of */
+ objc_module_info_addr; /* the (__OBJC,__module_info) section */
+ uint32_t /* for this module size of */
+ objc_module_info_size; /* the (__OBJC,__module_info) section */
+};
/* a 64-bit module table entry */
struct dylib_module_64 {
- uint32_t module_name; /* the module name (index into string table) */
-
- uint32_t iextdefsym; /* index into externally defined symbols */
- uint32_t nextdefsym; /* number of externally defined symbols */
- uint32_t irefsym; /* index into reference symbol table */
- uint32_t nrefsym; /* number of reference symbol table entries */
- uint32_t ilocalsym; /* index into symbols for local symbols */
- uint32_t nlocalsym; /* number of local symbols */
-
- uint32_t iextrel; /* index into external relocation entries */
- uint32_t nextrel; /* number of external relocation entries */
-
- uint32_t iinit_iterm; /* low 16 bits are the index into the init
- section, high 16 bits are the index into
- the term section */
- uint32_t ninit_nterm; /* low 16 bits are the number of init section
- entries, high 16 bits are the number of
- term section entries */
-
- uint32_t /* for this module size of */
- objc_module_info_size; /* the (__OBJC,__module_info) section */
- uint64_t /* for this module address of the start of */
- objc_module_info_addr; /* the (__OBJC,__module_info) section */
+ uint32_t module_name; /* the module name (index into string table) */
+
+ uint32_t iextdefsym; /* index into externally defined symbols */
+ uint32_t nextdefsym; /* number of externally defined symbols */
+ uint32_t irefsym; /* index into reference symbol table */
+ uint32_t nrefsym; /* number of reference symbol table entries */
+ uint32_t ilocalsym; /* index into symbols for local symbols */
+ uint32_t nlocalsym; /* number of local symbols */
+
+ uint32_t iextrel; /* index into external relocation entries */
+ uint32_t nextrel; /* number of external relocation entries */
+
+ uint32_t iinit_iterm; /* low 16 bits are the index into the init
+ section, high 16 bits are the index into
+ the term section */
+ uint32_t ninit_nterm; /* low 16 bits are the number of init section
+ entries, high 16 bits are the number of
+ term section entries */
+
+ uint32_t /* for this module size of */
+ objc_module_info_size; /* the (__OBJC,__module_info) section */
+ uint64_t /* for this module address of the start of */
+ objc_module_info_addr; /* the (__OBJC,__module_info) section */
};
/*
@@ -1035,8 +1078,8 @@ struct dylib_module_64 {
* <mach-o/nlist.h> as they are also used for symbol table entries.
*/
struct dylib_reference {
- uint32_t isym:24, /* index into the symbol table */
- flags:8; /* flags to indicate the type of reference */
+ uint32_t isym : 24, /* index into the symbol table */
+ flags : 8; /* flags to indicate the type of reference */
};
/*
@@ -1044,10 +1087,10 @@ struct dylib_reference {
* two-level namespace lookup hints table.
*/
struct twolevel_hints_command {
- uint32_t cmd; /* LC_TWOLEVEL_HINTS */
- uint32_t cmdsize; /* sizeof(struct twolevel_hints_command) */
- uint32_t offset; /* offset to the hint table */
- uint32_t nhints; /* number of hints in the hint table */
+ uint32_t cmd; /* LC_TWOLEVEL_HINTS */
+ uint32_t cmdsize; /* sizeof(struct twolevel_hints_command) */
+ uint32_t offset; /* offset to the hint table */
+ uint32_t nhints; /* number of hints in the hint table */
};
/*
@@ -1067,9 +1110,8 @@ struct twolevel_hints_command {
* binary search or a directed linear search.
*/
struct twolevel_hint {
- uint32_t
- isub_image:8, /* index into the sub images */
- itoc:24; /* index into the table of contents */
+ uint32_t isub_image : 8, /* index into the sub images */
+ itoc : 24; /* index into the table of contents */
};
/*
@@ -1083,9 +1125,9 @@ struct twolevel_hint {
* input file.
*/
struct prebind_cksum_command {
- uint32_t cmd; /* LC_PREBIND_CKSUM */
- uint32_t cmdsize; /* sizeof(struct prebind_cksum_command) */
- uint32_t cksum; /* the check sum or zero */
+ uint32_t cmd; /* LC_PREBIND_CKSUM */
+ uint32_t cmdsize; /* sizeof(struct prebind_cksum_command) */
+ uint32_t cksum; /* the check sum or zero */
};
/*
@@ -1093,9 +1135,9 @@ struct prebind_cksum_command {
* identifies an object produced by the static link editor.
*/
struct uuid_command {
- uint32_t cmd; /* LC_UUID */
- uint32_t cmdsize; /* sizeof(struct uuid_command) */
- uint8_t uuid[16]; /* the 128-bit uuid */
+ uint32_t cmd; /* LC_UUID */
+ uint32_t cmdsize; /* sizeof(struct uuid_command) */
+ uint8_t uuid[16]; /* the 128-bit uuid */
};
/*
@@ -1103,9 +1145,9 @@ struct uuid_command {
* the current run path used to find @rpath prefixed dylibs.
*/
struct rpath_command {
- uint32_t cmd; /* LC_RPATH */
- uint32_t cmdsize; /* includes string */
- union lc_str path; /* path to add to run path */
+ uint32_t cmd; /* LC_RPATH */
+ uint32_t cmdsize; /* includes string */
+ union lc_str path; /* path to add to run path */
};
/*
@@ -1113,10 +1155,10 @@ struct rpath_command {
* of data in the __LINKEDIT segment.
*/
struct linkedit_data_command {
- uint32_t cmd; /* LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO */
- uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */
- uint32_t dataoff; /* file offset of data in __LINKEDIT segment */
- uint32_t datasize; /* file size of data in __LINKEDIT segment */
+ uint32_t cmd; /* LC_CODE_SIGNATURE or LC_SEGMENT_SPLIT_INFO */
+ uint32_t cmdsize; /* sizeof(struct linkedit_data_command) */
+ uint32_t dataoff; /* file offset of data in __LINKEDIT segment */
+ uint32_t datasize; /* file size of data in __LINKEDIT segment */
};
/*
@@ -1124,12 +1166,12 @@ struct linkedit_data_command {
* of an encrypted segment.
*/
struct encryption_info_command {
- uint32_t cmd; /* LC_ENCRYPTION_INFO */
- uint32_t cmdsize; /* sizeof(struct encryption_info_command) */
- uint32_t cryptoff; /* file offset of encrypted range */
- uint32_t cryptsize; /* file size of encrypted range */
- uint32_t cryptid; /* which enryption system,
- 0 means not-encrypted yet */
+ uint32_t cmd; /* LC_ENCRYPTION_INFO */
+ uint32_t cmdsize; /* sizeof(struct encryption_info_command) */
+ uint32_t cryptoff; /* file offset of encrypted range */
+ uint32_t cryptsize; /* file size of encrypted range */
+ uint32_t cryptid; /* which enryption system,
+ 0 means not-encrypted yet */
};
/*
@@ -1141,161 +1183,159 @@ struct encryption_info_command {
* to interpret it.
*/
struct dyld_info_command {
- uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */
- uint32_t cmdsize; /* sizeof(struct dyld_info_command) */
-
- /*
- * Dyld rebases an image whenever dyld loads it at an address different
- * from its preferred address. The rebase information is a stream
- * of byte sized opcodes whose symbolic names start with REBASE_OPCODE_.
- * Conceptually the rebase information is a table of tuples:
- * <seg-index, seg-offset, type>
- * The opcodes are a compressed way to encode the table by only
- * encoding when a column changes. In addition simple patterns
- * like "every n'th offset for m times" can be encoded in a few
- * bytes.
- */
- uint32_t rebase_off; /* file offset to rebase info */
- uint32_t rebase_size; /* size of rebase info */
-
- /*
- * Dyld binds an image during the loading process, if the image
- * requires any pointers to be initialized to symbols in other images.
- * The bind information is a stream of byte sized
- * opcodes whose symbolic names start with BIND_OPCODE_.
- * Conceptually the bind information is a table of tuples:
- * <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend>
- * The opcodes are a compressed way to encode the table by only
- * encoding when a column changes. In addition simple patterns
- * like for runs of pointers initialzed to the same value can be
- * encoded in a few bytes.
- */
- uint32_t bind_off; /* file offset to binding info */
- uint32_t bind_size; /* size of binding info */
-
- /*
- * Some C++ programs require dyld to unique symbols so that all
- * images in the process use the same copy of some code/data.
- * This step is done after binding. The content of the weak_bind
- * info is an opcode stream like the bind_info. But it is sorted
- * alphabetically by symbol name. This enable dyld to walk
- * all images with weak binding information in order and look
- * for collisions. If there are no collisions, dyld does
- * no updating. That means that some fixups are also encoded
- * in the bind_info. For instance, all calls to "operator new"
- * are first bound to libstdc++.dylib using the information
- * in bind_info. Then if some image overrides operator new
- * that is detected when the weak_bind information is processed
- * and the call to operator new is then rebound.
- */
- uint32_t weak_bind_off; /* file offset to weak binding info */
- uint32_t weak_bind_size; /* size of weak binding info */
-
- /*
- * Some uses of external symbols do not need to be bound immediately.
- * Instead they can be lazily bound on first use. The lazy_bind
- * are contains a stream of BIND opcodes to bind all lazy symbols.
- * Normal use is that dyld ignores the lazy_bind section when
- * loading an image. Instead the static linker arranged for the
- * lazy pointer to initially point to a helper function which
- * pushes the offset into the lazy_bind area for the symbol
- * needing to be bound, then jumps to dyld which simply adds
- * the offset to lazy_bind_off to get the information on what
- * to bind.
- */
- uint32_t lazy_bind_off; /* file offset to lazy binding info */
- uint32_t lazy_bind_size; /* size of lazy binding infs */
-
- /*
- * The symbols exported by a dylib are encoded in a trie. This
- * is a compact representation that factors out common prefixes.
- * It also reduces LINKEDIT pages in RAM because it encodes all
- * information (name, address, flags) in one small, contiguous range.
- * The export area is a stream of nodes. The first node sequentially
- * is the start node for the trie.
- *
- * Nodes for a symbol start with a byte that is the length of
- * the exported symbol information for the string so far.
- * If there is no exported symbol, the byte is zero. If there
- * is exported info, it follows the length byte. The exported
- * info normally consists of a flags and offset both encoded
- * in uleb128. The offset is location of the content named
- * by the symbol. It is the offset from the mach_header for
- * the image.
- *
- * After the initial byte and optional exported symbol information
- * is a byte of how many edges (0-255) that this node has leaving
- * it, followed by each edge.
- * Each edge is a zero terminated cstring of the addition chars
- * in the symbol, followed by a uleb128 offset for the node that
- * edge points to.
- *
- */
- uint32_t export_off; /* file offset to lazy binding info */
- uint32_t export_size; /* size of lazy binding infs */
+ uint32_t cmd; /* LC_DYLD_INFO or LC_DYLD_INFO_ONLY */
+ uint32_t cmdsize; /* sizeof(struct dyld_info_command) */
+
+ /*
+ * Dyld rebases an image whenever dyld loads it at an address different
+ * from its preferred address. The rebase information is a stream
+ * of byte sized opcodes whose symbolic names start with REBASE_OPCODE_.
+ * Conceptually the rebase information is a table of tuples:
+ * <seg-index, seg-offset, type>
+ * The opcodes are a compressed way to encode the table by only
+ * encoding when a column changes. In addition simple patterns
+ * like "every n'th offset for m times" can be encoded in a few
+ * bytes.
+ */
+ uint32_t rebase_off; /* file offset to rebase info */
+ uint32_t rebase_size; /* size of rebase info */
+
+ /*
+ * Dyld binds an image during the loading process, if the image
+ * requires any pointers to be initialized to symbols in other images.
+ * The bind information is a stream of byte sized
+ * opcodes whose symbolic names start with BIND_OPCODE_.
+ * Conceptually the bind information is a table of tuples:
+ * <seg-index, seg-offset, type, symbol-library-ordinal, symbol-name, addend>
+ * The opcodes are a compressed way to encode the table by only
+ * encoding when a column changes. In addition simple patterns
+ * like for runs of pointers initialzed to the same value can be
+ * encoded in a few bytes.
+ */
+ uint32_t bind_off; /* file offset to binding info */
+ uint32_t bind_size; /* size of binding info */
+
+ /*
+ * Some C++ programs require dyld to unique symbols so that all
+ * images in the process use the same copy of some code/data.
+ * This step is done after binding. The content of the weak_bind
+ * info is an opcode stream like the bind_info. But it is sorted
+ * alphabetically by symbol name. This enable dyld to walk
+ * all images with weak binding information in order and look
+ * for collisions. If there are no collisions, dyld does
+ * no updating. That means that some fixups are also encoded
+ * in the bind_info. For instance, all calls to "operator new"
+ * are first bound to libstdc++.dylib using the information
+ * in bind_info. Then if some image overrides operator new
+ * that is detected when the weak_bind information is processed
+ * and the call to operator new is then rebound.
+ */
+ uint32_t weak_bind_off; /* file offset to weak binding info */
+ uint32_t weak_bind_size; /* size of weak binding info */
+
+ /*
+ * Some uses of external symbols do not need to be bound immediately.
+ * Instead they can be lazily bound on first use. The lazy_bind
+ * are contains a stream of BIND opcodes to bind all lazy symbols.
+ * Normal use is that dyld ignores the lazy_bind section when
+ * loading an image. Instead the static linker arranged for the
+ * lazy pointer to initially point to a helper function which
+ * pushes the offset into the lazy_bind area for the symbol
+ * needing to be bound, then jumps to dyld which simply adds
+ * the offset to lazy_bind_off to get the information on what
+ * to bind.
+ */
+ uint32_t lazy_bind_off; /* file offset to lazy binding info */
+ uint32_t lazy_bind_size; /* size of lazy binding infs */
+
+ /*
+ * The symbols exported by a dylib are encoded in a trie. This
+ * is a compact representation that factors out common prefixes.
+ * It also reduces LINKEDIT pages in RAM because it encodes all
+ * information (name, address, flags) in one small, contiguous range.
+ * The export area is a stream of nodes. The first node sequentially
+ * is the start node for the trie.
+ *
+ * Nodes for a symbol start with a byte that is the length of
+ * the exported symbol information for the string so far.
+ * If there is no exported symbol, the byte is zero. If there
+ * is exported info, it follows the length byte. The exported
+ * info normally consists of a flags and offset both encoded
+ * in uleb128. The offset is location of the content named
+ * by the symbol. It is the offset from the mach_header for
+ * the image.
+ *
+ * After the initial byte and optional exported symbol information
+ * is a byte of how many edges (0-255) that this node has leaving
+ * it, followed by each edge.
+ * Each edge is a zero terminated cstring of the addition chars
+ * in the symbol, followed by a uleb128 offset for the node that
+ * edge points to.
+ *
+ */
+ uint32_t export_off; /* file offset to lazy binding info */
+ uint32_t export_size; /* size of lazy binding infs */
};
/*
* The following are used to encode rebasing information
*/
-#define REBASE_TYPE_POINTER 1
-#define REBASE_TYPE_TEXT_ABSOLUTE32 2
-#define REBASE_TYPE_TEXT_PCREL32 3
-
-#define REBASE_OPCODE_MASK 0xF0
-#define REBASE_IMMEDIATE_MASK 0x0F
-#define REBASE_OPCODE_DONE 0x00
-#define REBASE_OPCODE_SET_TYPE_IMM 0x10
-#define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20
-#define REBASE_OPCODE_ADD_ADDR_ULEB 0x30
-#define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40
-#define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50
-#define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60
-#define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70
-#define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
-
+#define REBASE_TYPE_POINTER 1
+#define REBASE_TYPE_TEXT_ABSOLUTE32 2
+#define REBASE_TYPE_TEXT_PCREL32 3
+
+#define REBASE_OPCODE_MASK 0xF0
+#define REBASE_IMMEDIATE_MASK 0x0F
+#define REBASE_OPCODE_DONE 0x00
+#define REBASE_OPCODE_SET_TYPE_IMM 0x10
+#define REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x20
+#define REBASE_OPCODE_ADD_ADDR_ULEB 0x30
+#define REBASE_OPCODE_ADD_ADDR_IMM_SCALED 0x40
+#define REBASE_OPCODE_DO_REBASE_IMM_TIMES 0x50
+#define REBASE_OPCODE_DO_REBASE_ULEB_TIMES 0x60
+#define REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB 0x70
+#define REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB 0x80
/*
* The following are used to encode binding information
*/
-#define BIND_TYPE_POINTER 1
-#define BIND_TYPE_TEXT_ABSOLUTE32 2
-#define BIND_TYPE_TEXT_PCREL32 3
-
-#define BIND_SPECIAL_DYLIB_SELF 0
-#define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
-#define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2
-
-#define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1
-#define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8
-
-#define BIND_OPCODE_MASK 0xF0
-#define BIND_IMMEDIATE_MASK 0x0F
-#define BIND_OPCODE_DONE 0x00
-#define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10
-#define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20
-#define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30
-#define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40
-#define BIND_OPCODE_SET_TYPE_IMM 0x50
-#define BIND_OPCODE_SET_ADDEND_SLEB 0x60
-#define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70
-#define BIND_OPCODE_ADD_ADDR_ULEB 0x80
-#define BIND_OPCODE_DO_BIND 0x90
-#define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
-#define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
-#define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
-
+#define BIND_TYPE_POINTER 1
+#define BIND_TYPE_TEXT_ABSOLUTE32 2
+#define BIND_TYPE_TEXT_PCREL32 3
+
+#define BIND_SPECIAL_DYLIB_SELF 0
+#define BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE -1
+#define BIND_SPECIAL_DYLIB_FLAT_LOOKUP -2
+
+#define BIND_SYMBOL_FLAGS_WEAK_IMPORT 0x1
+#define BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION 0x8
+
+#define BIND_OPCODE_MASK 0xF0
+#define BIND_IMMEDIATE_MASK 0x0F
+#define BIND_OPCODE_DONE 0x00
+#define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM 0x10
+#define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB 0x20
+#define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM 0x30
+#define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM 0x40
+#define BIND_OPCODE_SET_TYPE_IMM 0x50
+#define BIND_OPCODE_SET_ADDEND_SLEB 0x60
+#define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB 0x70
+#define BIND_OPCODE_ADD_ADDR_ULEB 0x80
+#define BIND_OPCODE_DO_BIND 0x90
+#define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB 0xA0
+#define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED 0xB0
+#define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xC0
/*
* The following are used on the flags byte of a terminal node
* in the export information.
*/
-#define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03
-#define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00
-#define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01
-#define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04
-#define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08
-#define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10
+#define EXPORT_SYMBOL_FLAGS_KIND_MASK 0x03
+#define EXPORT_SYMBOL_FLAGS_KIND_REGULAR 0x00
+#define EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL 0x01
+#define EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION 0x04
+#define EXPORT_SYMBOL_FLAGS_INDIRECT_DEFINITION 0x08
+#define EXPORT_SYMBOL_FLAGS_HAS_SPECIALIZATIONS 0x10
/*
* The symseg_command contains the offset and size of the GNU style
@@ -1307,10 +1347,10 @@ struct dyld_info_command {
* zeroed. (THIS IS OBSOLETE and no longer supported).
*/
struct symseg_command {
- uint32_t cmd; /* LC_SYMSEG */
- uint32_t cmdsize; /* sizeof(struct symseg_command) */
- uint32_t offset; /* symbol segment offset */
- uint32_t size; /* symbol segment size in bytes */
+ uint32_t cmd; /* LC_SYMSEG */
+ uint32_t cmdsize; /* sizeof(struct symseg_command) */
+ uint32_t offset; /* symbol segment offset */
+ uint32_t size; /* symbol segment size in bytes */
};
/*
@@ -1320,8 +1360,8 @@ struct symseg_command {
* (THIS IS OBSOLETE and no longer supported).
*/
struct ident_command {
- uint32_t cmd; /* LC_IDENT */
- uint32_t cmdsize; /* strings that follow this command */
+ uint32_t cmd; /* LC_IDENT */
+ uint32_t cmdsize; /* strings that follow this command */
};
/*
@@ -1331,10 +1371,10 @@ struct ident_command {
* memory).
*/
struct fvmfile_command {
- uint32_t cmd; /* LC_FVMFILE */
- uint32_t cmdsize; /* includes pathname string */
- union lc_str name; /* files pathname */
- uint32_t header_addr; /* files virtual address */
+ uint32_t cmd; /* LC_FVMFILE */
+ uint32_t cmdsize; /* includes pathname string */
+ union lc_str name; /* files pathname */
+ uint32_t header_addr; /* files virtual address */
};
/// @amlel-el-mahrouss -- Nectar Port Code Begin
@@ -1345,9 +1385,9 @@ MACHO_DECL_TYPE(cpu_type_t);
MACHO_DECL_TYPE(cpu_subtype_t)
#ifdef __linux__
-# warning The OS X backend is currently being ported to other platforms.
+#warning The OS X backend is currently being ported to other platforms.
#endif
-
+
/// @amlel-el-mahrouss -- Nectar Port Code End
-
+
#endif /* _MACHO_LOADER_H_ */
diff --git a/include/mach-o/nlist.h b/include/mach-o/nlist.h
index 868ec20..517e1b6 100644
--- a/include/mach-o/nlist.h
+++ b/include/mach-o/nlist.h
@@ -1,15 +1,15 @@
/*
* Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
- *
+ *
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -17,7 +17,7 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _MACHO_NLIST_H_
@@ -74,29 +74,29 @@
* file.
*/
struct nlist {
- union {
+ union {
#ifndef __LP64__
- char *n_name; /* for use when in-core */
+ char* n_name; /* for use when in-core */
#endif
- int32_t n_strx; /* index into the string table */
- } n_un;
- uint8_t n_type; /* type flag, see below */
- uint8_t n_sect; /* section number or NO_SECT */
- int16_t n_desc; /* see <mach-o/stab.h> */
- uint32_t n_value; /* value of this symbol (or stab offset) */
+ int32_t n_strx; /* index into the string table */
+ } n_un;
+ uint8_t n_type; /* type flag, see below */
+ uint8_t n_sect; /* section number or NO_SECT */
+ int16_t n_desc; /* see <mach-o/stab.h> */
+ uint32_t n_value; /* value of this symbol (or stab offset) */
};
/*
* This is the symbol table entry structure for 64-bit architectures.
*/
struct nlist_64 {
- union {
- uint32_t n_strx; /* index into the string table */
- } n_un;
- uint8_t n_type; /* type flag, see below */
- uint8_t n_sect; /* section number or NO_SECT */
- uint16_t n_desc; /* see <mach-o/stab.h> */
- uint64_t n_value; /* value of this symbol (or stab offset) */
+ union {
+ uint32_t n_strx; /* index into the string table */
+ } n_un;
+ uint8_t n_type; /* type flag, see below */
+ uint8_t n_sect; /* section number or NO_SECT */
+ uint16_t n_desc; /* see <mach-o/stab.h> */
+ uint64_t n_value; /* value of this symbol (or stab offset) */
};
/*
@@ -114,10 +114,10 @@ struct nlist_64 {
* N_EXT:1;
* which are used via the following masks.
*/
-#define N_STAB 0xe0 /* if any of these bits set, a symbolic debugging entry */
-#define N_PEXT 0x10 /* private external symbol bit */
-#define N_TYPE 0x0e /* mask for the type bits */
-#define N_EXT 0x01 /* external symbol bit, set for external symbols */
+#define N_STAB 0xe0 /* if any of these bits set, a symbolic debugging entry */
+#define N_PEXT 0x10 /* private external symbol bit */
+#define N_TYPE 0x0e /* mask for the type bits */
+#define N_EXT 0x01 /* external symbol bit, set for external symbols */
/*
* Only symbolic debugging entries have some of the N_STAB bits set and if any
@@ -129,13 +129,13 @@ struct nlist_64 {
/*
* Values for N_TYPE bits of the n_type field.
*/
-#define N_UNDF 0x0 /* undefined, n_sect == NO_SECT */
-#define N_ABS 0x2 /* absolute, n_sect == NO_SECT */
-#define N_SECT 0xe /* defined in section number n_sect */
-#define N_PBUD 0xc /* prebound undefined (defined in a dylib) */
-#define N_INDR 0xa /* indirect */
+#define N_UNDF 0x0 /* undefined, n_sect == NO_SECT */
+#define N_ABS 0x2 /* absolute, n_sect == NO_SECT */
+#define N_SECT 0xe /* defined in section number n_sect */
+#define N_PBUD 0xc /* prebound undefined (defined in a dylib) */
+#define N_INDR 0xa /* indirect */
-/*
+/*
* If the type is N_INDR then the symbol is defined to be the same as another
* symbol. In this case the n_value field is an index into the string table
* of the other symbol's name. When the other symbol is defined then they both
@@ -144,18 +144,18 @@ struct nlist_64 {
/*
* If the type is N_SECT then the n_sect field contains an ordinal of the
- * section the symbol is defined in. The sections are numbered from 1 and
+ * section the symbol is defined in. The sections are numbered from 1 and
* refer to sections in order they appear in the load commands for the file
* they are in. This means the same ordinal may very well refer to different
* sections in different files.
*
* The n_value field for all symbol table entries (including N_STAB's) gets
* updated by the link editor based on the value of it's n_sect field and where
- * the section n_sect references gets relocated. If the value of the n_sect
+ * the section n_sect references gets relocated. If the value of the n_sect
* field is NO_SECT then it's n_value field is not changed by the link editor.
*/
-#define NO_SECT 0 /* symbol is not in any section */
-#define MAX_SECT 255 /* 1 thru 255 inclusive */
+#define NO_SECT 0 /* symbol is not in any section */
+#define MAX_SECT 255 /* 1 thru 255 inclusive */
/*
* Common symbols are represented by undefined (N_UNDF) external (N_EXT) types
@@ -167,8 +167,7 @@ struct nlist_64 {
* the size is used.
*/
#define GET_COMM_ALIGN(n_desc) (((n_desc) >> 8) & 0x0f)
-#define SET_COMM_ALIGN(n_desc,align) \
- (n_desc) = (((n_desc) & 0xf0ff) | (((align) & 0x0f) << 8))
+#define SET_COMM_ALIGN(n_desc, align) (n_desc) = (((n_desc) & 0xf0ff) | (((align) & 0x0f) << 8))
/*
* To support the lazy binding of undefined symbols in the dynamic link-editor,
@@ -190,14 +189,14 @@ struct nlist_64 {
* REFERENCE_FLAG_DEFINED, is also used.
*/
/* Reference type bits of the n_desc field of undefined symbols */
-#define REFERENCE_TYPE 0x7
+#define REFERENCE_TYPE 0x7
/* types of references */
-#define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
-#define REFERENCE_FLAG_UNDEFINED_LAZY 1
-#define REFERENCE_FLAG_DEFINED 2
-#define REFERENCE_FLAG_PRIVATE_DEFINED 3
-#define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
-#define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
+#define REFERENCE_FLAG_UNDEFINED_NON_LAZY 0
+#define REFERENCE_FLAG_UNDEFINED_LAZY 1
+#define REFERENCE_FLAG_DEFINED 2
+#define REFERENCE_FLAG_PRIVATE_DEFINED 3
+#define REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY 4
+#define REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY 5
/*
* To simplify stripping of objects that use are used with the dynamic link
@@ -205,7 +204,7 @@ struct nlist_64 {
* referenced by a dynamicly bound object (dynamic shared libraries, bundles).
* With this marking strip knows not to strip these symbols.
*/
-#define REFERENCED_DYNAMICALLY 0x0010
+#define REFERENCED_DYNAMICALLY 0x0010
/*
* For images created by the static link editor with the -twolevel_namespace
@@ -223,18 +222,18 @@ struct nlist_64 {
* SELF_LIBRARY_ORDINAL. The EXECUTABLE_ORDINAL refers to the executable
* image for references from plugins that refer to the executable that loads
* them.
- *
+ *
* The DYNAMIC_LOOKUP_ORDINAL is for undefined symbols in a two-level namespace
* image that are looked up by the dynamic linker with flat namespace semantics.
* This ordinal was added as a feature in Mac OS X 10.3 by reducing the
* value of MAX_LIBRARY_ORDINAL by one. So it is legal for existing binaries
* or binaries built with older tools to have 0xfe (254) dynamic libraries. In
* this case the ordinal value 0xfe (254) must be treated as a library ordinal
- * for compatibility.
+ * for compatibility.
*/
#define GET_LIBRARY_ORDINAL(n_desc) (((n_desc) >> 8) & 0xff)
-#define SET_LIBRARY_ORDINAL(n_desc,ordinal) \
- (n_desc) = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8))
+#define SET_LIBRARY_ORDINAL(n_desc, ordinal) \
+ (n_desc) = (((n_desc) & 0x00ff) | (((ordinal) & 0xff) << 8))
#define SELF_LIBRARY_ORDINAL 0x0
#define MAX_LIBRARY_ORDINAL 0xfd
#define DYNAMIC_LOOKUP_ORDINAL 0xfe
@@ -246,7 +245,7 @@ struct nlist_64 {
*/
/*
- * The N_NO_DEAD_STRIP bit of the n_desc field only ever appears in a
+ * The N_NO_DEAD_STRIP bit of the n_desc field only ever appears in a
* relocatable .o file (MH_OBJECT filetype). And is used to indicate to the
* static link editor it is never to dead strip the symbol.
*/
@@ -257,14 +256,14 @@ struct nlist_64 {
* But is used in very rare cases by the dynamic link editor to mark an in
* memory symbol as discared and longer used for linking.
*/
-#define N_DESC_DISCARDED 0x0020 /* symbol is discarded */
+#define N_DESC_DISCARDED 0x0020 /* symbol is discarded */
/*
* The N_WEAK_REF bit of the n_desc field indicates to the dynamic linker that
* the undefined symbol is allowed to be missing and is to have the address of
* zero when missing.
*/
-#define N_WEAK_REF 0x0040 /* symbol is weak referenced */
+#define N_WEAK_REF 0x0040 /* symbol is weak referenced */
/*
* The N_WEAK_DEF bit of the n_desc field indicates to the static and dynamic
@@ -272,19 +271,19 @@ struct nlist_64 {
* also be used which causes the weak definition to be discared. Currently this
* is only supported for symbols in coalesed sections.
*/
-#define N_WEAK_DEF 0x0080 /* coalesed symbol is a weak definition */
+#define N_WEAK_DEF 0x0080 /* coalesed symbol is a weak definition */
/*
* The N_REF_TO_WEAK bit of the n_desc field indicates to the dynamic linker
* that the undefined symbol should be resolved using flat namespace searching.
*/
-#define N_REF_TO_WEAK 0x0080 /* reference to a weak symbol */
+#define N_REF_TO_WEAK 0x0080 /* reference to a weak symbol */
/*
* The N_ARM_THUMB_DEF bit of the n_desc field indicates that the symbol is
* a defintion of a Thumb function.
*/
-#define N_ARM_THUMB_DEF 0x0008 /* symbol is a Thumb function (ARM) */
+#define N_ARM_THUMB_DEF 0x0008 /* symbol is a Thumb function (ARM) */
#ifndef __STRICT_BSD__
#if __cplusplus
@@ -293,7 +292,7 @@ extern "C" {
/*
* The function nlist(3) from the C library.
*/
-extern int nlist (const char *filename, struct nlist *list);
+extern int nlist(const char* filename, struct nlist* list);
#if __cplusplus
}
#endif /* __cplusplus */
diff --git a/include/mach-o/reloc.h b/include/mach-o/reloc.h
index e36f4f7..89aebf1 100644
--- a/include/mach-o/reloc.h
+++ b/include/mach-o/reloc.h
@@ -2,14 +2,14 @@
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -17,7 +17,7 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
/* $NetBSD: exec.h,v 1.6 1994/10/27 04:16:05 cgd Exp $ */
@@ -62,16 +62,16 @@
* Also the last 4 bits have had the r_type tag added to them.
*/
struct relocation_info {
- int32_t r_address; /* offset in the section to what is being
- relocated */
- uint32_t r_symbolnum:24, /* symbol index if r_extern == 1 or section
- ordinal if r_extern == 0 */
- r_pcrel:1, /* was relocated pc relative already */
- r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
- r_extern:1, /* does not include value of sym referenced */
- r_type:4; /* if not 0, machine specific relocation type */
+ int32_t r_address; /* offset in the section to what is being
+ relocated */
+ uint32_t r_symbolnum : 24, /* symbol index if r_extern == 1 or section
+ ordinal if r_extern == 0 */
+ r_pcrel : 1, /* was relocated pc relative already */
+ r_length : 2, /* 0=byte, 1=word, 2=long, 3=quad */
+ r_extern : 1, /* does not include value of sym referenced */
+ r_type : 4; /* if not 0, machine specific relocation type */
};
-#define R_ABS 0 /* absolute relocation type for Mach-O files */
+#define R_ABS 0 /* absolute relocation type for Mach-O files */
/*
* The r_address is not really the address as it's name indicates but an offset.
@@ -80,7 +80,7 @@ struct relocation_info {
* also an offset but from the start of the "section" for which the relocation
* entry is for. See comments in <mach-o/loader.h> about the r_address feild
* in images for used with the dynamic linker.
- *
+ *
* In 4.3BSD a.out objects if r_extern is zero then r_symbolnum is an ordinal
* for the segment the symbol being relocated is in. These ordinals are the
* symbol types N_TEXT, N_DATA, N_BSS or N_ABS. In Mach-O object files these
@@ -144,32 +144,32 @@ struct relocation_info {
* mask can be applied can check the same bit each time (r_scattered).
*/
#endif /* defined(__BIG_ENDIAN__) || defined(__LITTLE_ENDIAN__) */
-#define R_SCATTERED 0x80000000 /* mask to be applied to the r_address field
- of a relocation_info structure to tell that
- is is really a scattered_relocation_info
- stucture */
+#define R_SCATTERED \
+ 0x80000000 /* mask to be applied to the r_address field \
+of a relocation_info structure to tell that \
+is is really a scattered_relocation_info \
+stucture */
struct scattered_relocation_info {
#ifdef __BIG_ENDIAN__
- uint32_t r_scattered:1, /* 1=scattered, 0=non-scattered (see above) */
- r_pcrel:1, /* was relocated pc relative already */
- r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
- r_type:4, /* if not 0, machine specific relocation type */
- r_address:24; /* offset in the section to what is being
- relocated */
- int32_t r_value; /* the value the item to be relocated is
- refering to (without any offset added) */
-#endif /* __BIG_ENDIAN__ */
+ uint32_t r_scattered : 1, /* 1=scattered, 0=non-scattered (see above) */
+ r_pcrel : 1, /* was relocated pc relative already */
+ r_length : 2, /* 0=byte, 1=word, 2=long, 3=quad */
+ r_type : 4, /* if not 0, machine specific relocation type */
+ r_address : 24; /* offset in the section to what is being
+ relocated */
+ int32_t r_value; /* the value the item to be relocated is
+ refering to (without any offset added) */
+#endif /* __BIG_ENDIAN__ */
#ifdef __LITTLE_ENDIAN__
- uint32_t
- r_address:24, /* offset in the section to what is being
- relocated */
- r_type:4, /* if not 0, machine specific relocation type */
- r_length:2, /* 0=byte, 1=word, 2=long, 3=quad */
- r_pcrel:1, /* was relocated pc relative already */
- r_scattered:1; /* 1=scattered, 0=non-scattered (see above) */
- int32_t r_value; /* the value the item to be relocated is
- refering to (without any offset added) */
-#endif /* __LITTLE_ENDIAN__ */
+ uint32_t r_address : 24, /* offset in the section to what is being
+ relocated */
+ r_type : 4, /* if not 0, machine specific relocation type */
+ r_length : 2, /* 0=byte, 1=word, 2=long, 3=quad */
+ r_pcrel : 1, /* was relocated pc relative already */
+ r_scattered : 1; /* 1=scattered, 0=non-scattered (see above) */
+ int32_t r_value; /* the value the item to be relocated is
+ refering to (without any offset added) */
+#endif /* __LITTLE_ENDIAN__ */
};
/*
@@ -190,13 +190,12 @@ struct scattered_relocation_info {
* using the GENERIC_RELOC_PB_LA_PTR r_type. This is a scattered relocation
* entry where the r_value feild is the value of the lazy pointer not prebound.
*/
-enum reloc_type_generic
-{
- GENERIC_RELOC_VANILLA, /* generic relocation as discribed above */
- GENERIC_RELOC_PAIR, /* Only follows a GENERIC_RELOC_SECTDIFF */
- GENERIC_RELOC_SECTDIFF,
- GENERIC_RELOC_PB_LA_PTR, /* prebound lazy pointer */
- GENERIC_RELOC_LOCAL_SECTDIFF
+enum reloc_type_generic {
+ GENERIC_RELOC_VANILLA, /* generic relocation as discribed above */
+ GENERIC_RELOC_PAIR, /* Only follows a GENERIC_RELOC_SECTDIFF */
+ GENERIC_RELOC_SECTDIFF,
+ GENERIC_RELOC_PB_LA_PTR, /* prebound lazy pointer */
+ GENERIC_RELOC_LOCAL_SECTDIFF
};
#endif /* _MACHO_RELOC_H_ */
diff --git a/include/mach-o/stab.h b/include/mach-o/stab.h
index e9e15b2..409ed90 100644
--- a/include/mach-o/stab.h
+++ b/include/mach-o/stab.h
@@ -2,14 +2,14 @@
* Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
- *
+ *
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
- *
+ *
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -17,7 +17,7 @@
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
- *
+ *
* @APPLE_LICENSE_HEADER_END@
*/
#ifndef _MACHO_STAB_H_
@@ -71,52 +71,52 @@
* These must have one of the N_STAB bits on. The n_value fields are subject
* to relocation according to the value of their n_sect field. So for types
* that refer to things in sections the n_sect field must be filled in with the
- * proper section ordinal. For types that are not to have their n_value field
+ * proper section ordinal. For types that are not to have their n_value field
* relocatated the n_sect field must be NO_SECT.
*/
/*
* Symbolic debugger symbols. The comments give the conventional use for
- *
+ *
* .stabs "n_name", n_type, n_sect, n_desc, n_value
*
* where n_type is the defined constant and not listed in the comment. Other
* fields not listed are zero. n_sect is the section ordinal the entry is
* refering to.
*/
-#define N_GSYM 0x20 /* global symbol: name,,NO_SECT,type,0 */
-#define N_FNAME 0x22 /* procedure name (f77 kludge): name,,NO_SECT,0,0 */
-#define N_FUN 0x24 /* procedure: name,,n_sect,linenumber,address */
-#define N_STSYM 0x26 /* static symbol: name,,n_sect,type,address */
-#define N_LCSYM 0x28 /* .lcomm symbol: name,,n_sect,type,address */
-#define N_BNSYM 0x2e /* begin nsect sym: 0,,n_sect,0,address */
-#define N_OPT 0x3c /* emitted with gcc2_compiled and in gcc source */
-#define N_RSYM 0x40 /* register sym: name,,NO_SECT,type,register */
-#define N_SLINE 0x44 /* src line: 0,,n_sect,linenumber,address */
-#define N_ENSYM 0x4e /* end nsect sym: 0,,n_sect,0,address */
-#define N_SSYM 0x60 /* structure elt: name,,NO_SECT,type,struct_offset */
-#define N_SO 0x64 /* source file name: name,,n_sect,0,address */
-#define N_OSO 0x66 /* object file name: name,,0,0,st_mtime */
-#define N_LSYM 0x80 /* local sym: name,,NO_SECT,type,offset */
-#define N_BINCL 0x82 /* include file beginning: name,,NO_SECT,0,sum */
-#define N_SOL 0x84 /* #included file name: name,,n_sect,0,address */
-#define N_PARAMS 0x86 /* compiler parameters: name,,NO_SECT,0,0 */
-#define N_VERSION 0x88 /* compiler version: name,,NO_SECT,0,0 */
-#define N_OLEVEL 0x8A /* compiler -O level: name,,NO_SECT,0,0 */
-#define N_PSYM 0xa0 /* parameter: name,,NO_SECT,type,offset */
-#define N_EINCL 0xa2 /* include file end: name,,NO_SECT,0,0 */
-#define N_ENTRY 0xa4 /* alternate entry: name,,n_sect,linenumber,address */
-#define N_LBRAC 0xc0 /* left bracket: 0,,NO_SECT,nesting level,address */
-#define N_EXCL 0xc2 /* deleted include file: name,,NO_SECT,0,sum */
-#define N_RBRAC 0xe0 /* right bracket: 0,,NO_SECT,nesting level,address */
-#define N_BCOMM 0xe2 /* begin common: name,,NO_SECT,0,0 */
-#define N_ECOMM 0xe4 /* end common: name,,n_sect,0,0 */
-#define N_ECOML 0xe8 /* end common (local name): 0,,n_sect,0,address */
-#define N_LENG 0xfe /* second stab entry with length information */
+#define N_GSYM 0x20 /* global symbol: name,,NO_SECT,type,0 */
+#define N_FNAME 0x22 /* procedure name (f77 kludge): name,,NO_SECT,0,0 */
+#define N_FUN 0x24 /* procedure: name,,n_sect,linenumber,address */
+#define N_STSYM 0x26 /* static symbol: name,,n_sect,type,address */
+#define N_LCSYM 0x28 /* .lcomm symbol: name,,n_sect,type,address */
+#define N_BNSYM 0x2e /* begin nsect sym: 0,,n_sect,0,address */
+#define N_OPT 0x3c /* emitted with gcc2_compiled and in gcc source */
+#define N_RSYM 0x40 /* register sym: name,,NO_SECT,type,register */
+#define N_SLINE 0x44 /* src line: 0,,n_sect,linenumber,address */
+#define N_ENSYM 0x4e /* end nsect sym: 0,,n_sect,0,address */
+#define N_SSYM 0x60 /* structure elt: name,,NO_SECT,type,struct_offset */
+#define N_SO 0x64 /* source file name: name,,n_sect,0,address */
+#define N_OSO 0x66 /* object file name: name,,0,0,st_mtime */
+#define N_LSYM 0x80 /* local sym: name,,NO_SECT,type,offset */
+#define N_BINCL 0x82 /* include file beginning: name,,NO_SECT,0,sum */
+#define N_SOL 0x84 /* #included file name: name,,n_sect,0,address */
+#define N_PARAMS 0x86 /* compiler parameters: name,,NO_SECT,0,0 */
+#define N_VERSION 0x88 /* compiler version: name,,NO_SECT,0,0 */
+#define N_OLEVEL 0x8A /* compiler -O level: name,,NO_SECT,0,0 */
+#define N_PSYM 0xa0 /* parameter: name,,NO_SECT,type,offset */
+#define N_EINCL 0xa2 /* include file end: name,,NO_SECT,0,0 */
+#define N_ENTRY 0xa4 /* alternate entry: name,,n_sect,linenumber,address */
+#define N_LBRAC 0xc0 /* left bracket: 0,,NO_SECT,nesting level,address */
+#define N_EXCL 0xc2 /* deleted include file: name,,NO_SECT,0,sum */
+#define N_RBRAC 0xe0 /* right bracket: 0,,NO_SECT,nesting level,address */
+#define N_BCOMM 0xe2 /* begin common: name,,NO_SECT,0,0 */
+#define N_ECOMM 0xe4 /* end common: name,,n_sect,0,0 */
+#define N_ECOML 0xe8 /* end common (local name): 0,,n_sect,0,address */
+#define N_LENG 0xfe /* second stab entry with length information */
/*
* for the berkeley pascal compiler, pc(1):
*/
-#define N_PC 0x30 /* global pascal symbol: name,,NO_SECT,subtype,line */
+#define N_PC 0x30 /* global pascal symbol: name,,NO_SECT,subtype,line */
#endif /* _MACHO_STAB_H_ */
diff --git a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
index dfca499..d9b3551 100644
--- a/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
+++ b/src/CompilerKit/src/Compilers/NectarCompiler+AMD64.cc
@@ -365,7 +365,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
if (!nectar_get_variable_ref(left).empty())
syntax_tree.fUserValue += "mov rdi, " +
(isnumber(left[0]) ? left
- : (nectar_get_variable_ref(left).empty()
+ : (!nectar_get_variable_ref(left).empty()
? left
: nectar_get_variable_ref(left))) +
"\n";
@@ -373,16 +373,16 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
syntax_tree.fUserValue += "mov rdi, " +
(isnumber(left[0]) ? left
: (nectar_get_variable_ref(left).empty()
- ? left
+ ? "0x0"
: nectar_get_variable_ref(left))) +
"\n";
- if (!nectar_get_variable_ref(left).empty())
+ if (!nectar_get_variable_ref(right).empty())
syntax_tree.fUserValue +=
"lea rsi, " +
(isnumber(right[0])
? right
- : (nectar_get_variable_ref(right).empty() ? right
+ : (!nectar_get_variable_ref(right).empty() ? right
: nectar_get_variable_ref(right))) +
"\n";
else
@@ -390,7 +390,7 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
"mov rsi, " +
(isnumber(right[0])
? right
- : (nectar_get_variable_ref(right).empty() ? right
+ : (nectar_get_variable_ref(right).empty() ? "0x0"
: nectar_get_variable_ref(right))) +
"\n";
@@ -435,7 +435,10 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
dont_accept_func:
break;
- accept_func : {
+ accept_func: {
+ if (kFunctionEmbedLevel > 0)
+ CompilerKit::Detail::print_error("Clojures are a work in progress feature.", file);
+
CompilerKit::STLString symbol_name_fn = text;
size_t indexFnName = 0;
@@ -569,6 +572,26 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
case CompilerKit::KeywordKind::kKeywordKindAccess:
case CompilerKit::KeywordKind::kKeywordKindFunctionAccess:
case CompilerKit::KeywordKind::kKeywordKindAccessChecked: {
+ if (text.find("return ") != CompilerKit::STLString::npos) {
+ break;
+ }
+
+ if (text.find("if ") != CompilerKit::STLString::npos) {
+ break;
+ }
+
+ if (text.find("const ") != CompilerKit::STLString::npos) {
+ break;
+ }
+
+ if (text.find("let ") != CompilerKit::STLString::npos) {
+ break;
+ }
+
+ if (text.find("):") != CompilerKit::STLString::npos) {
+ break;
+ }
+
CompilerKit::STLString valueOfVar =
text.substr(text.find(keyword.first.fKeywordName) + keyword.first.fKeywordName.size());
@@ -923,7 +946,38 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
subText = subText.erase(subText.find(";"));
size_t indxReg = 0UL;
- if (subText.find("(") != CompilerKit::STLString::npos) subText.erase(subText.find("("));
+ // Extract and set up call arguments before erasing them
+ if (subText.find("):") != CompilerKit::STLString::npos) {
+ auto argStart = subText.find("(") + 1;
+ auto argEnd = subText.find("):");
+
+ if (argEnd != CompilerKit::STLString::npos && argEnd > argStart) {
+ auto argsStr = subText.substr(argStart, argEnd - argStart);
+ auto regIdx = 9;
+
+ CompilerKit::STLString currentArg;
+ for (std::size_t i = 0; i <= argsStr.size(); ++i) {
+ if (i == argsStr.size() || argsStr[i] == ',') {
+ while (!currentArg.empty() && currentArg[0] == ' ') currentArg.erase(0, 1);
+ while (!currentArg.empty() && currentArg.back() == ' ') currentArg.pop_back();
+
+ if (!currentArg.empty() && regIdx <= 15) {
+ auto val = nectar_get_variable_ref(currentArg);
+ if (val.empty()) val = currentArg;
+
+ syntax_tree.fUserValue += "mov r" + std::to_string(regIdx) + ", " + val + "\n";
+ ++regIdx;
+ }
+
+ currentArg.clear();
+ } else {
+ currentArg += argsStr[i];
+ }
+ }
+ }
+
+ subText.erase(subText.find("("));
+ }
auto ref = nectar_get_variable_ref(subText);
@@ -933,7 +987,16 @@ CompilerKit::SyntaxLeafList::SyntaxLeaf CompilerFrontendNectarAMD64::Compile(
syntax_tree.fUserValue += "mov rax, " + subText + "\n";
else if (text.find("(") != CompilerKit::STLString::npos &&
text.find(");") != CompilerKit::STLString::npos) {
- // Track as potential external symbol for NASM
+ // Track as potential external symbol for NASM.
+
+ subText.erase(subText.find("("));
+
+ for (const auto& keyword : kKeywords)
+ {
+ if (keyword.fKeywordName == subText)
+ CompilerKit::Detail::print_error("A Nectar keyword cannot be called.", file);
+ }
+
kExternalSymbols.insert(subText);
if (!kNasmOutput) {
@@ -1434,8 +1497,7 @@ static void nectar_process_function_parameters(const std::vector<CompilerKit::ST
/////////////////////////////////////////////////////////////////////////////////////////
-#define kExtListCxx \
- { ".nc", ".pp.nc" }
+#define kExtListCxx {".nc", ".pp.nc"}
class AssemblyNectarInterfaceAMD64 final CK_ASSEMBLY_INTERFACE {
public:
diff --git a/test/test_samples/inner.nc b/test/test_samples/inner.nc
new file mode 100644
index 0000000..05657d1
--- /dev/null
+++ b/test/test_samples/inner.nc
@@ -0,0 +1,13 @@
+let main()
+{
+ let foo := 42;
+
+ if (foo == 42)
+ {
+ const return_stub():
+ foo := 0;
+ return 0x0;
+ }
+
+ return 0x0;
+}