ld64: switch to patch set from reckenrode/ld64

This patch set is functionally similar to the in-tree patches but
contains the following improvements:

- Directly use OpenSSL instead of compatibility stubs;
- Builds the `dyldinfo` tool;
- Replaces (some) Darwin and private headers with LLVM-based headers;
- Uses LLVM instead of libtapi for reading text-based stubs; and
- Builds ld64 as a cross-linker by default (with no prefix).

+2684 -770
+30 -27
pkgs/by-name/ld/ld64/0004-Use-std-atomics-and-std-mutex.patch pkgs/by-name/ld/ld64/patches/0005-Use-std-atomics-and-std-mutex-for-portability.patch
··· 1 - From 5e92d65ef2b5cc07dc25b5b1bf645b314599f5d1 Mon Sep 17 00:00:00 2001 2 From: Randy Eckenrode <randy@largeandhighquality.com> 3 - Date: Sat, 6 Apr 2024 20:29:25 -0400 4 - Subject: [PATCH 4/8] Use std::atomics and std::mutex 5 6 --- 7 - src/ld/InputFiles.cpp | 13 ++++++------- 8 src/ld/InputFiles.h | 9 +++++---- 9 - src/ld/OutputFile.cpp | 13 ++++++------- 10 src/ld/ld.cpp | 11 +++++------ 11 - 4 files changed, 22 insertions(+), 24 deletions(-) 12 13 diff --git a/src/ld/InputFiles.cpp b/src/ld/InputFiles.cpp 14 - index ec53a60..427ab09 100644 15 --- a/src/ld/InputFiles.cpp 16 +++ b/src/ld/InputFiles.cpp 17 - @@ -42,7 +42,6 @@ 18 #include <mach-o/dyld.h> 19 #include <mach-o/fat.h> 20 #include <sys/sysctl.h> ··· 22 #if HAVE_LIBDISPATCH 23 #include <dispatch/dispatch.h> 24 #endif 25 @@ -387,16 +386,16 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib 26 27 ld::relocatable::File* objResult = mach_o::relocatable::parse(p, len, info.path, info.modTime, info.ordinal, objOpts); ··· 55 } 56 57 diff --git a/src/ld/InputFiles.h b/src/ld/InputFiles.h 58 - index c18ccf8..ffff26b 100644 59 --- a/src/ld/InputFiles.h 60 +++ b/src/ld/InputFiles.h 61 @@ -46,6 +46,7 @@ ··· 74 - volatile int64_t _totalArchiveSize; 75 - volatile int32_t _totalObjectLoaded; 76 - volatile int32_t _totalArchivesLoaded; 77 - + std::atomic<int64_t> _totalObjectSize; 78 - + std::atomic<int64_t> _totalArchiveSize; 79 - + std::atomic<int32_t> _totalObjectLoaded; 80 - + std::atomic<int32_t> _totalArchivesLoaded; 81 int32_t _totalDylibsLoaded; 82 83 84 diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp 85 - index e2c0397..15912a2 100644 86 --- a/src/ld/OutputFile.cpp 87 +++ b/src/ld/OutputFile.cpp 88 - @@ -43,11 +43,10 @@ 89 - #include <mach-o/dyld.h> 90 - #include <mach-o/fat.h> 91 - #include <dispatch/dispatch.h> 92 - -#include <os/lock_private.h> 93 extern "C" { 94 #include <corecrypto/ccsha2.h> 95 } 96 -#include <string> 97 +#include <mutex> 98 #include <string> 99 #include <list> 100 #include <algorithm> 101 - @@ -1362,7 +1361,7 @@ void OutputFile::rangeCheckRISCVBranch20(int64_t displacement, ld::Internal& sta 102 103 104 #if SUPPORT_ARCH_arm64e ··· 107 #endif 108 109 void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld::Atom* atom, uint8_t* buffer) 110 - @@ -1737,11 +1736,11 @@ void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld:: 111 } 112 else { 113 auto fixupOffset = (uintptr_t)(fixUpLocation - mhAddress); ··· 121 // Zero out this entry which we will expect later. 122 set64LE(fixUpLocation, 0); 123 } 124 - @@ -1768,11 +1767,11 @@ void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld:: 125 } 126 else { 127 auto fixupOffset = (uintptr_t)(fixUpLocation - mhAddress); ··· 136 set64LE(fixUpLocation, 0); 137 } 138 diff --git a/src/ld/ld.cpp b/src/ld/ld.cpp 139 - index b7590a3..f1bf9df 100644 140 --- a/src/ld/ld.cpp 141 +++ b/src/ld/ld.cpp 142 @@ -47,9 +47,8 @@ extern "C" double log2 ( double ); ··· 150 #include <map> 151 #include <set> 152 #include <string> 153 - @@ -1603,8 +1602,8 @@ int main(int argc, const char* argv[]) 154 statistics.vmEnd.faults-statistics.vmStart.faults); 155 fprintf(stderr, "memory active: %lu, wired: %lu\n", statistics.vmEnd.active_count * vm_page_size, statistics.vmEnd.wire_count * vm_page_size); 156 char temp[40]; ··· 161 fprintf(stderr, "processed %3u dylib files\n", inputFiles._totalDylibsLoaded); 162 fprintf(stderr, "wrote output file totaling %15s bytes\n", commatize(out.fileSize(), temp)); 163 } 164 - @@ -1634,12 +1633,12 @@ int main(int argc, const char* argv[]) 165 #ifndef NDEBUG 166 167 // now that the linker is multi-threaded, only allow one assert() to be processed ··· 172 void __assert_rtn(const char* func, const char* file, int line, const char* failedexpr) 173 { 174 - os_lock_lock(&sAssertLock); 175 - + sAssertLock.lock(); 176 177 Snapshot *snapshot = Snapshot::globalSnapshot; 178 179 -- 180 - 2.45.1 181
··· 1 + From effdf4d0f3a3d2332ec2a61eefe076ff37964594 Mon Sep 17 00:00:00 2001 2 From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 05/18] Use std::atomics and std::mutex for portability 5 6 --- 7 + src/ld/InputFiles.cpp | 15 +++++++-------- 8 src/ld/InputFiles.h | 9 +++++---- 9 + src/ld/OutputFile.cpp | 13 +++++++------ 10 src/ld/ld.cpp | 11 +++++------ 11 + 4 files changed, 24 insertions(+), 24 deletions(-) 12 13 diff --git a/src/ld/InputFiles.cpp b/src/ld/InputFiles.cpp 14 + index 4d49ba3..e045e90 100644 15 --- a/src/ld/InputFiles.cpp 16 +++ b/src/ld/InputFiles.cpp 17 + @@ -42,12 +42,11 @@ 18 #include <mach-o/dyld.h> 19 #include <mach-o/fat.h> 20 #include <sys/sysctl.h> ··· 22 #if HAVE_LIBDISPATCH 23 #include <dispatch/dispatch.h> 24 #endif 25 + 26 + -#include <string> 27 + +#include <atomic> 28 + #include <map> 29 + #include <set> 30 + #include <string> 31 @@ -387,16 +386,16 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib 32 33 ld::relocatable::File* objResult = mach_o::relocatable::parse(p, len, info.path, info.modTime, info.ordinal, objOpts); ··· 61 } 62 63 diff --git a/src/ld/InputFiles.h b/src/ld/InputFiles.h 64 + index c18ccf8..40353fa 100644 65 --- a/src/ld/InputFiles.h 66 +++ b/src/ld/InputFiles.h 67 @@ -46,6 +46,7 @@ ··· 80 - volatile int64_t _totalArchiveSize; 81 - volatile int32_t _totalObjectLoaded; 82 - volatile int32_t _totalArchivesLoaded; 83 + + std::atomic<int64_t> _totalObjectSize; 84 + + std::atomic<int64_t> _totalArchiveSize; 85 + + std::atomic<int32_t> _totalObjectLoaded; 86 + + std::atomic<int32_t> _totalArchivesLoaded; 87 int32_t _totalDylibsLoaded; 88 89 90 diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp 91 + index 487b338..2a175a7 100644 92 --- a/src/ld/OutputFile.cpp 93 +++ b/src/ld/OutputFile.cpp 94 + @@ -47,7 +47,8 @@ 95 extern "C" { 96 #include <corecrypto/ccsha2.h> 97 } 98 -#include <string> 99 + + 100 +#include <mutex> 101 #include <string> 102 #include <list> 103 #include <algorithm> 104 + @@ -1315,7 +1316,7 @@ void OutputFile::rangeCheckRISCVBranch20(int64_t displacement, ld::Internal& sta 105 106 107 #if SUPPORT_ARCH_arm64e ··· 110 #endif 111 112 void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld::Atom* atom, uint8_t* buffer) 113 + @@ -1690,11 +1691,11 @@ void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld:: 114 } 115 else { 116 auto fixupOffset = (uintptr_t)(fixUpLocation - mhAddress); ··· 124 // Zero out this entry which we will expect later. 125 set64LE(fixUpLocation, 0); 126 } 127 + @@ -1721,11 +1722,11 @@ void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld:: 128 } 129 else { 130 auto fixupOffset = (uintptr_t)(fixUpLocation - mhAddress); ··· 139 set64LE(fixUpLocation, 0); 140 } 141 diff --git a/src/ld/ld.cpp b/src/ld/ld.cpp 142 + index b532c9a..8608ea5 100644 143 --- a/src/ld/ld.cpp 144 +++ b/src/ld/ld.cpp 145 @@ -47,9 +47,8 @@ extern "C" double log2 ( double ); ··· 153 #include <map> 154 #include <set> 155 #include <string> 156 + @@ -1539,8 +1538,8 @@ int main(int argc, const char* argv[]) 157 statistics.vmEnd.faults-statistics.vmStart.faults); 158 fprintf(stderr, "memory active: %lu, wired: %lu\n", statistics.vmEnd.active_count * vm_page_size, statistics.vmEnd.wire_count * vm_page_size); 159 char temp[40]; ··· 164 fprintf(stderr, "processed %3u dylib files\n", inputFiles._totalDylibsLoaded); 165 fprintf(stderr, "wrote output file totaling %15s bytes\n", commatize(out.fileSize(), temp)); 166 } 167 + @@ -1570,12 +1569,12 @@ int main(int argc, const char* argv[]) 168 #ifndef NDEBUG 169 170 // now that the linker is multi-threaded, only allow one assert() to be processed ··· 175 void __assert_rtn(const char* func, const char* file, int line, const char* failedexpr) 176 { 177 - os_lock_lock(&sAssertLock); 178 + + sAssertLock.lock(); 179 180 Snapshot *snapshot = Snapshot::globalSnapshot; 181 182 -- 183 + 2.47.2 184
-48
pkgs/by-name/ld/ld64/0005-Support-LTO-in-nixpkgs.patch
··· 1 - From faa5ab7c6e8d9a6c6157a2b681edad592ce78555 Mon Sep 17 00:00:00 2001 2 - From: Randy Eckenrode <randy@largeandhighquality.com> 3 - Date: Sun, 7 Apr 2024 15:33:36 -0400 4 - Subject: [PATCH 5/8] Support LTO in nixpkgs 5 - 6 - --- 7 - src/ld/InputFiles.cpp | 11 ++--------- 8 - src/ld/parsers/lto_file.cpp | 2 +- 9 - 2 files changed, 3 insertions(+), 10 deletions(-) 10 - 11 - diff --git a/src/ld/InputFiles.cpp b/src/ld/InputFiles.cpp 12 - index 427ab09..b8a9870 100644 13 - --- a/src/ld/InputFiles.cpp 14 - +++ b/src/ld/InputFiles.cpp 15 - @@ -464,15 +464,8 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib 16 - if ( _options.overridePathlibLTO() != NULL ) { 17 - libLTO = _options.overridePathlibLTO(); 18 - } 19 - - else if ( _NSGetExecutablePath(ldPath, &bufSize) != -1 ) { 20 - - if ( realpath(ldPath, tmpPath) != NULL ) { 21 - - char* lastSlash = strrchr(tmpPath, '/'); 22 - - if ( lastSlash != NULL ) 23 - - strcpy(lastSlash, "/../lib/libLTO.dylib"); 24 - - libLTO = tmpPath; 25 - - if ( realpath(tmpPath, libLTOPath) != NULL ) 26 - - libLTO = libLTOPath; 27 - - } 28 - + else { 29 - + libLTO = "@libllvm@/lib/libLTO.dylib"; 30 - } 31 - throwf("could not process llvm bitcode object file, because %s could not be loaded", libLTO); 32 - } 33 - diff --git a/src/ld/parsers/lto_file.cpp b/src/ld/parsers/lto_file.cpp 34 - index 5318212..e18e974 100644 35 - --- a/src/ld/parsers/lto_file.cpp 36 - +++ b/src/ld/parsers/lto_file.cpp 37 - @@ -1807,7 +1807,7 @@ bool optimize( const std::vector<const ld::Atom*>& allAtoms, 38 - 39 - }; // namespace lto 40 - 41 - -static const char *sLTODylib = "@rpath/libLTO.dylib"; 42 - +static const char *sLTODylib = "@libllvm@/lib/libLTO.dylib"; 43 - static std::atomic<bool> sLTOIsLoaded(false); 44 - 45 - static void *getHandle() { 46 - -- 47 - 2.45.1 48 -
···
+22 -26
pkgs/by-name/ld/ld64/0006-Add-libcd_is_blob_a_linker_signature-implementation.patch pkgs/by-name/ld/ld64/patches/0015-Add-libcd_is_blob_a_linker_signature-implementation.patch
··· 1 - From add8bae5577ebe1c98cf7a711f87a3578a51d313 Mon Sep 17 00:00:00 2001 2 From: Randy Eckenrode <randy@largeandhighquality.com> 3 - Date: Mon, 8 Apr 2024 22:42:40 -0400 4 - Subject: [PATCH 6/8] Add libcd_is_blob_a_linker_signature implementation 5 6 --- 7 - compat/libcodedirectory.c | 74 +++++++++++++++++++++++++++++++++++++++ 8 - src/ld/libcodedirectory.h | 8 +++++ 9 - 2 files changed, 82 insertions(+) 10 - create mode 100644 compat/libcodedirectory.c 11 12 - diff --git a/compat/libcodedirectory.c b/compat/libcodedirectory.c 13 - new file mode 100644 14 - index 0000000..e584dfc 15 - --- /dev/null 16 - +++ b/compat/libcodedirectory.c 17 - @@ -0,0 +1,74 @@ 18 - +// SPDX-License-Identifier: APSL-2.0 19 - +// libcd_is_blob_a_linker_signature implementation written by Randy Eckenrode © 2024 20 - + 21 - +#include <libcodedirectory.h> 22 - + 23 - +#include <stdbool.h> 24 + 25 +// References: 26 +// - https://forums.developer.apple.com/forums/thread/702351 ··· 43 + 44 +static inline const uint8_t* find_code_directory(const uint8_t* data, size_t size) { 45 + const uint8_t* index_ptr = data + offsetof(CS_SuperBlob, index); 46 - + 47 + // There also needs to be space for the actual blobs, but there must be at least enough space 48 + // for the blob indexes. If there’s not, then something’s wrong, and the blob is invalid. 49 + uint32_t count = read32be(data + offsetof(CS_SuperBlob, count)); ··· 89 + 90 + return LIBCD_SIGNATURE_QUERY_SUCCESS; 91 +} 92 - diff --git a/src/ld/libcodedirectory.h b/src/ld/libcodedirectory.h 93 - index 0e989a9..7532648 100644 94 - --- a/src/ld/libcodedirectory.h 95 - +++ b/src/ld/libcodedirectory.h 96 - @@ -116,6 +116,14 @@ enum libcd_set_linkage_ret { 97 98 enum libcd_set_linkage_ret libcd_set_linkage(libcd *s, int linkage_hash_type, uint8_t *linkage_hash); 99 ··· 105 + 106 +enum libcd_signature_query_ret libcd_is_blob_a_linker_signature(const uint8_t* data, size_t size, int* linker_signed); 107 + 108 __END_DECLS 109 110 #endif // H_LIBCODEDIRECTORY 111 -- 112 - 2.45.1 113
··· 1 + From 1894e5752ebfe0572684c235da3cdcdfd10f29a1 Mon Sep 17 00:00:00 2001 2 From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Sat, 16 Nov 2024 16:21:17 -0500 4 + Subject: [PATCH 15/18] Add libcd_is_blob_a_linker_signature implementation 5 6 --- 7 + .../libcodedirectory/libcodedirectory.c | 68 +++++++++++++++++++ 8 + .../libcodedirectory/libcodedirectory.h | 9 +++ 9 + 2 files changed, 77 insertions(+) 10 11 + diff --git a/subprojects/libcodedirectory/libcodedirectory.c b/subprojects/libcodedirectory/libcodedirectory.c 12 + index 02e31b1..89908b9 100644 13 + --- a/subprojects/libcodedirectory/libcodedirectory.c 14 + +++ b/subprojects/libcodedirectory/libcodedirectory.c 15 + @@ -1221,3 +1221,71 @@ libcd_get_cdhash_for_type(libcd *s, int hash_type, uint8_t* cdhash_buf, size_t c 16 + } 17 + return LIBCD_CDHASH_TYPE_NOT_FOUND; 18 + } 19 + 20 +// References: 21 +// - https://forums.developer.apple.com/forums/thread/702351 ··· 38 + 39 +static inline const uint8_t* find_code_directory(const uint8_t* data, size_t size) { 40 + const uint8_t* index_ptr = data + offsetof(CS_SuperBlob, index); 41 + + 42 + // There also needs to be space for the actual blobs, but there must be at least enough space 43 + // for the blob indexes. If there’s not, then something’s wrong, and the blob is invalid. 44 + uint32_t count = read32be(data + offsetof(CS_SuperBlob, count)); ··· 84 + 85 + return LIBCD_SIGNATURE_QUERY_SUCCESS; 86 +} 87 + diff --git a/subprojects/libcodedirectory/libcodedirectory.h b/subprojects/libcodedirectory/libcodedirectory.h 88 + index 0e989a9..67a5a22 100644 89 + --- a/subprojects/libcodedirectory/libcodedirectory.h 90 + +++ b/subprojects/libcodedirectory/libcodedirectory.h 91 + @@ -116,6 +116,15 @@ enum libcd_set_linkage_ret { 92 93 enum libcd_set_linkage_ret libcd_set_linkage(libcd *s, int linkage_hash_type, uint8_t *linkage_hash); 94 ··· 100 + 101 +enum libcd_signature_query_ret libcd_is_blob_a_linker_signature(const uint8_t* data, size_t size, int* linker_signed); 102 + 103 + + 104 __END_DECLS 105 106 #endif // H_LIBCODEDIRECTORY 107 -- 108 + 2.47.2 109
-311
pkgs/by-name/ld/ld64/0007-Add-OpenSSL-based-CoreCrypto-digest-functions.patch
··· 1 - From 36767c7345161baf0ab125f95c8557f8e24f25db Mon Sep 17 00:00:00 2001 2 - From: Randy Eckenrode <randy@largeandhighquality.com> 3 - Date: Tue, 9 Apr 2024 19:28:17 -0400 4 - Subject: [PATCH 7/8] Add OpenSSL-based CoreCrypto digest functions 5 - 6 - --- 7 - compat/CommonCrypto/CommonDigest.h | 6 +++ 8 - compat/CommonCrypto/CommonDigestSPI.c | 21 +++++++++++ 9 - compat/CommonCrypto/CommonDigestSPI.h | 14 +++++++ 10 - compat/corecrypto/api_defines.h | 10 +++++ 11 - compat/corecrypto/ccdigest.c | 53 +++++++++++++++++++++++++++ 12 - compat/corecrypto/ccdigest.h | 27 ++++++++++++++ 13 - compat/corecrypto/ccdigest_private.h | 19 ++++++++++ 14 - compat/corecrypto/ccsha1.c | 22 +++++++++++ 15 - compat/corecrypto/ccsha1.h | 9 +++++ 16 - compat/corecrypto/ccsha2.c | 22 +++++++++++ 17 - compat/corecrypto/ccsha2.h | 9 +++++ 18 - 11 files changed, 212 insertions(+) 19 - create mode 100644 compat/CommonCrypto/CommonDigest.h 20 - create mode 100644 compat/CommonCrypto/CommonDigestSPI.c 21 - create mode 100644 compat/CommonCrypto/CommonDigestSPI.h 22 - create mode 100644 compat/corecrypto/api_defines.h 23 - create mode 100644 compat/corecrypto/ccdigest.c 24 - create mode 100644 compat/corecrypto/ccdigest.h 25 - create mode 100644 compat/corecrypto/ccdigest_private.h 26 - create mode 100644 compat/corecrypto/ccsha1.c 27 - create mode 100644 compat/corecrypto/ccsha1.h 28 - create mode 100644 compat/corecrypto/ccsha2.c 29 - create mode 100644 compat/corecrypto/ccsha2.h 30 - 31 - diff --git a/compat/CommonCrypto/CommonDigest.h b/compat/CommonCrypto/CommonDigest.h 32 - new file mode 100644 33 - index 0000000..a60eba7 34 - --- /dev/null 35 - +++ b/compat/CommonCrypto/CommonDigest.h 36 - @@ -0,0 +1,6 @@ 37 - +// SPDX-License-Identifier: APSL-2.0 38 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 39 - + 40 - +#pragma once 41 - + 42 - +#define CCSHA256_OUTPUT_SIZE 32 43 - diff --git a/compat/CommonCrypto/CommonDigestSPI.c b/compat/CommonCrypto/CommonDigestSPI.c 44 - new file mode 100644 45 - index 0000000..41269fc 46 - --- /dev/null 47 - +++ b/compat/CommonCrypto/CommonDigestSPI.c 48 - @@ -0,0 +1,21 @@ 49 - +// SPDX-License-Identifier: APSL-2.0 50 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 51 - + 52 - +#include "CommonDigestSPI.h" 53 - + 54 - +#include <stdlib.h> 55 - +#include <string.h> 56 - + 57 - +#include <corecrypto/ccsha2.h> 58 - + 59 - +void CCDigest(int type, const uint8_t* bytes, size_t count, uint8_t* digest) { 60 - + if (type != kCCDigestSHA256) { 61 - + abort(); 62 - + } 63 - + const struct ccdigest_info* di = ccsha256_di(); 64 - + 65 - + ccdigest_di_decl(_di, ctx); 66 - + ccdigest_init(di, ctx); 67 - + ccdigest_update(di, ctx, count, bytes); 68 - + ccdigest_final(di, ctx, digest); 69 - +} 70 - diff --git a/compat/CommonCrypto/CommonDigestSPI.h b/compat/CommonCrypto/CommonDigestSPI.h 71 - new file mode 100644 72 - index 0000000..172742a 73 - --- /dev/null 74 - +++ b/compat/CommonCrypto/CommonDigestSPI.h 75 - @@ -0,0 +1,14 @@ 76 - +// SPDX-License-Identifier: APSL-2.0 77 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 78 - + 79 - +#pragma once 80 - + 81 - +#include <stdint.h> 82 - + 83 - +#include <corecrypto/ccdigest.h> 84 - +#include <cs_blobs.h> 85 - + 86 - + 87 - +#define kCCDigestSHA256 10 88 - + 89 - +EXTERN_C void CCDigest(int type, const uint8_t* bytes, size_t count, uint8_t* digest); 90 - diff --git a/compat/corecrypto/api_defines.h b/compat/corecrypto/api_defines.h 91 - new file mode 100644 92 - index 0000000..13d1e7a 93 - --- /dev/null 94 - +++ b/compat/corecrypto/api_defines.h 95 - @@ -0,0 +1,10 @@ 96 - +// SPDX-License-Identifier: APSL-2.0 97 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 98 - + 99 - +#pragma once 100 - + 101 - +#ifdef __cplusplus 102 - +#define EXTERN_C extern "C" 103 - +#else 104 - +#define EXTERN_C 105 - +#endif 106 - diff --git a/compat/corecrypto/ccdigest.c b/compat/corecrypto/ccdigest.c 107 - new file mode 100644 108 - index 0000000..e29dcb8 109 - --- /dev/null 110 - +++ b/compat/corecrypto/ccdigest.c 111 - @@ -0,0 +1,53 @@ 112 - +// SPDX-License-Identifier: APSL-2.0 113 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 114 - + 115 - +#include "ccdigest.h" 116 - +#include "ccdigest_private.h" 117 - + 118 - +#include <stdlib.h> 119 - + 120 - +#include <openssl/err.h> 121 - + 122 - + 123 - +struct ccdigest_context* _ccdigest_context_new(void) 124 - +{ 125 - + struct ccdigest_context* ctx = malloc(sizeof(struct ccdigest_context)); 126 - + ctx->context = EVP_MD_CTX_new(); 127 - + return ctx; 128 - +} 129 - + 130 - +struct ccdigest_info* _ccdigest_newprovider(const char* name) 131 - +{ 132 - + struct ccdigest_info* di = malloc(sizeof(struct ccdigest_info)); 133 - + di->provider = EVP_MD_fetch(NULL, name, NULL); 134 - + return di; 135 - +} 136 - + 137 - +void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx) 138 - +{ 139 - + if (!EVP_DigestInit_ex2(ctx->context, di->provider, NULL)) { 140 - + ERR_print_errors_fp(stderr); 141 - + abort(); 142 - + } 143 - +} 144 - + 145 - +void ccdigest_update( 146 - + const struct ccdigest_info* _di, 147 - + struct ccdigest_context* ctx, 148 - + size_t count, 149 - + const void* bytes 150 - +) 151 - +{ 152 - + if (!EVP_DigestUpdate(ctx->context, bytes, count)) { 153 - + ERR_print_errors_fp(stderr); 154 - + abort(); 155 - + } 156 - +} 157 - + 158 - +void ccdigest_final(const struct ccdigest_info* _di, struct ccdigest_context* ctx, uint8_t* digest) 159 - +{ 160 - + if (!EVP_DigestFinal_ex(ctx->context, digest, NULL)) { 161 - + ERR_print_errors_fp(stderr); 162 - + abort(); 163 - + } 164 - +} 165 - diff --git a/compat/corecrypto/ccdigest.h b/compat/corecrypto/ccdigest.h 166 - new file mode 100644 167 - index 0000000..9af2394 168 - --- /dev/null 169 - +++ b/compat/corecrypto/ccdigest.h 170 - @@ -0,0 +1,27 @@ 171 - +// SPDX-License-Identifier: APSL-2.0 172 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 173 - + 174 - +#pragma once 175 - + 176 - +#include <stddef.h> 177 - +#include <stdint.h> 178 - + 179 - +#include "api_defines.h" 180 - + 181 - + 182 - +struct ccdigest_info; 183 - +struct ccdigest_context; 184 - + 185 - +EXTERN_C struct ccdigest_context* _ccdigest_context_new(void); 186 - + 187 - +#define ccdigest_di_decl(_di, ctxvar) \ 188 - + struct ccdigest_context* (ctxvar) = _ccdigest_context_new() 189 - + 190 - +EXTERN_C void ccdigest_init(const struct ccdigest_info* di, struct ccdigest_context* ctx); 191 - +EXTERN_C void ccdigest_update( 192 - + const struct ccdigest_info* _di, 193 - + struct ccdigest_context* ctx, 194 - + size_t count, 195 - + const void* bytes 196 - +); 197 - +EXTERN_C void ccdigest_final(const struct ccdigest_info* _di, struct ccdigest_context* ctx, uint8_t* digest); 198 - diff --git a/compat/corecrypto/ccdigest_private.h b/compat/corecrypto/ccdigest_private.h 199 - new file mode 100644 200 - index 0000000..0ea9759 201 - --- /dev/null 202 - +++ b/compat/corecrypto/ccdigest_private.h 203 - @@ -0,0 +1,19 @@ 204 - +// SPDX-License-Identifier: APSL-2.0 205 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 206 - + 207 - +#pragma once 208 - + 209 - +#include "api_defines.h" 210 - + 211 - +#include <openssl/evp.h> 212 - + 213 - + 214 - +struct ccdigest_info { 215 - + EVP_MD* provider; 216 - +}; 217 - + 218 - +struct ccdigest_context { 219 - + EVP_MD_CTX* context; 220 - +}; 221 - + 222 - +EXTERN_C struct ccdigest_info* _ccdigest_newprovider(const char* name); 223 - diff --git a/compat/corecrypto/ccsha1.c b/compat/corecrypto/ccsha1.c 224 - new file mode 100644 225 - index 0000000..e02b2b6 226 - --- /dev/null 227 - +++ b/compat/corecrypto/ccsha1.c 228 - @@ -0,0 +1,22 @@ 229 - +// SPDX-License-Identifier: APSL-2.0 230 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 231 - + 232 - +#include "ccsha1.h" 233 - + 234 - +#include <assert.h> 235 - + 236 - +#include <cs_blobs.h> 237 - + 238 - +#include "ccdigest_private.h" 239 - + 240 - + 241 - +static struct ccdigest_info* di = NULL; 242 - + 243 - +const struct ccdigest_info* ccsha1_di(void) 244 - +{ 245 - + if (!di) { 246 - + di = _ccdigest_newprovider("SHA-1"); 247 - + assert(EVP_MD_get_size(di->provider) == CS_SHA1_LEN); 248 - + } 249 - + return di; 250 - +} 251 - diff --git a/compat/corecrypto/ccsha1.h b/compat/corecrypto/ccsha1.h 252 - new file mode 100644 253 - index 0000000..8e3f85f 254 - --- /dev/null 255 - +++ b/compat/corecrypto/ccsha1.h 256 - @@ -0,0 +1,9 @@ 257 - +// SPDX-License-Identifier: APSL-2.0 258 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 259 - + 260 - +#pragma once 261 - + 262 - +#include <corecrypto/ccdigest.h> 263 - + 264 - + 265 - +EXTERN_C const struct ccdigest_info* ccsha1_di(void); 266 - diff --git a/compat/corecrypto/ccsha2.c b/compat/corecrypto/ccsha2.c 267 - new file mode 100644 268 - index 0000000..6504503 269 - --- /dev/null 270 - +++ b/compat/corecrypto/ccsha2.c 271 - @@ -0,0 +1,22 @@ 272 - +// SPDX-License-Identifier: APSL-2.0 273 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 274 - + 275 - +#include "ccsha2.h" 276 - + 277 - +#include <assert.h> 278 - + 279 - +#include <cs_blobs.h> 280 - + 281 - +#include "ccdigest_private.h" 282 - + 283 - + 284 - +static struct ccdigest_info* di = NULL; 285 - + 286 - +const struct ccdigest_info* ccsha256_di(void) 287 - +{ 288 - + if (!di) { 289 - + di = _ccdigest_newprovider("SHA-256"); 290 - + assert(EVP_MD_get_size(di->provider) == CS_SHA256_LEN); 291 - + } 292 - + return di; 293 - +} 294 - diff --git a/compat/corecrypto/ccsha2.h b/compat/corecrypto/ccsha2.h 295 - new file mode 100644 296 - index 0000000..9f30e03 297 - --- /dev/null 298 - +++ b/compat/corecrypto/ccsha2.h 299 - @@ -0,0 +1,9 @@ 300 - +// SPDX-License-Identifier: APSL-2.0 301 - +// CoreCrypto compatibility shims written by Randy Eckenrode © 2024 302 - + 303 - +#pragma once 304 - + 305 - +#include <corecrypto/ccdigest.h> 306 - + 307 - + 308 - +EXTERN_C const struct ccdigest_info* ccsha256_di(void); 309 - -- 310 - 2.45.1 311 -
···
-8
pkgs/by-name/ld/ld64/gen_compile_stubs.py
··· 1 - #!/usr/bin/env python 2 - import sys 3 - from pathlib import Path 4 - 5 - byteseq = (str(int(x)) for x in Path(sys.argv[1]).read_bytes()) 6 - 7 - print("#pragma once") 8 - print(f"static const char compile_stubs[] = {{ {', '.join(byteseq)} }};")
···
-211
pkgs/by-name/ld/ld64/meson.build
··· 1 - # Build settings based on the upstream Xcode project. 2 - # See: https://github.com/apple-oss-distributions/ld64/blob/main/ld64.xcodeproj/project.pbxproj 3 - 4 - # Project settings 5 - project( 6 - 'ld64', 7 - 'c', 'cpp', 8 - version : '@version@', 9 - default_options : {'cpp_std': 'c++20'}, 10 - ) 11 - 12 - fs = import('fs') 13 - 14 - # Options 15 - target_prefix = get_option('target_prefix') 16 - 17 - 18 - # Dependencies 19 - cc = meson.get_compiler('c') 20 - cxx = meson.get_compiler('cpp') 21 - python = find_program('python3') 22 - 23 - libtapi = cxx.find_library('tapi') 24 - openssl = dependency('openssl', version : '>=3.0') 25 - xar = cc.find_library('xar') 26 - 27 - 28 - # Generated files 29 - 30 - compile_stubs_h = custom_target( 31 - 'compile_stubs.h', 32 - capture : true, 33 - command : [python, '@INPUT0@', '@INPUT1@'], 34 - input : ['gen_compile_stubs.py', 'compile_stubs'], 35 - output : ['compile_stubs.h'], 36 - ) 37 - 38 - configure_h = custom_target( 39 - 'configure_h', 40 - command : ['bash', '@INPUT@'], 41 - env : { 42 - 'DERIVED_FILE_DIR' : meson.current_build_dir(), 43 - 'RC_ProjectSourceVersion': '@version@' 44 - }, 45 - input : ['src/create_configure'], 46 - output : ['configure.h'], 47 - ) 48 - 49 - incdirs = include_directories( 50 - 'compat', 51 - 'src/abstraction', 52 - 'src/ld', 53 - 'src/ld/code-sign-blobs', 54 - 'src/ld/parsers', 55 - 'src/ld/passes', 56 - 'src/mach_o', 57 - ) 58 - 59 - # Dynamic libraries 60 - libcodedirectory = library( 61 - 'codedirectory', 62 - dependencies : [openssl], 63 - include_directories : incdirs, 64 - install : true, 65 - sources : [ 66 - 'compat/corecrypto/ccdigest.c', 67 - 'compat/corecrypto/ccsha1.c', 68 - 'compat/corecrypto/ccsha2.c', 69 - 'compat/libcodedirectory.c', 70 - 'src/ld/libcodedirectory.c' 71 - ], 72 - soversion : 1, 73 - ) 74 - install_headers( 75 - 'src/ld/cs_blobs.h', 76 - 'src/ld/libcodedirectory.h', 77 - ) 78 - 79 - 80 - # Static libraries 81 - libprunetrie = static_library( 82 - 'prunetrie', 83 - include_directories : incdirs, 84 - install : true, 85 - override_options : {'b_lto': false}, 86 - sources : [ 87 - 'src/mach_o/Error.cpp', 88 - 'src/mach_o/ExportsTrie.cpp', 89 - 'src/other/PruneTrie.cpp', 90 - ], 91 - ) 92 - install_headers( 93 - 'src/other/prune_trie.h', 94 - subdir : 'mach-o', 95 - ) 96 - 97 - 98 - # Binaries 99 - ld64 = executable( 100 - f'@target_prefix@ld', 101 - dependencies : [libtapi, openssl, xar], 102 - include_directories : incdirs, 103 - install : true, 104 - cpp_args : [ 105 - # Required for `_COMM_PAGE_CPU_CAPABILITIES64` in 106 - # <System/machine/cpu_capabilities.h> on `x86_64-darwin` 107 - '-DPRIVATE', 108 - ], 109 - # These linker flags mirror those used in a release build of the Xcode project. 110 - # See: https://github.com/apple-oss-distributions/ld64/blob/47f477cb721755419018f7530038b272e9d0cdea/ld64.xcodeproj/project.pbxproj#L1292-L1299. 111 - link_args : [ 112 - '-Wl,-exported_symbol,__mh_execute_header', 113 - '-Wl,-stack_size,0x02000000', 114 - '-Wl,-client_name,ld', 115 - ], 116 - link_with : [libcodedirectory], 117 - sources : [ 118 - compile_stubs_h, 119 - configure_h, 120 - 'compat/CommonCrypto/CommonDigestSPI.c', 121 - 'compat/corecrypto/ccdigest.c', 122 - 'compat/corecrypto/ccsha1.c', 123 - 'compat/corecrypto/ccsha2.c', 124 - 'src/ld/FatFile.cpp', 125 - 'src/ld/InputFiles.cpp', 126 - 'src/ld/Mangling.cpp', 127 - 'src/ld/Options.cpp', 128 - 'src/ld/OutputFile.cpp', 129 - 'src/ld/PlatformSupport.cpp', 130 - 'src/ld/Resolver.cpp', 131 - 'src/ld/ResponseFiles.cpp', 132 - 'src/ld/Snapshot.cpp', 133 - 'src/ld/SymbolTable.cpp', 134 - 'src/ld/code-sign-blobs/blob.cpp', 135 - 'src/ld/code-sign-blobs/blob.h', 136 - 'src/ld/debugline.c', 137 - 'src/ld/ld.cpp', 138 - 'src/ld/parsers/archive_file.cpp', 139 - 'src/ld/parsers/generic_dylib_file.cpp', 140 - 'src/ld/parsers/lto_file.cpp', 141 - 'src/ld/parsers/macho_dylib_file.cpp', 142 - 'src/ld/parsers/macho_relocatable_file.cpp', 143 - 'src/ld/parsers/opaque_section_file.cpp', 144 - 'src/ld/parsers/textstub_dylib_file.cpp', 145 - 'src/ld/passes/bitcode_bundle.cpp', 146 - 'src/ld/passes/branch_island.cpp', 147 - 'src/ld/passes/branch_shim.cpp', 148 - 'src/ld/passes/code_dedup.cpp', 149 - 'src/ld/passes/compact_unwind.cpp', 150 - 'src/ld/passes/dtrace_dof.cpp', 151 - 'src/ld/passes/dylibs.cpp', 152 - 'src/ld/passes/got.cpp', 153 - 'src/ld/passes/huge.cpp', 154 - 'src/ld/passes/inits.cpp', 155 - 'src/ld/passes/objc.cpp', 156 - 'src/ld/passes/objc_constants.cpp', 157 - 'src/ld/passes/objc_stubs.cpp', 158 - 'src/ld/passes/order.cpp', 159 - 'src/ld/passes/stubs/stubs.cpp', 160 - 'src/ld/passes/thread_starts.cpp', 161 - 'src/ld/passes/tlvp.cpp', 162 - 'src/mach_o/Error.cpp', 163 - 'src/mach_o/ExportsTrie.cpp', 164 - ], 165 - ) 166 - install_man('doc/man/man1/ld-classic.1') 167 - 168 - # Extra tools 169 - unwinddump = executable( 170 - f'@target_prefix@unwinddump', 171 - include_directories : incdirs, 172 - install : true, 173 - sources : [ 174 - configure_h, 175 - 'src/other/UnwindDump.cpp', 176 - ], 177 - ) 178 - install_man('doc/man/man1/unwinddump.1') 179 - 180 - machocheck = executable( 181 - f'@target_prefix@machocheck', 182 - include_directories : incdirs, 183 - install : true, 184 - sources : [ 185 - configure_h, 186 - 'src/other/machochecker.cpp', 187 - ], 188 - ) 189 - 190 - objectdump = executable( 191 - f'@target_prefix@ObjectDump', 192 - include_directories : incdirs, 193 - install : true, 194 - sources : [ 195 - configure_h, 196 - 'src/ld/PlatformSupport.cpp', 197 - 'src/ld/debugline.c', 198 - 'src/ld/parsers/macho_relocatable_file.cpp', 199 - 'src/other/ObjectDump.cpp', 200 - ], 201 - ) 202 - 203 - objcimageinfo = executable( 204 - f'@target_prefix@objcimageinfo', 205 - include_directories : incdirs, 206 - install : true, 207 - sources : [ 208 - configure_h, 209 - 'src/other/objcimageinfo.cpp', 210 - ], 211 - )
···
-6
pkgs/by-name/ld/ld64/meson.options
··· 1 - option( 2 - 'target_prefix', 3 - type : 'string', 4 - value : '', 5 - description: 'Specifies the prefix to use when building for cross-compilation (e.g., `aarch64-apple-darwin`)' 6 - )
···
+98 -119
pkgs/by-name/ld/ld64/package.nix
··· 1 { 2 lib, 3 - stdenv, 4 - stdenvNoCC, 5 - fetchFromGitHub, 6 - fetchurl, 7 - apple-sdk, 8 - apple-sdk_14, 9 cctools, 10 darwin, 11 libtapi, 12 llvm, 13 meson, 14 ninja, 15 openssl, 16 pkg-config, 17 - python3, 18 - swiftPackages, 19 xar, 20 - gitUpdater, 21 }: 22 23 let 24 - # The targetPrefix is prepended to binary names to allow multiple binutils on the PATH to be usable. 25 - targetPrefix = lib.optionalString ( 26 - stdenv.targetPlatform != stdenv.hostPlatform 27 - ) "${stdenv.targetPlatform.config}-"; 28 29 - # ld64 needs CrashReporterClient.h, which is hard to find, but WebKit2 has it. 30 - # Fetch it directly because the Darwin stdenv bootstrap can’t depend on fetchgit. 31 - crashreporter_h = fetchurl { 32 - url = "https://raw.githubusercontent.com/apple-oss-distributions/WebKit2/WebKit2-7605.1.33.0.2/Platform/spi/Cocoa/CrashReporterClientSPI.h"; 33 - hash = "sha256-0ybVcwHuGEdThv0PPjYQc3SW0YVOyrM3/L9zG/l1Vtk="; 34 }; 35 36 - dyld = apple-sdk_14.sourceRelease "dyld"; 37 38 - libdispatchPrivate = apple-sdk.sourceRelease "libdispatch"; 39 - 40 - xnu = apple-sdk.sourceRelease "xnu"; 41 - 42 - privateHeaders = stdenvNoCC.mkDerivation { 43 - name = "ld64-deps-private-headers"; 44 - 45 - buildCommand = '' 46 - mkdir -p "$out/include/System" 47 - for dir in arm i386 machine; do 48 - cp -r '${xnu}/osfmk/'$dir "$out/include/System/$dir" 49 - done 50 - 51 - substitute '${crashreporter_h}' "$out/include/CrashReporterClient.h" \ 52 - --replace-fail 'USE(APPLE_INTERNAL_SDK)' '0' 53 - 54 - cp -r '${libdispatchPrivate}/private' "$out/include/dispatch" 55 - 56 - install -D -t "$out/include/mach-o" \ 57 - '${dyld}/include/mach-o/dyld_priv.h' \ 58 - '${cctools.src}/include/mach-o/loader.h' 59 - 60 - install -D -t "$out/include/mach-o/arm" \ 61 - '${cctools.src}/include/mach-o/arm/reloc.h' 62 - 63 - install -D -t "$out/include/sys" \ 64 - '${xnu}/bsd/sys/commpage.h' 65 - 66 - substituteInPlace "$out/include/mach-o/dyld_priv.h" \ 67 - --replace-fail ', bridgeos(3.0)' "" 68 - ''; 69 - }; 70 - 71 - # Avoid pulling in all of Swift just to build libdispatch 72 - libdispatch = swiftPackages.Dispatch.override { useSwift = false; }; 73 in 74 stdenv.mkDerivation (finalAttrs: { 75 pname = "ld64"; ··· 84 src = fetchFromGitHub { 85 owner = "apple-oss-distributions"; 86 repo = "ld64"; 87 - rev = "ld64-${finalAttrs.version}"; 88 hash = "sha256-hLkfqgBwVPlO4gfriYOawTO5E1zSD63ZcNetm1E5I70"; 89 }; 90 91 - xcodeHash = "sha256-+j7Ed/6aD46SJnr3DWPfWuYWylb2FNJRPmWsUVxZJHM="; 92 93 - postUnpack = '' 94 - # Verify that the Xcode project has not changed unexpectedly. 95 - hashType=$(echo $xcodeHash | cut -d- -f1) 96 - expectedHash=$(echo $xcodeHash | cut -d- -f2) 97 - hash=$(openssl "$hashType" -binary "$sourceRoot/ld64.xcodeproj/project.pbxproj" | base64) 98 99 - if [ "$hash" != "$expectedHash" ]; then 100 - echo 'error: hash mismatch in ld64.xcodeproj/project.pbxproj' 101 - echo " specified: $xcodeHash" 102 - echo " got: $hashType-$hash" 103 - echo 104 - echo 'Upstream Xcode project has changed. Update `meson.build` with any changes, then update `xcodeHash`.' 105 - echo 'Use `nix-hash --flat --sri --type sha256 ld64.xcodeproj/project.pbxproj` to regenerate it.' 106 - exit 1 107 - fi 108 ''; 109 110 - patches = [ 111 - # Use std::atomic for atomics. Replaces private APIs (`os/lock_private.h`) with standard APIs. 112 - ./0004-Use-std-atomics-and-std-mutex.patch 113 - # ld64 assumes the default libLTO.dylib can be found relative to its bindir, which is 114 - # not the case in nixpkgs. Override it to default to `stdenv.cc`’s libLTO.dylib. 115 - ./0005-Support-LTO-in-nixpkgs.patch 116 - # Add implementation of missing function required for code directory support. 117 - ./0006-Add-libcd_is_blob_a_linker_signature-implementation.patch 118 - # Add OpenSSL implementation of CoreCrypto digest functions. Avoids use of private and non-free APIs. 119 - ./0007-Add-OpenSSL-based-CoreCrypto-digest-functions.patch 120 - ./remove-unused-and-incomplete-blob-clone.diff 121 - ]; 122 - 123 - postPatch = '' 124 - substitute ${./meson.build} meson.build \ 125 - --subst-var version 126 - cp ${./meson.options} meson.options 127 - 128 - # Match the version format used by upstream. 129 - sed -i src/ld/Options.cpp \ 130 - -e '1iconst char ld_classicVersionString[] = "@(#)PROGRAM:ld PROJECT:ld64-${finalAttrs.version}\\n";' 131 - 132 - # Instead of messing around with trying to extract and run the script from the Xcode project, 133 - # just use our own Python script to generate `compile_stubs.h` 134 - cp ${./gen_compile_stubs.py} gen_compile_stubs.py 135 - 136 - # Enable LTO support using LLVM’s libLTO.dylib by default. 137 - substituteInPlace src/ld/InputFiles.cpp \ 138 - --subst-var-by libllvm '${lib.getLib llvm}' 139 - substituteInPlace src/ld/parsers/lto_file.cpp \ 140 - --subst-var-by libllvm '${lib.getLib llvm}' 141 - 142 - # Use portable includes 143 - substituteInPlace src/ld/code-sign-blobs/endian.h \ 144 - --replace-fail '#include <machine/endian.h>' '#include <sys/types.h>' 145 ''; 146 147 - strictDeps = true; 148 - 149 - env.NIX_CFLAGS_COMPILE = "-DTARGET_OS_BRIDGE=0 -I${privateHeaders}/include"; 150 151 nativeBuildInputs = [ 152 meson 153 ninja 154 openssl 155 pkg-config 156 - python3 157 ]; 158 159 buildInputs = [ 160 - libtapi 161 llvm 162 openssl 163 xar 164 - ] ++ lib.optionals stdenv.hostPlatform.isLinux [ libdispatch ]; 165 166 # Note for overrides: ld64 cannot be built as a debug build because of UB in its iteration implementations, 167 # which trigger libc++ debug assertions due to trying to take the address of the first element of an emtpy vector. ··· 170 mesonFlags = [ 171 (lib.mesonOption "b_ndebug" "if-release") 172 (lib.mesonOption "default_library" (if stdenv.hostPlatform.isStatic then "static" else "shared")) 173 - ] ++ lib.optionals (targetPrefix != "") [ (lib.mesonOption "target_prefix" targetPrefix) ]; 174 175 doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform; 176 ··· 182 183 cd "$NIX_BUILD_TOP/$sourceRoot" 184 185 - export NIX_CFLAGS_COMPILE+=" --ld-path=$out/bin/${targetPrefix}ld" 186 export NIX_CFLAGS_LINK+=" -L$SDKROOT/usr/lib" 187 - meson setup build-install-check -Db_lto=true --buildtype=$mesonBuildType${ 188 - lib.optionalString (targetPrefix != "") " -Dtarget_prefix=${targetPrefix}" 189 } 190 191 cd build-install-check 192 - ninja ${targetPrefix}ld "-j$NIX_BUILD_CORES" 193 194 # Confirm that ld found the LTO library and reports it. 195 - ./${targetPrefix}ld -v 2>&1 | grep -q 'LTO support' 196 197 runHook postInstallCheck 198 ''; ··· 204 ''; 205 206 __structuredAttrs = true; 207 - 208 - passthru.updateScript = gitUpdater { rev-prefix = "ld64-"; }; 209 210 meta = { 211 description = "The classic linker for Darwin";
··· 1 { 2 lib, 3 cctools, 4 + cmake, 5 darwin, 6 + fetchFromGitHub, 7 libtapi, 8 llvm, 9 meson, 10 ninja, 11 openssl, 12 pkg-config, 13 + stdenv, 14 xar, 15 }: 16 17 let 18 + # ld64 uses `#embed` to embed `compile_stubs`, which is only implemented in Clang 19. 19 + # This can be done unconditionally once the bootstrap tools have been updated. 20 + hasEmbed = lib.versionAtLeast (lib.getVersion stdenv.cc) "19"; 21 + 22 + # Copy the files from their original sources instead of using patches to reduce the size of the patch set in nixpkgs. 23 + otherSrcs = { 24 + # The last version of ld64 to have dyldinfo 25 + ld64 = fetchFromGitHub { 26 + owner = "apple-oss-distributions"; 27 + repo = "ld64"; 28 + tag = "ld64-762"; 29 + hash = "sha256-UIq/fwO40vk8yvoTfx+UlLhnuzkI0Ih+Ym6W/BwnP0s="; 30 + }; 31 32 + # Provides the source files used in the vendored libtapi. The libtapi derivation puts `tapi-src` first. 33 + libtapi = lib.head libtapi.srcs; 34 }; 35 36 + ld64src = lib.escapeShellArg "${otherSrcs.ld64}"; 37 + libtapisrc = lib.escapeShellArg "${otherSrcs.libtapi}"; 38 39 + llvmPath = "${lib.getLib llvm}"; 40 in 41 stdenv.mkDerivation (finalAttrs: { 42 pname = "ld64"; ··· 51 src = fetchFromGitHub { 52 owner = "apple-oss-distributions"; 53 repo = "ld64"; 54 + tag = "ld64-${finalAttrs.version}"; 55 hash = "sha256-hLkfqgBwVPlO4gfriYOawTO5E1zSD63ZcNetm1E5I70"; 56 }; 57 58 + patches = 59 + [ 60 + # These patches are vendored from https://github.com/reckenrode/ld64/tree/ld64-951.9-nixpkgs. 61 + # See their comments for more on what they do. 62 + ./patches/0001-Always-use-write-instead-of-mmap.patch 63 + ./patches/0003-Inline-missing-definitions-instead-of-using-private-.patch 64 + ./patches/0004-Removed-unused-Blob-clone-method.patch 65 + ./patches/0005-Use-std-atomics-and-std-mutex-for-portability.patch 66 + ./patches/0006-Add-Meson-build-system.patch 67 + ./patches/0007-Add-CrashReporterClient-header.patch 68 + ./patches/0008-Provide-mach-compatibility-headers-based-on-LLVM-s-h.patch 69 + ./patches/0009-Support-LTO-in-nixpkgs.patch 70 + ./patches/0010-Add-vendored-libtapi-to-the-ld64-build.patch 71 + ./patches/0011-Modify-vendored-libtapi-to-build-with-upstream-LLVM.patch 72 + ./patches/0012-Move-libcodedirectory-to-its-own-subproject.patch 73 + ./patches/0013-Set-the-version-string-in-the-build.patch 74 + ./patches/0014-Replace-corecrypto-and-CommonCrypto-with-OpenSSL.patch 75 + ./patches/0015-Add-libcd_is_blob_a_linker_signature-implementation.patch 76 + ./patches/0016-Add-dyldinfo-to-the-ld64-build.patch 77 + ./patches/0017-Fix-dyldinfo-build.patch 78 + ./patches/0018-Use-STL-containers-instead-of-LLVM-containers.patch 79 + ] 80 + ++ lib.optionals (hasEmbed) [ 81 + ./patches/0002-Add-compile_stubs.h-using-Clang-s-embed-extension-fo.patch 82 + ]; 83 84 + prePatch = '' 85 + # Copy dyldinfo source files 86 + cp ${ld64src}/doc/man/man1/dyldinfo.1 doc/man/man1/dyldinfo.1 87 + cp ${ld64src}/src/other/dyldinfo.cpp src/other/dyldinfo.cpp 88 + 89 + # Copy files needed from libtapi by ld64 90 + mkdir -p subprojects/libtapi/tapi 91 + cp ${libtapisrc}/tools/libtapi/*.cpp subprojects/libtapi 92 + cp ${libtapisrc}/LICENSE.TXT subprojects/libtapi/LICENSE.TXT 93 94 + declare -a tapiHeaders=( 95 + APIVersion.h 96 + Defines.h 97 + LinkerInterfaceFile.h 98 + PackedVersion32.h 99 + Symbol.h 100 + Version.h 101 + Version.inc.in 102 + tapi.h 103 + ) 104 + for header in "''${tapiHeaders[@]}"; do 105 + cp ${libtapisrc}/include/tapi/$header subprojects/libtapi/tapi/$header 106 + done 107 ''; 108 109 + # Clang 16 doesn’t support C23, but the patchset expects a compiler that supports it. Only `#embed` is used, so stub 110 + # out its usage and request an older C standard version. This can be dropped once the bootstrap tools are updated. 111 + postPatch = lib.optionalString (!hasEmbed) '' 112 + for meson_build in meson.build subprojects/libcodedirectory/meson.build subprojects/libtapi/meson.build; do 113 + substituteInPlace $meson_build --replace-fail c23 c2x 114 + done 115 + echo '#pragma once' > src/ld/compile_stubs.h 116 + echo 'static const char compile_stubs[] = "";' >> src/ld/compile_stubs.h 117 ''; 118 119 + xcodeHash = "sha256-+j7Ed/6aD46SJnr3DWPfWuYWylb2FNJRPmWsUVxZJHM="; 120 + xcodeProject = "ld64.xcodeproj"; 121 122 nativeBuildInputs = [ 123 + cmake 124 + darwin.xcodeProjectCheckHook 125 meson 126 ninja 127 openssl 128 pkg-config 129 ]; 130 131 buildInputs = [ 132 llvm 133 openssl 134 xar 135 + ]; 136 + 137 + dontUseCmakeConfigure = true; # CMake is only needed because it’s used by Meson to find LLVM. 138 139 # Note for overrides: ld64 cannot be built as a debug build because of UB in its iteration implementations, 140 # which trigger libc++ debug assertions due to trying to take the address of the first element of an emtpy vector. ··· 143 mesonFlags = [ 144 (lib.mesonOption "b_ndebug" "if-release") 145 (lib.mesonOption "default_library" (if stdenv.hostPlatform.isStatic then "static" else "shared")) 146 + (lib.mesonOption "libllvm_path" llvmPath) 147 + ]; 148 149 doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform; 150 ··· 156 157 cd "$NIX_BUILD_TOP/$sourceRoot" 158 159 + export NIX_CFLAGS_COMPILE+=" --ld-path=$out/bin/ld" 160 export NIX_CFLAGS_LINK+=" -L$SDKROOT/usr/lib" 161 + meson setup build-install-check --buildtype=$mesonBuildType ${ 162 + lib.escapeShellArgs [ 163 + (lib.mesonBool "b_lto" true) 164 + (lib.mesonOption "libllvm_path" llvmPath) 165 + ] 166 } 167 168 cd build-install-check 169 + ninja src/ld/ld "-j$NIX_BUILD_CORES" 170 171 # Confirm that ld found the LTO library and reports it. 172 + if ./src/ld/ld -v 2>&1 | grep -q 'LTO support'; then 173 + echo "LTO: supported" 174 + else 175 + echo "LTO: not supported" && exit 1 176 + fi 177 178 runHook postInstallCheck 179 ''; ··· 185 ''; 186 187 __structuredAttrs = true; 188 189 meta = { 190 description = "The classic linker for Darwin";
+50
pkgs/by-name/ld/ld64/patches/0001-Always-use-write-instead-of-mmap.patch
···
··· 1 + From 49489b079a3a2fd42f62c62441981cc734b0d7e7 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 01/18] Always use `write` instead of `mmap` 5 + 6 + This is already required on aarch64-darwin (even under Rosetta 2), so also do it on x86_64-darwin to 7 + avoid needing to use private headers to get the definition of `_COMM_PAGE_CPU_CAPABILITIES64`. 8 + --- 9 + src/ld/OutputFile.cpp | 18 ++---------------- 10 + 1 file changed, 2 insertions(+), 16 deletions(-) 11 + 12 + diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp 13 + index edefb71..487b338 100644 14 + --- a/src/ld/OutputFile.cpp 15 + +++ b/src/ld/OutputFile.cpp 16 + @@ -57,7 +57,7 @@ extern "C" { 17 + 18 + #include <CommonCrypto/CommonDigest.h> 19 + #include <AvailabilityMacros.h> 20 + -#include <System/machine/cpu_capabilities.h> 21 + + 22 + 23 + #include "ExportsTrie.h" 24 + 25 + @@ -4011,21 +4011,7 @@ void OutputFile::writeOutputFile(ld::Internal& state) 26 + } 27 + 28 + // assume mappable by default 29 + - bool outputIsMappableFile = true; 30 + - 31 + -#if __arm64__ 32 + - // <rdar://problem/66598213> work around VM limitation on Apple Silicon and use write() instead of mmap() to produce output file 33 + - outputIsMappableFile = false; 34 + -#elif __x86_64__ 35 + -#ifndef kIsTranslated 36 + - #define kIsTranslated 0x4000000000000000ULL 37 + -#endif 38 + - // <rdar://problem/70505306> 39 + - bool isTranslated = ((*(uint64_t*)_COMM_PAGE_CPU_CAPABILITIES64) & kIsTranslated); 40 + - if ( isTranslated ) { 41 + - outputIsMappableFile = false; 42 + - } 43 + -#endif 44 + + bool outputIsMappableFile = false; 45 + 46 + // rdar://107066824 (ld64: provide an environment variable or so to switch to the 47 + // allocate+pwrite writing mode (instead of mmap) on Intels) 48 + -- 49 + 2.47.2 50 +
+30
pkgs/by-name/ld/ld64/patches/0002-Add-compile_stubs.h-using-Clang-s-embed-extension-fo.patch
···
··· 1 + From 966a7c3af74fb0de0f97d344b14890dc2d45f7e1 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 02/18] =?UTF-8?q?Add=20compile=5Fstubs.h=20using=20Clang?= 5 + =?UTF-8?q?=E2=80=99s=20`#embed`=20extension=20for=20C++?= 6 + MIME-Version: 1.0 7 + Content-Type: text/plain; charset=UTF-8 8 + Content-Transfer-Encoding: 8bit 9 + 10 + --- 11 + src/ld/compile_stubs.h | 7 +++++++ 12 + 1 file changed, 7 insertions(+) 13 + create mode 100644 src/ld/compile_stubs.h 14 + 15 + diff --git a/src/ld/compile_stubs.h b/src/ld/compile_stubs.h 16 + new file mode 100644 17 + index 0000000..88b8462 18 + --- /dev/null 19 + +++ b/src/ld/compile_stubs.h 20 + @@ -0,0 +1,7 @@ 21 + +// SPDX-License-Identifier: APSL-2.0 22 + + 23 + +#pragma once 24 + + 25 + +static const char compile_stubs[] = { 26 + +#embed "../../compile_stubs" suffix(, '\0') if_empty('\0') 27 + +}; 28 + -- 29 + 2.47.2 30 +
+56
pkgs/by-name/ld/ld64/patches/0003-Inline-missing-definitions-instead-of-using-private-.patch
···
··· 1 + From ddcefc16f5db7fd36c885cf3bcd3713c8383e93b Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 03/18] Inline missing definitions instead of using private 5 + mach-o/dyld_private.h header 6 + 7 + Based on: https://github.com/llvm/llvm-project/blob/38870fe124eb5e6e24136f9d3e4551a62370faee/libunwind/src/AddressSpace.hpp#L57-L67 8 + --- 9 + src/ld/Options.cpp | 1 - 10 + src/ld/parsers/libunwind/AddressSpace.hpp | 10 +++++++++- 11 + 2 files changed, 9 insertions(+), 2 deletions(-) 12 + 13 + diff --git a/src/ld/Options.cpp b/src/ld/Options.cpp 14 + index 991387f..cde3fad 100644 15 + --- a/src/ld/Options.cpp 16 + +++ b/src/ld/Options.cpp 17 + @@ -35,7 +35,6 @@ 18 + #include <spawn.h> 19 + #include <Availability.h> 20 + #include <tapi/tapi.h> 21 + -#include <mach-o/dyld_priv.h> 22 + 23 + #include <algorithm> 24 + #include <vector> 25 + diff --git a/src/ld/parsers/libunwind/AddressSpace.hpp b/src/ld/parsers/libunwind/AddressSpace.hpp 26 + index eb47390..0788cc2 100644 27 + --- a/src/ld/parsers/libunwind/AddressSpace.hpp 28 + +++ b/src/ld/parsers/libunwind/AddressSpace.hpp 29 + @@ -35,7 +35,6 @@ 30 + #include <dlfcn.h> 31 + #include <mach-o/loader.h> 32 + #include <mach-o/getsect.h> 33 + -#include <mach-o/dyld_priv.h> 34 + #include <Availability.h> 35 + 36 + #include "FileAbstraction.hpp" 37 + @@ -73,7 +72,16 @@ bool _dyld_find_unwind_sections(void* addr, dyld_unwind_sections* info) 38 + } 39 + #endif // 0 40 + 41 + +struct dyld_unwind_sections 42 + +{ 43 + + const struct mach_header* mh; 44 + + const void* dwarf_section; 45 + + uintptr_t dwarf_section_length; 46 + + const void* compact_unwind_section; 47 + + uintptr_t compact_unwind_section_length; 48 + +}; 49 + 50 + +extern "C" bool _dyld_find_unwind_sections(void*, dyld_unwind_sections*); 51 + 52 + namespace libunwind { 53 + 54 + -- 55 + 2.47.2 56 +
+27
pkgs/by-name/ld/ld64/patches/0004-Removed-unused-Blob-clone-method.patch
···
··· 1 + From 3c0038576173103e8aaa5286f853046b619c35fe Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 04/18] Removed unused `Blob::clone` method 5 + 6 + Fixes a compiler error due to a missing `BlobCore::clone` method. 7 + --- 8 + src/ld/code-sign-blobs/blob.h | 3 --- 9 + 1 file changed, 3 deletions(-) 10 + 11 + diff --git a/src/ld/code-sign-blobs/blob.h b/src/ld/code-sign-blobs/blob.h 12 + index 19c63a9..2ac0aa8 100644 13 + --- a/src/ld/code-sign-blobs/blob.h 14 + +++ b/src/ld/code-sign-blobs/blob.h 15 + @@ -179,9 +179,6 @@ public: 16 + return p; 17 + return NULL; 18 + } 19 + - 20 + - BlobType *clone() const 21 + - { assert(validateBlob()); return specific(this->BlobCore::clone()); } 22 + 23 + static BlobType *readBlob(int fd) 24 + { return specific(BlobCore::readBlob(fd, _magic, sizeof(BlobType), 0), true); } 25 + -- 26 + 2.47.2 27 +
+328
pkgs/by-name/ld/ld64/patches/0006-Add-Meson-build-system.patch
···
··· 1 + From 099f663adc119ade6509569505358a0955c2b02a Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 06/18] Add Meson build system 5 + 6 + --- 7 + meson.build | 42 +++++++++++++++++++ 8 + meson.options | 5 +++ 9 + src/abstraction/meson.build | 3 ++ 10 + src/ld/meson.build | 68 +++++++++++++++++++++++++++++++ 11 + src/ld/parsers/meson.build | 26 ++++++++++++ 12 + src/mach_o/meson.build | 13 ++++++ 13 + src/meson.build | 16 ++++++++ 14 + src/other/meson.build | 80 +++++++++++++++++++++++++++++++++++++ 15 + 8 files changed, 253 insertions(+) 16 + create mode 100644 meson.build 17 + create mode 100644 meson.options 18 + create mode 100644 src/abstraction/meson.build 19 + create mode 100644 src/ld/meson.build 20 + create mode 100644 src/ld/parsers/meson.build 21 + create mode 100644 src/mach_o/meson.build 22 + create mode 100644 src/meson.build 23 + create mode 100644 src/other/meson.build 24 + 25 + diff --git a/meson.build b/meson.build 26 + new file mode 100644 27 + index 0000000..cd4e8da 28 + --- /dev/null 29 + +++ b/meson.build 30 + @@ -0,0 +1,42 @@ 31 + +project( 32 + + 'ld64', 33 + + 'c', 'cpp', 34 + + default_options : {'c_std': 'c23', 'cpp_std': 'c++23'}, 35 + + license : 'APSL-2.0', 36 + + license_files : 'APPLE_LICENSE', 37 + + meson_version : '>=1.6.0', 38 + + version : '954.16', 39 + +) 40 + + 41 + +add_project_arguments( 42 + + # Avoid needing to link libSupport, which helps avoid a dependency on LLVM in packages 43 + + # that link libprunetrie.a (such as cctools). 44 + + '-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1', 45 + + language : 'cpp', 46 + +) 47 + + 48 + + 49 + +cc = meson.get_compiler('c') 50 + +cxx = meson.get_compiler('cpp') 51 + + 52 + + 53 + +libcodedirectory_dep = dependency( 54 + + 'libcodedirectory', 55 + + version : '=819.6.1', 56 + +) 57 + +libtapi_dep = dependency( 58 + + 'libtapi', 59 + + version : [ '>=1500' , '<1600' ], 60 + +) 61 + +llvm_dep = dependency( 62 + + 'llvm', 63 + + version : '>=19.1' 64 + +).partial_dependency(includes : true) # ld64 only needs LLVM headers for ADTs. 65 + +openssl_dep = dependency( 66 + + 'openssl', 67 + + version : '>=3.0' 68 + +) 69 + +xar_dep = cc.find_library('xar') 70 + + 71 + + 72 + +subdir('src') 73 + diff --git a/meson.options b/meson.options 74 + new file mode 100644 75 + index 0000000..dd40e66 76 + --- /dev/null 77 + +++ b/meson.options 78 + @@ -0,0 +1,5 @@ 79 + +option( 80 + + 'libllvm_path', 81 + + type : 'string', 82 + + description: 'Specifies the default path to LLVM for `libLTO.dylib`' 83 + +) 84 + diff --git a/src/abstraction/meson.build b/src/abstraction/meson.build 85 + new file mode 100644 86 + index 0000000..eae50ea 87 + --- /dev/null 88 + +++ b/src/abstraction/meson.build 89 + @@ -0,0 +1,3 @@ 90 + +abstraction_dep = declare_dependency( 91 + + include_directories : [ '.' ] 92 + +) 93 + diff --git a/src/ld/meson.build b/src/ld/meson.build 94 + new file mode 100644 95 + index 0000000..8bc85b7 96 + --- /dev/null 97 + +++ b/src/ld/meson.build 98 + @@ -0,0 +1,68 @@ 99 + +subdir('parsers') 100 + + 101 + +executable( 102 + + 'ld', 103 + + cpp_args : [ 104 + + '-Wno-c23-extensions', 105 + + '-Wno-vla-cxx-extension', 106 + + ], 107 + + dependencies : [ 108 + + abstraction_dep, 109 + + libcodedirectory_dep, 110 + + libtapi_dep, 111 + + llvm_dep, 112 + + mach_o_dep, 113 + + openssl_dep, 114 + + parsers_dep, 115 + + xar_dep, 116 + + ], 117 + + include_directories : [ 118 + + 'code-sign-blobs', 119 + + 'parsers', 120 + + 'passes', 121 + + ], 122 + + install : true, 123 + + # These linker flags mirror those used in a release build of the Xcode project. 124 + + # See: https://github.com/apple-oss-distributions/ld64/blob/47f477cb721755419018f7530038b272e9d0cdea/ld64.xcodeproj/project.pbxproj#L1292-L1299. 125 + + link_args : [ 126 + + '-Wl,-exported_symbol,__mh_execute_header', 127 + + '-Wl,-stack_size,0x02000000', 128 + + '-Wl,-client_name,ld', 129 + + ], 130 + + sources : [ 131 + + configure_h, 132 + + 'FatFile.cpp', 133 + + 'InputFiles.cpp', 134 + + 'Mangling.cpp', 135 + + 'Options.cpp', 136 + + 'OutputFile.cpp', 137 + + 'PlatformSupport.cpp', 138 + + 'Resolver.cpp', 139 + + 'ResponseFiles.cpp', 140 + + 'Snapshot.cpp', 141 + + 'SymbolTable.cpp', 142 + + 'code-sign-blobs/blob.cpp', 143 + + 'code-sign-blobs/blob.h', 144 + + 'debugline.c', 145 + + 'ld.cpp', 146 + + 'libcodedirectory.c', 147 + + 'passes/bitcode_bundle.cpp', 148 + + 'passes/branch_island.cpp', 149 + + 'passes/branch_shim.cpp', 150 + + 'passes/code_dedup.cpp', 151 + + 'passes/compact_unwind.cpp', 152 + + 'passes/dtrace_dof.cpp', 153 + + 'passes/dylibs.cpp', 154 + + 'passes/got.cpp', 155 + + 'passes/huge.cpp', 156 + + 'passes/inits.cpp', 157 + + 'passes/objc.cpp', 158 + + 'passes/objc_constants.cpp', 159 + + 'passes/objc_stubs.cpp', 160 + + 'passes/order.cpp', 161 + + 'passes/stubs/stubs.cpp', 162 + + 'passes/thread_starts.cpp', 163 + + 'passes/tlvp.cpp', 164 + + ], 165 + +) 166 + +install_man(meson.global_source_root() / 'doc/man/man1/ld-classic.1') 167 + diff --git a/src/ld/parsers/meson.build b/src/ld/parsers/meson.build 168 + new file mode 100644 169 + index 0000000..a88f651 170 + --- /dev/null 171 + +++ b/src/ld/parsers/meson.build 172 + @@ -0,0 +1,26 @@ 173 + +parsers = static_library( 174 + + 'parsers', 175 + + cpp_args : [ '-Wno-vla-cxx-extension' ], 176 + + dependencies : [ 177 + + abstraction_dep, 178 + + libtapi_dep, 179 + + ], 180 + + include_directories : [ 181 + + '..', # For ld64 headers 182 + + ], 183 + + sources : [ 184 + + configure_h, 185 + + 'archive_file.cpp', 186 + + 'generic_dylib_file.cpp', 187 + + 'lto_file.cpp', 188 + + 'macho_dylib_file.cpp', 189 + + 'macho_relocatable_file.cpp', 190 + + 'opaque_section_file.cpp', 191 + + 'textstub_dylib_file.cpp', 192 + + ], 193 + +) 194 + + 195 + +parsers_dep = declare_dependency( 196 + + include_directories : [ '.' ], 197 + + link_with : parsers, 198 + +) 199 + diff --git a/src/mach_o/meson.build b/src/mach_o/meson.build 200 + new file mode 100644 201 + index 0000000..88d4f7a 202 + --- /dev/null 203 + +++ b/src/mach_o/meson.build 204 + @@ -0,0 +1,13 @@ 205 + +mach_o = static_library( 206 + + 'mach_o', 207 + + cpp_args : [ '-Wno-vla-cxx-extension' ], 208 + + sources : [ 209 + + 'Error.cpp', 210 + + 'ExportsTrie.cpp', 211 + + ], 212 + +) 213 + + 214 + +mach_o_dep = declare_dependency( 215 + + include_directories : [ '.' ], 216 + + link_with : mach_o, 217 + +) 218 + diff --git a/src/meson.build b/src/meson.build 219 + new file mode 100644 220 + index 0000000..e1e3b1a 221 + --- /dev/null 222 + +++ b/src/meson.build 223 + @@ -0,0 +1,16 @@ 224 + +configure_h = custom_target( 225 + + 'configure_h', 226 + + command : [ find_program('bash'), '@INPUT@' ], 227 + + env : { 228 + + 'DERIVED_FILE_DIR' : meson.current_build_dir(), 229 + + 'RC_ProjectSourceVersion': meson.project_version(), 230 + + }, 231 + + input : 'create_configure', 232 + + output : 'configure.h', 233 + +) 234 + + 235 + +subdir('abstraction') 236 + +subdir('mach_o') 237 + + 238 + +subdir('ld') 239 + +subdir('other') 240 + diff --git a/src/other/meson.build b/src/other/meson.build 241 + new file mode 100644 242 + index 0000000..067a69c 243 + --- /dev/null 244 + +++ b/src/other/meson.build 245 + @@ -0,0 +1,80 @@ 246 + +machocheck = executable( 247 + + 'machocheck', 248 + + dependencies : [ 249 + + abstraction_dep, 250 + + llvm_dep, 251 + + ], 252 + + include_directories : [ '../ld' ], 253 + + install : true, 254 + + sources : [ 255 + + configure_h, 256 + + 'machochecker.cpp', 257 + + ], 258 + +) 259 + + 260 + +ObjectDump = executable( 261 + + 'ObjectDump', 262 + + cpp_args : [ '-Wno-vla-cxx-extension' ], 263 + + dependencies : [ 264 + + abstraction_dep, 265 + + libtapi_dep, 266 + + parsers_dep, 267 + + ], 268 + + include_directories : [ '../ld' ], 269 + + install : true, 270 + + sources : [ 271 + + configure_h, 272 + + '../ld/PlatformSupport.cpp', 273 + + '../ld/debugline.c', 274 + + 'ObjectDump.cpp', 275 + + ], 276 + +) 277 + + 278 + +objcimageinfo = executable( 279 + + 'objcimageinfo', 280 + + dependencies : [ 281 + + abstraction_dep, 282 + + llvm_dep, 283 + + ], 284 + + include_directories : [ '../ld' ], 285 + + install : true, 286 + + sources : [ 287 + + configure_h, 288 + + 'objcimageinfo.cpp', 289 + + ], 290 + +) 291 + + 292 + +unwinddump = executable( 293 + + 'unwinddump', 294 + + dependencies : [ 295 + + abstraction_dep, 296 + + llvm_dep, 297 + + ], 298 + + include_directories : [ '../ld' ], 299 + + install : true, 300 + + sources : [ 301 + + configure_h, 302 + + 'UnwindDump.cpp', 303 + + ], 304 + +) 305 + +install_man(meson.global_source_root() / 'doc/man/man1/unwinddump.1') 306 + + 307 + +static_library( 308 + + 'prunetrie', 309 + + cpp_args : [ '-Wno-vla-cxx-extension' ], 310 + + dependencies : [ 311 + + abstraction_dep, 312 + + mach_o_dep 313 + + ], 314 + + include_directories : [ '../ld' ], 315 + + install : true, 316 + + override_options : {'b_lto': false}, 317 + + sources : [ 318 + + configure_h, 319 + + 'PruneTrie.cpp', 320 + + ], 321 + +) 322 + +install_headers( 323 + + 'prune_trie.h', 324 + + subdir : 'mach-o', 325 + +) 326 + -- 327 + 2.47.2 328 +
+91
pkgs/by-name/ld/ld64/patches/0007-Add-CrashReporterClient-header.patch
···
··· 1 + From 8bc85cdac6c39215d0d7ea4facfea593efe785ec Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 07/18] Add CrashReporterClient header 5 + 6 + Based on: https://github.com/apple-oss-distributions/WebKit2/blob/523170e4638816ec4a39c8128a4f3c4ab70a6f89/Platform/spi/Cocoa/CrashReporterClientSPI.h 7 + --- 8 + include/CrashReporterClient.h | 48 +++++++++++++++++++++++++++++++++++ 9 + include/meson.build | 4 +++ 10 + meson.build | 1 + 11 + 3 files changed, 53 insertions(+) 12 + create mode 100644 include/CrashReporterClient.h 13 + create mode 100644 include/meson.build 14 + 15 + diff --git a/include/CrashReporterClient.h b/include/CrashReporterClient.h 16 + new file mode 100644 17 + index 0000000..f892448 18 + --- /dev/null 19 + +++ b/include/CrashReporterClient.h 20 + @@ -0,0 +1,48 @@ 21 + +/* 22 + + * Copyright (C) 2017 Apple Inc. All rights reserved. 23 + + * 24 + + * Redistribution and use in source and binary forms, with or without 25 + + * modification, are permitted provided that the following conditions 26 + + * are met: 27 + + * 1. Redistributions of source code must retain the above copyright 28 + + * notice, this list of conditions and the following disclaimer. 29 + + * 2. Redistributions in binary form must reproduce the above copyright 30 + + * notice, this list of conditions and the following disclaimer in the 31 + + * documentation and/or other materials provided with the distribution. 32 + + * 33 + + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 34 + + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 35 + + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 36 + + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 37 + + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 38 + + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 39 + + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 40 + + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 41 + + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 42 + + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 43 + + * THE POSSIBILITY OF SUCH DAMAGE. 44 + + */ 45 + +#pragma once 46 + + 47 + +#define CRASHREPORTER_ANNOTATIONS_SECTION "__crash_info" 48 + +#define CRASHREPORTER_ANNOTATIONS_VERSION 5 49 + +#define CRASH_REPORTER_CLIENT_HIDDEN __attribute__((visibility("hidden"))) 50 + + 51 + +#define _crc_make_getter(attr) ((const char *)(unsigned long)gCRAnnotations.attr) 52 + +#define _crc_make_setter(attr, arg) (gCRAnnotations.attr = (uint64_t)(unsigned long)(arg)) 53 + +#define CRGetCrashLogMessage() _crc_make_getter(message) 54 + +#define CRSetCrashLogMessage(m) _crc_make_setter(message, m) 55 + + 56 + +struct crashreporter_annotations_t { 57 + + uint64_t version; 58 + + uint64_t message; 59 + + uint64_t signature_string; 60 + + uint64_t backtrace; 61 + + uint64_t message2; 62 + + uint64_t thread; 63 + + uint64_t dialog_mode; 64 + + uint64_t abort_cause; 65 + +}; 66 + + 67 + +CRASH_REPORTER_CLIENT_HIDDEN 68 + +extern struct crashreporter_annotations_t gCRAnnotations; 69 + diff --git a/include/meson.build b/include/meson.build 70 + new file mode 100644 71 + index 0000000..bbe6fcb 72 + --- /dev/null 73 + +++ b/include/meson.build 74 + @@ -0,0 +1,4 @@ 75 + +add_project_arguments( 76 + + '-I' + meson.global_source_root() / 'include', 77 + + language : [ 'c', 'cpp' ], 78 + +) 79 + diff --git a/meson.build b/meson.build 80 + index cd4e8da..a79f03f 100644 81 + --- a/meson.build 82 + +++ b/meson.build 83 + @@ -39,4 +39,5 @@ openssl_dep = dependency( 84 + xar_dep = cc.find_library('xar') 85 + 86 + 87 + +subdir('include') 88 + subdir('src') 89 + -- 90 + 2.47.2 91 +
+662
pkgs/by-name/ld/ld64/patches/0008-Provide-mach-compatibility-headers-based-on-LLVM-s-h.patch
···
··· 1 + From 5ce3538352b162cfaacca4a7e3c5e04fabf1d169 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 08/18] =?UTF-8?q?Provide=20mach=20compatibility=20headers?= 5 + =?UTF-8?q?=20based=20on=20LLVM=E2=80=99s=20headers?= 6 + MIME-Version: 1.0 7 + Content-Type: text/plain; charset=UTF-8 8 + Content-Transfer-Encoding: 8bit 9 + 10 + --- 11 + include/mach-o/fat.h | 16 ++ 12 + include/mach-o/loader.h | 224 +++++++++++++++++++++++ 13 + include/mach-o/nlist.h | 61 ++++++ 14 + include/mach/machine.h | 200 ++++++++++++++++++++ 15 + include/mach/vm_prot.h | 13 ++ 16 + src/abstraction/MachOFileAbstraction.hpp | 32 ++-- 17 + 6 files changed, 530 insertions(+), 16 deletions(-) 18 + create mode 100644 include/mach-o/fat.h 19 + create mode 100644 include/mach-o/loader.h 20 + create mode 100644 include/mach-o/nlist.h 21 + create mode 100644 include/mach/machine.h 22 + create mode 100644 include/mach/vm_prot.h 23 + 24 + diff --git a/include/mach-o/fat.h b/include/mach-o/fat.h 25 + new file mode 100644 26 + index 0000000..82f5dc1 27 + --- /dev/null 28 + +++ b/include/mach-o/fat.h 29 + @@ -0,0 +1,16 @@ 30 + +// SPDX-License-Identifier: APSL-2.0 31 + + 32 + +// Derive `fat.h` from LLVM to avoid macro conflicts. 33 + + 34 + +#pragma once 35 + + 36 + +#include <llvm/BinaryFormat/MachO.h> 37 + + 38 + +using llvm::MachO::fat_arch; 39 + +using llvm::MachO::fat_arch_64; 40 + +using llvm::MachO::fat_header; 41 + + 42 + +using llvm::MachO::FAT_CIGAM; 43 + +using llvm::MachO::FAT_CIGAM_64; 44 + +using llvm::MachO::FAT_MAGIC; 45 + +using llvm::MachO::FAT_MAGIC_64; 46 + diff --git a/include/mach-o/loader.h b/include/mach-o/loader.h 47 + new file mode 100644 48 + index 0000000..5306a20 49 + --- /dev/null 50 + +++ b/include/mach-o/loader.h 51 + @@ -0,0 +1,224 @@ 52 + +// SPDX-License-Identifier: APSL-2.0 53 + + 54 + +// Derive `loader.h` from LLVM to avoid macro conflicts. 55 + + 56 + +#pragma once 57 + + 58 + +#include <mach/vm_prot.h> 59 + + 60 + +#include <llvm/BinaryFormat/MachO.h> 61 + + 62 + +using llvm::MachO::mach_header; 63 + +using llvm::MachO::mach_header_64; 64 + + 65 + +using llvm::MachO::data_in_code_entry; 66 + + 67 + +using llvm::MachO::dylib_table_of_contents; 68 + + 69 + +using llvm::MachO::dylib_module; 70 + +using llvm::MachO::dylib_module_64; 71 + + 72 + +using llvm::MachO::section; 73 + +using llvm::MachO::section_64; 74 + + 75 + +using llvm::MachO::build_tool_version; 76 + +using llvm::MachO::build_version_command; 77 + +using llvm::MachO::dyld_info_command; 78 + +using llvm::MachO::dylib; 79 + +using llvm::MachO::dylib_command; 80 + +using llvm::MachO::dylinker_command; 81 + +using llvm::MachO::dysymtab_command; 82 + +using llvm::MachO::encryption_info_command; 83 + +using llvm::MachO::encryption_info_command_64; 84 + +using llvm::MachO::entry_point_command; 85 + +using llvm::MachO::linkedit_data_command; 86 + +using llvm::MachO::linker_option_command; 87 + +using llvm::MachO::load_command; 88 + +using llvm::MachO::routines_command; 89 + +using llvm::MachO::routines_command_64; 90 + +using llvm::MachO::rpath_command; 91 + +using llvm::MachO::segment_command; 92 + +using llvm::MachO::segment_command_64; 93 + +using llvm::MachO::source_version_command; 94 + +using llvm::MachO::sub_client_command; 95 + +using llvm::MachO::sub_framework_command; 96 + +using llvm::MachO::sub_library_command; 97 + +using llvm::MachO::sub_umbrella_command; 98 + +using llvm::MachO::symtab_command; 99 + +using llvm::MachO::thread_command; 100 + +using llvm::MachO::twolevel_hints_command; 101 + +using llvm::MachO::uuid_command; 102 + +using llvm::MachO::version_min_command; 103 + + 104 + +using llvm::MachO::LC_BUILD_VERSION; 105 + +using llvm::MachO::LC_CODE_SIGNATURE; 106 + +using llvm::MachO::LC_DATA_IN_CODE; 107 + +using llvm::MachO::LC_DYLD_ENVIRONMENT; 108 + +using llvm::MachO::LC_DYLD_INFO; 109 + +using llvm::MachO::LC_DYLD_INFO_ONLY; 110 + +using llvm::MachO::LC_DYSYMTAB; 111 + +using llvm::MachO::LC_ENCRYPTION_INFO; 112 + +using llvm::MachO::LC_ENCRYPTION_INFO_64; 113 + +using llvm::MachO::LC_FUNCTION_STARTS; 114 + +using llvm::MachO::LC_ID_DYLIB; 115 + +using llvm::MachO::LC_ID_DYLINKER; 116 + +using llvm::MachO::LC_LINKER_OPTION; 117 + +using llvm::MachO::LC_LOAD_DYLIB; 118 + +using llvm::MachO::LC_LOAD_DYLINKER; 119 + +using llvm::MachO::LC_LOAD_UPWARD_DYLIB; 120 + +using llvm::MachO::LC_LOAD_WEAK_DYLIB; 121 + +using llvm::MachO::LC_MAIN; 122 + +using llvm::MachO::LC_REEXPORT_DYLIB; 123 + +using llvm::MachO::LC_REQ_DYLD; 124 + +using llvm::MachO::LC_ROUTINES; 125 + +using llvm::MachO::LC_ROUTINES_64; 126 + +using llvm::MachO::LC_RPATH; 127 + +using llvm::MachO::LC_SEGMENT; 128 + +using llvm::MachO::LC_SEGMENT_64; 129 + +using llvm::MachO::LC_SEGMENT_SPLIT_INFO; 130 + +using llvm::MachO::LC_SOURCE_VERSION; 131 + +using llvm::MachO::LC_SUB_CLIENT; 132 + +using llvm::MachO::LC_SUB_FRAMEWORK; 133 + +using llvm::MachO::LC_SUB_LIBRARY; 134 + +using llvm::MachO::LC_SUB_UMBRELLA; 135 + +using llvm::MachO::LC_SYMTAB; 136 + +using llvm::MachO::LC_UNIXTHREAD; 137 + +using llvm::MachO::LC_UUID; 138 + +using llvm::MachO::LC_VERSION_MIN_IPHONEOS; 139 + +using llvm::MachO::LC_VERSION_MIN_MACOSX; 140 + +using llvm::MachO::LC_VERSION_MIN_TVOS; 141 + +using llvm::MachO::LC_VERSION_MIN_WATCHOS; 142 + +using llvm::MachO::LC_DYLIB_CODE_SIGN_DRS; 143 + +using llvm::MachO::LC_NOTE; 144 + +using llvm::MachO::LC_LAZY_LOAD_DYLIB; 145 + +using llvm::MachO::LC_PREBIND_CKSUM; 146 + +using llvm::MachO::LC_TWOLEVEL_HINTS; 147 + + 148 + +using llvm::MachO::MH_ALLOW_STACK_EXECUTION; 149 + +using llvm::MachO::MH_APP_EXTENSION_SAFE; 150 + +using llvm::MachO::MH_BINDS_TO_WEAK; 151 + +using llvm::MachO::MH_BUNDLE; 152 + +using llvm::MachO::MH_CIGAM; 153 + +using llvm::MachO::MH_CIGAM_64; 154 + +using llvm::MachO::MH_DEAD_STRIPPABLE_DYLIB; 155 + +using llvm::MachO::MH_DYLDLINK; 156 + +using llvm::MachO::MH_DYLIB; 157 + +using llvm::MachO::MH_DYLIB_STUB; 158 + +using llvm::MachO::MH_DYLINKER; 159 + +using llvm::MachO::MH_EXECUTE; 160 + +using llvm::MachO::MH_LAZY_INIT; 161 + +using llvm::MachO::MH_INCRLINK; 162 + +using llvm::MachO::MH_HAS_TLV_DESCRIPTORS; 163 + +using llvm::MachO::MH_KEXT_BUNDLE; 164 + +using llvm::MachO::MH_MAGIC; 165 + +using llvm::MachO::MH_MAGIC_64; 166 + +using llvm::MachO::MH_NOUNDEFS; 167 + +using llvm::MachO::MH_NO_HEAP_EXECUTION; 168 + +using llvm::MachO::MH_NO_REEXPORTED_DYLIBS; 169 + +using llvm::MachO::MH_OBJECT; 170 + +using llvm::MachO::MH_PIE; 171 + +using llvm::MachO::MH_PREBOUND; 172 + +using llvm::MachO::MH_PRELOAD; 173 + +using llvm::MachO::MH_SPLIT_SEGS; 174 + +using llvm::MachO::MH_SUBSECTIONS_VIA_SYMBOLS; 175 + +using llvm::MachO::MH_TWOLEVEL; 176 + +using llvm::MachO::MH_WEAK_DEFINES; 177 + + 178 + +using llvm::MachO::BIND_IMMEDIATE_MASK; 179 + + 180 + +using llvm::MachO::BIND_OPCODE_ADD_ADDR_ULEB; 181 + +using llvm::MachO::BIND_OPCODE_DONE; 182 + +using llvm::MachO::BIND_OPCODE_DO_BIND; 183 + +using llvm::MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED; 184 + +using llvm::MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB; 185 + +using llvm::MachO::BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB; 186 + +using llvm::MachO::BIND_OPCODE_SET_ADDEND_SLEB; 187 + +using llvm::MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_IMM; 188 + +using llvm::MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB; 189 + +using llvm::MachO::BIND_OPCODE_SET_DYLIB_SPECIAL_IMM; 190 + +using llvm::MachO::BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB; 191 + +using llvm::MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM; 192 + +using llvm::MachO::BIND_OPCODE_SET_TYPE_IMM; 193 + +using llvm::MachO::BIND_OPCODE_MASK; 194 + + 195 + +using llvm::MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP; 196 + +using llvm::MachO::BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE; 197 + +using llvm::MachO::BIND_SPECIAL_DYLIB_SELF; 198 + + 199 + +using llvm::MachO::BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION; 200 + +using llvm::MachO::BIND_SYMBOL_FLAGS_WEAK_IMPORT; 201 + + 202 + +using llvm::MachO::BIND_TYPE_POINTER; 203 + +using llvm::MachO::BIND_TYPE_TEXT_ABSOLUTE32; 204 + +using llvm::MachO::BIND_TYPE_TEXT_PCREL32; 205 + + 206 + +using llvm::MachO::DICE_KIND_ABS_JUMP_TABLE32; 207 + +using llvm::MachO::DICE_KIND_DATA; 208 + +using llvm::MachO::DICE_KIND_JUMP_TABLE16; 209 + +using llvm::MachO::DICE_KIND_JUMP_TABLE32; 210 + +using llvm::MachO::DICE_KIND_JUMP_TABLE8; 211 + + 212 + +using llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_MASK; 213 + +using llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_REGULAR; 214 + +using llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL; 215 + +using llvm::MachO::EXPORT_SYMBOL_FLAGS_REEXPORT; 216 + +using llvm::MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER; 217 + +using llvm::MachO::EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION; 218 + + 219 + +using llvm::MachO::REBASE_IMMEDIATE_MASK; 220 + + 221 + +using llvm::MachO::REBASE_OPCODE_MASK; 222 + +using llvm::MachO::REBASE_OPCODE_ADD_ADDR_IMM_SCALED; 223 + +using llvm::MachO::REBASE_OPCODE_ADD_ADDR_ULEB; 224 + +using llvm::MachO::REBASE_OPCODE_DONE; 225 + +using llvm::MachO::REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB; 226 + +using llvm::MachO::REBASE_OPCODE_DO_REBASE_IMM_TIMES; 227 + +using llvm::MachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES; 228 + +using llvm::MachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB; 229 + +using llvm::MachO::REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB; 230 + +using llvm::MachO::REBASE_OPCODE_SET_TYPE_IMM; 231 + + 232 + +using llvm::MachO::REBASE_TYPE_POINTER; 233 + +using llvm::MachO::REBASE_TYPE_TEXT_ABSOLUTE32; 234 + +using llvm::MachO::REBASE_TYPE_TEXT_PCREL32; 235 + + 236 + +using llvm::MachO::S_4BYTE_LITERALS; 237 + +using llvm::MachO::S_8BYTE_LITERALS; 238 + +using llvm::MachO::S_16BYTE_LITERALS; 239 + +using llvm::MachO::S_ATTR_DEBUG; 240 + +using llvm::MachO::S_ATTR_EXT_RELOC; 241 + +using llvm::MachO::S_ATTR_LIVE_SUPPORT; 242 + +using llvm::MachO::S_ATTR_LOC_RELOC; 243 + +using llvm::MachO::S_ATTR_LOC_RELOC; 244 + +using llvm::MachO::S_ATTR_NO_DEAD_STRIP; 245 + +using llvm::MachO::S_ATTR_PURE_INSTRUCTIONS; 246 + +using llvm::MachO::S_ATTR_SELF_MODIFYING_CODE; 247 + +using llvm::MachO::S_ATTR_SOME_INSTRUCTIONS; 248 + +using llvm::MachO::S_COALESCED; 249 + +using llvm::MachO::S_CSTRING_LITERALS; 250 + +using llvm::MachO::S_DTRACE_DOF; 251 + +using llvm::MachO::S_INTERPOSING; 252 + +using llvm::MachO::S_LAZY_DYLIB_SYMBOL_POINTERS; 253 + +using llvm::MachO::S_LAZY_SYMBOL_POINTERS; 254 + +using llvm::MachO::S_LITERAL_POINTERS; 255 + +using llvm::MachO::S_MOD_INIT_FUNC_POINTERS; 256 + +using llvm::MachO::S_MOD_TERM_FUNC_POINTERS; 257 + +using llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS; 258 + +using llvm::MachO::S_REGULAR; 259 + +using llvm::MachO::S_SYMBOL_STUBS; 260 + +using llvm::MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS; 261 + +using llvm::MachO::S_THREAD_LOCAL_REGULAR; 262 + +using llvm::MachO::S_THREAD_LOCAL_VARIABLES; 263 + +using llvm::MachO::S_THREAD_LOCAL_VARIABLE_POINTERS; 264 + +using llvm::MachO::S_THREAD_LOCAL_ZEROFILL; 265 + +using llvm::MachO::S_ZEROFILL; 266 + + 267 + +using llvm::MachO::SG_NORELOC; 268 + + 269 + +using llvm::MachO::INDIRECT_SYMBOL_ABS; 270 + +using llvm::MachO::INDIRECT_SYMBOL_LOCAL; 271 + +using llvm::MachO::SECTION_TYPE; 272 + +using llvm::MachO::TOOL_LD; 273 + + 274 + +template<typename T> 275 + +inline constexpr int operator| (llvm::MachO::SectionType lhs, T rhs) { return (int) lhs | (int) rhs; } 276 + diff --git a/include/mach-o/nlist.h b/include/mach-o/nlist.h 277 + new file mode 100644 278 + index 0000000..3c319a4 279 + --- /dev/null 280 + +++ b/include/mach-o/nlist.h 281 + @@ -0,0 +1,61 @@ 282 + +// SPDX-License-Identifier: APSL-2.0 283 + + 284 + +// Derive `nlist.h` from LLVM to avoid macro conflicts. 285 + + 286 + +#pragma once 287 + + 288 + +#include <llvm/BinaryFormat/MachO.h> 289 + + 290 + +using llvm::MachO::nlist; 291 + +using llvm::MachO::nlist_64; 292 + + 293 + +using llvm::MachO::N_ARM_THUMB_DEF; 294 + + 295 + +using llvm::MachO::N_ABS; 296 + +using llvm::MachO::N_EXT; 297 + +using llvm::MachO::N_INDR; 298 + +using llvm::MachO::N_PBUD; 299 + +using llvm::MachO::N_PEXT; 300 + +using llvm::MachO::N_SECT; 301 + +using llvm::MachO::N_STAB; 302 + +using llvm::MachO::N_TYPE; 303 + +using llvm::MachO::N_UNDF; 304 + + 305 + +using llvm::MachO::N_ALT_ENTRY; 306 + +using llvm::MachO::N_NO_DEAD_STRIP; 307 + +using llvm::MachO::N_SYMBOL_RESOLVER; 308 + +using llvm::MachO::N_WEAK_DEF; 309 + +using llvm::MachO::N_WEAK_REF; 310 + + 311 + +#define N_REF_TO_WEAK 0x80 // Not defined in LLVM headers 312 + + 313 + +using llvm::MachO::DYNAMIC_LOOKUP_ORDINAL; 314 + + 315 + +using llvm::MachO::EXECUTABLE_ORDINAL; 316 + + 317 + +using llvm::MachO::GET_COMM_ALIGN; 318 + +using llvm::MachO::SET_COMM_ALIGN; 319 + + 320 + +using llvm::MachO::GET_LIBRARY_ORDINAL; 321 + +using llvm::MachO::SET_LIBRARY_ORDINAL; 322 + + 323 + +using llvm::MachO::REFERENCE_FLAG_DEFINED; 324 + +using llvm::MachO::REFERENCE_FLAG_PRIVATE_DEFINED; 325 + +using llvm::MachO::REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY; 326 + +using llvm::MachO::REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY; 327 + +using llvm::MachO::REFERENCE_FLAG_UNDEFINED_LAZY; 328 + +using llvm::MachO::REFERENCE_FLAG_UNDEFINED_NON_LAZY; 329 + +using llvm::MachO::REFERENCE_TYPE; 330 + + 331 + +using llvm::MachO::REFERENCED_DYNAMICALLY; 332 + + 333 + +using llvm::MachO::MAX_SECT; 334 + +using llvm::MachO::NO_SECT; 335 + + 336 + +using llvm::MachO::SELF_LIBRARY_ORDINAL; 337 + + 338 + +template<typename T> 339 + +inline constexpr int operator| (llvm::MachO::NListType lhs, T rhs) { return (int) lhs | (int) rhs; } 340 + + 341 + +template<typename T> 342 + +inline constexpr int operator| (T lhs, llvm::MachO::NListType rhs) { return (int) lhs | (int) rhs; } 343 + diff --git a/include/mach/machine.h b/include/mach/machine.h 344 + new file mode 100644 345 + index 0000000..9162c1d 346 + --- /dev/null 347 + +++ b/include/mach/machine.h 348 + @@ -0,0 +1,200 @@ 349 + +// SPDX-License-Identifier: APSL-2.0 350 + + 351 + +// Derive `machine.h` from LLVM to avoid macro conflicts. 352 + + 353 + +#pragma once 354 + + 355 + +#include_next <mach/machine.h> 356 + + 357 + +#undef CPU_ARCH_MASK 358 + + 359 + +#undef CPU_ARCH_ABI64_32 360 + +#undef CPU_ARCH_ABI64 361 + + 362 + +#undef CPU_TYPE_ANY 363 + + 364 + +#undef CPU_TYPE_ARM 365 + +#undef CPU_TYPE_ARM64 366 + +#undef CPU_TYPE_ARM64_32 367 + +#undef CPU_TYPE_I386 368 + +#undef CPU_TYPE_X86 369 + +#undef CPU_TYPE_X86_64 370 + +#undef CPU_TYPE_MC98000 371 + +#undef CPU_TYPE_SPARC 372 + +#undef CPU_TYPE_POWERPC 373 + +#undef CPU_TYPE_POWERPC64 374 + + 375 + +#undef CPU_SUBTYPE_MASK 376 + + 377 + +#undef CPU_SUBTYPE_ARM64E 378 + +#undef CPU_SUBTYPE_ARM64_32_V8 379 + +#undef CPU_SUBTYPE_ARM64_ALL 380 + +#undef CPU_SUBTYPE_ARM64_V8 381 + +#undef CPU_SUBTYPE_ARM_ALL 382 + +#undef CPU_SUBTYPE_ARM_XSCALE 383 + +#undef CPU_SUBTYPE_ARM_V4T 384 + +#undef CPU_SUBTYPE_ARM_V5TEJ 385 + +#undef CPU_SUBTYPE_ARM_V6 386 + +#undef CPU_SUBTYPE_ARM_V6M 387 + +#undef CPU_SUBTYPE_ARM_V7 388 + +#undef CPU_SUBTYPE_ARM_V7EM 389 + +#undef CPU_SUBTYPE_ARM_V7F 390 + +#undef CPU_SUBTYPE_ARM_V7K 391 + +#undef CPU_SUBTYPE_ARM_V7M 392 + +#undef CPU_SUBTYPE_ARM_V7S 393 + +#undef CPU_SUBTYPE_ARM_V8 394 + + 395 + +#undef CPU_SUBTYPE_I386_ALL 396 + +#undef CPU_SUBTYPE_386 397 + +#undef CPU_SUBTYPE_486 398 + +#undef CPU_SUBTYPE_486SX 399 + +#undef CPU_SUBTYPE_586 400 + +#undef CPU_SUBTYPE_PENT 401 + +#undef CPU_SUBTYPE_PENTPRO 402 + +#undef CPU_SUBTYPE_PENTII_M3 403 + +#undef CPU_SUBTYPE_PENTII_M5 404 + +#undef CPU_SUBTYPE_CELERON 405 + +#undef CPU_SUBTYPE_CELERON_MOBILE 406 + +#undef CPU_SUBTYPE_PENTIUM_3 407 + +#undef CPU_SUBTYPE_PENTIUM_3_M 408 + +#undef CPU_SUBTYPE_PENTIUM_3_XEON 409 + +#undef CPU_SUBTYPE_PENTIUM_M 410 + +#undef CPU_SUBTYPE_PENTIUM_4 411 + +#undef CPU_SUBTYPE_PENTIUM_4_M 412 + +#undef CPU_SUBTYPE_ITANIUM 413 + +#undef CPU_SUBTYPE_ITANIUM_2 414 + +#undef CPU_SUBTYPE_XEON 415 + +#undef CPU_SUBTYPE_XEON_MP 416 + + 417 + +#undef CPU_SUBTYPE_X86_ALL 418 + +#undef CPU_SUBTYPE_X86_ARCH1 419 + + 420 + +#undef CPU_SUBTYPE_X86_64_ALL 421 + +#undef CPU_SUBTYPE_X86_64_H 422 + + 423 + +#undef CPU_SUBTYPE_INTEL 424 + +#undef CPU_SUBTYPE_INTEL_FAMILY 425 + +#undef CPU_SUBTYPE_INTEL_FAMILY_MAX 426 + +#undef CPU_SUBTYPE_INTEL_MODEL 427 + +#undef CPU_SUBTYPE_INTEL_MODEL_ALL 428 + + 429 + +#undef CPU_SUBTYPE_POWERPC_ALL 430 + +#undef CPU_SUBTYPE_POWERPC_601 431 + +#undef CPU_SUBTYPE_POWERPC_602 432 + +#undef CPU_SUBTYPE_POWERPC_603 433 + +#undef CPU_SUBTYPE_POWERPC_603e 434 + +#undef CPU_SUBTYPE_POWERPC_603ev 435 + +#undef CPU_SUBTYPE_POWERPC_604 436 + +#undef CPU_SUBTYPE_POWERPC_604e 437 + +#undef CPU_SUBTYPE_POWERPC_620 438 + +#undef CPU_SUBTYPE_POWERPC_750 439 + +#undef CPU_SUBTYPE_POWERPC_7400 440 + +#undef CPU_SUBTYPE_POWERPC_7450 441 + +#undef CPU_SUBTYPE_POWERPC_970 442 + + 443 + +#undef CPU_SUBTYPE_MC98601 444 + + 445 + +#undef CPU_SUBTYPE_SPARC_ALL 446 + + 447 + +#undef CPU_SUBTYPE_LIB64 448 + +#undef CPU_SUBTYPE_MULTIPLE 449 + + 450 + +#include <llvm/BinaryFormat/MachO.h> 451 + + 452 + +using llvm::MachO::CPU_ARCH_MASK; 453 + + 454 + +using llvm::MachO::CPU_ARCH_ABI64_32; 455 + +using llvm::MachO::CPU_ARCH_ABI64; 456 + + 457 + +using llvm::MachO::CPU_TYPE_ANY; 458 + + 459 + +using llvm::MachO::CPU_TYPE_ARM; 460 + +using llvm::MachO::CPU_TYPE_ARM64; 461 + +using llvm::MachO::CPU_TYPE_ARM64_32; 462 + +using llvm::MachO::CPU_TYPE_I386; 463 + +using llvm::MachO::CPU_TYPE_X86; 464 + +using llvm::MachO::CPU_TYPE_X86_64; 465 + +using llvm::MachO::CPU_TYPE_MC98000; 466 + +using llvm::MachO::CPU_TYPE_SPARC; 467 + +using llvm::MachO::CPU_TYPE_POWERPC; 468 + +using llvm::MachO::CPU_TYPE_POWERPC64; 469 + + 470 + +using llvm::MachO::CPU_SUBTYPE_MASK; 471 + + 472 + +using llvm::MachO::CPU_SUBTYPE_ARM64E; 473 + +using llvm::MachO::CPU_SUBTYPE_ARM64_32_V8; 474 + +using llvm::MachO::CPU_SUBTYPE_ARM64_ALL; 475 + +using llvm::MachO::CPU_SUBTYPE_ARM64_V8; 476 + +using llvm::MachO::CPU_SUBTYPE_ARM_ALL; 477 + +using llvm::MachO::CPU_SUBTYPE_ARM_XSCALE; 478 + +using llvm::MachO::CPU_SUBTYPE_ARM_V4T; 479 + +using llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ; 480 + +using llvm::MachO::CPU_SUBTYPE_ARM_V6; 481 + +using llvm::MachO::CPU_SUBTYPE_ARM_V6M; 482 + +using llvm::MachO::CPU_SUBTYPE_ARM_V7; 483 + +using llvm::MachO::CPU_SUBTYPE_ARM_V7EM; 484 + +using llvm::MachO::CPU_SUBTYPE_ARM_V7K; 485 + +using llvm::MachO::CPU_SUBTYPE_ARM_V7M; 486 + +using llvm::MachO::CPU_SUBTYPE_ARM_V7S; 487 + + 488 + +using llvm::MachO::CPU_SUBTYPE_I386_ALL; 489 + +using llvm::MachO::CPU_SUBTYPE_386; 490 + +using llvm::MachO::CPU_SUBTYPE_486; 491 + +using llvm::MachO::CPU_SUBTYPE_486SX; 492 + +using llvm::MachO::CPU_SUBTYPE_586; 493 + +using llvm::MachO::CPU_SUBTYPE_PENT; 494 + +using llvm::MachO::CPU_SUBTYPE_PENTPRO; 495 + +using llvm::MachO::CPU_SUBTYPE_PENTII_M3; 496 + +using llvm::MachO::CPU_SUBTYPE_PENTII_M5; 497 + +using llvm::MachO::CPU_SUBTYPE_CELERON; 498 + +using llvm::MachO::CPU_SUBTYPE_CELERON_MOBILE; 499 + +using llvm::MachO::CPU_SUBTYPE_PENTIUM_3; 500 + +using llvm::MachO::CPU_SUBTYPE_PENTIUM_3_M; 501 + +using llvm::MachO::CPU_SUBTYPE_PENTIUM_3_XEON; 502 + +using llvm::MachO::CPU_SUBTYPE_PENTIUM_M; 503 + +using llvm::MachO::CPU_SUBTYPE_PENTIUM_4; 504 + +using llvm::MachO::CPU_SUBTYPE_PENTIUM_4_M; 505 + +using llvm::MachO::CPU_SUBTYPE_ITANIUM; 506 + +using llvm::MachO::CPU_SUBTYPE_ITANIUM_2; 507 + +using llvm::MachO::CPU_SUBTYPE_XEON; 508 + +using llvm::MachO::CPU_SUBTYPE_XEON_MP; 509 + + 510 + +using llvm::MachO::CPU_SUBTYPE_X86_ALL; 511 + +using llvm::MachO::CPU_SUBTYPE_X86_ARCH1; 512 + + 513 + +using llvm::MachO::CPU_SUBTYPE_X86_64_ALL; 514 + +using llvm::MachO::CPU_SUBTYPE_X86_64_H; 515 + + 516 + +using llvm::MachO::CPU_SUBTYPE_INTEL; 517 + +using llvm::MachO::CPU_SUBTYPE_INTEL_FAMILY; 518 + +using llvm::MachO::CPU_SUBTYPE_INTEL_FAMILY_MAX; 519 + +using llvm::MachO::CPU_SUBTYPE_INTEL_MODEL; 520 + +using llvm::MachO::CPU_SUBTYPE_INTEL_MODEL_ALL; 521 + + 522 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_ALL; 523 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_601; 524 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_602; 525 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_603; 526 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_603e; 527 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_603ev; 528 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_604; 529 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_604e; 530 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_620; 531 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_750; 532 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_7400; 533 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_7450; 534 + +using llvm::MachO::CPU_SUBTYPE_POWERPC_970; 535 + + 536 + +using llvm::MachO::CPU_SUBTYPE_MC98601; 537 + + 538 + +using llvm::MachO::CPU_SUBTYPE_SPARC_ALL; 539 + + 540 + +using llvm::MachO::CPU_SUBTYPE_LIB64; 541 + +using llvm::MachO::CPU_SUBTYPE_MULTIPLE; 542 + + 543 + +// These definitions aren’t in the LLVM headers. 544 + +#define CPU_TYPE_RISCV32 24 545 + + 546 + +#define CPU_SUBTYPE_ARM_V7F 10 547 + +#define CPU_SUBTYPE_ARM_V8 CPU_SUBTYPE_ARM64_V8 548 + +#define CPU_SUBTYPE_RISCV32_ALL 0 549 + diff --git a/include/mach/vm_prot.h b/include/mach/vm_prot.h 550 + new file mode 100644 551 + index 0000000..e524808 552 + --- /dev/null 553 + +++ b/include/mach/vm_prot.h 554 + @@ -0,0 +1,13 @@ 555 + +// SPDX-License-Identifier: APSL-2.0 556 + + 557 + +// Derive `vm_prot.h` from LLVM to avoid macro conflicts. 558 + + 559 + +#pragma once 560 + + 561 + +#include <llvm/BinaryFormat/MachO.h> 562 + + 563 + +using llvm::MachO::VM_PROT_EXECUTE; 564 + +using llvm::MachO::VM_PROT_READ; 565 + +using llvm::MachO::VM_PROT_WRITE; 566 + + 567 + +#include_next <mach/vm_prot.h> 568 + diff --git a/src/abstraction/MachOFileAbstraction.hpp b/src/abstraction/MachOFileAbstraction.hpp 569 + index 71e7765..e8d9b5c 100644 570 + --- a/src/abstraction/MachOFileAbstraction.hpp 571 + +++ b/src/abstraction/MachOFileAbstraction.hpp 572 + @@ -847,8 +847,8 @@ public: 573 + uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); } 574 + void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); } 575 + 576 + - uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); } 577 + - void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); } 578 + + uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name); } 579 + + void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name, value); } 580 + 581 + uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); } 582 + void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); } 583 + @@ -880,8 +880,8 @@ public: 584 + uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); } 585 + void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); } 586 + 587 + - uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); } 588 + - void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); } 589 + + uint32_t name_offset() const INLINE { return E::get32(fields.name); } 590 + + void set_name_offset(uint32_t value) INLINE { E::set32(fields.name, value); } 591 + 592 + const char* name() const INLINE { return (const char*)&fields + name_offset(); } 593 + void set_name_offset() INLINE { set_name_offset(sizeof(fields)); } 594 + @@ -904,8 +904,8 @@ public: 595 + uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); } 596 + void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); } 597 + 598 + - uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); } 599 + - void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); } 600 + + uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella); } 601 + + void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella, value); } 602 + 603 + const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); } 604 + void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); } 605 + @@ -928,8 +928,8 @@ public: 606 + uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); } 607 + void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); } 608 + 609 + - uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); } 610 + - void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); } 611 + + uint32_t client_offset() const INLINE { return E::get32(fields.client); } 612 + + void set_client_offset(uint32_t value) INLINE { E::set32(fields.client, value); } 613 + 614 + const char* client() const INLINE { return (const char*)&fields + client_offset(); } 615 + void set_client_offset() INLINE { set_client_offset(sizeof(fields)); } 616 + @@ -952,8 +952,8 @@ public: 617 + uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); } 618 + void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); } 619 + 620 + - uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); } 621 + - void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); } 622 + + uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella); } 623 + + void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella, value); } 624 + 625 + const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); } 626 + void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); } 627 + @@ -976,8 +976,8 @@ public: 628 + uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); } 629 + void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); } 630 + 631 + - uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); } 632 + - void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); } 633 + + uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library); } 634 + + void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library, value); } 635 + 636 + const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); } 637 + void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); } 638 + @@ -1355,8 +1355,8 @@ public: 639 + uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); } 640 + void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); } 641 + 642 + - uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); } 643 + - void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); } 644 + + uint32_t path_offset() const INLINE { return E::get32(fields.path); } 645 + + void set_path_offset(uint32_t value) INLINE { E::set32(fields.path, value); } 646 + 647 + const char* path() const INLINE { return (const char*)&fields + path_offset(); } 648 + void set_path_offset() INLINE { set_path_offset(sizeof(fields)); } 649 + @@ -1381,8 +1381,8 @@ template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_ 650 + template <typename P> 651 + class macho_nlist { 652 + public: 653 + - uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); } 654 + - void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); } 655 + + uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_strx); } 656 + + void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_strx, value); } 657 + 658 + uint8_t n_type() const INLINE { return entry.fields.n_type; } 659 + void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; } 660 + -- 661 + 2.47.2 662 +
+111
pkgs/by-name/ld/ld64/patches/0009-Support-LTO-in-nixpkgs.patch
···
··· 1 + From 6a023ee77ca48497382050998d9b33c56330f735 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 09/18] Support LTO in nixpkgs 5 + 6 + --- 7 + src/ld/InputFiles.cpp | 11 ++--------- 8 + src/ld/meson.build | 13 ++++++++++++- 9 + src/ld/parsers/lto_file.cpp | 2 +- 10 + src/ld/parsers/meson.build | 13 ++++++++++++- 11 + 4 files changed, 27 insertions(+), 12 deletions(-) 12 + 13 + diff --git a/src/ld/InputFiles.cpp b/src/ld/InputFiles.cpp 14 + index e045e90..d5341d9 100644 15 + --- a/src/ld/InputFiles.cpp 16 + +++ b/src/ld/InputFiles.cpp 17 + @@ -464,15 +464,8 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib 18 + if ( _options.overridePathlibLTO() != NULL ) { 19 + libLTO = _options.overridePathlibLTO(); 20 + } 21 + - else if ( _NSGetExecutablePath(ldPath, &bufSize) != -1 ) { 22 + - if ( realpath(ldPath, tmpPath) != NULL ) { 23 + - char* lastSlash = strrchr(tmpPath, '/'); 24 + - if ( lastSlash != NULL ) 25 + - strcpy(lastSlash, "/../lib/libLTO.dylib"); 26 + - libLTO = tmpPath; 27 + - if ( realpath(tmpPath, libLTOPath) != NULL ) 28 + - libLTO = libLTOPath; 29 + - } 30 + + else { 31 + + libLTO = "@libllvm_path@/lib/libLTO.dylib"; 32 + } 33 + throwf("could not process llvm bitcode object file, because %s could not be loaded", libLTO); 34 + } 35 + diff --git a/src/ld/meson.build b/src/ld/meson.build 36 + index 8bc85b7..ad8359a 100644 37 + --- a/src/ld/meson.build 38 + +++ b/src/ld/meson.build 39 + @@ -1,5 +1,16 @@ 40 + subdir('parsers') 41 + 42 + +InputFiles_cpp = configure_file( 43 + + configuration : { 44 + + 'libllvm_path' : get_option('libllvm_path'), 45 + + # Silence warnings 46 + + 'APPLE_LICENSE_HEADER_START' : '@APPLE_LICENSE_HEADER_START@', 47 + + 'APPLE_LICENSE_HEADER_END' : '@APPLE_LICENSE_HEADER_END@', 48 + + }, 49 + + input : 'InputFiles.cpp', 50 + + output : '@PLAINNAME@', 51 + +) 52 + + 53 + executable( 54 + 'ld', 55 + cpp_args : [ 56 + @@ -31,8 +42,8 @@ executable( 57 + ], 58 + sources : [ 59 + configure_h, 60 + + InputFiles_cpp, 61 + 'FatFile.cpp', 62 + - 'InputFiles.cpp', 63 + 'Mangling.cpp', 64 + 'Options.cpp', 65 + 'OutputFile.cpp', 66 + diff --git a/src/ld/parsers/lto_file.cpp b/src/ld/parsers/lto_file.cpp 67 + index e32e2f8..1a3b846 100644 68 + --- a/src/ld/parsers/lto_file.cpp 69 + +++ b/src/ld/parsers/lto_file.cpp 70 + @@ -1839,7 +1839,7 @@ bool optimize( const std::vector<const ld::Atom*>& allAtoms, 71 + 72 + }; // namespace lto 73 + 74 + -static const char *sLTODylib = "@rpath/libLTO.dylib"; 75 + +static const char *sLTODylib = "@libllvm_path@/lib/libLTO.dylib"; 76 + static std::atomic<bool> sLTOIsLoaded(false); 77 + 78 + static void *getHandle() { 79 + diff --git a/src/ld/parsers/meson.build b/src/ld/parsers/meson.build 80 + index a88f651..7bd3e89 100644 81 + --- a/src/ld/parsers/meson.build 82 + +++ b/src/ld/parsers/meson.build 83 + @@ -1,3 +1,14 @@ 84 + +lto_file_cpp = configure_file( 85 + + configuration : { 86 + + 'libllvm_path' : get_option('libllvm_path'), 87 + + # Silence warnings 88 + + 'APPLE_LICENSE_HEADER_START' : '@APPLE_LICENSE_HEADER_START@', 89 + + 'APPLE_LICENSE_HEADER_END' : '@APPLE_LICENSE_HEADER_END@', 90 + + }, 91 + + input : 'lto_file.cpp', 92 + + output : '@PLAINNAME@', 93 + +) 94 + + 95 + parsers = static_library( 96 + 'parsers', 97 + cpp_args : [ '-Wno-vla-cxx-extension' ], 98 + @@ -10,9 +21,9 @@ parsers = static_library( 99 + ], 100 + sources : [ 101 + configure_h, 102 + + lto_file_cpp, 103 + 'archive_file.cpp', 104 + 'generic_dylib_file.cpp', 105 + - 'lto_file.cpp', 106 + 'macho_dylib_file.cpp', 107 + 'macho_relocatable_file.cpp', 108 + 'opaque_section_file.cpp', 109 + -- 110 + 2.47.2 111 +
+97
pkgs/by-name/ld/ld64/patches/0010-Add-vendored-libtapi-to-the-ld64-build.patch
···
··· 1 + From 2846b56c7e1d88942bd3de96cbe3fec6b0304012 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 10/18] Add vendored libtapi to the ld64 build 5 + 6 + --- 7 + meson.build | 3 +- 8 + subprojects/libtapi/meson.build | 44 ++++++++++++++++++++++++++++ 9 + subprojects/libtapi/tapi/meson.build | 11 +++++++ 10 + 3 files changed, 57 insertions(+), 1 deletion(-) 11 + create mode 100644 subprojects/libtapi/meson.build 12 + create mode 100644 subprojects/libtapi/tapi/meson.build 13 + 14 + diff --git a/meson.build b/meson.build 15 + index a79f03f..244458c 100644 16 + --- a/meson.build 17 + +++ b/meson.build 18 + @@ -26,7 +26,8 @@ libcodedirectory_dep = dependency( 19 + ) 20 + libtapi_dep = dependency( 21 + 'libtapi', 22 + - version : [ '>=1500' , '<1600' ], 23 + + version : [ '>=1600' , '<1700' ], 24 + + fallback : [ 'libtapi', 'libtapi_dep' ], 25 + ) 26 + llvm_dep = dependency( 27 + 'llvm', 28 + diff --git a/subprojects/libtapi/meson.build b/subprojects/libtapi/meson.build 29 + new file mode 100644 30 + index 0000000..9cd1dcc 31 + --- /dev/null 32 + +++ b/subprojects/libtapi/meson.build 33 + @@ -0,0 +1,44 @@ 34 + +project( 35 + + 'libtapi', 36 + + 'c', 'cpp', 37 + + default_options : {'c_std': 'c23', 'cpp_std': 'c++23'}, 38 + + license : 'NCSA', 39 + + license_files : 'LICENSE.TXT', 40 + + meson_version : '>=1.6.0', 41 + + version : '1600.0.11.8', 42 + +) 43 + + 44 + + 45 + +cc = meson.get_compiler('c') 46 + +cxx = meson.get_compiler('cpp') 47 + + 48 + +# libtapi only needs a subset of functionality from LLVM, so link only what it needs statically 49 + +# to avoid ODR violations when loading LTO plugins (which don’t use these APIs). 50 + +llvm_dep = dependency( 51 + + 'llvm', 52 + + modules : [ 53 + + 'Demangle', 54 + + 'TargetParser', 55 + + 'TextAPI', 56 + + ], 57 + + static : true, 58 + + version : '>=19.1' 59 + +) 60 + + 61 + + 62 + +subdir('tapi') 63 + + 64 + +libtapi = static_library( 65 + + 'tapi', 66 + + sources : [ 67 + + 'APIVersion.cpp', 68 + + 'LinkerInterfaceFile.cpp', 69 + + 'Version.cpp', 70 + + ], 71 + +) 72 + + 73 + +libtapi_dep = declare_dependency( 74 + + dependencies : [ llvm_dep ], 75 + + include_directories : [ '.' ], 76 + + link_with : libtapi, 77 + +) 78 + diff --git a/subprojects/libtapi/tapi/meson.build b/subprojects/libtapi/tapi/meson.build 79 + new file mode 100644 80 + index 0000000..c9e463a 81 + --- /dev/null 82 + +++ b/subprojects/libtapi/tapi/meson.build 83 + @@ -0,0 +1,11 @@ 84 + +version_components = meson.project_version().split('.') 85 + +version_inc = configure_file( 86 + + configuration : { 87 + + 'TAPI_VERSION' : meson.project_version(), 88 + + 'TAPI_VERSION_MAJOR' : version_components[0], 89 + + 'TAPI_VERSION_MINOR' : version_components[1], 90 + + 'TAPI_VERSION_PATCH' : version_components[2], 91 + + }, 92 + + input : 'Version.inc.in', 93 + + output : '@BASENAME@', 94 + +) 95 + -- 96 + 2.47.2 97 +
+120
pkgs/by-name/ld/ld64/patches/0011-Modify-vendored-libtapi-to-build-with-upstream-LLVM.patch
···
··· 1 + From ef6039563489695e2593f0c156d13b01491d2644 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 11/18] Modify vendored libtapi to build with upstream LLVM 5 + 6 + --- 7 + subprojects/libtapi/LinkerInterfaceFile.cpp | 47 +++++++++------------ 8 + 1 file changed, 21 insertions(+), 26 deletions(-) 9 + 10 + diff --git a/subprojects/libtapi/LinkerInterfaceFile.cpp b/subprojects/libtapi/LinkerInterfaceFile.cpp 11 + index 76797e3..632eac8 100644 12 + --- a/subprojects/libtapi/LinkerInterfaceFile.cpp 13 + +++ b/subprojects/libtapi/LinkerInterfaceFile.cpp 14 + @@ -10,12 +10,12 @@ 15 + /// \brief Implements the C++ linker interface file API. 16 + /// 17 + //===----------------------------------------------------------------------===// 18 + -#include "tapi/Core/LLVM.h" 19 + -#include "tapi/Core/Registry.h" 20 + -#include "tapi/Core/Utils.h" 21 + -#include "llvm/ADT/StringExtras.h" 22 + -#include "llvm/Object/MachO.h" 23 + -#include "llvm/TextAPI/InterfaceFile.h" 24 + +#include <llvm/ADT/StringExtras.h> 25 + +#include <llvm/Object/MachO.h> 26 + +#include <llvm/Support/Process.h> 27 + +#include <llvm/TextAPI/InterfaceFile.h> 28 + +#include <llvm/TextAPI/TextAPIReader.h> 29 + +#include <llvm/TextAPI/Utils.h> 30 + #include <string> 31 + #include <tapi/LinkerInterfaceFile.h> 32 + #include <tapi/PackedVersion32.h> 33 + @@ -27,10 +27,17 @@ using namespace llvm::MachO; 34 + 35 + TAPI_NAMESPACE_V1_BEGIN 36 + 37 + -using namespace tapi::internal; 38 + using InterfaceFile = llvm::MachO::InterfaceFile; 39 + using PackedVersion = llvm::MachO::PackedVersion; 40 + 41 + +/// Determine if tapi is running in a B&I context. 42 + +static inline bool inBnIEnvironment() { 43 + + if (auto isBnI = llvm::sys::Process::GetEnv("RC_XBS")) 44 + + return (isBnI.value() == "YES") && 45 + + (!llvm::sys::Process::GetEnv("RC_BUILDIT")); 46 + + return false; 47 + +} 48 + + 49 + static PackedVersion parseVersion32(StringRef str) { 50 + uint32_t version = 0; 51 + if (str.empty()) 52 + @@ -118,7 +125,7 @@ public: 53 + void processSymbol(StringRef name, PackedVersion minOSVersion, 54 + bool disallowWeakImports) { 55 + // $ld$ <action> $ <condition> $ <symbol-name> 56 + - if (!name.startswith("$ld$")) 57 + + if (!name.starts_with("$ld$")) 58 + return; 59 + 60 + StringRef action, condition, symbolName; 61 + @@ -127,7 +134,7 @@ public: 62 + if (action.empty() || condition.empty() || symbolName.empty()) 63 + return; 64 + 65 + - if (!condition.startswith("os")) 66 + + if (!condition.starts_with("os")) 67 + return; 68 + 69 + auto version = parseVersion32(condition.drop_front(2)); 70 + @@ -198,33 +205,21 @@ LinkerInterfaceFile::getSupportedFileExtensions() noexcept { 71 + /// \brief Load and parse the provided TBD file in the buffer and return on 72 + /// success the interface file. 73 + static Expected<std::unique_ptr<const InterfaceFile>> 74 + -loadFile(std::unique_ptr<MemoryBuffer> buffer, 75 + - ReadFlags readFlags = ReadFlags::Symbols) { 76 + - Registry registry; 77 + - registry.addYAMLReaders(); 78 + - registry.addJSONReaders(); 79 + - registry.addDiagnosticReader(); 80 + - 81 + - auto textFile = registry.readTextFile(std::move(buffer), readFlags); 82 + +loadFile(std::unique_ptr<MemoryBuffer> buffer) { 83 + + auto textFile = llvm::MachO::TextAPIReader::get(buffer->getMemBufferRef()); 84 + if (!textFile) 85 + return textFile.takeError(); 86 + 87 + return std::unique_ptr<const InterfaceFile>( 88 + cast<const InterfaceFile>(textFile.get().release())); 89 + - 90 + - return std::make_unique<const InterfaceFile>(InterfaceFile()); 91 + } 92 + 93 + bool LinkerInterfaceFile::isSupported(const std::string &path, 94 + const uint8_t *data, 95 + size_t size) noexcept { 96 + - Registry registry; 97 + - registry.addYAMLReaders(); 98 + - registry.addJSONReaders(); 99 + - registry.addDiagnosticReader(); 100 + auto memBuffer = MemoryBufferRef( 101 + StringRef(reinterpret_cast<const char *>(data), size), path); 102 + - return registry.canRead(memBuffer); 103 + + return !!llvm::MachO::TextAPIReader::canRead(memBuffer); 104 + } 105 + 106 + bool LinkerInterfaceFile::shouldPreferTextBasedStubFile( 107 + @@ -316,8 +311,8 @@ bool LinkerInterfaceFile::Impl::init( 108 + 109 + switch (symbol->getKind()) { 110 + case EncodeKind::GlobalSymbol: 111 + - if (symbol->getName().startswith("$ld$") && 112 + - !symbol->getName().startswith("$ld$previous")) 113 + + if (symbol->getName().starts_with("$ld$") && 114 + + !symbol->getName().starts_with("$ld$previous")) 115 + continue; 116 + addSymbol(symbol->getName(), symbol->getFlags()); 117 + break; 118 + -- 119 + 2.47.2 120 +
+471
pkgs/by-name/ld/ld64/patches/0012-Move-libcodedirectory-to-its-own-subproject.patch
···
··· 1 + From 4f186ca22f34cda1cbdea131a15f2bc79db440ba Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 12/18] Move libcodedirectory to its own subproject 5 + 6 + --- 7 + meson.build | 1 + 8 + src/ld/meson.build | 1 - 9 + subprojects/libcodedirectory/APPLE_LICENSE | 367 ++++++++++++++++++ 10 + .../libcodedirectory}/cs_blobs.h | 0 11 + .../libcodedirectory}/libcodedirectory.c | 0 12 + .../libcodedirectory}/libcodedirectory.h | 0 13 + subprojects/libcodedirectory/meson.build | 33 ++ 14 + 7 files changed, 401 insertions(+), 1 deletion(-) 15 + create mode 100644 subprojects/libcodedirectory/APPLE_LICENSE 16 + rename {src/ld => subprojects/libcodedirectory}/cs_blobs.h (100%) 17 + rename {src/ld => subprojects/libcodedirectory}/libcodedirectory.c (100%) 18 + rename {src/ld => subprojects/libcodedirectory}/libcodedirectory.h (100%) 19 + create mode 100644 subprojects/libcodedirectory/meson.build 20 + 21 + diff --git a/meson.build b/meson.build 22 + index 244458c..c053d20 100644 23 + --- a/meson.build 24 + +++ b/meson.build 25 + @@ -23,6 +23,7 @@ cxx = meson.get_compiler('cpp') 26 + libcodedirectory_dep = dependency( 27 + 'libcodedirectory', 28 + version : '=819.6.1', 29 + + fallback : [ 'libcodedirectory', 'libcodedirectory_dep' ], 30 + ) 31 + libtapi_dep = dependency( 32 + 'libtapi', 33 + diff --git a/src/ld/meson.build b/src/ld/meson.build 34 + index ad8359a..201e891 100644 35 + --- a/src/ld/meson.build 36 + +++ b/src/ld/meson.build 37 + @@ -56,7 +56,6 @@ executable( 38 + 'code-sign-blobs/blob.h', 39 + 'debugline.c', 40 + 'ld.cpp', 41 + - 'libcodedirectory.c', 42 + 'passes/bitcode_bundle.cpp', 43 + 'passes/branch_island.cpp', 44 + 'passes/branch_shim.cpp', 45 + diff --git a/subprojects/libcodedirectory/APPLE_LICENSE b/subprojects/libcodedirectory/APPLE_LICENSE 46 + new file mode 100644 47 + index 0000000..fe81a60 48 + --- /dev/null 49 + +++ b/subprojects/libcodedirectory/APPLE_LICENSE 50 + @@ -0,0 +1,367 @@ 51 + +APPLE PUBLIC SOURCE LICENSE 52 + +Version 2.0 - August 6, 2003 53 + + 54 + +Please read this License carefully before downloading this software. 55 + +By downloading or using this software, you are agreeing to be bound by 56 + +the terms of this License. If you do not or cannot agree to the terms 57 + +of this License, please do not download or use the software. 58 + + 59 + +1. General; Definitions. This License applies to any program or other 60 + +work which Apple Computer, Inc. ("Apple") makes publicly available and 61 + +which contains a notice placed by Apple identifying such program or 62 + +work as "Original Code" and stating that it is subject to the terms of 63 + +this Apple Public Source License version 2.0 ("License"). As used in 64 + +this License: 65 + + 66 + +1.1 "Applicable Patent Rights" mean: (a) in the case where Apple is 67 + +the grantor of rights, (i) claims of patents that are now or hereafter 68 + +acquired, owned by or assigned to Apple and (ii) that cover subject 69 + +matter contained in the Original Code, but only to the extent 70 + +necessary to use, reproduce and/or distribute the Original Code 71 + +without infringement; and (b) in the case where You are the grantor of 72 + +rights, (i) claims of patents that are now or hereafter acquired, 73 + +owned by or assigned to You and (ii) that cover subject matter in Your 74 + +Modifications, taken alone or in combination with Original Code. 75 + + 76 + +1.2 "Contributor" means any person or entity that creates or 77 + +contributes to the creation of Modifications. 78 + + 79 + +1.3 "Covered Code" means the Original Code, Modifications, the 80 + +combination of Original Code and any Modifications, and/or any 81 + +respective portions thereof. 82 + + 83 + +1.4 "Externally Deploy" means: (a) to sublicense, distribute or 84 + +otherwise make Covered Code available, directly or indirectly, to 85 + +anyone other than You; and/or (b) to use Covered Code, alone or as 86 + +part of a Larger Work, in any way to provide a service, including but 87 + +not limited to delivery of content, through electronic communication 88 + +with a client other than You. 89 + + 90 + +1.5 "Larger Work" means a work which combines Covered Code or portions 91 + +thereof with code not governed by the terms of this License. 92 + + 93 + +1.6 "Modifications" mean any addition to, deletion from, and/or change 94 + +to, the substance and/or structure of the Original Code, any previous 95 + +Modifications, the combination of Original Code and any previous 96 + +Modifications, and/or any respective portions thereof. When code is 97 + +released as a series of files, a Modification is: (a) any addition to 98 + +or deletion from the contents of a file containing Covered Code; 99 + +and/or (b) any new file or other representation of computer program 100 + +statements that contains any part of Covered Code. 101 + + 102 + +1.7 "Original Code" means (a) the Source Code of a program or other 103 + +work as originally made available by Apple under this License, 104 + +including the Source Code of any updates or upgrades to such programs 105 + +or works made available by Apple under this License, and that has been 106 + +expressly identified by Apple as such in the header file(s) of such 107 + +work; and (b) the object code compiled from such Source Code and 108 + +originally made available by Apple under this License. 109 + + 110 + +1.8 "Source Code" means the human readable form of a program or other 111 + +work that is suitable for making modifications to it, including all 112 + +modules it contains, plus any associated interface definition files, 113 + +scripts used to control compilation and installation of an executable 114 + +(object code). 115 + + 116 + +1.9 "You" or "Your" means an individual or a legal entity exercising 117 + +rights under this License. For legal entities, "You" or "Your" 118 + +includes any entity which controls, is controlled by, or is under 119 + +common control with, You, where "control" means (a) the power, direct 120 + +or indirect, to cause the direction or management of such entity, 121 + +whether by contract or otherwise, or (b) ownership of fifty percent 122 + +(50%) or more of the outstanding shares or beneficial ownership of 123 + +such entity. 124 + + 125 + +2. Permitted Uses; Conditions & Restrictions. Subject to the terms 126 + +and conditions of this License, Apple hereby grants You, effective on 127 + +the date You accept this License and download the Original Code, a 128 + +world-wide, royalty-free, non-exclusive license, to the extent of 129 + +Apple's Applicable Patent Rights and copyrights covering the Original 130 + +Code, to do the following: 131 + + 132 + +2.1 Unmodified Code. You may use, reproduce, display, perform, 133 + +internally distribute within Your organization, and Externally Deploy 134 + +verbatim, unmodified copies of the Original Code, for commercial or 135 + +non-commercial purposes, provided that in each instance: 136 + + 137 + +(a) You must retain and reproduce in all copies of Original Code the 138 + +copyright and other proprietary notices and disclaimers of Apple as 139 + +they appear in the Original Code, and keep intact all notices in the 140 + +Original Code that refer to this License; and 141 + + 142 + +(b) You must include a copy of this License with every copy of Source 143 + +Code of Covered Code and documentation You distribute or Externally 144 + +Deploy, and You may not offer or impose any terms on such Source Code 145 + +that alter or restrict this License or the recipients' rights 146 + +hereunder, except as permitted under Section 6. 147 + + 148 + +2.2 Modified Code. You may modify Covered Code and use, reproduce, 149 + +display, perform, internally distribute within Your organization, and 150 + +Externally Deploy Your Modifications and Covered Code, for commercial 151 + +or non-commercial purposes, provided that in each instance You also 152 + +meet all of these conditions: 153 + + 154 + +(a) You must satisfy all the conditions of Section 2.1 with respect to 155 + +the Source Code of the Covered Code; 156 + + 157 + +(b) You must duplicate, to the extent it does not already exist, the 158 + +notice in Exhibit A in each file of the Source Code of all Your 159 + +Modifications, and cause the modified files to carry prominent notices 160 + +stating that You changed the files and the date of any change; and 161 + + 162 + +(c) If You Externally Deploy Your Modifications, You must make 163 + +Source Code of all Your Externally Deployed Modifications either 164 + +available to those to whom You have Externally Deployed Your 165 + +Modifications, or publicly available. Source Code of Your Externally 166 + +Deployed Modifications must be released under the terms set forth in 167 + +this License, including the license grants set forth in Section 3 168 + +below, for as long as you Externally Deploy the Covered Code or twelve 169 + +(12) months from the date of initial External Deployment, whichever is 170 + +longer. You should preferably distribute the Source Code of Your 171 + +Externally Deployed Modifications electronically (e.g. download from a 172 + +web site). 173 + + 174 + +2.3 Distribution of Executable Versions. In addition, if You 175 + +Externally Deploy Covered Code (Original Code and/or Modifications) in 176 + +object code, executable form only, You must include a prominent 177 + +notice, in the code itself as well as in related documentation, 178 + +stating that Source Code of the Covered Code is available under the 179 + +terms of this License with information on how and where to obtain such 180 + +Source Code. 181 + + 182 + +2.4 Third Party Rights. You expressly acknowledge and agree that 183 + +although Apple and each Contributor grants the licenses to their 184 + +respective portions of the Covered Code set forth herein, no 185 + +assurances are provided by Apple or any Contributor that the Covered 186 + +Code does not infringe the patent or other intellectual property 187 + +rights of any other entity. Apple and each Contributor disclaim any 188 + +liability to You for claims brought by any other entity based on 189 + +infringement of intellectual property rights or otherwise. As a 190 + +condition to exercising the rights and licenses granted hereunder, You 191 + +hereby assume sole responsibility to secure any other intellectual 192 + +property rights needed, if any. For example, if a third party patent 193 + +license is required to allow You to distribute the Covered Code, it is 194 + +Your responsibility to acquire that license before distributing the 195 + +Covered Code. 196 + + 197 + +3. Your Grants. In consideration of, and as a condition to, the 198 + +licenses granted to You under this License, You hereby grant to any 199 + +person or entity receiving or distributing Covered Code under this 200 + +License a non-exclusive, royalty-free, perpetual, irrevocable license, 201 + +under Your Applicable Patent Rights and other intellectual property 202 + +rights (other than patent) owned or controlled by You, to use, 203 + +reproduce, display, perform, modify, sublicense, distribute and 204 + +Externally Deploy Your Modifications of the same scope and extent as 205 + +Apple's licenses under Sections 2.1 and 2.2 above. 206 + + 207 + +4. Larger Works. You may create a Larger Work by combining Covered 208 + +Code with other code not governed by the terms of this License and 209 + +distribute the Larger Work as a single product. In each such instance, 210 + +You must make sure the requirements of this License are fulfilled for 211 + +the Covered Code or any portion thereof. 212 + + 213 + +5. Limitations on Patent License. Except as expressly stated in 214 + +Section 2, no other patent rights, express or implied, are granted by 215 + +Apple herein. Modifications and/or Larger Works may require additional 216 + +patent licenses from Apple which Apple may grant in its sole 217 + +discretion. 218 + + 219 + +6. Additional Terms. You may choose to offer, and to charge a fee for, 220 + +warranty, support, indemnity or liability obligations and/or other 221 + +rights consistent with the scope of the license granted herein 222 + +("Additional Terms") to one or more recipients of Covered Code. 223 + +However, You may do so only on Your own behalf and as Your sole 224 + +responsibility, and not on behalf of Apple or any Contributor. You 225 + +must obtain the recipient's agreement that any such Additional Terms 226 + +are offered by You alone, and You hereby agree to indemnify, defend 227 + +and hold Apple and every Contributor harmless for any liability 228 + +incurred by or claims asserted against Apple or such Contributor by 229 + +reason of any such Additional Terms. 230 + + 231 + +7. Versions of the License. Apple may publish revised and/or new 232 + +versions of this License from time to time. Each version will be given 233 + +a distinguishing version number. Once Original Code has been published 234 + +under a particular version of this License, You may continue to use it 235 + +under the terms of that version. You may also choose to use such 236 + +Original Code under the terms of any subsequent version of this 237 + +License published by Apple. No one other than Apple has the right to 238 + +modify the terms applicable to Covered Code created under this 239 + +License. 240 + + 241 + +8. NO WARRANTY OR SUPPORT. The Covered Code may contain in whole or in 242 + +part pre-release, untested, or not fully tested works. The Covered 243 + +Code may contain errors that could cause failures or loss of data, and 244 + +may be incomplete or contain inaccuracies. You expressly acknowledge 245 + +and agree that use of the Covered Code, or any portion thereof, is at 246 + +Your sole and entire risk. THE COVERED CODE IS PROVIDED "AS IS" AND 247 + +WITHOUT WARRANTY, UPGRADES OR SUPPORT OF ANY KIND AND APPLE AND 248 + +APPLE'S LICENSOR(S) (COLLECTIVELY REFERRED TO AS "APPLE" FOR THE 249 + +PURPOSES OF SECTIONS 8 AND 9) AND ALL CONTRIBUTORS EXPRESSLY DISCLAIM 250 + +ALL WARRANTIES AND/OR CONDITIONS, EXPRESS OR IMPLIED, INCLUDING, BUT 251 + +NOT LIMITED TO, THE IMPLIED WARRANTIES AND/OR CONDITIONS OF 252 + +MERCHANTABILITY, OF SATISFACTORY QUALITY, OF FITNESS FOR A PARTICULAR 253 + +PURPOSE, OF ACCURACY, OF QUIET ENJOYMENT, AND NONINFRINGEMENT OF THIRD 254 + +PARTY RIGHTS. APPLE AND EACH CONTRIBUTOR DOES NOT WARRANT AGAINST 255 + +INTERFERENCE WITH YOUR ENJOYMENT OF THE COVERED CODE, THAT THE 256 + +FUNCTIONS CONTAINED IN THE COVERED CODE WILL MEET YOUR REQUIREMENTS, 257 + +THAT THE OPERATION OF THE COVERED CODE WILL BE UNINTERRUPTED OR 258 + +ERROR-FREE, OR THAT DEFECTS IN THE COVERED CODE WILL BE CORRECTED. NO 259 + +ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY APPLE, AN APPLE 260 + +AUTHORIZED REPRESENTATIVE OR ANY CONTRIBUTOR SHALL CREATE A WARRANTY. 261 + +You acknowledge that the Covered Code is not intended for use in the 262 + +operation of nuclear facilities, aircraft navigation, communication 263 + +systems, or air traffic control machines in which case the failure of 264 + +the Covered Code could lead to death, personal injury, or severe 265 + +physical or environmental damage. 266 + + 267 + +9. LIMITATION OF LIABILITY. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO 268 + +EVENT SHALL APPLE OR ANY CONTRIBUTOR BE LIABLE FOR ANY INCIDENTAL, 269 + +SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING 270 + +TO THIS LICENSE OR YOUR USE OR INABILITY TO USE THE COVERED CODE, OR 271 + +ANY PORTION THEREOF, WHETHER UNDER A THEORY OF CONTRACT, WARRANTY, 272 + +TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, EVEN IF 273 + +APPLE OR SUCH CONTRIBUTOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 274 + +DAMAGES AND NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OF ANY 275 + +REMEDY. SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OF LIABILITY OF 276 + +INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT APPLY 277 + +TO YOU. In no event shall Apple's total liability to You for all 278 + +damages (other than as may be required by applicable law) under this 279 + +License exceed the amount of fifty dollars ($50.00). 280 + + 281 + +10. Trademarks. This License does not grant any rights to use the 282 + +trademarks or trade names "Apple", "Apple Computer", "Mac", "Mac OS", 283 + +"QuickTime", "QuickTime Streaming Server" or any other trademarks, 284 + +service marks, logos or trade names belonging to Apple (collectively 285 + +"Apple Marks") or to any trademark, service mark, logo or trade name 286 + +belonging to any Contributor. You agree not to use any Apple Marks in 287 + +or as part of the name of products derived from the Original Code or 288 + +to endorse or promote products derived from the Original Code other 289 + +than as expressly permitted by and in strict compliance at all times 290 + +with Apple's third party trademark usage guidelines which are posted 291 + +at http://www.apple.com/legal/guidelinesfor3rdparties.html. 292 + + 293 + +11. Ownership. Subject to the licenses granted under this License, 294 + +each Contributor retains all rights, title and interest in and to any 295 + +Modifications made by such Contributor. Apple retains all rights, 296 + +title and interest in and to the Original Code and any Modifications 297 + +made by or on behalf of Apple ("Apple Modifications"), and such Apple 298 + +Modifications will not be automatically subject to this License. Apple 299 + +may, at its sole discretion, choose to license such Apple 300 + +Modifications under this License, or on different terms from those 301 + +contained in this License or may choose not to license them at all. 302 + + 303 + +12. Termination. 304 + + 305 + +12.1 Termination. This License and the rights granted hereunder will 306 + +terminate: 307 + + 308 + +(a) automatically without notice from Apple if You fail to comply with 309 + +any term(s) of this License and fail to cure such breach within 30 310 + +days of becoming aware of such breach; 311 + + 312 + +(b) immediately in the event of the circumstances described in Section 313 + +13.5(b); or 314 + + 315 + +(c) automatically without notice from Apple if You, at any time during 316 + +the term of this License, commence an action for patent infringement 317 + +against Apple; provided that Apple did not first commence 318 + +an action for patent infringement against You in that instance. 319 + + 320 + +12.2 Effect of Termination. Upon termination, You agree to immediately 321 + +stop any further use, reproduction, modification, sublicensing and 322 + +distribution of the Covered Code. All sublicenses to the Covered Code 323 + +which have been properly granted prior to termination shall survive 324 + +any termination of this License. Provisions which, by their nature, 325 + +should remain in effect beyond the termination of this License shall 326 + +survive, including but not limited to Sections 3, 5, 8, 9, 10, 11, 327 + +12.2 and 13. No party will be liable to any other for compensation, 328 + +indemnity or damages of any sort solely as a result of terminating 329 + +this License in accordance with its terms, and termination of this 330 + +License will be without prejudice to any other right or remedy of 331 + +any party. 332 + + 333 + +13. Miscellaneous. 334 + + 335 + +13.1 Government End Users. The Covered Code is a "commercial item" as 336 + +defined in FAR 2.101. Government software and technical data rights in 337 + +the Covered Code include only those rights customarily provided to the 338 + +public as defined in this License. This customary commercial license 339 + +in technical data and software is provided in accordance with FAR 340 + +12.211 (Technical Data) and 12.212 (Computer Software) and, for 341 + +Department of Defense purchases, DFAR 252.227-7015 (Technical Data -- 342 + +Commercial Items) and 227.7202-3 (Rights in Commercial Computer 343 + +Software or Computer Software Documentation). Accordingly, all U.S. 344 + +Government End Users acquire Covered Code with only those rights set 345 + +forth herein. 346 + + 347 + +13.2 Relationship of Parties. This License will not be construed as 348 + +creating an agency, partnership, joint venture or any other form of 349 + +legal association between or among You, Apple or any Contributor, and 350 + +You will not represent to the contrary, whether expressly, by 351 + +implication, appearance or otherwise. 352 + + 353 + +13.3 Independent Development. Nothing in this License will impair 354 + +Apple's right to acquire, license, develop, have others develop for 355 + +it, market and/or distribute technology or products that perform the 356 + +same or similar functions as, or otherwise compete with, 357 + +Modifications, Larger Works, technology or products that You may 358 + +develop, produce, market or distribute. 359 + + 360 + +13.4 Waiver; Construction. Failure by Apple or any Contributor to 361 + +enforce any provision of this License will not be deemed a waiver of 362 + +future enforcement of that or any other provision. Any law or 363 + +regulation which provides that the language of a contract shall be 364 + +construed against the drafter will not apply to this License. 365 + + 366 + +13.5 Severability. (a) If for any reason a court of competent 367 + +jurisdiction finds any provision of this License, or portion thereof, 368 + +to be unenforceable, that provision of the License will be enforced to 369 + +the maximum extent permissible so as to effect the economic benefits 370 + +and intent of the parties, and the remainder of this License will 371 + +continue in full force and effect. (b) Notwithstanding the foregoing, 372 + +if applicable law prohibits or restricts You from fully and/or 373 + +specifically complying with Sections 2 and/or 3 or prevents the 374 + +enforceability of either of those Sections, this License will 375 + +immediately terminate and You must immediately discontinue any use of 376 + +the Covered Code and destroy all copies of it that are in your 377 + +possession or control. 378 + + 379 + +13.6 Dispute Resolution. Any litigation or other dispute resolution 380 + +between You and Apple relating to this License shall take place in the 381 + +Northern District of California, and You and Apple hereby consent to 382 + +the personal jurisdiction of, and venue in, the state and federal 383 + +courts within that District with respect to this License. The 384 + +application of the United Nations Convention on Contracts for the 385 + +International Sale of Goods is expressly excluded. 386 + + 387 + +13.7 Entire Agreement; Governing Law. This License constitutes the 388 + +entire agreement between the parties with respect to the subject 389 + +matter hereof. This License shall be governed by the laws of the 390 + +United States and the State of California, except that body of 391 + +California law concerning conflicts of law. 392 + + 393 + +Where You are located in the province of Quebec, Canada, the following 394 + +clause applies: The parties hereby confirm that they have requested 395 + +that this License and all related documents be drafted in English. Les 396 + +parties ont exige que le present contrat et tous les documents 397 + +connexes soient rediges en anglais. 398 + + 399 + +EXHIBIT A. 400 + + 401 + +"Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights 402 + +Reserved. 403 + + 404 + +This file contains Original Code and/or Modifications of Original Code 405 + +as defined in and that are subject to the Apple Public Source License 406 + +Version 2.0 (the 'License'). You may not use this file except in 407 + +compliance with the License. Please obtain a copy of the License at 408 + +http://www.opensource.apple.com/apsl/ and read it before using this 409 + +file. 410 + + 411 + +The Original Code and all software distributed under the License are 412 + +distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 413 + +EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 414 + +INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 415 + +FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 416 + +Please see the License for the specific language governing rights and 417 + +limitations under the License." 418 + diff --git a/src/ld/cs_blobs.h b/subprojects/libcodedirectory/cs_blobs.h 419 + similarity index 100% 420 + rename from src/ld/cs_blobs.h 421 + rename to subprojects/libcodedirectory/cs_blobs.h 422 + diff --git a/src/ld/libcodedirectory.c b/subprojects/libcodedirectory/libcodedirectory.c 423 + similarity index 100% 424 + rename from src/ld/libcodedirectory.c 425 + rename to subprojects/libcodedirectory/libcodedirectory.c 426 + diff --git a/src/ld/libcodedirectory.h b/subprojects/libcodedirectory/libcodedirectory.h 427 + similarity index 100% 428 + rename from src/ld/libcodedirectory.h 429 + rename to subprojects/libcodedirectory/libcodedirectory.h 430 + diff --git a/subprojects/libcodedirectory/meson.build b/subprojects/libcodedirectory/meson.build 431 + new file mode 100644 432 + index 0000000..de8a4ae 433 + --- /dev/null 434 + +++ b/subprojects/libcodedirectory/meson.build 435 + @@ -0,0 +1,33 @@ 436 + +project( 437 + + 'libcodedirectory', 438 + + 'c', 439 + + default_options : {'c_std': 'c23'}, 440 + + license : 'APSL-2.0', 441 + + license_files : 'APPLE_LICENSE', 442 + + meson_version : '>=1.6.0', 443 + + version : '819.6.1', 444 + +) 445 + + 446 + + 447 + +cc = meson.get_compiler('c') 448 + + 449 + +openssl_dep = dependency('openssl', version : '>=3.0') 450 + + 451 + + 452 + +libcodedirectory = library( 453 + + 'codedirectory', 454 + + c_args : [ '-Wno-gnu-folding-constant' ], 455 + + dependencies : [ openssl_dep ], 456 + + install : true, 457 + + sources : [ 'libcodedirectory.c' ], 458 + + soversion : 1, 459 + +) 460 + +install_headers( 461 + + 'cs_blobs.h', 462 + + 'libcodedirectory.h', 463 + +) 464 + + 465 + +libcodedirectory_dep = declare_dependency( 466 + + include_directories : [ '.' ], 467 + + link_with : libcodedirectory, 468 + +) 469 + -- 470 + 2.47.2 471 +
+41
pkgs/by-name/ld/ld64/patches/0013-Set-the-version-string-in-the-build.patch
···
··· 1 + From fb1ec0eeac424d72175b14b08da9c2d85681b245 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Sun, 17 Nov 2024 10:02:34 -0500 4 + Subject: [PATCH 13/18] Set the version string in the build 5 + 6 + --- 7 + src/ld/meson.build | 11 +++++++++++ 8 + 1 file changed, 11 insertions(+) 9 + 10 + diff --git a/src/ld/meson.build b/src/ld/meson.build 11 + index 201e891..769ac28 100644 12 + --- a/src/ld/meson.build 13 + +++ b/src/ld/meson.build 14 + @@ -11,6 +11,16 @@ InputFiles_cpp = configure_file( 15 + output : '@PLAINNAME@', 16 + ) 17 + 18 + +version_string_cpp = configure_file( 19 + + capture : true, 20 + + command : [ 21 + + find_program('bash', native : true), 22 + + '-c', 23 + + 'echo \'extern const char ld_classicVersionString[] = "@(#)PROGRAM:ld PROJECT:ld64-' + meson.project_version() + '\\n";\'' 24 + + ], 25 + + output : 'version_string.cpp', 26 + +) 27 + + 28 + executable( 29 + 'ld', 30 + cpp_args : [ 31 + @@ -43,6 +53,7 @@ executable( 32 + sources : [ 33 + configure_h, 34 + InputFiles_cpp, 35 + + version_string_cpp, 36 + 'FatFile.cpp', 37 + 'Mangling.cpp', 38 + 'Options.cpp', 39 + -- 40 + 2.47.2 41 +
+341
pkgs/by-name/ld/ld64/patches/0014-Replace-corecrypto-and-CommonCrypto-with-OpenSSL.patch
···
··· 1 + From b2cfb2019b79e674a507a8b428bba4b82b2276d0 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 14/18] Replace corecrypto and CommonCrypto with OpenSSL 5 + 6 + --- 7 + src/ld/LinkEdit.hpp | 2 - 8 + src/ld/OutputFile.cpp | 78 ++++++++++++---- 9 + subprojects/libcodedirectory/cs_blobs.h | 1 + 10 + .../libcodedirectory/libcodedirectory.c | 90 +++++++++++++------ 11 + 4 files changed, 126 insertions(+), 45 deletions(-) 12 + 13 + diff --git a/src/ld/LinkEdit.hpp b/src/ld/LinkEdit.hpp 14 + index 4a6d5fe..818fcdf 100644 15 + --- a/src/ld/LinkEdit.hpp 16 + +++ b/src/ld/LinkEdit.hpp 17 + @@ -30,8 +30,6 @@ 18 + #include <errno.h> 19 + #include <limits.h> 20 + #include <unistd.h> 21 + -#include <CommonCrypto/CommonDigest.h> 22 + -#include <CommonCrypto/CommonDigestSPI.h> 23 + 24 + #include <vector> 25 + #include <unordered_map> 26 + diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp 27 + index 2a175a7..69b476f 100644 28 + --- a/src/ld/OutputFile.cpp 29 + +++ b/src/ld/OutputFile.cpp 30 + @@ -43,10 +43,6 @@ 31 + #include <mach-o/dyld.h> 32 + #include <mach-o/fat.h> 33 + #include <dispatch/dispatch.h> 34 + -#include <os/lock_private.h> 35 + -extern "C" { 36 + - #include <corecrypto/ccsha2.h> 37 + -} 38 + 39 + #include <mutex> 40 + #include <string> 41 + @@ -56,9 +52,10 @@ extern "C" { 42 + #include <iostream> 43 + #include <fstream> 44 + 45 + -#include <CommonCrypto/CommonDigest.h> 46 + #include <AvailabilityMacros.h> 47 + 48 + +#include <openssl/err.h> 49 + +#include <openssl/evp.h> 50 + 51 + #include "ExportsTrie.h" 52 + 53 + @@ -79,6 +76,17 @@ uint32_t sAdrpNA = 0; 54 + uint32_t sAdrpNoped = 0; 55 + uint32_t sAdrpNotNoped = 0; 56 + 57 + +static void 58 + +EVP_MD_cleanup(EVP_MD** digest) { 59 + + EVP_MD_free(*digest); 60 + + *digest = nullptr; 61 + +} 62 + + 63 + +static void 64 + +EVP_MD_CTX_cleanup(EVP_MD_CTX** context) { 65 + + EVP_MD_CTX_free(*context); 66 + + *context = nullptr; 67 + +} 68 + 69 + 70 + OutputFile::OutputFile(const Options& opts, ld::Internal& state) 71 + @@ -3834,7 +3842,7 @@ void OutputFile::computeContentUUID(ld::Internal& state, uint8_t* wholeBuffer) 72 + { 73 + const bool log = false; 74 + if ( (_options.outputKind() != Options::kObjectFile) || state.someObjectFileHasDwarf ) { 75 + - uint8_t digest[CCSHA256_OUTPUT_SIZE]; 76 + + uint8_t digest[CS_SHA256_LEN]; 77 + std::vector<std::pair<uint64_t, uint64_t>> excludeRegions; 78 + uint64_t bitcodeCmdOffset; 79 + uint64_t bitcodeCmdEnd; 80 + @@ -3902,18 +3910,27 @@ void OutputFile::computeContentUUID(ld::Internal& state, uint8_t* wholeBuffer) 81 + excludeRegions.emplace_back(std::pair<uint64_t, uint64_t>(symbolTableCmdOffset, symbolTableCmdOffset+symbolTableCmdSize)); 82 + if ( log ) fprintf(stderr, "linkedit SegCmdOffset=0x%08llX, size=0x%08llX\n", symbolTableCmdOffset, symbolTableCmdSize); 83 + } 84 + - const ccdigest_info* di = ccsha256_di(); 85 + - ccdigest_di_decl(di, ctx); 86 + - ccdigest_init(di, ctx); 87 + + 88 + + [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* sha256_digest = EVP_MD_fetch(nullptr, "SHA-256", nullptr); 89 + + [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new(); 90 + + 91 + + if ( !EVP_DigestInit_ex2(context, sha256_digest, nullptr) ) { 92 + + ERR_print_errors_fp(stderr); 93 + + abort(); 94 + + } 95 + + 96 + // rdar://problem/19487042 include the output leaf file name in the hash 97 + const char* lastSlash = strrchr(_options.outputFilePath(), '/'); 98 + - if ( lastSlash != NULL ) { 99 + - ccdigest_update(di, ctx, strlen(lastSlash), lastSlash); 100 + + if ( lastSlash != NULL && !EVP_DigestUpdate(context, lastSlash, strlen(lastSlash)) ) { 101 + + ERR_print_errors_fp(stderr); 102 + + abort(); 103 + } 104 + + 105 + // <rdar://problem/38679559> use train name when calculating a binary's UUID 106 + const char* buildName = _options.buildContextName(); 107 + - if ( buildName != NULL ) { 108 + - ccdigest_update(di, ctx, strlen(buildName), buildName); 109 + + if ( buildName != NULL && !EVP_DigestUpdate(context, buildName, strlen(buildName)) ) { 110 + + ERR_print_errors_fp(stderr); 111 + + abort(); 112 + } 113 + 114 + if ( !excludeRegions.empty() ) { 115 + @@ -3937,22 +3954,47 @@ void OutputFile::computeContentUUID(ld::Internal& state, uint8_t* wholeBuffer) 116 + // Measure the ranges we want in parallel 117 + struct Digest 118 + { 119 + - uint8_t digest[CCSHA256_OUTPUT_SIZE]; 120 + + uint8_t digest[CS_SHA256_LEN]; 121 + }; 122 + __block std::vector<Digest> digests(regionsToMeasure.size()); 123 + dispatch_apply(regionsToMeasure.size(), DISPATCH_APPLY_AUTO, ^(size_t index) { 124 + uint64_t startOffset = regionsToMeasure[index].first; 125 + uint64_t size = regionsToMeasure[index].second; 126 + - CCDigest(kCCDigestSHA256, &wholeBuffer[startOffset], size, digests[index].digest); 127 + + 128 + + [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* sha256_digest = EVP_MD_fetch(nullptr, "SHA-256", nullptr); 129 + + [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new(); 130 + + 131 + + if (!EVP_DigestInit_ex2(context, sha256_digest, nullptr)) { 132 + + ERR_print_errors_fp(stderr); 133 + + abort(); 134 + + } 135 + + if (!EVP_DigestUpdate(context, &wholeBuffer[startOffset], size)) { 136 + + ERR_print_errors_fp(stderr); 137 + + abort(); 138 + + } 139 + + if (!EVP_DigestFinal_ex(context, digests[index].digest, nullptr)) { 140 + + ERR_print_errors_fp(stderr); 141 + + abort(); 142 + + } 143 + }); 144 + 145 + // Merge the resuls in serial 146 + - ccdigest_update(di, ctx, digests.size() * sizeof(Digest), digests.data()); 147 + + if ( !EVP_DigestUpdate(context, digests.data(), digests.size() * sizeof(Digest)) ) { 148 + + ERR_print_errors_fp(stderr); 149 + + abort(); 150 + + } 151 + } else { 152 + - ccdigest_update(di, ctx, _fileSize, wholeBuffer); 153 + + if ( !EVP_DigestUpdate(context, wholeBuffer, _fileSize) ) { 154 + + ERR_print_errors_fp(stderr); 155 + + abort(); 156 + + } 157 + + } 158 + + 159 + + if ( !EVP_DigestFinal_ex(context, digest, nullptr) ) { 160 + + ERR_print_errors_fp(stderr); 161 + + abort(); 162 + } 163 + 164 + - ccdigest_final(di, ctx, digest); 165 + if ( log ) fprintf(stderr, "uuid=%02X, %02X, %02X, %02X, %02X, %02X, %02X, %02X\n", digest[0], digest[1], digest[2], 166 + digest[3], digest[4], digest[5], digest[6], digest[7]); 167 + 168 + diff --git a/subprojects/libcodedirectory/cs_blobs.h b/subprojects/libcodedirectory/cs_blobs.h 169 + index 899a6a2..ce9cac6 100644 170 + --- a/subprojects/libcodedirectory/cs_blobs.h 171 + +++ b/subprojects/libcodedirectory/cs_blobs.h 172 + @@ -129,6 +129,7 @@ enum { 173 + CS_SHA1_LEN = 20, 174 + CS_SHA256_LEN = 32, 175 + CS_SHA256_TRUNCATED_LEN = 20, 176 + + CS_SHA384_LEN = 48, 177 + 178 + CS_CDHASH_LEN = 20, /* always - larger hashes are truncated */ 179 + CS_HASH_MAX_SIZE = 48, /* max size of the hash we'll support */ 180 + diff --git a/subprojects/libcodedirectory/libcodedirectory.c b/subprojects/libcodedirectory/libcodedirectory.c 181 + index 583ac96..02e31b1 100644 182 + --- a/subprojects/libcodedirectory/libcodedirectory.c 183 + +++ b/subprojects/libcodedirectory/libcodedirectory.c 184 + @@ -14,10 +14,6 @@ 185 + #include <sys/mman.h> 186 + #include <sys/queue.h> 187 + 188 + -#include <corecrypto/ccdigest.h> 189 + -#include <corecrypto/ccsha1.h> 190 + -#include <corecrypto/ccsha2.h> 191 + - 192 + #define LIBCD_HAS_PLATFORM_VERSION 1 193 + #include "libcodedirectory.h" 194 + 195 + @@ -46,6 +42,21 @@ 196 + #include <sysexits.h> 197 + #endif 198 + 199 + +#include <openssl/err.h> 200 + +#include <openssl/evp.h> 201 + + 202 + +static void 203 + +EVP_MD_cleanup(EVP_MD** digest) { 204 + + EVP_MD_free(*digest); 205 + + *digest = NULL; 206 + +} 207 + + 208 + +static void 209 + +EVP_MD_CTX_cleanup(EVP_MD_CTX** context) { 210 + + EVP_MD_CTX_free(*context); 211 + + *context = NULL; 212 + +} 213 + + 214 + #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 215 + #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 216 + 217 + @@ -459,17 +470,17 @@ void libcd_set_exec_seg (libcd *s, uint64_t base, uint64_t limit, uint64_t flags 218 + 219 + struct _hash_info { 220 + size_t hash_len; 221 + - const struct ccdigest_info *(*di)(void); 222 + + const char* name; 223 + }; 224 + 225 + static const struct _hash_info _known_hash_types[] = { 226 + { 0, NULL }, 227 + - { CS_SHA1_LEN, ccsha1_di }, // CS_HASHTYPE_SHA1 228 + - { CS_SHA256_LEN, ccsha256_di }, // CS_HASHTYPE_SHA256 229 + - // { 0, NULL }, // CS_HASHTYPE_SHA256_TRUNCATED, unsupported 230 + - // { 0, NULL }, // CS_HASHTYPE_SHA384, unsupported 231 + + { CS_SHA1_LEN, "SHA-1" }, // CS_HASHTYPE_SHA1 232 + + { CS_SHA256_LEN, "SHA-256" }, // CS_HASHTYPE_SHA256 233 + + { CS_HASHTYPE_SHA256_TRUNCATED, "SHA-256" }, // CS_HASHTYPE_SHA256_TRUNCATED 234 + + { CS_SHA384_LEN, "SHA-384" }, // CS_HASHTYPE_SHA384 235 + }; 236 + -static const size_t _max_known_hash_len = CS_SHA256_LEN; 237 + +static const size_t _max_known_hash_len = CS_SHA384_LEN; 238 + static const int _known_hash_types_count = sizeof(_known_hash_types)/sizeof(_known_hash_types[0]); 239 + 240 + static struct _hash_info const * 241 + @@ -781,8 +792,8 @@ _libcd_hash_page(libcd *s, 242 + uint8_t page_hash[_max_known_hash_len] = {0}; 243 + const unsigned int page_no = (unsigned int)page_idx; 244 + 245 + - struct ccdigest_info const *di = hi->di(); 246 + - ccdigest_di_decl(di, ctx); 247 + + [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* digest = EVP_MD_fetch(NULL, hi->name, NULL); 248 + + [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new(); 249 + 250 + const size_t pos = page_idx * _cs_page_bytes; 251 + uint8_t page[_cs_page_bytes] = {0}; 252 + @@ -794,9 +805,18 @@ _libcd_hash_page(libcd *s, 253 + return LIBCD_SERIALIZE_READ_PAGE_ERROR; 254 + } 255 + 256 + - ccdigest_init(di, ctx); 257 + - ccdigest_update(di, ctx, read_bytes, page); 258 + - ccdigest_final(di, ctx, page_hash); 259 + + if (!EVP_DigestInit_ex2(context, digest, NULL)) { 260 + + ERR_print_errors_fp(stderr); 261 + + abort(); 262 + + } 263 + + if (!EVP_DigestUpdate(context, page, read_bytes)) { 264 + + ERR_print_errors_fp(stderr); 265 + + abort(); 266 + + } 267 + + if (!EVP_DigestFinal_ex(context, page_hash, NULL)) { 268 + + ERR_print_errors_fp(stderr); 269 + + abort(); 270 + + } 271 + 272 + memcpy(hash_destination, page_hash, hi->hash_len); 273 + 274 + @@ -894,16 +914,25 @@ _libcd_serialize_cd (libcd *s, uint32_t hash_type) 275 + //// code directory hashes 276 + { 277 + if (s->special_slot_count > 0) { 278 + - struct ccdigest_info const *di = hi->di(); 279 + - ccdigest_di_decl(di, ctx); 280 + + [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* digest = EVP_MD_fetch(NULL, hi->name, NULL); 281 + + [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new(); 282 + 283 + uint8_t *special_slot_buf = calloc(s->special_slot_count, hi->hash_len); 284 + 285 + struct _sslot_data *sslot = NULL; 286 + SLIST_FOREACH(sslot, &s->sslot_data, entries) { 287 + - ccdigest_init(di, ctx); 288 + - ccdigest_update(di, ctx, sslot->len, sslot->data); 289 + - ccdigest_final(di, ctx, special_slot_buf + (s->special_slot_count-sslot->slot)*hi->hash_len); 290 + + if (!EVP_DigestInit_ex2(context, digest, NULL)) { 291 + + ERR_print_errors_fp(stderr); 292 + + abort(); 293 + + } 294 + + if (!EVP_DigestUpdate(context, sslot->data, sslot->len)) { 295 + + ERR_print_errors_fp(stderr); 296 + + abort(); 297 + + } 298 + + if (!EVP_DigestFinal_ex(context, special_slot_buf + (s->special_slot_count-sslot->slot)*hi->hash_len, NULL)) { 299 + + ERR_print_errors_fp(stderr); 300 + + abort(); 301 + + } 302 + } 303 + memcpy(cursor, special_slot_buf, s->special_slot_count*hi->hash_len); 304 + cursor += s->special_slot_count*hi->hash_len; 305 + @@ -949,17 +978,28 @@ _libcd_serialize_cd (libcd *s, uint32_t hash_type) 306 + 307 + //Record the cdhash for this codedirectory 308 + { 309 + - struct ccdigest_info const *di = hi->di(); 310 + - ccdigest_di_decl(di, ctx); 311 + + [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* digest = EVP_MD_fetch(NULL, hi->name, NULL); 312 + + [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new(); 313 + + 314 + uint8_t *cdhash_buf = calloc(1, hi->hash_len); 315 + if (cdhash_buf == NULL) { 316 + _libcd_err("Failed to allocated memory for cdhash"); 317 + free(cd_mem); 318 + return LIBCD_SERIALIZE_NO_MEM; 319 + } 320 + - ccdigest_init(di, ctx); 321 + - ccdigest_update(di, ctx, cd_size, cd_mem); 322 + - ccdigest_final(di, ctx, cdhash_buf); 323 + + 324 + + if (!EVP_DigestInit_ex2(context, digest, NULL)) { 325 + + ERR_print_errors_fp(stderr); 326 + + abort(); 327 + + } 328 + + if (!EVP_DigestUpdate(context, cd_mem, cd_size)) { 329 + + ERR_print_errors_fp(stderr); 330 + + abort(); 331 + + } 332 + + if (!EVP_DigestFinal_ex(context, cdhash_buf, NULL)) { 333 + + ERR_print_errors_fp(stderr); 334 + + abort(); 335 + + } 336 + 337 + for (size_t i = 0; i < s->hash_types_count; i++) { 338 + if (s->cdhashes[i].set) { 339 + -- 340 + 2.47.2 341 +
+35
pkgs/by-name/ld/ld64/patches/0016-Add-dyldinfo-to-the-ld64-build.patch
···
··· 1 + From 1bd02ac97fd47d8f7c8f1f21893d7107ae2319b5 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Sun, 17 Nov 2024 10:02:34 -0500 4 + Subject: [PATCH 16/18] Add dyldinfo to the ld64 build 5 + 6 + --- 7 + src/other/meson.build | 15 +++++++++++++++ 8 + 1 file changed, 15 insertions(+) 9 + 10 + diff --git a/src/other/meson.build b/src/other/meson.build 11 + index 067a69c..663b9ee 100644 12 + --- a/src/other/meson.build 13 + +++ b/src/other/meson.build 14 + @@ -1,3 +1,18 @@ 15 + +dyldinfo = executable( 16 + + 'dyldinfo', 17 + + dependencies : [ 18 + + abstraction_dep, 19 + + llvm_dep, 20 + + ], 21 + + include_directories : [ '../ld' ], 22 + + install : true, 23 + + sources : [ 24 + + configure_h, 25 + + 'dyldinfo.cpp', 26 + + ], 27 + +) 28 + +install_man(meson.global_source_root() / 'doc/man/man1/dyldinfo.1') 29 + + 30 + machocheck = executable( 31 + 'machocheck', 32 + dependencies : [ 33 + -- 34 + 2.47.2 35 +
+37
pkgs/by-name/ld/ld64/patches/0017-Fix-dyldinfo-build.patch
···
··· 1 + From 477911db0045e8b1925fcd5db523aab2888fdcc9 Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Sun, 17 Nov 2024 10:02:34 -0500 4 + Subject: [PATCH 17/18] Fix dyldinfo build 5 + 6 + `isSubType` was removed in 907, but the fix is simple. This mirrors the 7 + changes that were made in that update to other parts of ld64. 8 + --- 9 + src/other/dyldinfo.cpp | 5 ++--- 10 + 1 file changed, 2 insertions(+), 3 deletions(-) 11 + 12 + diff --git a/src/other/dyldinfo.cpp b/src/other/dyldinfo.cpp 13 + index dbfd0de..96aa109 100644 14 + --- a/src/other/dyldinfo.cpp 15 + +++ b/src/other/dyldinfo.cpp 16 + @@ -427,7 +427,7 @@ DyldInfoPrinter<A>::DyldInfoPrinter(const uint8_t* fileContent, uint32_t fileLen 17 + if ( printArch ) { 18 + for (const ArchInfo* t=archInfoArray; t->archName != NULL; ++t) { 19 + if ( (cpu_type_t)fHeader->cputype() == t->cpuType ) { 20 + - if ( t->isSubType && ((cpu_subtype_t)fHeader->cpusubtype() != t->cpuSubType) ) 21 + + if ( ((cpu_subtype_t)fHeader->cpusubtype() != t->cpuSubType) ) 22 + continue; 23 + printf("for arch %s:\n", t->archName); 24 + } 25 + @@ -2801,8 +2801,7 @@ int main(int argc, const char* argv[]) 26 + for (const ArchInfo* t=archInfoArray; t->archName != NULL; ++t) { 27 + if ( strcmp(t->archName,arch) == 0 ) { 28 + sPreferredArch = t->cpuType; 29 + - if ( t->isSubType ) 30 + - sPreferredSubArch = t->cpuSubType; 31 + + sPreferredSubArch = t->cpuSubType; 32 + found = true; 33 + break; 34 + } 35 + -- 36 + 2.47.2 37 +
+37
pkgs/by-name/ld/ld64/patches/0018-Use-STL-containers-instead-of-LLVM-containers.patch
···
··· 1 + From 98119b91fc3cf85d65c2e320707324af3c56565d Mon Sep 17 00:00:00 2001 2 + From: Randy Eckenrode <randy@largeandhighquality.com> 3 + Date: Wed, 13 Nov 2024 13:53:14 -0500 4 + Subject: [PATCH 18/18] Use STL containers instead of LLVM containers 5 + MIME-Version: 1.0 6 + Content-Type: text/plain; charset=UTF-8 7 + Content-Transfer-Encoding: 8bit 8 + 9 + Upstream LLVM doesn’t support `std::string_view` in `DenseMap`s. 10 + --- 11 + src/abstraction/Containers.h | 4 ++-- 12 + 1 file changed, 2 insertions(+), 2 deletions(-) 13 + 14 + diff --git a/src/abstraction/Containers.h b/src/abstraction/Containers.h 15 + index a27dc83..fca312c 100644 16 + --- a/src/abstraction/Containers.h 17 + +++ b/src/abstraction/Containers.h 18 + @@ -31,14 +31,14 @@ 19 + #include <set> 20 + #include <string_view> 21 + 22 + -#define USE_LLVM_CONTAINERS 1 23 + +#define USE_LLVM_CONTAINERS 0 24 + 25 + #if USE_LLVM_CONTAINERS 26 + #include "../llvm/llvm-DenseSet.h" 27 + #include "../llvm/llvm-DenseMap.h" 28 + #else 29 + // Include DenseMapInfo helpers even when not using LLVM containers. 30 + -#include "../llvm/llvm-DenseMapInfo.h" 31 + +// #include "../llvm/llvm-DenseMapInfo.h" 32 + #endif 33 + 34 + namespace ld { 35 + -- 36 + 2.47.2 37 +
-14
pkgs/by-name/ld/ld64/remove-unused-and-incomplete-blob-clone.diff
··· 1 - diff --git a/src/ld/code-sign-blobs/blob.h b/src/ld/code-sign-blobs/blob.h 2 - index 19c63a9..1dfb380 100644 3 - --- a/src/ld/code-sign-blobs/blob.h 4 - +++ b/src/ld/code-sign-blobs/blob.h 5 - @@ -180,9 +180,6 @@ public: 6 - return NULL; 7 - } 8 - 9 - - BlobType *clone() const 10 - - { assert(validateBlob()); return specific(this->BlobCore::clone()); } 11 - - 12 - static BlobType *readBlob(int fd) 13 - { return specific(BlobCore::readBlob(fd, _magic, sizeof(BlobType), 0), true); } 14 -
···