push sheeet
Some checks failed
Periodic Merges (6h) / master → staging-nixos (push) Failing after 12m50s
Periodic Merges (6h) / master → staging-next (push) Failing after 12m54s
Periodic Merges (24h) / merge-base(master,staging) → haskell-updates (push) Failing after 11m54s
Periodic Merges (6h) / staging-next → staging (push) Failing after 12m13s
Periodic Merges (24h) / staging-next-25.05 → staging-25.05 (push) Failing after 13m24s
Periodic Merges (24h) / release-25.05 → staging-next-25.05 (push) Failing after 14m28s

This commit is contained in:
Dark Steveneq
2025-10-09 14:15:47 +02:00
commit 646b892680
49168 changed files with 5897842 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
{
cmake,
fetchFromGitHub,
lib,
stdenv,
storeDir ? builtins.storeDir,
spdlog,
yaml-cpp,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "ld-audit-search-mod";
version = "0-unstable-2025-06-19";
src = fetchFromGitHub {
repo = "ld-audit-search-mod";
owner = "DDoSolitary";
rev = "261f475f154d0f1f0766d6756af9c714eeeb14ea";
hash = "sha256-c6ub+m4ihIE3gh6yHtLfJIVqm12C46wThrBCqp8SOLE=";
sparseCheckout = [ "src" ];
};
sourceRoot = "${finalAttrs.src.name}/src";
buildInputs = [
spdlog
yaml-cpp
];
nativeBuildInputs = [ cmake ];
cmakeFlags = [
(lib.cmakeFeature "NIX_RTLD_NAME" (baseNameOf stdenv.cc.bintools.dynamicLinker))
(lib.cmakeFeature "NIX_STORE_DIR" storeDir)
];
meta = {
inherit (finalAttrs.src.meta) homepage;
description = "Audit module that modifies ld.so library search behavior";
license = lib.licenses.mit;
maintainers = [
lib.maintainers.atry
lib.maintainers.DDoSolitary
];
platforms = lib.platforms.linux;
};
})

View File

@@ -0,0 +1,182 @@
{
lib,
cctools,
cmake,
darwin,
fetchFromGitHub,
libtapi,
llvm,
libxml2,
meson,
ninja,
openssl,
pkg-config,
stdenv,
xar,
}:
let
# Copy the files from their original sources instead of using patches to reduce the size of the patch set in nixpkgs.
otherSrcs = {
# The last version of ld64 to have dyldinfo
ld64 = fetchFromGitHub {
owner = "apple-oss-distributions";
repo = "ld64";
tag = "ld64-762";
hash = "sha256-UIq/fwO40vk8yvoTfx+UlLhnuzkI0Ih+Ym6W/BwnP0s=";
};
# Provides the source files used in the vendored libtapi. The libtapi derivation puts `tapi-src` first.
libtapi = lib.head libtapi.srcs;
};
ld64src = lib.escapeShellArg "${otherSrcs.ld64}";
libtapisrc = lib.escapeShellArg "${otherSrcs.libtapi}";
llvmPath = "${lib.getLib llvm}";
in
stdenv.mkDerivation (finalAttrs: {
pname = "ld64";
version = "954.16";
outputs = [
"out"
"dev"
"lib"
];
src = fetchFromGitHub {
owner = "apple-oss-distributions";
repo = "ld64";
tag = "ld64-${finalAttrs.version}";
hash = "sha256-CVIyL2J9ISZnI4+r+wp4QtOb3+3Tmz2z2Z7/qeRqHS0=";
};
patches = [
# These patches are vendored from https://github.com/reckenrode/ld64/tree/ld64-951.9-nixpkgs.
# See their comments for more on what they do.
./patches/0001-Always-use-write-instead-of-mmap.patch
./patches/0002-Add-compile_stubs.h-using-Clang-s-embed-extension-fo.patch
./patches/0003-Inline-missing-definitions-instead-of-using-private-.patch
./patches/0004-Removed-unused-Blob-clone-method.patch
./patches/0005-Use-std-atomics-and-std-mutex-for-portability.patch
./patches/0006-Add-Meson-build-system.patch
./patches/0007-Add-CrashReporterClient-header.patch
./patches/0008-Provide-mach-compatibility-headers-based-on-LLVM-s-h.patch
./patches/0009-Support-LTO-in-nixpkgs.patch
./patches/0010-Add-vendored-libtapi-to-the-ld64-build.patch
./patches/0011-Modify-vendored-libtapi-to-build-with-upstream-LLVM.patch
./patches/0012-Move-libcodedirectory-to-its-own-subproject.patch
./patches/0013-Set-the-version-string-in-the-build.patch
./patches/0014-Replace-corecrypto-and-CommonCrypto-with-OpenSSL.patch
./patches/0015-Add-libcd_is_blob_a_linker_signature-implementation.patch
./patches/0016-Add-dyldinfo-to-the-ld64-build.patch
./patches/0017-Fix-dyldinfo-build.patch
./patches/0018-Use-STL-containers-instead-of-LLVM-containers.patch
];
prePatch = ''
# Copy dyldinfo source files
cp ${ld64src}/doc/man/man1/dyldinfo.1 doc/man/man1/dyldinfo.1
cp ${ld64src}/src/other/dyldinfo.cpp src/other/dyldinfo.cpp
# Copy files needed from libtapi by ld64
mkdir -p subprojects/libtapi/tapi
cp ${libtapisrc}/tools/libtapi/*.cpp subprojects/libtapi
cp ${libtapisrc}/LICENSE.TXT subprojects/libtapi/LICENSE.TXT
declare -a tapiHeaders=(
APIVersion.h
Defines.h
LinkerInterfaceFile.h
PackedVersion32.h
Symbol.h
Version.h
Version.inc.in
tapi.h
)
for header in "''${tapiHeaders[@]}"; do
cp ${libtapisrc}/include/tapi/$header subprojects/libtapi/tapi/$header
done
'';
xcodeHash = "sha256-qip/1eiGn8PdLThonhPq3oq2veN4E1zOiamDPBfTeNE=";
xcodeProject = "ld64.xcodeproj";
nativeBuildInputs = [
cmake
darwin.xcodeProjectCheckHook
meson
ninja
openssl
pkg-config
];
buildInputs = [
llvm
libxml2
openssl
xar
];
dontUseCmakeConfigure = true; # CMake is only needed because its used by Meson to find LLVM.
# Note for overrides: ld64 cannot be built as a debug build because of UB in its iteration implementations,
# which trigger libc++ debug assertions due to trying to take the address of the first element of an empty vector.
mesonBuildType = "release";
mesonFlags = [
(lib.mesonOption "b_ndebug" "if-release")
(lib.mesonOption "default_library" (if stdenv.hostPlatform.isStatic then "static" else "shared"))
(lib.mesonOption "libllvm_path" llvmPath)
];
doInstallCheck = stdenv.buildPlatform.canExecute stdenv.hostPlatform;
# ld64 has a test suite, but many of the tests fail (even with ld from Xcode). Instead
# of running the test suite, rebuild ld64 using itself to link itself as a check.
# LTO is enabled only to confirm that it is set up and working properly in nixpkgs.
installCheckPhase = ''
runHook preInstallCheck
cd "$NIX_BUILD_TOP/$sourceRoot"
export NIX_CFLAGS_COMPILE+=" --ld-path=$out/bin/ld"
export NIX_CFLAGS_LINK+=" -L$SDKROOT/usr/lib"
meson setup build-install-check --buildtype=$mesonBuildType ${
lib.escapeShellArgs [
(lib.mesonBool "b_lto" true)
(lib.mesonOption "libllvm_path" llvmPath)
]
}
cd build-install-check
ninja src/ld/ld "-j$NIX_BUILD_CORES"
# Confirm that ld found the LTO library and reports it.
if ./src/ld/ld -v 2>&1 | grep -q 'LTO support'; then
echo "LTO: supported"
else
echo "LTO: not supported" && exit 1
fi
runHook postInstallCheck
'';
postInstall = ''
ln -s ld-classic.1 "$out/share/man/man1/ld.1"
ln -s ld.1 "$out/share/man/man1/ld64.1"
moveToOutput lib/libprunetrie.a "$dev"
'';
__structuredAttrs = true;
meta = {
description = "Classic linker for Darwin";
homepage = "https://opensource.apple.com/releases/";
license = lib.licenses.apple-psl20;
mainProgram = "ld";
teams = [ lib.teams.darwin ];
platforms = lib.platforms.darwin; # Porting to other platforms is incomplete. Support only Darwin for now.
};
})

View File

@@ -0,0 +1,50 @@
From 49489b079a3a2fd42f62c62441981cc734b0d7e7 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 01/18] Always use `write` instead of `mmap`
This is already required on aarch64-darwin (even under Rosetta 2), so also do it on x86_64-darwin to
avoid needing to use private headers to get the definition of `_COMM_PAGE_CPU_CAPABILITIES64`.
---
src/ld/OutputFile.cpp | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp
index edefb71..487b338 100644
--- a/src/ld/OutputFile.cpp
+++ b/src/ld/OutputFile.cpp
@@ -57,7 +57,7 @@ extern "C" {
#include <CommonCrypto/CommonDigest.h>
#include <AvailabilityMacros.h>
-#include <System/machine/cpu_capabilities.h>
+
#include "ExportsTrie.h"
@@ -4011,21 +4011,7 @@ void OutputFile::writeOutputFile(ld::Internal& state)
}
// assume mappable by default
- bool outputIsMappableFile = true;
-
-#if __arm64__
- // <rdar://problem/66598213> work around VM limitation on Apple Silicon and use write() instead of mmap() to produce output file
- outputIsMappableFile = false;
-#elif __x86_64__
-#ifndef kIsTranslated
- #define kIsTranslated 0x4000000000000000ULL
-#endif
- // <rdar://problem/70505306>
- bool isTranslated = ((*(uint64_t*)_COMM_PAGE_CPU_CAPABILITIES64) & kIsTranslated);
- if ( isTranslated ) {
- outputIsMappableFile = false;
- }
-#endif
+ bool outputIsMappableFile = false;
// rdar://107066824 (ld64: provide an environment variable or so to switch to the
// allocate+pwrite writing mode (instead of mmap) on Intels)
--
2.47.2

View File

@@ -0,0 +1,30 @@
From 966a7c3af74fb0de0f97d344b14890dc2d45f7e1 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 02/18] =?UTF-8?q?Add=20compile=5Fstubs.h=20using=20Clang?=
=?UTF-8?q?=E2=80=99s=20`#embed`=20extension=20for=20C++?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/ld/compile_stubs.h | 7 +++++++
1 file changed, 7 insertions(+)
create mode 100644 src/ld/compile_stubs.h
diff --git a/src/ld/compile_stubs.h b/src/ld/compile_stubs.h
new file mode 100644
index 0000000..88b8462
--- /dev/null
+++ b/src/ld/compile_stubs.h
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: APSL-2.0
+
+#pragma once
+
+static const char compile_stubs[] = {
+#embed "../../compile_stubs" suffix(, '\0') if_empty('\0')
+};
--
2.47.2

View File

@@ -0,0 +1,56 @@
From ddcefc16f5db7fd36c885cf3bcd3713c8383e93b Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 03/18] Inline missing definitions instead of using private
mach-o/dyld_private.h header
Based on: https://github.com/llvm/llvm-project/blob/38870fe124eb5e6e24136f9d3e4551a62370faee/libunwind/src/AddressSpace.hpp#L57-L67
---
src/ld/Options.cpp | 1 -
src/ld/parsers/libunwind/AddressSpace.hpp | 10 +++++++++-
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/src/ld/Options.cpp b/src/ld/Options.cpp
index 991387f..cde3fad 100644
--- a/src/ld/Options.cpp
+++ b/src/ld/Options.cpp
@@ -35,7 +35,6 @@
#include <spawn.h>
#include <Availability.h>
#include <tapi/tapi.h>
-#include <mach-o/dyld_priv.h>
#include <algorithm>
#include <vector>
diff --git a/src/ld/parsers/libunwind/AddressSpace.hpp b/src/ld/parsers/libunwind/AddressSpace.hpp
index eb47390..0788cc2 100644
--- a/src/ld/parsers/libunwind/AddressSpace.hpp
+++ b/src/ld/parsers/libunwind/AddressSpace.hpp
@@ -35,7 +35,6 @@
#include <dlfcn.h>
#include <mach-o/loader.h>
#include <mach-o/getsect.h>
-#include <mach-o/dyld_priv.h>
#include <Availability.h>
#include "FileAbstraction.hpp"
@@ -73,7 +72,16 @@ bool _dyld_find_unwind_sections(void* addr, dyld_unwind_sections* info)
}
#endif // 0
+struct dyld_unwind_sections
+{
+ const struct mach_header* mh;
+ const void* dwarf_section;
+ uintptr_t dwarf_section_length;
+ const void* compact_unwind_section;
+ uintptr_t compact_unwind_section_length;
+};
+extern "C" bool _dyld_find_unwind_sections(void*, dyld_unwind_sections*);
namespace libunwind {
--
2.47.2

View File

@@ -0,0 +1,27 @@
From 3c0038576173103e8aaa5286f853046b619c35fe Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 04/18] Removed unused `Blob::clone` method
Fixes a compiler error due to a missing `BlobCore::clone` method.
---
src/ld/code-sign-blobs/blob.h | 3 ---
1 file changed, 3 deletions(-)
diff --git a/src/ld/code-sign-blobs/blob.h b/src/ld/code-sign-blobs/blob.h
index 19c63a9..2ac0aa8 100644
--- a/src/ld/code-sign-blobs/blob.h
+++ b/src/ld/code-sign-blobs/blob.h
@@ -179,9 +179,6 @@ public:
return p;
return NULL;
}
-
- BlobType *clone() const
- { assert(validateBlob()); return specific(this->BlobCore::clone()); }
static BlobType *readBlob(int fd)
{ return specific(BlobCore::readBlob(fd, _magic, sizeof(BlobType), 0), true); }
--
2.47.2

View File

@@ -0,0 +1,184 @@
From effdf4d0f3a3d2332ec2a61eefe076ff37964594 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 05/18] Use std::atomics and std::mutex for portability
---
src/ld/InputFiles.cpp | 15 +++++++--------
src/ld/InputFiles.h | 9 +++++----
src/ld/OutputFile.cpp | 13 +++++++------
src/ld/ld.cpp | 11 +++++------
4 files changed, 24 insertions(+), 24 deletions(-)
diff --git a/src/ld/InputFiles.cpp b/src/ld/InputFiles.cpp
index 4d49ba3..e045e90 100644
--- a/src/ld/InputFiles.cpp
+++ b/src/ld/InputFiles.cpp
@@ -42,12 +42,11 @@
#include <mach-o/dyld.h>
#include <mach-o/fat.h>
#include <sys/sysctl.h>
-#include <libkern/OSAtomic.h>
#if HAVE_LIBDISPATCH
#include <dispatch/dispatch.h>
#endif
-#include <string>
+#include <atomic>
#include <map>
#include <set>
#include <string>
@@ -387,16 +386,16 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib
ld::relocatable::File* objResult = mach_o::relocatable::parse(p, len, info.path, info.modTime, info.ordinal, objOpts);
if ( objResult != NULL ) {
- OSAtomicAdd64(len, &_totalObjectSize);
- OSAtomicIncrement32(&_totalObjectLoaded);
+ _totalObjectSize += len;
+ ++_totalObjectLoaded;
return objResult;
}
// see if it is an llvm object file
objResult = lto::parse(p, len, info.path, info.modTime, info.ordinal, _options.architecture(), _options.subArchitecture(), _options.logAllFiles(), _options.verboseOptimizationHints());
if ( objResult != NULL ) {
- OSAtomicAdd64(len, &_totalObjectSize);
- OSAtomicIncrement32(&_totalObjectLoaded);
+ _totalObjectSize += len;
+ ++_totalObjectLoaded;
return objResult;
}
@@ -444,8 +443,8 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib
ld::archive::File* archiveResult = ::archive::parse(p, len, info.path, info.modTime, info.ordinal, archOpts);
if ( archiveResult != NULL ) {
- OSAtomicAdd64(len, &_totalArchiveSize);
- OSAtomicIncrement32(&_totalArchivesLoaded);
+ _totalArchiveSize += len;
+ ++_totalArchivesLoaded;
return archiveResult;
}
diff --git a/src/ld/InputFiles.h b/src/ld/InputFiles.h
index c18ccf8..40353fa 100644
--- a/src/ld/InputFiles.h
+++ b/src/ld/InputFiles.h
@@ -46,6 +46,7 @@
#include <pthread.h>
#endif
+#include <atomic>
#include <vector>
#include "Options.h"
@@ -78,10 +79,10 @@ public:
size_t count() const { return _inputFiles.size(); }
// for -print_statistics
- volatile int64_t _totalObjectSize;
- volatile int64_t _totalArchiveSize;
- volatile int32_t _totalObjectLoaded;
- volatile int32_t _totalArchivesLoaded;
+ std::atomic<int64_t> _totalObjectSize;
+ std::atomic<int64_t> _totalArchiveSize;
+ std::atomic<int32_t> _totalObjectLoaded;
+ std::atomic<int32_t> _totalArchivesLoaded;
int32_t _totalDylibsLoaded;
diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp
index 487b338..2a175a7 100644
--- a/src/ld/OutputFile.cpp
+++ b/src/ld/OutputFile.cpp
@@ -47,7 +47,8 @@
extern "C" {
#include <corecrypto/ccsha2.h>
}
-#include <string>
+
+#include <mutex>
#include <string>
#include <list>
#include <algorithm>
@@ -1315,7 +1316,7 @@ void OutputFile::rangeCheckRISCVBranch20(int64_t displacement, ld::Internal& sta
#if SUPPORT_ARCH_arm64e
-static os_lock_unfair_s sAuthenticatedFixupDataLock = OS_LOCK_UNFAIR_INIT; // to serialize building of _authenticatedFixupData
+static std::mutex sAuthenticatedFixupDataLock; // to serialize building of _authenticatedFixupData
#endif
void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld::Atom* atom, uint8_t* buffer)
@@ -1690,11 +1691,11 @@ void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld::
}
else {
auto fixupOffset = (uintptr_t)(fixUpLocation - mhAddress);
- os_lock_lock(&sAuthenticatedFixupDataLock);
+ sAuthenticatedFixupDataLock.lock();
assert(_authenticatedFixupData.find(fixupOffset) == _authenticatedFixupData.end());
auto authneticatedData = std::make_pair(authData, accumulator);
_authenticatedFixupData[fixupOffset] = authneticatedData;
- os_lock_unlock(&sAuthenticatedFixupDataLock);
+ sAuthenticatedFixupDataLock.unlock();
// Zero out this entry which we will expect later.
set64LE(fixUpLocation, 0);
}
@@ -1721,11 +1722,11 @@ void OutputFile::applyFixUps(ld::Internal& state, uint64_t mhAddress, const ld::
}
else {
auto fixupOffset = (uintptr_t)(fixUpLocation - mhAddress);
- os_lock_lock(&sAuthenticatedFixupDataLock);
+ sAuthenticatedFixupDataLock.lock();
assert(_authenticatedFixupData.find(fixupOffset) == _authenticatedFixupData.end());
auto authneticatedData = std::make_pair(authData, accumulator);
_authenticatedFixupData[fixupOffset] = authneticatedData;
- os_lock_unlock(&sAuthenticatedFixupDataLock);
+ sAuthenticatedFixupDataLock.unlock();
// Zero out this entry which we will expect later.
set64LE(fixUpLocation, 0);
}
diff --git a/src/ld/ld.cpp b/src/ld/ld.cpp
index b532c9a..8608ea5 100644
--- a/src/ld/ld.cpp
+++ b/src/ld/ld.cpp
@@ -47,9 +47,8 @@ extern "C" double log2 ( double );
#include <mach-o/dyld.h>
#include <dlfcn.h>
#include <AvailabilityMacros.h>
-#include <os/lock_private.h>
-#include <string>
+#include <mutex>
#include <map>
#include <set>
#include <string>
@@ -1539,8 +1538,8 @@ int main(int argc, const char* argv[])
statistics.vmEnd.faults-statistics.vmStart.faults);
fprintf(stderr, "memory active: %lu, wired: %lu\n", statistics.vmEnd.active_count * vm_page_size, statistics.vmEnd.wire_count * vm_page_size);
char temp[40];
- fprintf(stderr, "processed %3u object files, totaling %15s bytes\n", inputFiles._totalObjectLoaded, commatize(inputFiles._totalObjectSize, temp));
- fprintf(stderr, "processed %3u archive files, totaling %15s bytes\n", inputFiles._totalArchivesLoaded, commatize(inputFiles._totalArchiveSize, temp));
+ fprintf(stderr, "processed %3u object files, totaling %15s bytes\n", inputFiles._totalObjectLoaded.load(), commatize(inputFiles._totalObjectSize.load(), temp));
+ fprintf(stderr, "processed %3u archive files, totaling %15s bytes\n", inputFiles._totalArchivesLoaded.load(), commatize(inputFiles._totalArchiveSize.load(), temp));
fprintf(stderr, "processed %3u dylib files\n", inputFiles._totalDylibsLoaded);
fprintf(stderr, "wrote output file totaling %15s bytes\n", commatize(out.fileSize(), temp));
}
@@ -1570,12 +1569,12 @@ int main(int argc, const char* argv[])
#ifndef NDEBUG
// now that the linker is multi-threaded, only allow one assert() to be processed
-static os_lock_unfair_s sAssertLock = OS_LOCK_UNFAIR_INIT;
+static std::mutex sAssertLock;
// implement assert() function to print out a backtrace before aborting
void __assert_rtn(const char* func, const char* file, int line, const char* failedexpr)
{
- os_lock_lock(&sAssertLock);
+ sAssertLock.lock();
Snapshot *snapshot = Snapshot::globalSnapshot;
--
2.47.2

View File

@@ -0,0 +1,328 @@
From 099f663adc119ade6509569505358a0955c2b02a Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 06/18] Add Meson build system
---
meson.build | 42 +++++++++++++++++++
meson.options | 5 +++
src/abstraction/meson.build | 3 ++
src/ld/meson.build | 68 +++++++++++++++++++++++++++++++
src/ld/parsers/meson.build | 26 ++++++++++++
src/mach_o/meson.build | 13 ++++++
src/meson.build | 16 ++++++++
src/other/meson.build | 80 +++++++++++++++++++++++++++++++++++++
8 files changed, 253 insertions(+)
create mode 100644 meson.build
create mode 100644 meson.options
create mode 100644 src/abstraction/meson.build
create mode 100644 src/ld/meson.build
create mode 100644 src/ld/parsers/meson.build
create mode 100644 src/mach_o/meson.build
create mode 100644 src/meson.build
create mode 100644 src/other/meson.build
diff --git a/meson.build b/meson.build
new file mode 100644
index 0000000..cd4e8da
--- /dev/null
+++ b/meson.build
@@ -0,0 +1,42 @@
+project(
+ 'ld64',
+ 'c', 'cpp',
+ default_options : {'c_std': 'c23', 'cpp_std': 'c++23'},
+ license : 'APSL-2.0',
+ license_files : 'APPLE_LICENSE',
+ meson_version : '>=1.6.0',
+ version : '954.16',
+)
+
+add_project_arguments(
+ # Avoid needing to link libSupport, which helps avoid a dependency on LLVM in packages
+ # that link libprunetrie.a (such as cctools).
+ '-DLLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING=1',
+ language : 'cpp',
+)
+
+
+cc = meson.get_compiler('c')
+cxx = meson.get_compiler('cpp')
+
+
+libcodedirectory_dep = dependency(
+ 'libcodedirectory',
+ version : '=819.6.1',
+)
+libtapi_dep = dependency(
+ 'libtapi',
+ version : [ '>=1500' , '<1600' ],
+)
+llvm_dep = dependency(
+ 'llvm',
+ version : '>=19.1'
+).partial_dependency(includes : true) # ld64 only needs LLVM headers for ADTs.
+openssl_dep = dependency(
+ 'openssl',
+ version : '>=3.0'
+)
+xar_dep = cc.find_library('xar')
+
+
+subdir('src')
diff --git a/meson.options b/meson.options
new file mode 100644
index 0000000..dd40e66
--- /dev/null
+++ b/meson.options
@@ -0,0 +1,5 @@
+option(
+ 'libllvm_path',
+ type : 'string',
+ description: 'Specifies the default path to LLVM for `libLTO.dylib`'
+)
diff --git a/src/abstraction/meson.build b/src/abstraction/meson.build
new file mode 100644
index 0000000..eae50ea
--- /dev/null
+++ b/src/abstraction/meson.build
@@ -0,0 +1,3 @@
+abstraction_dep = declare_dependency(
+ include_directories : [ '.' ]
+)
diff --git a/src/ld/meson.build b/src/ld/meson.build
new file mode 100644
index 0000000..8bc85b7
--- /dev/null
+++ b/src/ld/meson.build
@@ -0,0 +1,68 @@
+subdir('parsers')
+
+executable(
+ 'ld',
+ cpp_args : [
+ '-Wno-c23-extensions',
+ '-Wno-vla-cxx-extension',
+ ],
+ dependencies : [
+ abstraction_dep,
+ libcodedirectory_dep,
+ libtapi_dep,
+ llvm_dep,
+ mach_o_dep,
+ openssl_dep,
+ parsers_dep,
+ xar_dep,
+ ],
+ include_directories : [
+ 'code-sign-blobs',
+ 'parsers',
+ 'passes',
+ ],
+ install : true,
+ # These linker flags mirror those used in a release build of the Xcode project.
+ # See: https://github.com/apple-oss-distributions/ld64/blob/47f477cb721755419018f7530038b272e9d0cdea/ld64.xcodeproj/project.pbxproj#L1292-L1299.
+ link_args : [
+ '-Wl,-exported_symbol,__mh_execute_header',
+ '-Wl,-stack_size,0x02000000',
+ '-Wl,-client_name,ld',
+ ],
+ sources : [
+ configure_h,
+ 'FatFile.cpp',
+ 'InputFiles.cpp',
+ 'Mangling.cpp',
+ 'Options.cpp',
+ 'OutputFile.cpp',
+ 'PlatformSupport.cpp',
+ 'Resolver.cpp',
+ 'ResponseFiles.cpp',
+ 'Snapshot.cpp',
+ 'SymbolTable.cpp',
+ 'code-sign-blobs/blob.cpp',
+ 'code-sign-blobs/blob.h',
+ 'debugline.c',
+ 'ld.cpp',
+ 'libcodedirectory.c',
+ 'passes/bitcode_bundle.cpp',
+ 'passes/branch_island.cpp',
+ 'passes/branch_shim.cpp',
+ 'passes/code_dedup.cpp',
+ 'passes/compact_unwind.cpp',
+ 'passes/dtrace_dof.cpp',
+ 'passes/dylibs.cpp',
+ 'passes/got.cpp',
+ 'passes/huge.cpp',
+ 'passes/inits.cpp',
+ 'passes/objc.cpp',
+ 'passes/objc_constants.cpp',
+ 'passes/objc_stubs.cpp',
+ 'passes/order.cpp',
+ 'passes/stubs/stubs.cpp',
+ 'passes/thread_starts.cpp',
+ 'passes/tlvp.cpp',
+ ],
+)
+install_man(meson.global_source_root() / 'doc/man/man1/ld-classic.1')
diff --git a/src/ld/parsers/meson.build b/src/ld/parsers/meson.build
new file mode 100644
index 0000000..a88f651
--- /dev/null
+++ b/src/ld/parsers/meson.build
@@ -0,0 +1,26 @@
+parsers = static_library(
+ 'parsers',
+ cpp_args : [ '-Wno-vla-cxx-extension' ],
+ dependencies : [
+ abstraction_dep,
+ libtapi_dep,
+ ],
+ include_directories : [
+ '..', # For ld64 headers
+ ],
+ sources : [
+ configure_h,
+ 'archive_file.cpp',
+ 'generic_dylib_file.cpp',
+ 'lto_file.cpp',
+ 'macho_dylib_file.cpp',
+ 'macho_relocatable_file.cpp',
+ 'opaque_section_file.cpp',
+ 'textstub_dylib_file.cpp',
+ ],
+)
+
+parsers_dep = declare_dependency(
+ include_directories : [ '.' ],
+ link_with : parsers,
+)
diff --git a/src/mach_o/meson.build b/src/mach_o/meson.build
new file mode 100644
index 0000000..88d4f7a
--- /dev/null
+++ b/src/mach_o/meson.build
@@ -0,0 +1,13 @@
+mach_o = static_library(
+ 'mach_o',
+ cpp_args : [ '-Wno-vla-cxx-extension' ],
+ sources : [
+ 'Error.cpp',
+ 'ExportsTrie.cpp',
+ ],
+)
+
+mach_o_dep = declare_dependency(
+ include_directories : [ '.' ],
+ link_with : mach_o,
+)
diff --git a/src/meson.build b/src/meson.build
new file mode 100644
index 0000000..e1e3b1a
--- /dev/null
+++ b/src/meson.build
@@ -0,0 +1,16 @@
+configure_h = custom_target(
+ 'configure_h',
+ command : [ find_program('bash'), '@INPUT@' ],
+ env : {
+ 'DERIVED_FILE_DIR' : meson.current_build_dir(),
+ 'RC_ProjectSourceVersion': meson.project_version(),
+ },
+ input : 'create_configure',
+ output : 'configure.h',
+)
+
+subdir('abstraction')
+subdir('mach_o')
+
+subdir('ld')
+subdir('other')
diff --git a/src/other/meson.build b/src/other/meson.build
new file mode 100644
index 0000000..067a69c
--- /dev/null
+++ b/src/other/meson.build
@@ -0,0 +1,80 @@
+machocheck = executable(
+ 'machocheck',
+ dependencies : [
+ abstraction_dep,
+ llvm_dep,
+ ],
+ include_directories : [ '../ld' ],
+ install : true,
+ sources : [
+ configure_h,
+ 'machochecker.cpp',
+ ],
+)
+
+ObjectDump = executable(
+ 'ObjectDump',
+ cpp_args : [ '-Wno-vla-cxx-extension' ],
+ dependencies : [
+ abstraction_dep,
+ libtapi_dep,
+ parsers_dep,
+ ],
+ include_directories : [ '../ld' ],
+ install : true,
+ sources : [
+ configure_h,
+ '../ld/PlatformSupport.cpp',
+ '../ld/debugline.c',
+ 'ObjectDump.cpp',
+ ],
+)
+
+objcimageinfo = executable(
+ 'objcimageinfo',
+ dependencies : [
+ abstraction_dep,
+ llvm_dep,
+ ],
+ include_directories : [ '../ld' ],
+ install : true,
+ sources : [
+ configure_h,
+ 'objcimageinfo.cpp',
+ ],
+)
+
+unwinddump = executable(
+ 'unwinddump',
+ dependencies : [
+ abstraction_dep,
+ llvm_dep,
+ ],
+ include_directories : [ '../ld' ],
+ install : true,
+ sources : [
+ configure_h,
+ 'unwinddump.cpp',
+ ],
+)
+install_man(meson.global_source_root() / 'doc/man/man1/unwinddump.1')
+
+static_library(
+ 'prunetrie',
+ cpp_args : [ '-Wno-vla-cxx-extension' ],
+ dependencies : [
+ abstraction_dep,
+ mach_o_dep
+ ],
+ include_directories : [ '../ld' ],
+ install : true,
+ override_options : {'b_lto': false},
+ sources : [
+ configure_h,
+ 'PruneTrie.cpp',
+ ],
+)
+install_headers(
+ 'prune_trie.h',
+ subdir : 'mach-o',
+)
--
2.47.2

View File

@@ -0,0 +1,91 @@
From 8bc85cdac6c39215d0d7ea4facfea593efe785ec Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 07/18] Add CrashReporterClient header
Based on: https://github.com/apple-oss-distributions/WebKit2/blob/523170e4638816ec4a39c8128a4f3c4ab70a6f89/Platform/spi/Cocoa/CrashReporterClientSPI.h
---
include/CrashReporterClient.h | 48 +++++++++++++++++++++++++++++++++++
include/meson.build | 4 +++
meson.build | 1 +
3 files changed, 53 insertions(+)
create mode 100644 include/CrashReporterClient.h
create mode 100644 include/meson.build
diff --git a/include/CrashReporterClient.h b/include/CrashReporterClient.h
new file mode 100644
index 0000000..f892448
--- /dev/null
+++ b/include/CrashReporterClient.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#pragma once
+
+#define CRASHREPORTER_ANNOTATIONS_SECTION "__crash_info"
+#define CRASHREPORTER_ANNOTATIONS_VERSION 5
+#define CRASH_REPORTER_CLIENT_HIDDEN __attribute__((visibility("hidden")))
+
+#define _crc_make_getter(attr) ((const char *)(unsigned long)gCRAnnotations.attr)
+#define _crc_make_setter(attr, arg) (gCRAnnotations.attr = (uint64_t)(unsigned long)(arg))
+#define CRGetCrashLogMessage() _crc_make_getter(message)
+#define CRSetCrashLogMessage(m) _crc_make_setter(message, m)
+
+struct crashreporter_annotations_t {
+ uint64_t version;
+ uint64_t message;
+ uint64_t signature_string;
+ uint64_t backtrace;
+ uint64_t message2;
+ uint64_t thread;
+ uint64_t dialog_mode;
+ uint64_t abort_cause;
+};
+
+CRASH_REPORTER_CLIENT_HIDDEN
+extern struct crashreporter_annotations_t gCRAnnotations;
diff --git a/include/meson.build b/include/meson.build
new file mode 100644
index 0000000..bbe6fcb
--- /dev/null
+++ b/include/meson.build
@@ -0,0 +1,4 @@
+add_project_arguments(
+ '-I' + meson.global_source_root() / 'include',
+ language : [ 'c', 'cpp' ],
+)
diff --git a/meson.build b/meson.build
index cd4e8da..a79f03f 100644
--- a/meson.build
+++ b/meson.build
@@ -39,4 +39,5 @@ openssl_dep = dependency(
xar_dep = cc.find_library('xar')
+subdir('include')
subdir('src')
--
2.47.2

View File

@@ -0,0 +1,662 @@
From 5ce3538352b162cfaacca4a7e3c5e04fabf1d169 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 08/18] =?UTF-8?q?Provide=20mach=20compatibility=20headers?=
=?UTF-8?q?=20based=20on=20LLVM=E2=80=99s=20headers?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
include/mach-o/fat.h | 16 ++
include/mach-o/loader.h | 224 +++++++++++++++++++++++
include/mach-o/nlist.h | 61 ++++++
include/mach/machine.h | 200 ++++++++++++++++++++
include/mach/vm_prot.h | 13 ++
src/abstraction/MachOFileAbstraction.hpp | 32 ++--
6 files changed, 530 insertions(+), 16 deletions(-)
create mode 100644 include/mach-o/fat.h
create mode 100644 include/mach-o/loader.h
create mode 100644 include/mach-o/nlist.h
create mode 100644 include/mach/machine.h
create mode 100644 include/mach/vm_prot.h
diff --git a/include/mach-o/fat.h b/include/mach-o/fat.h
new file mode 100644
index 0000000..82f5dc1
--- /dev/null
+++ b/include/mach-o/fat.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: APSL-2.0
+
+// Derive `fat.h` from LLVM to avoid macro conflicts.
+
+#pragma once
+
+#include <llvm/BinaryFormat/MachO.h>
+
+using llvm::MachO::fat_arch;
+using llvm::MachO::fat_arch_64;
+using llvm::MachO::fat_header;
+
+using llvm::MachO::FAT_CIGAM;
+using llvm::MachO::FAT_CIGAM_64;
+using llvm::MachO::FAT_MAGIC;
+using llvm::MachO::FAT_MAGIC_64;
diff --git a/include/mach-o/loader.h b/include/mach-o/loader.h
new file mode 100644
index 0000000..5306a20
--- /dev/null
+++ b/include/mach-o/loader.h
@@ -0,0 +1,224 @@
+// SPDX-License-Identifier: APSL-2.0
+
+// Derive `loader.h` from LLVM to avoid macro conflicts.
+
+#pragma once
+
+#include <mach/vm_prot.h>
+
+#include <llvm/BinaryFormat/MachO.h>
+
+using llvm::MachO::mach_header;
+using llvm::MachO::mach_header_64;
+
+using llvm::MachO::data_in_code_entry;
+
+using llvm::MachO::dylib_table_of_contents;
+
+using llvm::MachO::dylib_module;
+using llvm::MachO::dylib_module_64;
+
+using llvm::MachO::section;
+using llvm::MachO::section_64;
+
+using llvm::MachO::build_tool_version;
+using llvm::MachO::build_version_command;
+using llvm::MachO::dyld_info_command;
+using llvm::MachO::dylib;
+using llvm::MachO::dylib_command;
+using llvm::MachO::dylinker_command;
+using llvm::MachO::dysymtab_command;
+using llvm::MachO::encryption_info_command;
+using llvm::MachO::encryption_info_command_64;
+using llvm::MachO::entry_point_command;
+using llvm::MachO::linkedit_data_command;
+using llvm::MachO::linker_option_command;
+using llvm::MachO::load_command;
+using llvm::MachO::routines_command;
+using llvm::MachO::routines_command_64;
+using llvm::MachO::rpath_command;
+using llvm::MachO::segment_command;
+using llvm::MachO::segment_command_64;
+using llvm::MachO::source_version_command;
+using llvm::MachO::sub_client_command;
+using llvm::MachO::sub_framework_command;
+using llvm::MachO::sub_library_command;
+using llvm::MachO::sub_umbrella_command;
+using llvm::MachO::symtab_command;
+using llvm::MachO::thread_command;
+using llvm::MachO::twolevel_hints_command;
+using llvm::MachO::uuid_command;
+using llvm::MachO::version_min_command;
+
+using llvm::MachO::LC_BUILD_VERSION;
+using llvm::MachO::LC_CODE_SIGNATURE;
+using llvm::MachO::LC_DATA_IN_CODE;
+using llvm::MachO::LC_DYLD_ENVIRONMENT;
+using llvm::MachO::LC_DYLD_INFO;
+using llvm::MachO::LC_DYLD_INFO_ONLY;
+using llvm::MachO::LC_DYSYMTAB;
+using llvm::MachO::LC_ENCRYPTION_INFO;
+using llvm::MachO::LC_ENCRYPTION_INFO_64;
+using llvm::MachO::LC_FUNCTION_STARTS;
+using llvm::MachO::LC_ID_DYLIB;
+using llvm::MachO::LC_ID_DYLINKER;
+using llvm::MachO::LC_LINKER_OPTION;
+using llvm::MachO::LC_LOAD_DYLIB;
+using llvm::MachO::LC_LOAD_DYLINKER;
+using llvm::MachO::LC_LOAD_UPWARD_DYLIB;
+using llvm::MachO::LC_LOAD_WEAK_DYLIB;
+using llvm::MachO::LC_MAIN;
+using llvm::MachO::LC_REEXPORT_DYLIB;
+using llvm::MachO::LC_REQ_DYLD;
+using llvm::MachO::LC_ROUTINES;
+using llvm::MachO::LC_ROUTINES_64;
+using llvm::MachO::LC_RPATH;
+using llvm::MachO::LC_SEGMENT;
+using llvm::MachO::LC_SEGMENT_64;
+using llvm::MachO::LC_SEGMENT_SPLIT_INFO;
+using llvm::MachO::LC_SOURCE_VERSION;
+using llvm::MachO::LC_SUB_CLIENT;
+using llvm::MachO::LC_SUB_FRAMEWORK;
+using llvm::MachO::LC_SUB_LIBRARY;
+using llvm::MachO::LC_SUB_UMBRELLA;
+using llvm::MachO::LC_SYMTAB;
+using llvm::MachO::LC_UNIXTHREAD;
+using llvm::MachO::LC_UUID;
+using llvm::MachO::LC_VERSION_MIN_IPHONEOS;
+using llvm::MachO::LC_VERSION_MIN_MACOSX;
+using llvm::MachO::LC_VERSION_MIN_TVOS;
+using llvm::MachO::LC_VERSION_MIN_WATCHOS;
+using llvm::MachO::LC_DYLIB_CODE_SIGN_DRS;
+using llvm::MachO::LC_NOTE;
+using llvm::MachO::LC_LAZY_LOAD_DYLIB;
+using llvm::MachO::LC_PREBIND_CKSUM;
+using llvm::MachO::LC_TWOLEVEL_HINTS;
+
+using llvm::MachO::MH_ALLOW_STACK_EXECUTION;
+using llvm::MachO::MH_APP_EXTENSION_SAFE;
+using llvm::MachO::MH_BINDS_TO_WEAK;
+using llvm::MachO::MH_BUNDLE;
+using llvm::MachO::MH_CIGAM;
+using llvm::MachO::MH_CIGAM_64;
+using llvm::MachO::MH_DEAD_STRIPPABLE_DYLIB;
+using llvm::MachO::MH_DYLDLINK;
+using llvm::MachO::MH_DYLIB;
+using llvm::MachO::MH_DYLIB_STUB;
+using llvm::MachO::MH_DYLINKER;
+using llvm::MachO::MH_EXECUTE;
+using llvm::MachO::MH_LAZY_INIT;
+using llvm::MachO::MH_INCRLINK;
+using llvm::MachO::MH_HAS_TLV_DESCRIPTORS;
+using llvm::MachO::MH_KEXT_BUNDLE;
+using llvm::MachO::MH_MAGIC;
+using llvm::MachO::MH_MAGIC_64;
+using llvm::MachO::MH_NOUNDEFS;
+using llvm::MachO::MH_NO_HEAP_EXECUTION;
+using llvm::MachO::MH_NO_REEXPORTED_DYLIBS;
+using llvm::MachO::MH_OBJECT;
+using llvm::MachO::MH_PIE;
+using llvm::MachO::MH_PREBOUND;
+using llvm::MachO::MH_PRELOAD;
+using llvm::MachO::MH_SPLIT_SEGS;
+using llvm::MachO::MH_SUBSECTIONS_VIA_SYMBOLS;
+using llvm::MachO::MH_TWOLEVEL;
+using llvm::MachO::MH_WEAK_DEFINES;
+
+using llvm::MachO::BIND_IMMEDIATE_MASK;
+
+using llvm::MachO::BIND_OPCODE_ADD_ADDR_ULEB;
+using llvm::MachO::BIND_OPCODE_DONE;
+using llvm::MachO::BIND_OPCODE_DO_BIND;
+using llvm::MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED;
+using llvm::MachO::BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB;
+using llvm::MachO::BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB;
+using llvm::MachO::BIND_OPCODE_SET_ADDEND_SLEB;
+using llvm::MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_IMM;
+using llvm::MachO::BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB;
+using llvm::MachO::BIND_OPCODE_SET_DYLIB_SPECIAL_IMM;
+using llvm::MachO::BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB;
+using llvm::MachO::BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM;
+using llvm::MachO::BIND_OPCODE_SET_TYPE_IMM;
+using llvm::MachO::BIND_OPCODE_MASK;
+
+using llvm::MachO::BIND_SPECIAL_DYLIB_FLAT_LOOKUP;
+using llvm::MachO::BIND_SPECIAL_DYLIB_MAIN_EXECUTABLE;
+using llvm::MachO::BIND_SPECIAL_DYLIB_SELF;
+
+using llvm::MachO::BIND_SYMBOL_FLAGS_NON_WEAK_DEFINITION;
+using llvm::MachO::BIND_SYMBOL_FLAGS_WEAK_IMPORT;
+
+using llvm::MachO::BIND_TYPE_POINTER;
+using llvm::MachO::BIND_TYPE_TEXT_ABSOLUTE32;
+using llvm::MachO::BIND_TYPE_TEXT_PCREL32;
+
+using llvm::MachO::DICE_KIND_ABS_JUMP_TABLE32;
+using llvm::MachO::DICE_KIND_DATA;
+using llvm::MachO::DICE_KIND_JUMP_TABLE16;
+using llvm::MachO::DICE_KIND_JUMP_TABLE32;
+using llvm::MachO::DICE_KIND_JUMP_TABLE8;
+
+using llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_MASK;
+using llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_REGULAR;
+using llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_THREAD_LOCAL;
+using llvm::MachO::EXPORT_SYMBOL_FLAGS_REEXPORT;
+using llvm::MachO::EXPORT_SYMBOL_FLAGS_STUB_AND_RESOLVER;
+using llvm::MachO::EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION;
+
+using llvm::MachO::REBASE_IMMEDIATE_MASK;
+
+using llvm::MachO::REBASE_OPCODE_MASK;
+using llvm::MachO::REBASE_OPCODE_ADD_ADDR_IMM_SCALED;
+using llvm::MachO::REBASE_OPCODE_ADD_ADDR_ULEB;
+using llvm::MachO::REBASE_OPCODE_DONE;
+using llvm::MachO::REBASE_OPCODE_DO_REBASE_ADD_ADDR_ULEB;
+using llvm::MachO::REBASE_OPCODE_DO_REBASE_IMM_TIMES;
+using llvm::MachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES;
+using llvm::MachO::REBASE_OPCODE_DO_REBASE_ULEB_TIMES_SKIPPING_ULEB;
+using llvm::MachO::REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB;
+using llvm::MachO::REBASE_OPCODE_SET_TYPE_IMM;
+
+using llvm::MachO::REBASE_TYPE_POINTER;
+using llvm::MachO::REBASE_TYPE_TEXT_ABSOLUTE32;
+using llvm::MachO::REBASE_TYPE_TEXT_PCREL32;
+
+using llvm::MachO::S_4BYTE_LITERALS;
+using llvm::MachO::S_8BYTE_LITERALS;
+using llvm::MachO::S_16BYTE_LITERALS;
+using llvm::MachO::S_ATTR_DEBUG;
+using llvm::MachO::S_ATTR_EXT_RELOC;
+using llvm::MachO::S_ATTR_LIVE_SUPPORT;
+using llvm::MachO::S_ATTR_LOC_RELOC;
+using llvm::MachO::S_ATTR_LOC_RELOC;
+using llvm::MachO::S_ATTR_NO_DEAD_STRIP;
+using llvm::MachO::S_ATTR_PURE_INSTRUCTIONS;
+using llvm::MachO::S_ATTR_SELF_MODIFYING_CODE;
+using llvm::MachO::S_ATTR_SOME_INSTRUCTIONS;
+using llvm::MachO::S_COALESCED;
+using llvm::MachO::S_CSTRING_LITERALS;
+using llvm::MachO::S_DTRACE_DOF;
+using llvm::MachO::S_INTERPOSING;
+using llvm::MachO::S_LAZY_DYLIB_SYMBOL_POINTERS;
+using llvm::MachO::S_LAZY_SYMBOL_POINTERS;
+using llvm::MachO::S_LITERAL_POINTERS;
+using llvm::MachO::S_MOD_INIT_FUNC_POINTERS;
+using llvm::MachO::S_MOD_TERM_FUNC_POINTERS;
+using llvm::MachO::S_NON_LAZY_SYMBOL_POINTERS;
+using llvm::MachO::S_REGULAR;
+using llvm::MachO::S_SYMBOL_STUBS;
+using llvm::MachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS;
+using llvm::MachO::S_THREAD_LOCAL_REGULAR;
+using llvm::MachO::S_THREAD_LOCAL_VARIABLES;
+using llvm::MachO::S_THREAD_LOCAL_VARIABLE_POINTERS;
+using llvm::MachO::S_THREAD_LOCAL_ZEROFILL;
+using llvm::MachO::S_ZEROFILL;
+
+using llvm::MachO::SG_NORELOC;
+
+using llvm::MachO::INDIRECT_SYMBOL_ABS;
+using llvm::MachO::INDIRECT_SYMBOL_LOCAL;
+using llvm::MachO::SECTION_TYPE;
+using llvm::MachO::TOOL_LD;
+
+template<typename T>
+inline constexpr int operator| (llvm::MachO::SectionType lhs, T rhs) { return (int) lhs | (int) rhs; }
diff --git a/include/mach-o/nlist.h b/include/mach-o/nlist.h
new file mode 100644
index 0000000..3c319a4
--- /dev/null
+++ b/include/mach-o/nlist.h
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: APSL-2.0
+
+// Derive `nlist.h` from LLVM to avoid macro conflicts.
+
+#pragma once
+
+#include <llvm/BinaryFormat/MachO.h>
+
+using llvm::MachO::nlist;
+using llvm::MachO::nlist_64;
+
+using llvm::MachO::N_ARM_THUMB_DEF;
+
+using llvm::MachO::N_ABS;
+using llvm::MachO::N_EXT;
+using llvm::MachO::N_INDR;
+using llvm::MachO::N_PBUD;
+using llvm::MachO::N_PEXT;
+using llvm::MachO::N_SECT;
+using llvm::MachO::N_STAB;
+using llvm::MachO::N_TYPE;
+using llvm::MachO::N_UNDF;
+
+using llvm::MachO::N_ALT_ENTRY;
+using llvm::MachO::N_NO_DEAD_STRIP;
+using llvm::MachO::N_SYMBOL_RESOLVER;
+using llvm::MachO::N_WEAK_DEF;
+using llvm::MachO::N_WEAK_REF;
+
+#define N_REF_TO_WEAK 0x80 // Not defined in LLVM headers
+
+using llvm::MachO::DYNAMIC_LOOKUP_ORDINAL;
+
+using llvm::MachO::EXECUTABLE_ORDINAL;
+
+using llvm::MachO::GET_COMM_ALIGN;
+using llvm::MachO::SET_COMM_ALIGN;
+
+using llvm::MachO::GET_LIBRARY_ORDINAL;
+using llvm::MachO::SET_LIBRARY_ORDINAL;
+
+using llvm::MachO::REFERENCE_FLAG_DEFINED;
+using llvm::MachO::REFERENCE_FLAG_PRIVATE_DEFINED;
+using llvm::MachO::REFERENCE_FLAG_PRIVATE_UNDEFINED_LAZY;
+using llvm::MachO::REFERENCE_FLAG_PRIVATE_UNDEFINED_NON_LAZY;
+using llvm::MachO::REFERENCE_FLAG_UNDEFINED_LAZY;
+using llvm::MachO::REFERENCE_FLAG_UNDEFINED_NON_LAZY;
+using llvm::MachO::REFERENCE_TYPE;
+
+using llvm::MachO::REFERENCED_DYNAMICALLY;
+
+using llvm::MachO::MAX_SECT;
+using llvm::MachO::NO_SECT;
+
+using llvm::MachO::SELF_LIBRARY_ORDINAL;
+
+template<typename T>
+inline constexpr int operator| (llvm::MachO::NListType lhs, T rhs) { return (int) lhs | (int) rhs; }
+
+template<typename T>
+inline constexpr int operator| (T lhs, llvm::MachO::NListType rhs) { return (int) lhs | (int) rhs; }
diff --git a/include/mach/machine.h b/include/mach/machine.h
new file mode 100644
index 0000000..9162c1d
--- /dev/null
+++ b/include/mach/machine.h
@@ -0,0 +1,200 @@
+// SPDX-License-Identifier: APSL-2.0
+
+// Derive `machine.h` from LLVM to avoid macro conflicts.
+
+#pragma once
+
+#include_next <mach/machine.h>
+
+#undef CPU_ARCH_MASK
+
+#undef CPU_ARCH_ABI64_32
+#undef CPU_ARCH_ABI64
+
+#undef CPU_TYPE_ANY
+
+#undef CPU_TYPE_ARM
+#undef CPU_TYPE_ARM64
+#undef CPU_TYPE_ARM64_32
+#undef CPU_TYPE_I386
+#undef CPU_TYPE_X86
+#undef CPU_TYPE_X86_64
+#undef CPU_TYPE_MC98000
+#undef CPU_TYPE_SPARC
+#undef CPU_TYPE_POWERPC
+#undef CPU_TYPE_POWERPC64
+
+#undef CPU_SUBTYPE_MASK
+
+#undef CPU_SUBTYPE_ARM64E
+#undef CPU_SUBTYPE_ARM64_32_V8
+#undef CPU_SUBTYPE_ARM64_ALL
+#undef CPU_SUBTYPE_ARM64_V8
+#undef CPU_SUBTYPE_ARM_ALL
+#undef CPU_SUBTYPE_ARM_XSCALE
+#undef CPU_SUBTYPE_ARM_V4T
+#undef CPU_SUBTYPE_ARM_V5TEJ
+#undef CPU_SUBTYPE_ARM_V6
+#undef CPU_SUBTYPE_ARM_V6M
+#undef CPU_SUBTYPE_ARM_V7
+#undef CPU_SUBTYPE_ARM_V7EM
+#undef CPU_SUBTYPE_ARM_V7F
+#undef CPU_SUBTYPE_ARM_V7K
+#undef CPU_SUBTYPE_ARM_V7M
+#undef CPU_SUBTYPE_ARM_V7S
+#undef CPU_SUBTYPE_ARM_V8
+
+#undef CPU_SUBTYPE_I386_ALL
+#undef CPU_SUBTYPE_386
+#undef CPU_SUBTYPE_486
+#undef CPU_SUBTYPE_486SX
+#undef CPU_SUBTYPE_586
+#undef CPU_SUBTYPE_PENT
+#undef CPU_SUBTYPE_PENTPRO
+#undef CPU_SUBTYPE_PENTII_M3
+#undef CPU_SUBTYPE_PENTII_M5
+#undef CPU_SUBTYPE_CELERON
+#undef CPU_SUBTYPE_CELERON_MOBILE
+#undef CPU_SUBTYPE_PENTIUM_3
+#undef CPU_SUBTYPE_PENTIUM_3_M
+#undef CPU_SUBTYPE_PENTIUM_3_XEON
+#undef CPU_SUBTYPE_PENTIUM_M
+#undef CPU_SUBTYPE_PENTIUM_4
+#undef CPU_SUBTYPE_PENTIUM_4_M
+#undef CPU_SUBTYPE_ITANIUM
+#undef CPU_SUBTYPE_ITANIUM_2
+#undef CPU_SUBTYPE_XEON
+#undef CPU_SUBTYPE_XEON_MP
+
+#undef CPU_SUBTYPE_X86_ALL
+#undef CPU_SUBTYPE_X86_ARCH1
+
+#undef CPU_SUBTYPE_X86_64_ALL
+#undef CPU_SUBTYPE_X86_64_H
+
+#undef CPU_SUBTYPE_INTEL
+#undef CPU_SUBTYPE_INTEL_FAMILY
+#undef CPU_SUBTYPE_INTEL_FAMILY_MAX
+#undef CPU_SUBTYPE_INTEL_MODEL
+#undef CPU_SUBTYPE_INTEL_MODEL_ALL
+
+#undef CPU_SUBTYPE_POWERPC_ALL
+#undef CPU_SUBTYPE_POWERPC_601
+#undef CPU_SUBTYPE_POWERPC_602
+#undef CPU_SUBTYPE_POWERPC_603
+#undef CPU_SUBTYPE_POWERPC_603e
+#undef CPU_SUBTYPE_POWERPC_603ev
+#undef CPU_SUBTYPE_POWERPC_604
+#undef CPU_SUBTYPE_POWERPC_604e
+#undef CPU_SUBTYPE_POWERPC_620
+#undef CPU_SUBTYPE_POWERPC_750
+#undef CPU_SUBTYPE_POWERPC_7400
+#undef CPU_SUBTYPE_POWERPC_7450
+#undef CPU_SUBTYPE_POWERPC_970
+
+#undef CPU_SUBTYPE_MC98601
+
+#undef CPU_SUBTYPE_SPARC_ALL
+
+#undef CPU_SUBTYPE_LIB64
+#undef CPU_SUBTYPE_MULTIPLE
+
+#include <llvm/BinaryFormat/MachO.h>
+
+using llvm::MachO::CPU_ARCH_MASK;
+
+using llvm::MachO::CPU_ARCH_ABI64_32;
+using llvm::MachO::CPU_ARCH_ABI64;
+
+using llvm::MachO::CPU_TYPE_ANY;
+
+using llvm::MachO::CPU_TYPE_ARM;
+using llvm::MachO::CPU_TYPE_ARM64;
+using llvm::MachO::CPU_TYPE_ARM64_32;
+using llvm::MachO::CPU_TYPE_I386;
+using llvm::MachO::CPU_TYPE_X86;
+using llvm::MachO::CPU_TYPE_X86_64;
+using llvm::MachO::CPU_TYPE_MC98000;
+using llvm::MachO::CPU_TYPE_SPARC;
+using llvm::MachO::CPU_TYPE_POWERPC;
+using llvm::MachO::CPU_TYPE_POWERPC64;
+
+using llvm::MachO::CPU_SUBTYPE_MASK;
+
+using llvm::MachO::CPU_SUBTYPE_ARM64E;
+using llvm::MachO::CPU_SUBTYPE_ARM64_32_V8;
+using llvm::MachO::CPU_SUBTYPE_ARM64_ALL;
+using llvm::MachO::CPU_SUBTYPE_ARM64_V8;
+using llvm::MachO::CPU_SUBTYPE_ARM_ALL;
+using llvm::MachO::CPU_SUBTYPE_ARM_XSCALE;
+using llvm::MachO::CPU_SUBTYPE_ARM_V4T;
+using llvm::MachO::CPU_SUBTYPE_ARM_V5TEJ;
+using llvm::MachO::CPU_SUBTYPE_ARM_V6;
+using llvm::MachO::CPU_SUBTYPE_ARM_V6M;
+using llvm::MachO::CPU_SUBTYPE_ARM_V7;
+using llvm::MachO::CPU_SUBTYPE_ARM_V7EM;
+using llvm::MachO::CPU_SUBTYPE_ARM_V7K;
+using llvm::MachO::CPU_SUBTYPE_ARM_V7M;
+using llvm::MachO::CPU_SUBTYPE_ARM_V7S;
+
+using llvm::MachO::CPU_SUBTYPE_I386_ALL;
+using llvm::MachO::CPU_SUBTYPE_386;
+using llvm::MachO::CPU_SUBTYPE_486;
+using llvm::MachO::CPU_SUBTYPE_486SX;
+using llvm::MachO::CPU_SUBTYPE_586;
+using llvm::MachO::CPU_SUBTYPE_PENT;
+using llvm::MachO::CPU_SUBTYPE_PENTPRO;
+using llvm::MachO::CPU_SUBTYPE_PENTII_M3;
+using llvm::MachO::CPU_SUBTYPE_PENTII_M5;
+using llvm::MachO::CPU_SUBTYPE_CELERON;
+using llvm::MachO::CPU_SUBTYPE_CELERON_MOBILE;
+using llvm::MachO::CPU_SUBTYPE_PENTIUM_3;
+using llvm::MachO::CPU_SUBTYPE_PENTIUM_3_M;
+using llvm::MachO::CPU_SUBTYPE_PENTIUM_3_XEON;
+using llvm::MachO::CPU_SUBTYPE_PENTIUM_M;
+using llvm::MachO::CPU_SUBTYPE_PENTIUM_4;
+using llvm::MachO::CPU_SUBTYPE_PENTIUM_4_M;
+using llvm::MachO::CPU_SUBTYPE_ITANIUM;
+using llvm::MachO::CPU_SUBTYPE_ITANIUM_2;
+using llvm::MachO::CPU_SUBTYPE_XEON;
+using llvm::MachO::CPU_SUBTYPE_XEON_MP;
+
+using llvm::MachO::CPU_SUBTYPE_X86_ALL;
+using llvm::MachO::CPU_SUBTYPE_X86_ARCH1;
+
+using llvm::MachO::CPU_SUBTYPE_X86_64_ALL;
+using llvm::MachO::CPU_SUBTYPE_X86_64_H;
+
+using llvm::MachO::CPU_SUBTYPE_INTEL;
+using llvm::MachO::CPU_SUBTYPE_INTEL_FAMILY;
+using llvm::MachO::CPU_SUBTYPE_INTEL_FAMILY_MAX;
+using llvm::MachO::CPU_SUBTYPE_INTEL_MODEL;
+using llvm::MachO::CPU_SUBTYPE_INTEL_MODEL_ALL;
+
+using llvm::MachO::CPU_SUBTYPE_POWERPC_ALL;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_601;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_602;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_603;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_603e;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_603ev;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_604;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_604e;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_620;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_750;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_7400;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_7450;
+using llvm::MachO::CPU_SUBTYPE_POWERPC_970;
+
+using llvm::MachO::CPU_SUBTYPE_MC98601;
+
+using llvm::MachO::CPU_SUBTYPE_SPARC_ALL;
+
+using llvm::MachO::CPU_SUBTYPE_LIB64;
+using llvm::MachO::CPU_SUBTYPE_MULTIPLE;
+
+// These definitions arent in the LLVM headers.
+#define CPU_TYPE_RISCV32 24
+
+#define CPU_SUBTYPE_ARM_V7F 10
+#define CPU_SUBTYPE_ARM_V8 CPU_SUBTYPE_ARM64_V8
+#define CPU_SUBTYPE_RISCV32_ALL 0
diff --git a/include/mach/vm_prot.h b/include/mach/vm_prot.h
new file mode 100644
index 0000000..e524808
--- /dev/null
+++ b/include/mach/vm_prot.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: APSL-2.0
+
+// Derive `vm_prot.h` from LLVM to avoid macro conflicts.
+
+#pragma once
+
+#include <llvm/BinaryFormat/MachO.h>
+
+using llvm::MachO::VM_PROT_EXECUTE;
+using llvm::MachO::VM_PROT_READ;
+using llvm::MachO::VM_PROT_WRITE;
+
+#include_next <mach/vm_prot.h>
diff --git a/src/abstraction/MachOFileAbstraction.hpp b/src/abstraction/MachOFileAbstraction.hpp
index 71e7765..e8d9b5c 100644
--- a/src/abstraction/MachOFileAbstraction.hpp
+++ b/src/abstraction/MachOFileAbstraction.hpp
@@ -847,8 +847,8 @@ public:
uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
- uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name.offset); }
- void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name.offset, value); }
+ uint32_t name_offset() const INLINE { return E::get32(fields.dylib.name); }
+ void set_name_offset(uint32_t value) INLINE { E::set32(fields.dylib.name, value); }
uint32_t timestamp() const INLINE { return E::get32(fields.dylib.timestamp); }
void set_timestamp(uint32_t value) INLINE { E::set32(fields.dylib.timestamp, value); }
@@ -880,8 +880,8 @@ public:
uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
- uint32_t name_offset() const INLINE { return E::get32(fields.name.offset); }
- void set_name_offset(uint32_t value) INLINE { E::set32(fields.name.offset, value); }
+ uint32_t name_offset() const INLINE { return E::get32(fields.name); }
+ void set_name_offset(uint32_t value) INLINE { E::set32(fields.name, value); }
const char* name() const INLINE { return (const char*)&fields + name_offset(); }
void set_name_offset() INLINE { set_name_offset(sizeof(fields)); }
@@ -904,8 +904,8 @@ public:
uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
- uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella.offset); }
- void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella.offset, value); }
+ uint32_t umbrella_offset() const INLINE { return E::get32(fields.umbrella); }
+ void set_umbrella_offset(uint32_t value) INLINE { E::set32(fields.umbrella, value); }
const char* umbrella() const INLINE { return (const char*)&fields + umbrella_offset(); }
void set_umbrella_offset() INLINE { set_umbrella_offset(sizeof(fields)); }
@@ -928,8 +928,8 @@ public:
uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
- uint32_t client_offset() const INLINE { return E::get32(fields.client.offset); }
- void set_client_offset(uint32_t value) INLINE { E::set32(fields.client.offset, value); }
+ uint32_t client_offset() const INLINE { return E::get32(fields.client); }
+ void set_client_offset(uint32_t value) INLINE { E::set32(fields.client, value); }
const char* client() const INLINE { return (const char*)&fields + client_offset(); }
void set_client_offset() INLINE { set_client_offset(sizeof(fields)); }
@@ -952,8 +952,8 @@ public:
uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
- uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella.offset); }
- void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella.offset, value); }
+ uint32_t sub_umbrella_offset() const INLINE { return E::get32(fields.sub_umbrella); }
+ void set_sub_umbrella_offset(uint32_t value) INLINE { E::set32(fields.sub_umbrella, value); }
const char* sub_umbrella() const INLINE { return (const char*)&fields + sub_umbrella_offset(); }
void set_sub_umbrella_offset() INLINE { set_sub_umbrella_offset(sizeof(fields)); }
@@ -976,8 +976,8 @@ public:
uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
- uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library.offset); }
- void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library.offset, value); }
+ uint32_t sub_library_offset() const INLINE { return E::get32(fields.sub_library); }
+ void set_sub_library_offset(uint32_t value) INLINE { E::set32(fields.sub_library, value); }
const char* sub_library() const INLINE { return (const char*)&fields + sub_library_offset(); }
void set_sub_library_offset() INLINE { set_sub_library_offset(sizeof(fields)); }
@@ -1355,8 +1355,8 @@ public:
uint32_t cmdsize() const INLINE { return E::get32(fields.cmdsize); }
void set_cmdsize(uint32_t value) INLINE { E::set32(fields.cmdsize, value); }
- uint32_t path_offset() const INLINE { return E::get32(fields.path.offset); }
- void set_path_offset(uint32_t value) INLINE { E::set32(fields.path.offset, value); }
+ uint32_t path_offset() const INLINE { return E::get32(fields.path); }
+ void set_path_offset(uint32_t value) INLINE { E::set32(fields.path, value); }
const char* path() const INLINE { return (const char*)&fields + path_offset(); }
void set_path_offset() INLINE { set_path_offset(sizeof(fields)); }
@@ -1381,8 +1381,8 @@ template <> struct macho_nlist_content<Pointer64<LittleEndian> > { struct nlist_
template <typename P>
class macho_nlist {
public:
- uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_un.n_strx); }
- void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_un.n_strx, value); }
+ uint32_t n_strx() const INLINE { return E::get32(entry.fields.n_strx); }
+ void set_n_strx(uint32_t value) INLINE { E::set32((uint32_t&)entry.fields.n_strx, value); }
uint8_t n_type() const INLINE { return entry.fields.n_type; }
void set_n_type(uint8_t value) INLINE { entry.fields.n_type = value; }
--
2.47.2

View File

@@ -0,0 +1,111 @@
From 6a023ee77ca48497382050998d9b33c56330f735 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 09/18] Support LTO in nixpkgs
---
src/ld/InputFiles.cpp | 11 ++---------
src/ld/meson.build | 13 ++++++++++++-
src/ld/parsers/lto_file.cpp | 2 +-
src/ld/parsers/meson.build | 13 ++++++++++++-
4 files changed, 27 insertions(+), 12 deletions(-)
diff --git a/src/ld/InputFiles.cpp b/src/ld/InputFiles.cpp
index e045e90..d5341d9 100644
--- a/src/ld/InputFiles.cpp
+++ b/src/ld/InputFiles.cpp
@@ -464,15 +464,8 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib
if ( _options.overridePathlibLTO() != NULL ) {
libLTO = _options.overridePathlibLTO();
}
- else if ( _NSGetExecutablePath(ldPath, &bufSize) != -1 ) {
- if ( realpath(ldPath, tmpPath) != NULL ) {
- char* lastSlash = strrchr(tmpPath, '/');
- if ( lastSlash != NULL )
- strcpy(lastSlash, "/../lib/libLTO.dylib");
- libLTO = tmpPath;
- if ( realpath(tmpPath, libLTOPath) != NULL )
- libLTO = libLTOPath;
- }
+ else {
+ libLTO = "@libllvm_path@/lib/libLTO.dylib";
}
throwf("could not process llvm bitcode object file, because %s could not be loaded", libLTO);
}
diff --git a/src/ld/meson.build b/src/ld/meson.build
index 8bc85b7..ad8359a 100644
--- a/src/ld/meson.build
+++ b/src/ld/meson.build
@@ -1,5 +1,16 @@
subdir('parsers')
+InputFiles_cpp = configure_file(
+ configuration : {
+ 'libllvm_path' : get_option('libllvm_path'),
+ # Silence warnings
+ 'APPLE_LICENSE_HEADER_START' : '@APPLE_LICENSE_HEADER_START@',
+ 'APPLE_LICENSE_HEADER_END' : '@APPLE_LICENSE_HEADER_END@',
+ },
+ input : 'InputFiles.cpp',
+ output : '@PLAINNAME@',
+)
+
executable(
'ld',
cpp_args : [
@@ -31,8 +42,8 @@ executable(
],
sources : [
configure_h,
+ InputFiles_cpp,
'FatFile.cpp',
- 'InputFiles.cpp',
'Mangling.cpp',
'Options.cpp',
'OutputFile.cpp',
diff --git a/src/ld/parsers/lto_file.cpp b/src/ld/parsers/lto_file.cpp
index e32e2f8..1a3b846 100644
--- a/src/ld/parsers/lto_file.cpp
+++ b/src/ld/parsers/lto_file.cpp
@@ -1839,7 +1839,7 @@ bool optimize( const std::vector<const ld::Atom*>& allAtoms,
}; // namespace lto
-static const char *sLTODylib = "@rpath/libLTO.dylib";
+static const char *sLTODylib = "@libllvm_path@/lib/libLTO.dylib";
static std::atomic<bool> sLTOIsLoaded(false);
static void *getHandle() {
diff --git a/src/ld/parsers/meson.build b/src/ld/parsers/meson.build
index a88f651..7bd3e89 100644
--- a/src/ld/parsers/meson.build
+++ b/src/ld/parsers/meson.build
@@ -1,3 +1,14 @@
+lto_file_cpp = configure_file(
+ configuration : {
+ 'libllvm_path' : get_option('libllvm_path'),
+ # Silence warnings
+ 'APPLE_LICENSE_HEADER_START' : '@APPLE_LICENSE_HEADER_START@',
+ 'APPLE_LICENSE_HEADER_END' : '@APPLE_LICENSE_HEADER_END@',
+ },
+ input : 'lto_file.cpp',
+ output : '@PLAINNAME@',
+)
+
parsers = static_library(
'parsers',
cpp_args : [ '-Wno-vla-cxx-extension' ],
@@ -10,9 +21,9 @@ parsers = static_library(
],
sources : [
configure_h,
+ lto_file_cpp,
'archive_file.cpp',
'generic_dylib_file.cpp',
- 'lto_file.cpp',
'macho_dylib_file.cpp',
'macho_relocatable_file.cpp',
'opaque_section_file.cpp',
--
2.47.2

View File

@@ -0,0 +1,97 @@
From 2846b56c7e1d88942bd3de96cbe3fec6b0304012 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 10/18] Add vendored libtapi to the ld64 build
---
meson.build | 3 +-
subprojects/libtapi/meson.build | 44 ++++++++++++++++++++++++++++
subprojects/libtapi/tapi/meson.build | 11 +++++++
3 files changed, 57 insertions(+), 1 deletion(-)
create mode 100644 subprojects/libtapi/meson.build
create mode 100644 subprojects/libtapi/tapi/meson.build
diff --git a/meson.build b/meson.build
index a79f03f..244458c 100644
--- a/meson.build
+++ b/meson.build
@@ -26,7 +26,8 @@ libcodedirectory_dep = dependency(
)
libtapi_dep = dependency(
'libtapi',
- version : [ '>=1500' , '<1600' ],
+ version : [ '>=1600' , '<1700' ],
+ fallback : [ 'libtapi', 'libtapi_dep' ],
)
llvm_dep = dependency(
'llvm',
diff --git a/subprojects/libtapi/meson.build b/subprojects/libtapi/meson.build
new file mode 100644
index 0000000..9cd1dcc
--- /dev/null
+++ b/subprojects/libtapi/meson.build
@@ -0,0 +1,44 @@
+project(
+ 'libtapi',
+ 'c', 'cpp',
+ default_options : {'c_std': 'c23', 'cpp_std': 'c++23'},
+ license : 'NCSA',
+ license_files : 'LICENSE.TXT',
+ meson_version : '>=1.6.0',
+ version : '1600.0.11.8',
+)
+
+
+cc = meson.get_compiler('c')
+cxx = meson.get_compiler('cpp')
+
+# libtapi only needs a subset of functionality from LLVM, so link only what it needs statically
+# to avoid ODR violations when loading LTO plugins (which dont use these APIs).
+llvm_dep = dependency(
+ 'llvm',
+ modules : [
+ 'demangle',
+ 'targetparser',
+ 'textapi',
+ ],
+ static : true,
+ version : '>=19.1'
+)
+
+
+subdir('tapi')
+
+libtapi = static_library(
+ 'tapi',
+ sources : [
+ 'APIVersion.cpp',
+ 'LinkerInterfaceFile.cpp',
+ 'Version.cpp',
+ ],
+)
+
+libtapi_dep = declare_dependency(
+ dependencies : [ llvm_dep ],
+ include_directories : [ '.' ],
+ link_with : libtapi,
+)
diff --git a/subprojects/libtapi/tapi/meson.build b/subprojects/libtapi/tapi/meson.build
new file mode 100644
index 0000000..c9e463a
--- /dev/null
+++ b/subprojects/libtapi/tapi/meson.build
@@ -0,0 +1,11 @@
+version_components = meson.project_version().split('.')
+version_inc = configure_file(
+ configuration : {
+ 'TAPI_VERSION' : meson.project_version(),
+ 'TAPI_VERSION_MAJOR' : version_components[0],
+ 'TAPI_VERSION_MINOR' : version_components[1],
+ 'TAPI_VERSION_PATCH' : version_components[2],
+ },
+ input : 'Version.inc.in',
+ output : '@BASENAME@',
+)
--
2.47.2

View File

@@ -0,0 +1,120 @@
From ef6039563489695e2593f0c156d13b01491d2644 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 11/18] Modify vendored libtapi to build with upstream LLVM
---
subprojects/libtapi/LinkerInterfaceFile.cpp | 47 +++++++++------------
1 file changed, 21 insertions(+), 26 deletions(-)
diff --git a/subprojects/libtapi/LinkerInterfaceFile.cpp b/subprojects/libtapi/LinkerInterfaceFile.cpp
index 76797e3..632eac8 100644
--- a/subprojects/libtapi/LinkerInterfaceFile.cpp
+++ b/subprojects/libtapi/LinkerInterfaceFile.cpp
@@ -10,12 +10,12 @@
/// \brief Implements the C++ linker interface file API.
///
//===----------------------------------------------------------------------===//
-#include "tapi/Core/LLVM.h"
-#include "tapi/Core/Registry.h"
-#include "tapi/Core/Utils.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/Object/MachO.h"
-#include "llvm/TextAPI/InterfaceFile.h"
+#include <llvm/ADT/StringExtras.h>
+#include <llvm/Object/MachO.h>
+#include <llvm/Support/Process.h>
+#include <llvm/TextAPI/InterfaceFile.h>
+#include <llvm/TextAPI/TextAPIReader.h>
+#include <llvm/TextAPI/Utils.h>
#include <string>
#include <tapi/LinkerInterfaceFile.h>
#include <tapi/PackedVersion32.h>
@@ -27,10 +27,17 @@ using namespace llvm::MachO;
TAPI_NAMESPACE_V1_BEGIN
-using namespace tapi::internal;
using InterfaceFile = llvm::MachO::InterfaceFile;
using PackedVersion = llvm::MachO::PackedVersion;
+/// Determine if tapi is running in a B&I context.
+static inline bool inBnIEnvironment() {
+ if (auto isBnI = llvm::sys::Process::GetEnv("RC_XBS"))
+ return (isBnI.value() == "YES") &&
+ (!llvm::sys::Process::GetEnv("RC_BUILDIT"));
+ return false;
+}
+
static PackedVersion parseVersion32(StringRef str) {
uint32_t version = 0;
if (str.empty())
@@ -118,7 +125,7 @@ public:
void processSymbol(StringRef name, PackedVersion minOSVersion,
bool disallowWeakImports) {
// $ld$ <action> $ <condition> $ <symbol-name>
- if (!name.startswith("$ld$"))
+ if (!name.starts_with("$ld$"))
return;
StringRef action, condition, symbolName;
@@ -127,7 +134,7 @@ public:
if (action.empty() || condition.empty() || symbolName.empty())
return;
- if (!condition.startswith("os"))
+ if (!condition.starts_with("os"))
return;
auto version = parseVersion32(condition.drop_front(2));
@@ -198,33 +205,21 @@ LinkerInterfaceFile::getSupportedFileExtensions() noexcept {
/// \brief Load and parse the provided TBD file in the buffer and return on
/// success the interface file.
static Expected<std::unique_ptr<const InterfaceFile>>
-loadFile(std::unique_ptr<MemoryBuffer> buffer,
- ReadFlags readFlags = ReadFlags::Symbols) {
- Registry registry;
- registry.addYAMLReaders();
- registry.addJSONReaders();
- registry.addDiagnosticReader();
-
- auto textFile = registry.readTextFile(std::move(buffer), readFlags);
+loadFile(std::unique_ptr<MemoryBuffer> buffer) {
+ auto textFile = llvm::MachO::TextAPIReader::get(buffer->getMemBufferRef());
if (!textFile)
return textFile.takeError();
return std::unique_ptr<const InterfaceFile>(
cast<const InterfaceFile>(textFile.get().release()));
-
- return std::make_unique<const InterfaceFile>(InterfaceFile());
}
bool LinkerInterfaceFile::isSupported(const std::string &path,
const uint8_t *data,
size_t size) noexcept {
- Registry registry;
- registry.addYAMLReaders();
- registry.addJSONReaders();
- registry.addDiagnosticReader();
auto memBuffer = MemoryBufferRef(
StringRef(reinterpret_cast<const char *>(data), size), path);
- return registry.canRead(memBuffer);
+ return !!llvm::MachO::TextAPIReader::canRead(memBuffer);
}
bool LinkerInterfaceFile::shouldPreferTextBasedStubFile(
@@ -316,8 +311,8 @@ bool LinkerInterfaceFile::Impl::init(
switch (symbol->getKind()) {
case EncodeKind::GlobalSymbol:
- if (symbol->getName().startswith("$ld$") &&
- !symbol->getName().startswith("$ld$previous"))
+ if (symbol->getName().starts_with("$ld$") &&
+ !symbol->getName().starts_with("$ld$previous"))
continue;
addSymbol(symbol->getName(), symbol->getFlags());
break;
--
2.47.2

View File

@@ -0,0 +1,471 @@
From 4f186ca22f34cda1cbdea131a15f2bc79db440ba Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 12/18] Move libcodedirectory to its own subproject
---
meson.build | 1 +
src/ld/meson.build | 1 -
subprojects/libcodedirectory/APPLE_LICENSE | 367 ++++++++++++++++++
.../libcodedirectory}/cs_blobs.h | 0
.../libcodedirectory}/libcodedirectory.c | 0
.../libcodedirectory}/libcodedirectory.h | 0
subprojects/libcodedirectory/meson.build | 33 ++
7 files changed, 401 insertions(+), 1 deletion(-)
create mode 100644 subprojects/libcodedirectory/APPLE_LICENSE
rename {src/ld => subprojects/libcodedirectory}/cs_blobs.h (100%)
rename {src/ld => subprojects/libcodedirectory}/libcodedirectory.c (100%)
rename {src/ld => subprojects/libcodedirectory}/libcodedirectory.h (100%)
create mode 100644 subprojects/libcodedirectory/meson.build
diff --git a/meson.build b/meson.build
index 244458c..c053d20 100644
--- a/meson.build
+++ b/meson.build
@@ -23,6 +23,7 @@ cxx = meson.get_compiler('cpp')
libcodedirectory_dep = dependency(
'libcodedirectory',
version : '=819.6.1',
+ fallback : [ 'libcodedirectory', 'libcodedirectory_dep' ],
)
libtapi_dep = dependency(
'libtapi',
diff --git a/src/ld/meson.build b/src/ld/meson.build
index ad8359a..201e891 100644
--- a/src/ld/meson.build
+++ b/src/ld/meson.build
@@ -56,7 +56,6 @@ executable(
'code-sign-blobs/blob.h',
'debugline.c',
'ld.cpp',
- 'libcodedirectory.c',
'passes/bitcode_bundle.cpp',
'passes/branch_island.cpp',
'passes/branch_shim.cpp',
diff --git a/subprojects/libcodedirectory/APPLE_LICENSE b/subprojects/libcodedirectory/APPLE_LICENSE
new file mode 100644
index 0000000..fe81a60
--- /dev/null
+++ b/subprojects/libcodedirectory/APPLE_LICENSE
@@ -0,0 +1,367 @@
+APPLE PUBLIC SOURCE LICENSE
+Version 2.0 - August 6, 2003
+
+Please read this License carefully before downloading this software.
+By downloading or using this software, you are agreeing to be bound by
+the terms of this License. If you do not or cannot agree to the terms
+of this License, please do not download or use the software.
+
+1. General; Definitions. This License applies to any program or other
+work which Apple Computer, Inc. ("Apple") makes publicly available and
+which contains a notice placed by Apple identifying such program or
+work as "Original Code" and stating that it is subject to the terms of
+this Apple Public Source License version 2.0 ("License"). As used in
+this License:
+
+1.1 "Applicable Patent Rights" mean: (a) in the case where Apple is
+the grantor of rights, (i) claims of patents that are now or hereafter
+acquired, owned by or assigned to Apple and (ii) that cover subject
+matter contained in the Original Code, but only to the extent
+necessary to use, reproduce and/or distribute the Original Code
+without infringement; and (b) in the case where You are the grantor of
+rights, (i) claims of patents that are now or hereafter acquired,
+owned by or assigned to You and (ii) that cover subject matter in Your
+Modifications, taken alone or in combination with Original Code.
+
+1.2 "Contributor" means any person or entity that creates or
+contributes to the creation of Modifications.
+
+1.3 "Covered Code" means the Original Code, Modifications, the
+combination of Original Code and any Modifications, and/or any
+respective portions thereof.
+
+1.4 "Externally Deploy" means: (a) to sublicense, distribute or
+otherwise make Covered Code available, directly or indirectly, to
+anyone other than You; and/or (b) to use Covered Code, alone or as
+part of a Larger Work, in any way to provide a service, including but
+not limited to delivery of content, through electronic communication
+with a client other than You.
+
+1.5 "Larger Work" means a work which combines Covered Code or portions
+thereof with code not governed by the terms of this License.
+
+1.6 "Modifications" mean any addition to, deletion from, and/or change
+to, the substance and/or structure of the Original Code, any previous
+Modifications, the combination of Original Code and any previous
+Modifications, and/or any respective portions thereof. When code is
+released as a series of files, a Modification is: (a) any addition to
+or deletion from the contents of a file containing Covered Code;
+and/or (b) any new file or other representation of computer program
+statements that contains any part of Covered Code.
+
+1.7 "Original Code" means (a) the Source Code of a program or other
+work as originally made available by Apple under this License,
+including the Source Code of any updates or upgrades to such programs
+or works made available by Apple under this License, and that has been
+expressly identified by Apple as such in the header file(s) of such
+work; and (b) the object code compiled from such Source Code and
+originally made available by Apple under this License.
+
+1.8 "Source Code" means the human readable form of a program or other
+work that is suitable for making modifications to it, including all
+modules it contains, plus any associated interface definition files,
+scripts used to control compilation and installation of an executable
+(object code).
+
+1.9 "You" or "Your" means an individual or a legal entity exercising
+rights under this License. For legal entities, "You" or "Your"
+includes any entity which controls, is controlled by, or is under
+common control with, You, where "control" means (a) the power, direct
+or indirect, to cause the direction or management of such entity,
+whether by contract or otherwise, or (b) ownership of fifty percent
+(50%) or more of the outstanding shares or beneficial ownership of
+such entity.
+
+2. Permitted Uses; Conditions & Restrictions. Subject to the terms
+and conditions of this License, Apple hereby grants You, effective on
+the date You accept this License and download the Original Code, a
+world-wide, royalty-free, non-exclusive license, to the extent of
+Apple's Applicable Patent Rights and copyrights covering the Original
+Code, to do the following:
+
+2.1 Unmodified Code. You may use, reproduce, display, perform,
+internally distribute within Your organization, and Externally Deploy
+verbatim, unmodified copies of the Original Code, for commercial or
+non-commercial purposes, provided that in each instance:
+
+(a) You must retain and reproduce in all copies of Original Code the
+copyright and other proprietary notices and disclaimers of Apple as
+they appear in the Original Code, and keep intact all notices in the
+Original Code that refer to this License; and
+
+(b) You must include a copy of this License with every copy of Source
+Code of Covered Code and documentation You distribute or Externally
+Deploy, and You may not offer or impose any terms on such Source Code
+that alter or restrict this License or the recipients' rights
+hereunder, except as permitted under Section 6.
+
+2.2 Modified Code. You may modify Covered Code and use, reproduce,
+display, perform, internally distribute within Your organization, and
+Externally Deploy Your Modifications and Covered Code, for commercial
+or non-commercial purposes, provided that in each instance You also
+meet all of these conditions:
+
+(a) You must satisfy all the conditions of Section 2.1 with respect to
+the Source Code of the Covered Code;
+
+(b) You must duplicate, to the extent it does not already exist, the
+notice in Exhibit A in each file of the Source Code of all Your
+Modifications, and cause the modified files to carry prominent notices
+stating that You changed the files and the date of any change; and
+
+(c) If You Externally Deploy Your Modifications, You must make
+Source Code of all Your Externally Deployed Modifications either
+available to those to whom You have Externally Deployed Your
+Modifications, or publicly available. Source Code of Your Externally
+Deployed Modifications must be released under the terms set forth in
+this License, including the license grants set forth in Section 3
+below, for as long as you Externally Deploy the Covered Code or twelve
+(12) months from the date of initial External Deployment, whichever is
+longer. You should preferably distribute the Source Code of Your
+Externally Deployed Modifications electronically (e.g. download from a
+web site).
+
+2.3 Distribution of Executable Versions. In addition, if You
+Externally Deploy Covered Code (Original Code and/or Modifications) in
+object code, executable form only, You must include a prominent
+notice, in the code itself as well as in related documentation,
+stating that Source Code of the Covered Code is available under the
+terms of this License with information on how and where to obtain such
+Source Code.
+
+2.4 Third Party Rights. You expressly acknowledge and agree that
+although Apple and each Contributor grants the licenses to their
+respective portions of the Covered Code set forth herein, no
+assurances are provided by Apple or any Contributor that the Covered
+Code does not infringe the patent or other intellectual property
+rights of any other entity. Apple and each Contributor disclaim any
+liability to You for claims brought by any other entity based on
+infringement of intellectual property rights or otherwise. As a
+condition to exercising the rights and licenses granted hereunder, You
+hereby assume sole responsibility to secure any other intellectual
+property rights needed, if any. For example, if a third party patent
+license is required to allow You to distribute the Covered Code, it is
+Your responsibility to acquire that license before distributing the
+Covered Code.
+
+3. Your Grants. In consideration of, and as a condition to, the
+licenses granted to You under this License, You hereby grant to any
+person or entity receiving or distributing Covered Code under this
+License a non-exclusive, royalty-free, perpetual, irrevocable license,
+under Your Applicable Patent Rights and other intellectual property
+rights (other than patent) owned or controlled by You, to use,
+reproduce, display, perform, modify, sublicense, distribute and
+Externally Deploy Your Modifications of the same scope and extent as
+Apple's licenses under Sections 2.1 and 2.2 above.
+
+4. Larger Works. You may create a Larger Work by combining Covered
+Code with other code not governed by the terms of this License and
+distribute the Larger Work as a single product. In each such instance,
+You must make sure the requirements of this License are fulfilled for
+the Covered Code or any portion thereof.
+
+5. Limitations on Patent License. Except as expressly stated in
+Section 2, no other patent rights, express or implied, are granted by
+Apple herein. Modifications and/or Larger Works may require additional
+patent licenses from Apple which Apple may grant in its sole
+discretion.
+
+6. Additional Terms. You may choose to offer, and to charge a fee for,
+warranty, support, indemnity or liability obligations and/or other
+rights consistent with the scope of the license granted herein
+("Additional Terms") to one or more recipients of Covered Code.
+However, You may do so only on Your own behalf and as Your sole
+responsibility, and not on behalf of Apple or any Contributor. You
+must obtain the recipient's agreement that any such Additional Terms
+are offered by You alone, and You hereby agree to indemnify, defend
+and hold Apple and every Contributor harmless for any liability
+incurred by or claims asserted against Apple or such Contributor by
+reason of any such Additional Terms.
+
+7. Versions of the License. Apple may publish revised and/or new
+versions of this License from time to time. Each version will be given
+a distinguishing version number. Once Original Code has been published
+under a particular version of this License, You may continue to use it
+under the terms of that version. You may also choose to use such
+Original Code under the terms of any subsequent version of this
+License published by Apple. No one other than Apple has the right to
+modify the terms applicable to Covered Code created under this
+License.
+
+8. NO WARRANTY OR SUPPORT. The Covered Code may contain in whole or in
+part pre-release, untested, or not fully tested works. The Covered
+Code may contain errors that could cause failures or loss of data, and
+may be incomplete or contain inaccuracies. You expressly acknowledge
+and agree that use of the Covered Code, or any portion thereof, is at
+Your sole and entire risk. THE COVERED CODE IS PROVIDED "AS IS" AND
+WITHOUT WARRANTY, UPGRADES OR SUPPORT OF ANY KIND AND APPLE AND
+APPLE'S LICENSOR(S) (COLLECTIVELY REFERRED TO AS "APPLE" FOR THE
+PURPOSES OF SECTIONS 8 AND 9) AND ALL CONTRIBUTORS EXPRESSLY DISCLAIM
+ALL WARRANTIES AND/OR CONDITIONS, EXPRESS OR IMPLIED, INCLUDING, BUT
+NOT LIMITED TO, THE IMPLIED WARRANTIES AND/OR CONDITIONS OF
+MERCHANTABILITY, OF SATISFACTORY QUALITY, OF FITNESS FOR A PARTICULAR
+PURPOSE, OF ACCURACY, OF QUIET ENJOYMENT, AND NONINFRINGEMENT OF THIRD
+PARTY RIGHTS. APPLE AND EACH CONTRIBUTOR DOES NOT WARRANT AGAINST
+INTERFERENCE WITH YOUR ENJOYMENT OF THE COVERED CODE, THAT THE
+FUNCTIONS CONTAINED IN THE COVERED CODE WILL MEET YOUR REQUIREMENTS,
+THAT THE OPERATION OF THE COVERED CODE WILL BE UNINTERRUPTED OR
+ERROR-FREE, OR THAT DEFECTS IN THE COVERED CODE WILL BE CORRECTED. NO
+ORAL OR WRITTEN INFORMATION OR ADVICE GIVEN BY APPLE, AN APPLE
+AUTHORIZED REPRESENTATIVE OR ANY CONTRIBUTOR SHALL CREATE A WARRANTY.
+You acknowledge that the Covered Code is not intended for use in the
+operation of nuclear facilities, aircraft navigation, communication
+systems, or air traffic control machines in which case the failure of
+the Covered Code could lead to death, personal injury, or severe
+physical or environmental damage.
+
+9. LIMITATION OF LIABILITY. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO
+EVENT SHALL APPLE OR ANY CONTRIBUTOR BE LIABLE FOR ANY INCIDENTAL,
+SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING
+TO THIS LICENSE OR YOUR USE OR INABILITY TO USE THE COVERED CODE, OR
+ANY PORTION THEREOF, WHETHER UNDER A THEORY OF CONTRACT, WARRANTY,
+TORT (INCLUDING NEGLIGENCE), PRODUCTS LIABILITY OR OTHERWISE, EVEN IF
+APPLE OR SUCH CONTRIBUTOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
+DAMAGES AND NOTWITHSTANDING THE FAILURE OF ESSENTIAL PURPOSE OF ANY
+REMEDY. SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OF LIABILITY OF
+INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT APPLY
+TO YOU. In no event shall Apple's total liability to You for all
+damages (other than as may be required by applicable law) under this
+License exceed the amount of fifty dollars ($50.00).
+
+10. Trademarks. This License does not grant any rights to use the
+trademarks or trade names "Apple", "Apple Computer", "Mac", "Mac OS",
+"QuickTime", "QuickTime Streaming Server" or any other trademarks,
+service marks, logos or trade names belonging to Apple (collectively
+"Apple Marks") or to any trademark, service mark, logo or trade name
+belonging to any Contributor. You agree not to use any Apple Marks in
+or as part of the name of products derived from the Original Code or
+to endorse or promote products derived from the Original Code other
+than as expressly permitted by and in strict compliance at all times
+with Apple's third party trademark usage guidelines which are posted
+at http://www.apple.com/legal/guidelinesfor3rdparties.html.
+
+11. Ownership. Subject to the licenses granted under this License,
+each Contributor retains all rights, title and interest in and to any
+Modifications made by such Contributor. Apple retains all rights,
+title and interest in and to the Original Code and any Modifications
+made by or on behalf of Apple ("Apple Modifications"), and such Apple
+Modifications will not be automatically subject to this License. Apple
+may, at its sole discretion, choose to license such Apple
+Modifications under this License, or on different terms from those
+contained in this License or may choose not to license them at all.
+
+12. Termination.
+
+12.1 Termination. This License and the rights granted hereunder will
+terminate:
+
+(a) automatically without notice from Apple if You fail to comply with
+any term(s) of this License and fail to cure such breach within 30
+days of becoming aware of such breach;
+
+(b) immediately in the event of the circumstances described in Section
+13.5(b); or
+
+(c) automatically without notice from Apple if You, at any time during
+the term of this License, commence an action for patent infringement
+against Apple; provided that Apple did not first commence
+an action for patent infringement against You in that instance.
+
+12.2 Effect of Termination. Upon termination, You agree to immediately
+stop any further use, reproduction, modification, sublicensing and
+distribution of the Covered Code. All sublicenses to the Covered Code
+which have been properly granted prior to termination shall survive
+any termination of this License. Provisions which, by their nature,
+should remain in effect beyond the termination of this License shall
+survive, including but not limited to Sections 3, 5, 8, 9, 10, 11,
+12.2 and 13. No party will be liable to any other for compensation,
+indemnity or damages of any sort solely as a result of terminating
+this License in accordance with its terms, and termination of this
+License will be without prejudice to any other right or remedy of
+any party.
+
+13. Miscellaneous.
+
+13.1 Government End Users. The Covered Code is a "commercial item" as
+defined in FAR 2.101. Government software and technical data rights in
+the Covered Code include only those rights customarily provided to the
+public as defined in this License. This customary commercial license
+in technical data and software is provided in accordance with FAR
+12.211 (Technical Data) and 12.212 (Computer Software) and, for
+Department of Defense purchases, DFAR 252.227-7015 (Technical Data --
+Commercial Items) and 227.7202-3 (Rights in Commercial Computer
+Software or Computer Software Documentation). Accordingly, all U.S.
+Government End Users acquire Covered Code with only those rights set
+forth herein.
+
+13.2 Relationship of Parties. This License will not be construed as
+creating an agency, partnership, joint venture or any other form of
+legal association between or among You, Apple or any Contributor, and
+You will not represent to the contrary, whether expressly, by
+implication, appearance or otherwise.
+
+13.3 Independent Development. Nothing in this License will impair
+Apple's right to acquire, license, develop, have others develop for
+it, market and/or distribute technology or products that perform the
+same or similar functions as, or otherwise compete with,
+Modifications, Larger Works, technology or products that You may
+develop, produce, market or distribute.
+
+13.4 Waiver; Construction. Failure by Apple or any Contributor to
+enforce any provision of this License will not be deemed a waiver of
+future enforcement of that or any other provision. Any law or
+regulation which provides that the language of a contract shall be
+construed against the drafter will not apply to this License.
+
+13.5 Severability. (a) If for any reason a court of competent
+jurisdiction finds any provision of this License, or portion thereof,
+to be unenforceable, that provision of the License will be enforced to
+the maximum extent permissible so as to effect the economic benefits
+and intent of the parties, and the remainder of this License will
+continue in full force and effect. (b) Notwithstanding the foregoing,
+if applicable law prohibits or restricts You from fully and/or
+specifically complying with Sections 2 and/or 3 or prevents the
+enforceability of either of those Sections, this License will
+immediately terminate and You must immediately discontinue any use of
+the Covered Code and destroy all copies of it that are in your
+possession or control.
+
+13.6 Dispute Resolution. Any litigation or other dispute resolution
+between You and Apple relating to this License shall take place in the
+Northern District of California, and You and Apple hereby consent to
+the personal jurisdiction of, and venue in, the state and federal
+courts within that District with respect to this License. The
+application of the United Nations Convention on Contracts for the
+International Sale of Goods is expressly excluded.
+
+13.7 Entire Agreement; Governing Law. This License constitutes the
+entire agreement between the parties with respect to the subject
+matter hereof. This License shall be governed by the laws of the
+United States and the State of California, except that body of
+California law concerning conflicts of law.
+
+Where You are located in the province of Quebec, Canada, the following
+clause applies: The parties hereby confirm that they have requested
+that this License and all related documents be drafted in English. Les
+parties ont exige que le present contrat et tous les documents
+connexes soient rediges en anglais.
+
+EXHIBIT A.
+
+"Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
+Reserved.
+
+This file contains Original Code and/or Modifications of Original Code
+as defined in and that are subject to the Apple Public Source License
+Version 2.0 (the 'License'). You may not use this file except in
+compliance with the License. Please obtain a copy of the License at
+http://www.opensource.apple.com/apsl/ and read it before using this
+file.
+
+The Original Code and all software distributed under the License are
+distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
+INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+Please see the License for the specific language governing rights and
+limitations under the License."
diff --git a/src/ld/cs_blobs.h b/subprojects/libcodedirectory/cs_blobs.h
similarity index 100%
rename from src/ld/cs_blobs.h
rename to subprojects/libcodedirectory/cs_blobs.h
diff --git a/src/ld/libcodedirectory.c b/subprojects/libcodedirectory/libcodedirectory.c
similarity index 100%
rename from src/ld/libcodedirectory.c
rename to subprojects/libcodedirectory/libcodedirectory.c
diff --git a/src/ld/libcodedirectory.h b/subprojects/libcodedirectory/libcodedirectory.h
similarity index 100%
rename from src/ld/libcodedirectory.h
rename to subprojects/libcodedirectory/libcodedirectory.h
diff --git a/subprojects/libcodedirectory/meson.build b/subprojects/libcodedirectory/meson.build
new file mode 100644
index 0000000..de8a4ae
--- /dev/null
+++ b/subprojects/libcodedirectory/meson.build
@@ -0,0 +1,33 @@
+project(
+ 'libcodedirectory',
+ 'c',
+ default_options : {'c_std': 'c23'},
+ license : 'APSL-2.0',
+ license_files : 'APPLE_LICENSE',
+ meson_version : '>=1.6.0',
+ version : '819.6.1',
+)
+
+
+cc = meson.get_compiler('c')
+
+openssl_dep = dependency('openssl', version : '>=3.0')
+
+
+libcodedirectory = library(
+ 'codedirectory',
+ c_args : [ '-Wno-gnu-folding-constant' ],
+ dependencies : [ openssl_dep ],
+ install : true,
+ sources : [ 'libcodedirectory.c' ],
+ soversion : 1,
+)
+install_headers(
+ 'cs_blobs.h',
+ 'libcodedirectory.h',
+)
+
+libcodedirectory_dep = declare_dependency(
+ include_directories : [ '.' ],
+ link_with : libcodedirectory,
+)
--
2.47.2

View File

@@ -0,0 +1,41 @@
From fb1ec0eeac424d72175b14b08da9c2d85681b245 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Sun, 17 Nov 2024 10:02:34 -0500
Subject: [PATCH 13/18] Set the version string in the build
---
src/ld/meson.build | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/src/ld/meson.build b/src/ld/meson.build
index 201e891..769ac28 100644
--- a/src/ld/meson.build
+++ b/src/ld/meson.build
@@ -11,6 +11,16 @@ InputFiles_cpp = configure_file(
output : '@PLAINNAME@',
)
+version_string_cpp = configure_file(
+ capture : true,
+ command : [
+ find_program('bash', native : true),
+ '-c',
+ 'echo \'extern const char ld_classicVersionString[] = "@(#)PROGRAM:ld PROJECT:ld64-' + meson.project_version() + '\\n";\''
+ ],
+ output : 'version_string.cpp',
+)
+
executable(
'ld',
cpp_args : [
@@ -43,6 +53,7 @@ executable(
sources : [
configure_h,
InputFiles_cpp,
+ version_string_cpp,
'FatFile.cpp',
'Mangling.cpp',
'Options.cpp',
--
2.47.2

View File

@@ -0,0 +1,341 @@
From b2cfb2019b79e674a507a8b428bba4b82b2276d0 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 14/18] Replace corecrypto and CommonCrypto with OpenSSL
---
src/ld/LinkEdit.hpp | 2 -
src/ld/OutputFile.cpp | 78 ++++++++++++----
subprojects/libcodedirectory/cs_blobs.h | 1 +
.../libcodedirectory/libcodedirectory.c | 90 +++++++++++++------
4 files changed, 126 insertions(+), 45 deletions(-)
diff --git a/src/ld/LinkEdit.hpp b/src/ld/LinkEdit.hpp
index 4a6d5fe..818fcdf 100644
--- a/src/ld/LinkEdit.hpp
+++ b/src/ld/LinkEdit.hpp
@@ -30,8 +30,6 @@
#include <errno.h>
#include <limits.h>
#include <unistd.h>
-#include <CommonCrypto/CommonDigest.h>
-#include <CommonCrypto/CommonDigestSPI.h>
#include <vector>
#include <unordered_map>
diff --git a/src/ld/OutputFile.cpp b/src/ld/OutputFile.cpp
index 2a175a7..69b476f 100644
--- a/src/ld/OutputFile.cpp
+++ b/src/ld/OutputFile.cpp
@@ -43,10 +43,6 @@
#include <mach-o/dyld.h>
#include <mach-o/fat.h>
#include <dispatch/dispatch.h>
-#include <os/lock_private.h>
-extern "C" {
- #include <corecrypto/ccsha2.h>
-}
#include <mutex>
#include <string>
@@ -56,9 +52,10 @@ extern "C" {
#include <iostream>
#include <fstream>
-#include <CommonCrypto/CommonDigest.h>
#include <AvailabilityMacros.h>
+#include <openssl/err.h>
+#include <openssl/evp.h>
#include "ExportsTrie.h"
@@ -79,6 +76,17 @@ uint32_t sAdrpNA = 0;
uint32_t sAdrpNoped = 0;
uint32_t sAdrpNotNoped = 0;
+static void
+EVP_MD_cleanup(EVP_MD** digest) {
+ EVP_MD_free(*digest);
+ *digest = nullptr;
+}
+
+static void
+EVP_MD_CTX_cleanup(EVP_MD_CTX** context) {
+ EVP_MD_CTX_free(*context);
+ *context = nullptr;
+}
OutputFile::OutputFile(const Options& opts, ld::Internal& state)
@@ -3834,7 +3842,7 @@ void OutputFile::computeContentUUID(ld::Internal& state, uint8_t* wholeBuffer)
{
const bool log = false;
if ( (_options.outputKind() != Options::kObjectFile) || state.someObjectFileHasDwarf ) {
- uint8_t digest[CCSHA256_OUTPUT_SIZE];
+ uint8_t digest[CS_SHA256_LEN];
std::vector<std::pair<uint64_t, uint64_t>> excludeRegions;
uint64_t bitcodeCmdOffset;
uint64_t bitcodeCmdEnd;
@@ -3902,18 +3910,27 @@ void OutputFile::computeContentUUID(ld::Internal& state, uint8_t* wholeBuffer)
excludeRegions.emplace_back(std::pair<uint64_t, uint64_t>(symbolTableCmdOffset, symbolTableCmdOffset+symbolTableCmdSize));
if ( log ) fprintf(stderr, "linkedit SegCmdOffset=0x%08llX, size=0x%08llX\n", symbolTableCmdOffset, symbolTableCmdSize);
}
- const ccdigest_info* di = ccsha256_di();
- ccdigest_di_decl(di, ctx);
- ccdigest_init(di, ctx);
+
+ [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* sha256_digest = EVP_MD_fetch(nullptr, "SHA-256", nullptr);
+ [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new();
+
+ if ( !EVP_DigestInit_ex2(context, sha256_digest, nullptr) ) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+
// rdar://problem/19487042 include the output leaf file name in the hash
const char* lastSlash = strrchr(_options.outputFilePath(), '/');
- if ( lastSlash != NULL ) {
- ccdigest_update(di, ctx, strlen(lastSlash), lastSlash);
+ if ( lastSlash != NULL && !EVP_DigestUpdate(context, lastSlash, strlen(lastSlash)) ) {
+ ERR_print_errors_fp(stderr);
+ abort();
}
+
// <rdar://problem/38679559> use train name when calculating a binary's UUID
const char* buildName = _options.buildContextName();
- if ( buildName != NULL ) {
- ccdigest_update(di, ctx, strlen(buildName), buildName);
+ if ( buildName != NULL && !EVP_DigestUpdate(context, buildName, strlen(buildName)) ) {
+ ERR_print_errors_fp(stderr);
+ abort();
}
if ( !excludeRegions.empty() ) {
@@ -3937,22 +3954,47 @@ void OutputFile::computeContentUUID(ld::Internal& state, uint8_t* wholeBuffer)
// Measure the ranges we want in parallel
struct Digest
{
- uint8_t digest[CCSHA256_OUTPUT_SIZE];
+ uint8_t digest[CS_SHA256_LEN];
};
__block std::vector<Digest> digests(regionsToMeasure.size());
dispatch_apply(regionsToMeasure.size(), DISPATCH_APPLY_AUTO, ^(size_t index) {
uint64_t startOffset = regionsToMeasure[index].first;
uint64_t size = regionsToMeasure[index].second;
- CCDigest(kCCDigestSHA256, &wholeBuffer[startOffset], size, digests[index].digest);
+
+ [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* sha256_digest = EVP_MD_fetch(nullptr, "SHA-256", nullptr);
+ [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new();
+
+ if (!EVP_DigestInit_ex2(context, sha256_digest, nullptr)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (!EVP_DigestUpdate(context, &wholeBuffer[startOffset], size)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (!EVP_DigestFinal_ex(context, digests[index].digest, nullptr)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
});
// Merge the resuls in serial
- ccdigest_update(di, ctx, digests.size() * sizeof(Digest), digests.data());
+ if ( !EVP_DigestUpdate(context, digests.data(), digests.size() * sizeof(Digest)) ) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
} else {
- ccdigest_update(di, ctx, _fileSize, wholeBuffer);
+ if ( !EVP_DigestUpdate(context, wholeBuffer, _fileSize) ) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ }
+
+ if ( !EVP_DigestFinal_ex(context, digest, nullptr) ) {
+ ERR_print_errors_fp(stderr);
+ abort();
}
- ccdigest_final(di, ctx, digest);
if ( log ) fprintf(stderr, "uuid=%02X, %02X, %02X, %02X, %02X, %02X, %02X, %02X\n", digest[0], digest[1], digest[2],
digest[3], digest[4], digest[5], digest[6], digest[7]);
diff --git a/subprojects/libcodedirectory/cs_blobs.h b/subprojects/libcodedirectory/cs_blobs.h
index 899a6a2..ce9cac6 100644
--- a/subprojects/libcodedirectory/cs_blobs.h
+++ b/subprojects/libcodedirectory/cs_blobs.h
@@ -129,6 +129,7 @@ enum {
CS_SHA1_LEN = 20,
CS_SHA256_LEN = 32,
CS_SHA256_TRUNCATED_LEN = 20,
+ CS_SHA384_LEN = 48,
CS_CDHASH_LEN = 20, /* always - larger hashes are truncated */
CS_HASH_MAX_SIZE = 48, /* max size of the hash we'll support */
diff --git a/subprojects/libcodedirectory/libcodedirectory.c b/subprojects/libcodedirectory/libcodedirectory.c
index 583ac96..02e31b1 100644
--- a/subprojects/libcodedirectory/libcodedirectory.c
+++ b/subprojects/libcodedirectory/libcodedirectory.c
@@ -14,10 +14,6 @@
#include <sys/mman.h>
#include <sys/queue.h>
-#include <corecrypto/ccdigest.h>
-#include <corecrypto/ccsha1.h>
-#include <corecrypto/ccsha2.h>
-
#define LIBCD_HAS_PLATFORM_VERSION 1
#include "libcodedirectory.h"
@@ -46,6 +42,21 @@
#include <sysexits.h>
#endif
+#include <openssl/err.h>
+#include <openssl/evp.h>
+
+static void
+EVP_MD_cleanup(EVP_MD** digest) {
+ EVP_MD_free(*digest);
+ *digest = NULL;
+}
+
+static void
+EVP_MD_CTX_cleanup(EVP_MD_CTX** context) {
+ EVP_MD_CTX_free(*context);
+ *context = NULL;
+}
+
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
@@ -459,17 +470,17 @@ void libcd_set_exec_seg (libcd *s, uint64_t base, uint64_t limit, uint64_t flags
struct _hash_info {
size_t hash_len;
- const struct ccdigest_info *(*di)(void);
+ const char* name;
};
static const struct _hash_info _known_hash_types[] = {
{ 0, NULL },
- { CS_SHA1_LEN, ccsha1_di }, // CS_HASHTYPE_SHA1
- { CS_SHA256_LEN, ccsha256_di }, // CS_HASHTYPE_SHA256
- // { 0, NULL }, // CS_HASHTYPE_SHA256_TRUNCATED, unsupported
- // { 0, NULL }, // CS_HASHTYPE_SHA384, unsupported
+ { CS_SHA1_LEN, "SHA-1" }, // CS_HASHTYPE_SHA1
+ { CS_SHA256_LEN, "SHA-256" }, // CS_HASHTYPE_SHA256
+ { CS_HASHTYPE_SHA256_TRUNCATED, "SHA-256" }, // CS_HASHTYPE_SHA256_TRUNCATED
+ { CS_SHA384_LEN, "SHA-384" }, // CS_HASHTYPE_SHA384
};
-static const size_t _max_known_hash_len = CS_SHA256_LEN;
+static const size_t _max_known_hash_len = CS_SHA384_LEN;
static const int _known_hash_types_count = sizeof(_known_hash_types)/sizeof(_known_hash_types[0]);
static struct _hash_info const *
@@ -781,8 +792,8 @@ _libcd_hash_page(libcd *s,
uint8_t page_hash[_max_known_hash_len] = {0};
const unsigned int page_no = (unsigned int)page_idx;
- struct ccdigest_info const *di = hi->di();
- ccdigest_di_decl(di, ctx);
+ [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* digest = EVP_MD_fetch(NULL, hi->name, NULL);
+ [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new();
const size_t pos = page_idx * _cs_page_bytes;
uint8_t page[_cs_page_bytes] = {0};
@@ -794,9 +805,18 @@ _libcd_hash_page(libcd *s,
return LIBCD_SERIALIZE_READ_PAGE_ERROR;
}
- ccdigest_init(di, ctx);
- ccdigest_update(di, ctx, read_bytes, page);
- ccdigest_final(di, ctx, page_hash);
+ if (!EVP_DigestInit_ex2(context, digest, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (!EVP_DigestUpdate(context, page, read_bytes)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (!EVP_DigestFinal_ex(context, page_hash, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
memcpy(hash_destination, page_hash, hi->hash_len);
@@ -894,16 +914,25 @@ _libcd_serialize_cd (libcd *s, uint32_t hash_type)
//// code directory hashes
{
if (s->special_slot_count > 0) {
- struct ccdigest_info const *di = hi->di();
- ccdigest_di_decl(di, ctx);
+ [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* digest = EVP_MD_fetch(NULL, hi->name, NULL);
+ [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new();
uint8_t *special_slot_buf = calloc(s->special_slot_count, hi->hash_len);
struct _sslot_data *sslot = NULL;
SLIST_FOREACH(sslot, &s->sslot_data, entries) {
- ccdigest_init(di, ctx);
- ccdigest_update(di, ctx, sslot->len, sslot->data);
- ccdigest_final(di, ctx, special_slot_buf + (s->special_slot_count-sslot->slot)*hi->hash_len);
+ if (!EVP_DigestInit_ex2(context, digest, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (!EVP_DigestUpdate(context, sslot->data, sslot->len)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (!EVP_DigestFinal_ex(context, special_slot_buf + (s->special_slot_count-sslot->slot)*hi->hash_len, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
}
memcpy(cursor, special_slot_buf, s->special_slot_count*hi->hash_len);
cursor += s->special_slot_count*hi->hash_len;
@@ -949,17 +978,28 @@ _libcd_serialize_cd (libcd *s, uint32_t hash_type)
//Record the cdhash for this codedirectory
{
- struct ccdigest_info const *di = hi->di();
- ccdigest_di_decl(di, ctx);
+ [[gnu::cleanup(EVP_MD_cleanup)]] EVP_MD* digest = EVP_MD_fetch(NULL, hi->name, NULL);
+ [[gnu::cleanup(EVP_MD_CTX_cleanup)]] EVP_MD_CTX* context = EVP_MD_CTX_new();
+
uint8_t *cdhash_buf = calloc(1, hi->hash_len);
if (cdhash_buf == NULL) {
_libcd_err("Failed to allocated memory for cdhash");
free(cd_mem);
return LIBCD_SERIALIZE_NO_MEM;
}
- ccdigest_init(di, ctx);
- ccdigest_update(di, ctx, cd_size, cd_mem);
- ccdigest_final(di, ctx, cdhash_buf);
+
+ if (!EVP_DigestInit_ex2(context, digest, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (!EVP_DigestUpdate(context, cd_mem, cd_size)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
+ if (!EVP_DigestFinal_ex(context, cdhash_buf, NULL)) {
+ ERR_print_errors_fp(stderr);
+ abort();
+ }
for (size_t i = 0; i < s->hash_types_count; i++) {
if (s->cdhashes[i].set) {
--
2.47.2

View File

@@ -0,0 +1,109 @@
From 1894e5752ebfe0572684c235da3cdcdfd10f29a1 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Sat, 16 Nov 2024 16:21:17 -0500
Subject: [PATCH 15/18] Add libcd_is_blob_a_linker_signature implementation
---
.../libcodedirectory/libcodedirectory.c | 68 +++++++++++++++++++
.../libcodedirectory/libcodedirectory.h | 9 +++
2 files changed, 77 insertions(+)
diff --git a/subprojects/libcodedirectory/libcodedirectory.c b/subprojects/libcodedirectory/libcodedirectory.c
index 02e31b1..89908b9 100644
--- a/subprojects/libcodedirectory/libcodedirectory.c
+++ b/subprojects/libcodedirectory/libcodedirectory.c
@@ -1221,3 +1221,71 @@ libcd_get_cdhash_for_type(libcd *s, int hash_type, uint8_t* cdhash_buf, size_t c
}
return LIBCD_CDHASH_TYPE_NOT_FOUND;
}
+
+// References:
+// - https://forums.developer.apple.com/forums/thread/702351
+// - https://redmaple.tech/blogs/macho-files/#codedirectory-blob
+
+static inline uint32_t read32be(const uint8_t* data)
+{
+ return (data[0] << 24) + (data[1] << 16) + (data[2] << 8) + data[3];
+}
+
+static inline bool is_embedded_signature(uint32_t magic) {
+ switch (magic) {
+ case CSMAGIC_EMBEDDED_SIGNATURE:
+ case CSMAGIC_EMBEDDED_SIGNATURE_OLD:
+ return true;
+ default:
+ return false;
+ }
+}
+
+static inline const uint8_t* find_code_directory(const uint8_t* data, size_t size) {
+ const uint8_t* index_ptr = data + offsetof(CS_SuperBlob, index);
+
+ // There also needs to be space for the actual blobs, but there must be at least enough space
+ // for the blob indexes. If theres not, then somethings wrong, and the blob is invalid.
+ uint32_t count = read32be(data + offsetof(CS_SuperBlob, count));
+ if (count > ((data + size) - index_ptr) / sizeof(CS_BlobIndex)) {
+ return NULL;
+ }
+
+ for (uint32_t n = 0; n < count; ++n) {
+ const uint8_t* current_index_ptr = index_ptr + n * sizeof(CS_BlobIndex);
+ uint32_t type = read32be(current_index_ptr + offsetof(CS_BlobIndex, type));
+ if (type == CSSLOT_CODEDIRECTORY) {
+ uint32_t offset = read32be(current_index_ptr + offsetof(CS_BlobIndex, offset));
+ if (offset > size - sizeof(CS_CodeDirectory)) {
+ return NULL;
+ } else {
+ return data + offset;
+ }
+ }
+ }
+ return NULL;
+}
+
+enum libcd_signature_query_ret
+libcd_is_blob_a_linker_signature(const uint8_t* data, size_t size, int* linker_signed)
+{
+ if (size < sizeof(CS_SuperBlob) + sizeof(CS_BlobIndex) + sizeof(CS_CodeDirectory)) {
+ return LIBCD_SIGNATURE_QUERY_INVALID_ARGUMENT;
+ }
+
+ if (!is_embedded_signature(read32be(data + offsetof(CS_SuperBlob, magic)))) {
+ return LIBCD_SIGNATURE_QUERY_NOT_A_SIGNATURE;
+ }
+
+ const uint8_t* cd = find_code_directory(data, size);
+ if (!cd) {
+ return LIBCD_SIGNATURE_QUERY_INVALID_ARGUMENT;
+ }
+
+ uint32_t flags = read32be(cd + offsetof(CS_CodeDirectory, flags));
+ if ((flags & CS_LINKER_SIGNED) == CS_LINKER_SIGNED) {
+ *linker_signed = 1;
+ }
+
+ return LIBCD_SIGNATURE_QUERY_SUCCESS;
+}
diff --git a/subprojects/libcodedirectory/libcodedirectory.h b/subprojects/libcodedirectory/libcodedirectory.h
index 0e989a9..67a5a22 100644
--- a/subprojects/libcodedirectory/libcodedirectory.h
+++ b/subprojects/libcodedirectory/libcodedirectory.h
@@ -116,6 +116,15 @@ enum libcd_set_linkage_ret {
enum libcd_set_linkage_ret libcd_set_linkage(libcd *s, int linkage_hash_type, uint8_t *linkage_hash);
+enum libcd_signature_query_ret {
+ LIBCD_SIGNATURE_QUERY_SUCCESS,
+ LIBCD_SIGNATURE_QUERY_INVALID_ARGUMENT,
+ LIBCD_SIGNATURE_QUERY_NOT_A_SIGNATURE,
+};
+
+enum libcd_signature_query_ret libcd_is_blob_a_linker_signature(const uint8_t* data, size_t size, int* linker_signed);
+
+
__END_DECLS
#endif // H_LIBCODEDIRECTORY
--
2.47.2

View File

@@ -0,0 +1,35 @@
From 1bd02ac97fd47d8f7c8f1f21893d7107ae2319b5 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Sun, 17 Nov 2024 10:02:34 -0500
Subject: [PATCH 16/18] Add dyldinfo to the ld64 build
---
src/other/meson.build | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/other/meson.build b/src/other/meson.build
index 067a69c..663b9ee 100644
--- a/src/other/meson.build
+++ b/src/other/meson.build
@@ -1,3 +1,18 @@
+dyldinfo = executable(
+ 'dyldinfo',
+ dependencies : [
+ abstraction_dep,
+ llvm_dep,
+ ],
+ include_directories : [ '../ld' ],
+ install : true,
+ sources : [
+ configure_h,
+ 'dyldinfo.cpp',
+ ],
+)
+install_man(meson.global_source_root() / 'doc/man/man1/dyldinfo.1')
+
machocheck = executable(
'machocheck',
dependencies : [
--
2.47.2

View File

@@ -0,0 +1,37 @@
From 477911db0045e8b1925fcd5db523aab2888fdcc9 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Sun, 17 Nov 2024 10:02:34 -0500
Subject: [PATCH 17/18] Fix dyldinfo build
`isSubType` was removed in 907, but the fix is simple. This mirrors the
changes that were made in that update to other parts of ld64.
---
src/other/dyldinfo.cpp | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/other/dyldinfo.cpp b/src/other/dyldinfo.cpp
index dbfd0de..96aa109 100644
--- a/src/other/dyldinfo.cpp
+++ b/src/other/dyldinfo.cpp
@@ -427,7 +427,7 @@ DyldInfoPrinter<A>::DyldInfoPrinter(const uint8_t* fileContent, uint32_t fileLen
if ( printArch ) {
for (const ArchInfo* t=archInfoArray; t->archName != NULL; ++t) {
if ( (cpu_type_t)fHeader->cputype() == t->cpuType ) {
- if ( t->isSubType && ((cpu_subtype_t)fHeader->cpusubtype() != t->cpuSubType) )
+ if ( ((cpu_subtype_t)fHeader->cpusubtype() != t->cpuSubType) )
continue;
printf("for arch %s:\n", t->archName);
}
@@ -2801,8 +2801,7 @@ int main(int argc, const char* argv[])
for (const ArchInfo* t=archInfoArray; t->archName != NULL; ++t) {
if ( strcmp(t->archName,arch) == 0 ) {
sPreferredArch = t->cpuType;
- if ( t->isSubType )
- sPreferredSubArch = t->cpuSubType;
+ sPreferredSubArch = t->cpuSubType;
found = true;
break;
}
--
2.47.2

View File

@@ -0,0 +1,37 @@
From 98119b91fc3cf85d65c2e320707324af3c56565d Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 13 Nov 2024 13:53:14 -0500
Subject: [PATCH 18/18] Use STL containers instead of LLVM containers
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Upstream LLVM doesnt support `std::string_view` in `DenseMap`s.
---
src/abstraction/Containers.h | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/abstraction/Containers.h b/src/abstraction/Containers.h
index a27dc83..fca312c 100644
--- a/src/abstraction/Containers.h
+++ b/src/abstraction/Containers.h
@@ -31,14 +31,14 @@
#include <set>
#include <string_view>
-#define USE_LLVM_CONTAINERS 1
+#define USE_LLVM_CONTAINERS 0
#if USE_LLVM_CONTAINERS
#include "../llvm/llvm-DenseSet.h"
#include "../llvm/llvm-DenseMap.h"
#else
// Include DenseMapInfo helpers even when not using LLVM containers.
-#include "../llvm/llvm-DenseMapInfo.h"
+// #include "../llvm/llvm-DenseMapInfo.h"
#endif
namespace ld {
--
2.47.2

View File

@@ -0,0 +1,52 @@
{
lib,
stdenv,
fetchFromGitHub,
cmake,
}:
stdenv.mkDerivation rec {
pname = "ldacBT";
version = "2.0.2.3";
src = fetchFromGitHub {
repo = "ldacBT";
owner = "ehfive";
tag = "v${version}";
sha256 = "09dalysx4fgrgpfdm9a51x6slnf4iik1sqba4xjgabpvq91bnb63";
fetchSubmodules = true;
};
outputs = [
"out"
"dev"
];
nativeBuildInputs = [
cmake
];
cmakeFlags = [
# CMakeLists.txt by default points to $out
"-DINSTALL_INCLUDEDIR=${placeholder "dev"}/include"
];
# Fix the build with CMake 4.
#
# See: <https://github.com/EHfive/ldacBT/pull/1>
postPatch = ''
substituteInPlace CMakeLists.txt \
--replace-fail \
'cmake_minimum_required(VERSION 3.0)' \
'cmake_minimum_required(VERSION 3.0...3.10)'
'';
meta = with lib; {
description = "AOSP libldac dispatcher";
homepage = "https://github.com/EHfive/ldacBT";
license = licenses.asl20;
# libldac code detects & #error's out on non-LE byte order
platforms = platforms.littleEndian;
maintainers = [ ];
};
}

View File

@@ -0,0 +1,43 @@
{
lib,
fetchFromGitHub,
python3,
}:
python3.pkgs.buildPythonApplication rec {
pname = "ldapmonitor";
version = "1.4";
format = "other";
src = fetchFromGitHub {
owner = "p0dalirius";
repo = "ldapmonitor";
tag = version;
hash = "sha256-BmTj/6dOUYfia6wO4nvkEW01MIC9TuBk4kYAsVHMsWY=";
};
sourceRoot = "${src.name}/python";
propagatedBuildInputs = with python3.pkgs; [
impacket
ldap3
python-ldap
];
installPhase = ''
runHook preInstall
install -vD pyLDAPmonitor.py $out/bin/ldapmonitor
runHook postInstall
'';
meta = {
description = "Tool to monitor creation, deletion and changes to LDAP objects";
mainProgram = "ldapmonitor";
homepage = "https://github.com/p0dalirius/LDAPmonitor";
changelog = "https://github.com/p0dalirius/LDAPmonitor/releases/tag/${version}";
license = with lib.licenses; [ gpl3Only ];
maintainers = with lib.maintainers; [ fab ];
};
}

View File

@@ -0,0 +1,33 @@
{
lib,
buildGoModule,
fetchFromGitHub,
}:
buildGoModule rec {
pname = "ldapnomnom";
version = "1.5.1";
src = fetchFromGitHub {
owner = "lkarlslund";
repo = "ldapnomnom";
tag = "v${version}";
hash = "sha256-BKErfWJ6XKG4cKIjp5WU8SVZvyQlqtm/mvDwbUtDYIw=";
};
vendorHash = "sha256-lm801UM7JOYsGRe92FErY2jonrqRRjLKojN5YyytqvY=";
ldflags = [
"-w"
"-s"
];
meta = {
description = "Tool to anonymously bruteforce usernames from Domain controllers";
homepage = "https://github.com/lkarlslund/ldapnomnom";
changelog = "https://github.com/lkarlslund/ldapnomnom/releases/tag/v${version}";
license = lib.licenses.mit;
maintainers = with lib.maintainers; [ fab ];
mainProgram = "ldapnomnom";
};
}

View File

@@ -0,0 +1,68 @@
{
lib,
stdenv,
fetchgit,
openldap,
openssl,
popt,
glib,
libxcrypt,
ncurses,
readline,
pkg-config,
cyrus_sasl,
autoconf,
automake,
}:
stdenv.mkDerivation {
pname = "ldapvi";
version = "unstable-2012-04-28";
# use latest git, it includes some important patches since 2007 release
src = fetchgit {
url = "http://www.lichteblau.com/git/ldapvi.git";
rev = "f1d42bad66cc4623d1ff21fbd5dddbf5009d3e40";
sha256 = "3ef3103030ecb04d7fe80180e3fd490377cf81fb2af96782323fddabc3225030";
};
env.NIX_CFLAGS_COMPILE = toString [
"-Wno-implicit-function-declaration"
"-Wno-error=int-conversion"
"-Wno-error=return-mismatch"
];
nativeBuildInputs = [
pkg-config
autoconf
automake
];
buildInputs = [
openldap
openssl
popt
glib
libxcrypt
ncurses
readline
cyrus_sasl
];
preConfigure = ''
cd ldapvi
./autogen.sh
'';
meta = with lib; {
description = "Interactive LDAP client for Unix terminals";
longDescription = ''
ldapvi is an interactive LDAP client for Unix terminals. Using it, you
can update LDAP entries with a text editor.
'';
homepage = "http://www.lichteblau.com/ldapvi/";
license = licenses.gpl2Plus;
maintainers = [ ];
platforms = lib.platforms.linux;
mainProgram = "ldapvi";
};
}

View File

@@ -0,0 +1,105 @@
{
lib,
stdenv,
fetchurl,
python3,
pkg-config,
readline,
tdb,
talloc,
tevent,
popt,
libxslt,
docbook-xsl-nons,
docbook_xml_dtd_42,
cmocka,
wafHook,
buildPackages,
libxcrypt,
testers,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "ldb";
version = "2.9.2";
src = fetchurl {
url = "mirror://samba/ldb/ldb-${finalAttrs.version}.tar.gz";
hash = "sha256-0VWIQALHnbscPYZC+LEBPy5SCzru/W6WQSrexbjWy8A=";
};
outputs = [
"out"
"dev"
];
nativeBuildInputs = [
pkg-config
python3
wafHook
libxslt
docbook-xsl-nons
docbook_xml_dtd_42
tdb
tevent
];
buildInputs = [
python3
readline # required to build python
tdb
talloc
tevent
popt
cmocka
libxcrypt
];
# otherwise the configure script fails with
# PYTHONHASHSEED=1 missing! Don't use waf directly, use ./configure and make!
preConfigure = ''
export PKGCONFIG="$PKG_CONFIG"
export PYTHONHASHSEED=1
'';
wafPath = "buildtools/bin/waf";
wafConfigureFlags = [
"--bundled-libraries=NONE"
"--builtin-libraries=replace"
"--without-ldb-lmdb"
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"--cross-compile"
"--cross-execute=${stdenv.hostPlatform.emulator buildPackages}"
];
# python-config from build Python gives incorrect values when cross-compiling.
# If python-config is not found, the build falls back to using the sysconfig
# module, which works correctly in all cases.
PYTHON_CONFIG = "/invalid";
# https://reviews.llvm.org/D135402
NIX_LDFLAGS = lib.optional (
stdenv.cc.bintools.isLLVM && lib.versionAtLeast stdenv.cc.bintools.version "17"
) "--undefined-version";
stripDebugList = [
"bin"
"lib"
"modules"
];
passthru.tests.pkg-config = testers.hasPkgConfigModules {
package = finalAttrs.finalPackage;
};
meta = with lib; {
broken = stdenv.hostPlatform.isDarwin;
description = "LDAP-like embedded database";
homepage = "https://ldb.samba.org/";
license = licenses.lgpl3Plus;
pkgConfigModules = [ "ldb" ];
platforms = platforms.all;
};
})

View File

@@ -0,0 +1,80 @@
{
lib,
stdenv,
fetchurl,
curl,
tzdata,
autoPatchelfHook,
fixDarwinDylibNames,
libxml2,
}:
let
inherit (stdenv) hostPlatform;
OS = if hostPlatform.isDarwin then "osx" else hostPlatform.parsed.kernel.name;
ARCH =
if hostPlatform.isDarwin && hostPlatform.isAarch64 then "arm64" else hostPlatform.parsed.cpu.name;
version = "1.41.0";
hashes = {
# Get these from `nix store prefetch-file https://github.com/ldc-developers/ldc/releases/download/v1.19.0/ldc2-1.19.0-osx-x86_64.tar.xz` etc..
osx-x86_64 = "sha256-W8/0i2PFakXbqs2wxb3cjqa+htSgx7LHyDGOBH9yEYE=";
linux-x86_64 = "sha256-SkOUV/D+WeadAv1rV1Sfw8h60PVa2fueQlB7b44yfI8=";
linux-aarch64 = "sha256-HEuVChPVM3ntT1ZDZsJ+xW1iYeIWhogNcMdIaz6Me6g=";
osx-arm64 = "sha256-FXJnBC8QsEchBhkxSqcZtPC/iHYB6TscY0qh7LPFRuQ=";
};
in
stdenv.mkDerivation {
pname = "ldc-bootstrap";
inherit version;
src = fetchurl rec {
name = "ldc2-${version}-${OS}-${ARCH}.tar.xz";
url = "https://github.com/ldc-developers/ldc/releases/download/v${version}/${name}";
hash = hashes."${OS}-${ARCH}" or (throw "missing bootstrap hash for ${OS}-${ARCH}");
};
dontConfigure = true;
dontBuild = true;
nativeBuildInputs =
lib.optionals hostPlatform.isLinux [
autoPatchelfHook
]
++ lib.optional hostPlatform.isDarwin fixDarwinDylibNames;
buildInputs = lib.optionals stdenv.hostPlatform.isLinux [
libxml2
stdenv.cc.cc
];
propagatedBuildInputs = [
curl
tzdata
];
installPhase = ''
mkdir -p $out
mv bin etc import lib LICENSE README $out/
'';
meta = with lib; {
description = "LLVM-based D Compiler";
homepage = "https://github.com/ldc-developers/ldc";
# from https://github.com/ldc-developers/ldc/blob/master/LICENSE
license = with licenses; [
bsd3
boost
mit
ncsa
gpl2Plus
];
maintainers = with maintainers; [ lionello ];
platforms = [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
};
}

View File

@@ -0,0 +1,218 @@
{
lib,
stdenv,
fetchFromGitHub,
fetchpatch,
callPackage,
makeWrapper,
removeReferencesTo,
runCommand,
writeText,
targetPackages,
cmake,
ninja,
llvm_18,
curl,
tzdata,
lit,
gdb,
unzip,
ldcBootstrap ? callPackage ./bootstrap.nix { },
}:
let
pathConfig = runCommand "ldc-lib-paths" { } ''
mkdir $out
echo ${tzdata}/share/zoneinfo/ > $out/TZDatabaseDirFile
echo ${curl.out}/lib/libcurl${stdenv.hostPlatform.extensions.sharedLibrary} > $out/LibcurlPathFile
'';
in
stdenv.mkDerivation (finalAttrs: {
pname = "ldc";
version = "1.41.0";
src = fetchFromGitHub {
owner = "ldc-developers";
repo = "ldc";
tag = "v${finalAttrs.version}";
hash = "sha256-6LcpY3LSFK4KgEiGrFp/LONu5Vr+/+vI04wEEpF3s+s=";
fetchSubmodules = true;
};
# https://issues.dlang.org/show_bug.cgi?id=19553
hardeningDisable = [ "fortify" ];
postPatch = ''
patchShebangs runtime tools tests
rm tests/dmd/fail_compilation/mixin_gc.d
rm tests/dmd/runnable/xtest46_gc.d
rm tests/dmd/runnable/testptrref_gc.d
# test depends on current year
rm tests/dmd/compilable/ddocYear.d
''
+ lib.optionalString stdenv.hostPlatform.isLinux ''
substituteInPlace runtime/phobos/std/socket.d --replace-fail "assert(ih.addrList[0] == 0x7F_00_00_01);" ""
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
substituteInPlace runtime/phobos/std/socket.d --replace-fail "foreach (name; names)" "names = []; foreach (name; names)"
# https://github.com/NixOS/nixpkgs/issues/34817
rm -r tests/plugins/addFuncEntryCall
'';
nativeBuildInputs = [
cmake
ldcBootstrap
lit
lit.python
llvm_18.dev
makeWrapper
ninja
unzip
]
++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
# https://github.com/NixOS/nixpkgs/pull/36378#issuecomment-385034818
gdb
];
buildInputs = [
curl
tzdata
];
outputs = [
"out"
"include"
];
outputInclude = "include";
cmakeFlags = [
"-DD_FLAGS=-d-version=TZDatabaseDir;-d-version=LibcurlPath;-J${pathConfig}"
"-DINCLUDE_INSTALL_DIR=${placeholder "include"}/include/d"
];
postConfigure = ''
export DMD=$PWD/bin/ldmd2
'';
makeFlags = [ "DMD=$DMD" ];
fixNames = lib.optionalString stdenv.hostPlatform.isDarwin ''
fixDarwinDylibNames() {
local flags=()
for fn in "$@"; do
flags+=(-change "$(basename "$fn")" "$fn")
done
for fn in "$@"; do
if [ -L "$fn" ]; then continue; fi
echo "$fn: fixing dylib"
install_name_tool -id "$fn" "''${flags[@]}" "$fn"
done
}
fixDarwinDylibNames $(find "$(pwd)/lib" -name "*.dylib")
export DYLD_LIBRARY_PATH=$(pwd)/lib
'';
# https://github.com/ldc-developers/ldc/issues/2497#issuecomment-459633746
additionalExceptions = lib.optionalString stdenv.hostPlatform.isDarwin "|druntime-test-shared";
checkPhase = ''
# Build default lib test runners
ninja -j$NIX_BUILD_CORES all-test-runners
${finalAttrs.fixNames}
# Run dmd testsuite
export DMD_TESTSUITE_MAKE_ARGS="-j$NIX_BUILD_CORES DMD=$DMD"
ctest -V -R "dmd-testsuite"
# Build and run LDC D unittests.
ctest --output-on-failure -R "ldc2-unittest"
# Run LIT testsuite.
ctest -V -R "lit-tests"
# Run default lib unittests
ctest -j$NIX_BUILD_CORES --output-on-failure -E "ldc2-unittest|lit-tests|dmd-testsuite${finalAttrs.additionalExceptions}"
'';
postInstall = ''
wrapProgram $out/bin/ldc2 \
--prefix PATH : ${targetPackages.stdenv.cc}/bin \
--set-default CC ${targetPackages.stdenv.cc}/bin/cc
'';
preFixup = ''
find $out/bin -type f -exec ${removeReferencesTo}/bin/remove-references-to -t ${ldcBootstrap} '{}' +
'';
disallowedReferences = [ ldcBootstrap ];
meta = with lib; {
description = "LLVM-based D compiler";
homepage = "https://github.com/ldc-developers/ldc";
changelog = "https://github.com/ldc-developers/ldc/releases/tag/v${finalAttrs.version}";
# from https://github.com/ldc-developers/ldc/blob/master/LICENSE
license = with licenses; [
bsd3
boost
mit
ncsa
gpl2Plus
];
mainProgram = "ldc2";
maintainers = with maintainers; [
lionello
jtbx
];
platforms = [
"x86_64-linux"
"i686-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
};
passthru.ldcBootstrap = ldcBootstrap;
passthru.tests =
let
ldc = finalAttrs.finalPackage;
helloWorld = stdenv.mkDerivation (finalAttrs: {
name = "ldc-hello-world";
src = writeText "hello_world.d" ''
module hello_world;
import std.stdio;
void main() {
writeln("Hello, world!");
}
'';
dontUnpack = true;
buildInputs = [ ldc ];
dFlags = [ ];
buildPhase = ''
ldc2 ${lib.escapeShellArgs finalAttrs.dFlags} -of=test $src
'';
installPhase = ''
mkdir -p $out/bin
mv test $out/bin
'';
});
in
{
# Without -shared, built binaries should not contain
# references to the compiler binaries.
no-references-to-compiler = helloWorld.overrideAttrs {
disallowedReferences = [ ldc ];
dFlags = [ "-g" ];
};
};
})

View File

@@ -0,0 +1,56 @@
{
lib,
fetchFromGitHub,
python3,
}:
python3.pkgs.buildPythonApplication rec {
pname = "ldeep";
version = "1.0.89";
pyproject = true;
src = fetchFromGitHub {
owner = "franc-pentest";
repo = "ldeep";
tag = version;
hash = "sha256-aod+0wd4Ek8mTiP4H5C5vUJ+94THMrFGDGVzWEH3G+U=";
};
pythonRelaxDeps = [
"termcolor"
"cryptography"
"ldap3-bleeding-edge"
];
build-system = with python3.pkgs; [ pdm-backend ];
nativeBuildInputs = with python3.pkgs; [ cython ];
dependencies = with python3.pkgs; [
commandparse
cryptography
dnspython
gssapi
ldap3-bleeding-edge
oscrypto
pycryptodome
pycryptodomex
six
termcolor
tqdm
];
# Project has no tests
doCheck = false;
pythonImportsCheck = [ "ldeep" ];
meta = with lib; {
description = "In-depth LDAP enumeration utility";
homepage = "https://github.com/franc-pentest/ldeep";
changelog = "https://github.com/franc-pentest/ldeep/releases/tag/${src.tag}";
license = licenses.mit;
maintainers = with maintainers; [ fab ];
mainProgram = "ldeep";
};
}

View File

@@ -0,0 +1,63 @@
{
lib,
stdenv,
fetchFromGitHub,
installShellFiles,
fetchpatch,
pkg-config,
libplist,
openssl,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "ldid-procursus";
version = "2.1.5-procursus7";
src = fetchFromGitHub {
owner = "ProcursusTeam";
repo = "ldid";
rev = "v${finalAttrs.version}";
hash = "sha256-QnSmWY9zCOPYAn2VHc5H+VQXjTCyr0EuosxvKGGpDtQ=";
};
nativeBuildInputs = [
pkg-config
installShellFiles
];
buildInputs = [
libplist
openssl
];
stripDebugFlags = [ "--strip-unneeded" ];
makeFlags = [ "PREFIX=${placeholder "out"}" ];
dontConfigure = true;
patches = [
(fetchpatch {
name = "fix-memory-issues-with-various-entitlements.patch";
url = "https://github.com/ProcursusTeam/ldid/commit/f38a095aa0cc721c40050cb074116c153608a11b.patch";
hash = "sha256-D5o/E2tCbuNOv2D9UVaLEx8ZiwSB/wT0hf7XaTGzxE0=";
})
];
postPatch = ''
substituteInPlace Makefile \
--replace-fail "pkg-config" "$PKG_CONFIG"
'';
postInstall = ''
installShellCompletion --cmd ldid --zsh _ldid
'';
meta = with lib; {
mainProgram = "ldid";
description = "Put real or fake signatures in a Mach-O binary";
homepage = "https://github.com/ProcursusTeam/ldid";
maintainers = with maintainers; [ keto ];
platforms = platforms.unix;
license = licenses.agpl3Only;
};
})

View File

@@ -0,0 +1,59 @@
{
lib,
stdenv,
fetchgit,
libplist,
libxml2,
openssl,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "ldid";
version = "2.1.5";
src = fetchgit {
url = "git://git.saurik.com/ldid.git";
rev = "v${finalAttrs.version}";
hash = "sha256-RM5pU3mrgyvwNfWKNvCT3UYVGKtVhD7ifgp8fq9xXiM=";
};
strictDeps = true;
buildInputs = [
libplist
libxml2
openssl
];
env.NIX_LDFLAGS = toString [
"-lcrypto"
"-lplist-2.0"
];
buildPhase = ''
runHook preBuild
cc -c -o lookup2.o lookup2.c -I.
c++ -std=c++11 -o ldid lookup2.o ldid.cpp -I.
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -Dm755 {,$out/bin/}ldid
ln -s $out/bin/ldid $out/bin/ldid2
runHook postInstall
'';
meta = {
description = "Link Identity Editor";
homepage = "https://cydia.saurik.com/info/ldid/";
license = lib.licenses.agpl3Only;
mainProgram = "ldid";
maintainers = with lib.maintainers; [ wegank ];
platforms = lib.platforms.unix;
};
})

View File

@@ -0,0 +1,52 @@
{
lib,
stdenv,
fetchgit,
udev,
util-linux,
mountPath ? "/media/",
}:
assert mountPath != "";
let
version = "0.5";
in
stdenv.mkDerivation rec {
pname = "ldm";
inherit version;
# There is a stable release, but we'll use the lvm branch, which
# contains important fixes for LVM setups.
src = fetchgit {
url = "https://github.com/LemonBoy/ldm";
tag = "v${version}";
sha256 = "0lxfypnbamfx6p9ar5k9wra20gvwn665l4pp2j4vsx4yi5q7rw2n";
};
buildInputs = [
udev
util-linux
];
postPatch = ''
substituteInPlace ldm.c \
--replace "/mnt/" "${mountPath}"
sed '16i#include <sys/stat.h>' -i ldm.c
'';
buildFlags = [ "ldm" ];
installPhase = ''
mkdir -p $out/bin
cp -v ldm $out/bin
'';
meta = {
description = "Lightweight device mounter, with libudev as only dependency";
homepage = "https://github.com/LemonBoy/ldm";
mainProgram = "ldm";
license = lib.licenses.mit;
platforms = lib.platforms.linux;
};
}

View File

@@ -0,0 +1,73 @@
{
lib,
stdenv,
fetchFromGitHub,
autoconf,
automake,
gtk-doc,
pkg-config,
libuuid,
libtool,
readline,
gobject-introspection,
json-glib,
lvm2,
libxslt,
docbook_xsl,
fetchpatch,
}:
stdenv.mkDerivation rec {
pname = "ldmtool";
version = "0.2.4";
src = fetchFromGitHub {
owner = "mdbooth";
repo = "libldm";
rev = "libldm-${version}";
sha256 = "1fy5wbmk8kwl86lzswq0d1z2j5y023qzfm2ppm8knzv9c47kniqk";
};
patches = [
# Remove usage of deprecrated G_PARAM_PRIVATE
(fetchpatch {
url = "https://github.com/mdbooth/libldm/commit/ee1b37a034038f09d61b121cc8b3651024acc46f.patch";
sha256 = "02y34kbcpcpffvy1n9yqngvdldmxmvdkha1v2xjqvrnclanpigcp";
})
];
preConfigure = ''
sed -i docs/reference/ldmtool/Makefile.am \
-e 's|-nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl|--nonet ${docbook_xsl}/xml/xsl/docbook/manpages/docbook.xsl|g'
'';
# glib-2.62 deprecations
env.NIX_CFLAGS_COMPILE = "-DGLIB_DISABLE_DEPRECATION_WARNINGS";
configureScript = "sh autogen.sh";
nativeBuildInputs = [
pkg-config
autoconf
automake
gobject-introspection
];
buildInputs = [
gtk-doc
lvm2
libxslt.bin
libtool
readline
json-glib
libuuid
];
meta = with lib; {
description = "Tool and library for managing Microsoft Windows Dynamic Disks";
homepage = "https://github.com/mdbooth/libldm";
maintainers = with maintainers; [ jensbin ];
license = licenses.gpl3;
platforms = platforms.linux;
mainProgram = "ldmtool";
};
}

View File

@@ -0,0 +1,13 @@
diff --git src/autoconf/configure.ac src/autoconf/configure.ac
index 156e97f4..6d70bf33 100644
--- src/autoconf/configure.ac
+++ src/autoconf/configure.ac
@@ -1410,7 +1410,7 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <mysql.h>
#include <errmsg.h>
-struct MYSQL * foo(void)
+struct st_mysql * foo(void)
{
static MYSQL var;

View File

@@ -0,0 +1,126 @@
{
lib,
fetchFromGitHub,
stdenv,
autoreconfHook,
pkg-config,
bison,
libiconv,
pcre,
libgcrypt,
libxcrypt-legacy,
json_c,
libxml2,
ipv6Support ? false,
mccpSupport ? false,
zlib,
mysqlSupport ? false,
libmysqlclient,
postgresSupport ? false,
libpq,
sqliteSupport ? false,
sqlite,
tlsSupport ? false,
openssl,
pythonSupport ? false,
python310,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "ldmud";
version = "3.6.8";
src = fetchFromGitHub {
owner = "ldmud";
repo = "ldmud";
tag = finalAttrs.version;
hash = "sha256-ojOLM1vkuwuF0vXx6lCH0+OlyLkkOOnTJEUiZPpUhzo=";
};
patches = [
./mysql-compat.patch
];
sourceRoot = "${finalAttrs.src.name}/src";
nativeBuildInputs = [
autoreconfHook
pkg-config
bison
];
buildInputs = [
libgcrypt
libxcrypt-legacy
pcre
json_c
libxml2
]
++ lib.optional mccpSupport zlib
++ lib.optional mysqlSupport libmysqlclient
++ lib.optional postgresSupport libpq
++ lib.optional sqliteSupport sqlite
++ lib.optional tlsSupport openssl
++ lib.optional pythonSupport python310
++ lib.optionals stdenv.hostPlatform.isDarwin [ libiconv ];
# To support systems without autoconf LD puts its configure.ac in a non-default
# location and uses a helper script. We skip that script and symlink the .ac
# file to where the autoreconfHook find it.
preAutoreconf = ''
ln -fs ./autoconf/configure.ac ./
'';
configureFlags = [
"--enable-erq=xerq"
"--enable-filename-spaces"
"--enable-use-json"
"--enable-use-xml=xml2"
(lib.enableFeature ipv6Support "use-ipv6")
(lib.enableFeature mccpSupport "use-mccp")
(lib.enableFeature mysqlSupport "use-mysql")
(lib.enableFeature postgresSupport "use-pgsql")
(lib.enableFeature sqliteSupport "use-sqlite")
(lib.enableFeatureAs tlsSupport "use-tls" "ssl")
(lib.enableFeature pythonSupport "use-python")
];
preConfigure =
lib.optionalString mysqlSupport ''
export CPPFLAGS="-I${lib.getDev libmysqlclient}/include/mysql"
export LDFLAGS="-L${libmysqlclient}/lib/mysql"
''
+ lib.optionalString stdenv.hostPlatform.isDarwin ''
export LDFLAGS="$LDFLAGS -L${libiconv}/lib -liconv"
'';
installTargets = [
"install-driver"
"install-utils"
"install-headers"
];
postInstall = ''
mkdir -p "$out/share/"
cp -v ../COPYRIGHT $out/share/
'';
meta = {
description = "Gamedriver for LPMuds including a LPC compiler, interpreter and runtime";
homepage = "https://ldmud.eu";
changelog = "https://github.com/ldmud/ldmud/blob/${finalAttrs.version}/HISTORY";
longDescription = ''
LDMud started as a project to clean up and modernize Amylaar's LPMud
gamedriver. Primary goals are full documentation, a commented source body
and out-of-the-box support for the major mudlibs, of which the commented
source body has been pretty much completed. During the course of work
a lot of bug fixes and improvements found their way into the driver - much
more than originally expected, and definitely enough to make LDMud
a driver in its own right.
'';
# See https://github.com/ldmud/ldmud/blob/master/COPYRIGHT
license = lib.licenses.unfreeRedistributable;
platforms = with lib.platforms; linux ++ darwin;
maintainers = with lib.maintainers; [ cpu ];
};
})

View File

@@ -0,0 +1,70 @@
{
lib,
stdenv,
fetchurl,
openssl,
perl,
which,
dns-root-data,
autoreconfHook,
}:
stdenv.mkDerivation rec {
pname = "ldns";
version = "1.8.4";
src = fetchurl {
url = "https://www.nlnetlabs.nl/downloads/ldns/${pname}-${version}.tar.gz";
sha256 = "sha256-g4uQdZS6r/HNdn6VRmp3RZmK5kvHS+A43Mxi4t4uQkc=";
};
postPatch = ''
patchShebangs doc/doxyparse.pl
'';
outputs = [
"out"
"dev"
"man"
"examples"
];
nativeBuildInputs = [
perl
autoreconfHook
];
buildInputs = [ openssl ];
configureFlags = [
"--with-ssl=${openssl.dev}"
"--with-trust-anchor=${dns-root-data}/root.key"
"--with-drill"
"--disable-gost"
"--with-examples"
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
"ac_cv_func_malloc_0_nonnull=yes"
"ac_cv_func_realloc_0_nonnull=yes"
];
nativeCheckInputs = [ which ];
doCheck = false; # fails. missing some files
postInstall = ''
# Only 'drill' stays in $out
# the rest are examples:
moveToOutput "bin/ldns*" "$examples"
# with exception of ldns-config, which goes to $dev:
moveToOutput "bin/ldns-config" "$dev"
'';
meta = with lib; {
description = "Library with the aim of simplifying DNS programming in C";
homepage = "https://www.nlnetlabs.nl/projects/ldns/";
license = licenses.bsd3;
maintainers = with maintainers; [ dtzWill ];
mainProgram = "drill";
platforms = platforms.unix;
};
}

View File

@@ -0,0 +1,36 @@
{
lib,
rustPlatform,
fetchFromGitHub,
}:
rustPlatform.buildRustPackage rec {
pname = "ldproxy";
version = "0.31.4";
# The source of this tools actually comes from the set of tools located in the `esp-rs:embuild` repository
# cf: https://github.com/esp-rs/embuild
src = fetchFromGitHub {
owner = "esp-rs";
repo = "embuild";
rev = "v${version}";
hash = "sha256-YH2CPb3uBlPncd+KkP25xhCVvDB7HDxJuSqWOJ1LT3k=";
};
cargoHash = "sha256-/WBhgPyd5hR3DBYvV8pd7uZb6FeD3yiDe3wOKtyFRG8=";
# However we are only interested in building the specific crate located at `/ldproxy`
# cf: https://github.com/esp-rs/embuild/tree/v0.31.4/ldproxy
buildAndTestSubdir = "ldproxy";
meta = {
description = "Linker Proxy: a simple tool to forward linker arguments to the actual linker executable";
homepage = "https://github.com/esp-rs/embuild";
changelog = "https://github.com/esp-rs/embuild/blob/v${version}/CHANGELOG.md";
license = with lib.licenses; [
mit # or
asl20
];
maintainers = with lib.maintainers; [ vpochapuis ];
};
}

View File

@@ -0,0 +1,76 @@
{
lib,
stdenv,
fetchurl,
makeWrapper,
makeDesktopItem,
copyDesktopItems,
unzip,
appimage-run,
nix-update-script,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "ldtk";
version = "1.5.3";
src = fetchurl {
url = "https://github.com/deepnight/ldtk/releases/download/v${finalAttrs.version}/ubuntu-distribution.zip";
hash = "sha256-i7HIcKs10srfvwihGdMEnnmGoqgFWNJhC6vGf81QJWY=";
};
nativeBuildInputs = [
unzip
makeWrapper
copyDesktopItems
appimage-run
];
buildInputs = [ appimage-run ];
unpackPhase = ''
runHook preUnpack
unzip $src
appimage-run -x src 'LDtk ${finalAttrs.version} installer.AppImage'
runHook postUnpack
'';
installPhase = ''
runHook preInstall
install -Dm644 'LDtk ${finalAttrs.version} installer.AppImage' $out/share/ldtk.AppImage
makeWrapper ${appimage-run}/bin/appimage-run $out/bin/ldtk \
--add-flags $out/share/ldtk.AppImage
install -Dm644 src/ldtk.png $out/share/icons/hicolor/512x512/apps/ldtk.png
runHook postInstall
'';
desktopItems = [
(makeDesktopItem {
name = "ldtk";
exec = "ldtk";
icon = "ldtk";
terminal = false;
desktopName = "LDtk";
comment = "2D level editor";
categories = [ "Utility" ];
mimeTypes = [ "application/json" ];
})
];
passthru.updateScript = nix-update-script { };
meta = with lib; {
description = "Modern, lightweight and efficient 2D level editor";
homepage = "https://ldtk.io/";
changelog = "https://github.com/deepnight/ldtk/releases/tag/v${finalAttrs.version}";
license = licenses.mit;
platforms = [ "x86_64-linux" ];
maintainers = with maintainers; [ felschr ];
sourceProvenance = with sourceTypes; [ binaryBytecode ];
mainProgram = "ldtk";
};
})