diff -r --unified ld64-ld64-62.1-unpatched/ld64.xcodeproj/project.pbxproj ld64-ld64-62.1-ppc64/ld64.xcodeproj/project.pbxproj --- ld64-ld64-62.1-unpatched/ld64.xcodeproj/project.pbxproj 2021-10-06 00:21:03.000000000 -0500 +++ ld64-ld64-62.1-ppc64/ld64.xcodeproj/project.pbxproj 2025-03-11 22:51:35.000000000 -0500 @@ -562,6 +582,7 @@ F933D92409291AC90083EAC8 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = ppc64; GCC_DYNAMIC_NO_PIC = NO; GCC_TREAT_WARNINGS_AS_ERRORS = NO; }; @@ -570,6 +591,7 @@ F933D92509291AC90083EAC8 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ARCHS = ppc64; GCC_DYNAMIC_NO_PIC = NO; GCC_TREAT_WARNINGS_AS_ERRORS = NO; }; diff -r --unified ld64-ld64-62.1-unpatched/src/MachOReaderRelocatable.hpp ld64-ld64-62.1-ppc64/src/MachOReaderRelocatable.hpp --- ld64-ld64-62.1-unpatched/src/MachOReaderRelocatable.hpp 2021-10-06 00:21:03.000000000 -0500 +++ ld64-ld64-62.1-ppc64/src/MachOReaderRelocatable.hpp 2025-03-11 21:57:38.000000000 -0500 @@ -31,7 +31,25 @@ #include #include #include -#include +//#include +enum reloc_type_x86_64 +{ + X86_64_RELOC_UNSIGNED, // for absolute addresses + X86_64_RELOC_SIGNED, // for signed 32-bit displacement + X86_64_RELOC_BRANCH, // a CALL/JMP instruction with 32-bit displacement + X86_64_RELOC_GOT_LOAD, // a MOVQ load of a GOT entry + X86_64_RELOC_GOT, // other GOT references + X86_64_RELOC_SUBTRACTOR, // must be followed by a X86_64_RELOC_UNSIGNED + X86_64_RELOC_SIGNED_1, // for signed 32-bit displacement with a -1 addend + X86_64_RELOC_SIGNED_2, // for signed 32-bit displacement with a -2 addend + X86_64_RELOC_SIGNED_4, // for signed 32-bit displacement with a -4 addend + X86_64_RELOC_TLV, // for thread local variables +}; + +#ifndef CPU_TYPE_X86_64 +#define CPU_TYPE_X86_64 ((cpu_type_t) (CPU_TYPE_I386 | CPU_ARCH_ABI64)) +#endif + #ifndef S_ATTR_DEBUG #define S_ATTR_DEBUG 0x02000000 #endif diff -r --unified ld64-ld64-62.1-unpatched/src/MachOWriterExecutable.hpp ld64-ld64-62.1-ppc64/src/MachOWriterExecutable.hpp --- ld64-ld64-62.1-unpatched/src/MachOWriterExecutable.hpp 2021-10-06 00:21:03.000000000 -0500 +++ ld64-ld64-62.1-ppc64/src/MachOWriterExecutable.hpp 2025-03-11 22:28:15.000000000 -0500 @@ -50,6 +50,72 @@ #include "MachOFileAbstraction.hpp" +#ifndef CPU_SUBTYPE_X86_64_ALL +#define CPU_SUBTYPE_X86_64_ALL CPU_SUBTYPE_I386_ALL +#endif + +#ifndef x86_THREAD_STATE64 +#define x86_THREAD_STATE64 4 +#endif + +#ifndef x86_THREAD_STATE64_COUNT +#if __DARWIN_UNIX03 +#define _STRUCT_X86_THREAD_STATE64 struct __darwin_x86_thread_state64 +_STRUCT_X86_THREAD_STATE64 +{ + __uint64_t __rax; + __uint64_t __rbx; + __uint64_t __rcx; + __uint64_t __rdx; + __uint64_t __rdi; + __uint64_t __rsi; + __uint64_t __rbp; + __uint64_t __rsp; + __uint64_t __r8; + __uint64_t __r9; + __uint64_t __r10; + __uint64_t __r11; + __uint64_t __r12; + __uint64_t __r13; + __uint64_t __r14; + __uint64_t __r15; + __uint64_t __rip; + __uint64_t __rflags; + __uint64_t __cs; + __uint64_t __fs; + __uint64_t __gs; +}; +#else /* !__DARWIN_UNIX03 */ +#define _STRUCT_X86_THREAD_STATE64 struct x86_thread_state64 +_STRUCT_X86_THREAD_STATE64 +{ + __uint64_t rax; + __uint64_t rbx; + __uint64_t rcx; + __uint64_t rdx; + __uint64_t rdi; + __uint64_t rsi; + __uint64_t rbp; + __uint64_t rsp; + __uint64_t r8; + __uint64_t r9; + __uint64_t r10; + __uint64_t r11; + __uint64_t r12; + __uint64_t r13; + __uint64_t r14; + __uint64_t r15; + __uint64_t rip; + __uint64_t rflags; + __uint64_t cs; + __uint64_t fs; + __uint64_t gs; +}; +#endif /* !__DARWIN_UNIX03 */ +typedef _STRUCT_X86_THREAD_STATE64 x86_thread_state64_t; +#define x86_THREAD_STATE64_COUNT ((mach_msg_type_number_t) \ + ( sizeof (x86_thread_state64_t) / sizeof (int) )) +#endif // // @@ -450,7 +516,7 @@ { protected: LoadCommandAtom(Writer& writer, Segment& segment) : WriterAtom(writer, segment) {} - virtual ObjectFile::Alignment getAlignment() const { return ObjectFile::Alignment(log2(sizeof(typename A::P::uint_t))); } + virtual ObjectFile::Alignment getAlignment() const { return ObjectFile::Alignment((int) log2(sizeof(typename A::P::uint_t))); } virtual const char* getSectionName() const { return "._load_commands"; } static uint64_t alignedSize(uint64_t size); }; diff -r --unified ld64-ld64-62.1-unpatched/src/Options.cpp ld64-ld64-62.1-ppc64/src/Options.cpp --- ld64-ld64-62.1-unpatched/src/Options.cpp 2021-10-06 00:21:03.000000000 -0500 +++ ld64-ld64-62.1-ppc64/src/Options.cpp 2025-03-11 21:58:00.000000000 -0500 @@ -31,6 +31,10 @@ #include "Options.h" +#ifndef CPU_TYPE_X86_64 +#define CPU_TYPE_X86_64 ((cpu_type_t) (CPU_TYPE_I386 | CPU_ARCH_ABI64)) +#endif + void throwf(const char* format, ...) { va_list list; diff -r --unified ld64-ld64-62.1-unpatched/src/machochecker.cpp ld64-ld64-62.1-ppc64/src/machochecker.cpp --- ld64-ld64-62.1-unpatched/src/machochecker.cpp 2021-10-06 00:21:03.000000000 -0500 +++ ld64-ld64-62.1-ppc64/src/machochecker.cpp 2025-03-11 22:12:04.000000000 -0500 @@ -34,7 +34,24 @@ #include #include #include -#include +//#include +enum reloc_type_x86_64 +{ + X86_64_RELOC_UNSIGNED, // for absolute addresses + X86_64_RELOC_SIGNED, // for signed 32-bit displacement + X86_64_RELOC_BRANCH, // a CALL/JMP instruction with 32-bit displacement + X86_64_RELOC_GOT_LOAD, // a MOVQ load of a GOT entry + X86_64_RELOC_GOT, // other GOT references + X86_64_RELOC_SUBTRACTOR, // must be followed by a X86_64_RELOC_UNSIGNED + X86_64_RELOC_SIGNED_1, // for signed 32-bit displacement with a -1 addend + X86_64_RELOC_SIGNED_2, // for signed 32-bit displacement with a -2 addend + X86_64_RELOC_SIGNED_4, // for signed 32-bit displacement with a -4 addend + X86_64_RELOC_TLV, // for thread local variables +}; + +#ifndef CPU_TYPE_X86_64 +#define CPU_TYPE_X86_64 ((cpu_type_t) (CPU_TYPE_I386 | CPU_ARCH_ABI64)) +#endif #include diff -r --unified ld64-ld64-62.1-unpatched/src/rebase.cpp ld64-ld64-62.1-ppc64/src/rebase.cpp --- ld64-ld64-62.1-unpatched/src/rebase.cpp 2021-10-06 00:21:03.000000000 -0500 +++ ld64-ld64-62.1-ppc64/src/rebase.cpp 2025-03-11 22:11:09.000000000 -0500 @@ -36,13 +36,30 @@ #include #include #include -#include +// #include #include #include #include "MachOFileAbstraction.hpp" #include "Architectures.hpp" +enum reloc_type_x86_64 +{ + X86_64_RELOC_UNSIGNED, // for absolute addresses + X86_64_RELOC_SIGNED, // for signed 32-bit displacement + X86_64_RELOC_BRANCH, // a CALL/JMP instruction with 32-bit displacement + X86_64_RELOC_GOT_LOAD, // a MOVQ load of a GOT entry + X86_64_RELOC_GOT, // other GOT references + X86_64_RELOC_SUBTRACTOR, // must be followed by a X86_64_RELOC_UNSIGNED + X86_64_RELOC_SIGNED_1, // for signed 32-bit displacement with a -1 addend + X86_64_RELOC_SIGNED_2, // for signed 32-bit displacement with a -2 addend + X86_64_RELOC_SIGNED_4, // for signed 32-bit displacement with a -4 addend + X86_64_RELOC_TLV, // for thread local variables +}; + +#ifndef CPU_TYPE_X86_64 +#define CPU_TYPE_X86_64 ((cpu_type_t) (CPU_TYPE_I386 | CPU_ARCH_ABI64)) +#endif static bool verbose = false; diff -r --unified ld64-ld64-62.1-unpatched/unit-tests/test-cases/align-modulus/align.s ld64-ld64-62.1-ppc64/unit-tests/test-cases/align-modulus/align.s --- ld64-ld64-62.1-unpatched/unit-tests/test-cases/align-modulus/align.s 2021-10-06 00:21:03.000000000 -0500 +++ ld64-ld64-62.1-ppc64/unit-tests/test-cases/align-modulus/align.s 2025-03-11 22:33:14.000000000 -0500 @@ -29,7 +29,8 @@ .globl _b _b: .byte 4 ;# address is 3 .align 4 -L1: .quad 0 +L1: /* .quad 0 */ + .byte 0,0,0,0,0,0,0,0 _c: .long 8 .subsections_via_symbols