Skip to content

Commit

Permalink
Merge pull request #307880 from reckenrode/ld64
Browse files Browse the repository at this point in the history
cctools: 973.0.1 -> 1010.6
  • Loading branch information
toonn authored Jul 17, 2024
2 parents 4c086d8 + 9641ac5 commit c3c5870
Show file tree
Hide file tree
Showing 54 changed files with 3,150 additions and 1,058 deletions.
23 changes: 1 addition & 22 deletions pkgs/build-support/bintools-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@
(!(targetPlatform.isAarch && targetPlatform.isStatic))
])
]) "pie"

# Darwin code signing support utilities
, postLinkSignHook ? null, signingUtils ? null
}:

assert propagateDoc -> bintools ? man;
Expand Down Expand Up @@ -357,7 +354,7 @@ stdenvNoCC.mkDerivation {
##

# TODO(@sternenseemann): make a generic strip wrapper?
+ optionalString (bintools.isGNU or false) ''
+ optionalString (bintools.isGNU or false || bintools.isCCTools or false) ''
wrap ${targetPrefix}strip ${./gnu-binutils-strip-wrapper.sh} \
"${bintools_bin}/bin/${targetPrefix}strip"
''
Expand Down Expand Up @@ -396,24 +393,6 @@ stdenvNoCC.mkDerivation {
''
)

##
## Code signing on Apple Silicon
##
+ optionalString (targetPlatform.isDarwin && targetPlatform.isAarch64) ''
echo 'source ${postLinkSignHook}' >> $out/nix-support/post-link-hook
export signingUtils=${signingUtils}
wrap \
${targetPrefix}install_name_tool \
${./darwin-install_name_tool-wrapper.sh} \
"${bintools_bin}/bin/${targetPrefix}install_name_tool"
wrap \
${targetPrefix}strip ${./darwin-strip-wrapper.sh} \
"${bintools_bin}/bin/${targetPrefix}strip"
''

##
## Extra custom steps
##
Expand Down
11 changes: 7 additions & 4 deletions pkgs/build-support/bintools-wrapper/ld-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,13 @@ PATH="$path_backup"
# Old bash workaround, see above.

if (( "${NIX_LD_USE_RESPONSE_FILE:-@use_response_file_by_default@}" >= 1 )); then
@prog@ @<(printf "%q\n" \
${extraBefore+"${extraBefore[@]}"} \
${params+"${params[@]}"} \
${extraAfter+"${extraAfter[@]}"})
responseFile=$(mktemp "${TMPDIR:-/tmp}/ld-params.XXXXXX")
trap 'rm -f -- "$responseFile"' EXIT
printf "%q\n" \
${extraBefore+"${extraBefore[@]}"} \
${params+"${params[@]}"} \
${extraAfter+"${extraAfter[@]}"} > "$responseFile"
@prog@ "@$responseFile"
else
@prog@ \
${extraBefore+"${extraBefore[@]}"} \
Expand Down
19 changes: 6 additions & 13 deletions pkgs/build-support/libredirect/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{ lib, stdenv, bintools-unwrapped, llvmPackages, llvmPackages_13, coreutils }:

let
# aarch64-darwin needs a clang that can build arm64e binaries, so make sure a version of LLVM
# is used that can do that, but prefer the stdenv one if it is new enough.
llvmPkgs = if (lib.versionAtLeast (lib.getVersion llvmPackages.clang) "13")
then llvmPackages
else llvmPackages_13;
in
{ lib, stdenv, bintools-unwrapped, llvmPackages, coreutils }:

if stdenv.hostPlatform.isStatic
then throw ''
libredirect is not available on static builds.
Expand Down Expand Up @@ -46,11 +39,11 @@ else stdenv.mkDerivation rec {
# and the library search directory for libdl.
# We can't build this on x86_64, because the libSystem we point to doesn't
# like arm64(e).
PATH=${bintools-unwrapped}/bin:${llvmPkgs.clang-unwrapped}/bin:$PATH \
PATH=${bintools-unwrapped}/bin:${llvmPackages.clang-unwrapped}/bin:$PATH \
clang -arch x86_64 -arch arm64 -arch arm64e \
-isystem ${llvmPkgs.clang.libc}/include \
-isystem ${llvmPkgs.libclang.lib}/lib/clang/*/include \
-L${llvmPkgs.clang.libc}/lib \
-isystem ${llvmPackages.clang.libc}/include \
-isystem ${llvmPackages.libclang.lib}/lib/clang/*/include \
-L${llvmPackages.clang.libc}/lib \
-Wl,-install_name,$libName \
-Wall -std=c99 -O3 -fPIC libredirect.c \
-shared -o "$libName"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
From 55b2a5fcc38eb62f53e155bd8c741481690f1c73 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 10 Apr 2024 19:08:39 -0400
Subject: [PATCH 1/6] Fix build issues with misc/redo_prebinding.c

- Add missing headers; and
- Add missing arguments to `writeout`.
---
misc/redo_prebinding.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/misc/redo_prebinding.c b/misc/redo_prebinding.c
index a5a3c81..9d0f4c8 100644
--- a/misc/redo_prebinding.c
+++ b/misc/redo_prebinding.c
@@ -83,6 +83,7 @@
#include <mach-o/redo_prebinding.h>
#endif /* defined(LIBRARY_API) */

+#import <stdint.h>
#import <stdio.h>
#import <stdlib.h>
#import <string.h>
@@ -106,7 +107,7 @@
#import <stuff/hppa.h>
#import <stuff/execute.h>
#import <stuff/guess_short_name.h>
-//#import <stuff/seg_addr_table.h>
+#import <stuff/seg_addr_table.h>
#import <stuff/macosx_deployment_target.h>

#include <mach-o/dyld.h>
@@ -918,7 +919,7 @@ char *envp[])
if(write_to_stdout)
output_file = NULL;
writeout(archs, narchs, output_file, mode, TRUE, FALSE, FALSE,
- FALSE, NULL);
+ FALSE, FALSE, NULL);
if(errors){
if(write_to_stdout == FALSE)
unlink(output_file);
@@ -928,7 +929,7 @@ char *envp[])
else{
output_file = makestr(input_file, ".redo_prebinding", NULL);
writeout(archs, narchs, output_file, mode, TRUE, FALSE, FALSE,
- FALSE, NULL);
+ FALSE, FALSE, NULL);
if(errors){
unlink(output_file);
return(2);
--
2.45.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From 419c469634891d09f6688d56da9e26431018f342 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Wed, 10 Apr 2024 20:36:53 -0400
Subject: [PATCH 2/6] Rely on libcd_is_blob_a_linker_signature

---
libstuff/code_directory.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libstuff/code_directory.c b/libstuff/code_directory.c
index 7c158fa..3b8eb77 100644
--- a/libstuff/code_directory.c
+++ b/libstuff/code_directory.c
@@ -146,7 +146,7 @@ static const char* format_version_xyz(uint32_t version)
*/
int codedir_is_linker_signed(const char* data, uint32_t size)
{
-#if 1
+#if 0
// HACK: libcodedirectory.h is in both the macOS SDK in /usr/local/include, and in the tool chain at /usr/include.
// but there is no way to control clang's search path to look in the toolchain first.
// So, declare newer API locally. Once this new header is in all SDKs we can remove this.
--
2.45.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
From 989ba5e30cefa0dd8990da158661713c4a21c0fe Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Thu, 11 Apr 2024 18:05:34 -0400
Subject: [PATCH 3/6] Fix utimensat compatability with the 10.12 SDK

---
include/compat.h | 3 +++
libstuff/writeout.c | 2 +-
misc/lipo.c | 2 +-
3 files changed, 5 insertions(+), 2 deletions(-)
create mode 100644 include/compat.h

diff --git a/include/compat.h b/include/compat.h
new file mode 100644
index 0000000..8b1b866
--- /dev/null
+++ b/include/compat.h
@@ -0,0 +1,3 @@
+#pragma once
+#include <time.h>
+extern int utimensat(int dirfd, const char* pathname, const struct timespec times[_Nullable 2], int flags);
diff --git a/libstuff/writeout.c b/libstuff/writeout.c
index f904caa..03fa535 100644
--- a/libstuff/writeout.c
+++ b/libstuff/writeout.c
@@ -297,7 +297,7 @@ no_throttle:
* have been zeroed out when the library was created. writeout
* will not zero out the modification time in the filesystem.
*/
- if (__builtin_available(macOS 10.12, *)) {
+ if (__builtin_available(macOS 10.13, *)) {
struct timespec times[2] = {0};
memcpy(&times[0], &toc_timespec, sizeof(struct timespec));
memcpy(&times[1], &toc_timespec, sizeof(struct timespec));
diff --git a/misc/lipo.c b/misc/lipo.c
index 04a3eca..887c049 100644
--- a/misc/lipo.c
+++ b/misc/lipo.c
@@ -607,7 +607,7 @@ unknown_flag:
if(close(fd) == -1)
system_fatal("can't close output file: %s",output_file);
#ifndef __OPENSTEP__
- if (__builtin_available(macOS 10.12, *)) {
+ if (__builtin_available(macOS 10.13, *)) {
time_result = utimensat(AT_FDCWD, output_file,
output_times, 0);
}
--
2.45.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
From 86b5ad551ef0ffc7ca4da24b7619937bec738522 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Mon, 15 Apr 2024 20:47:59 -0400
Subject: [PATCH 4/6] Use nixpkgs clang with the assembler driver

---
as/driver.c | 20 +++-----------------
1 file changed, 3 insertions(+), 17 deletions(-)

diff --git a/as/driver.c b/as/driver.c
index a0d49ad..c15dcbf 100644
--- a/as/driver.c
+++ b/as/driver.c
@@ -36,7 +36,7 @@ char **envp)
char *p, c, *arch_name, *as, *as_local;
char **new_argv;
const char *CLANG = "clang";
- char *prefix, buf[MAXPATHLEN], resolved_name[PATH_MAX];
+ char *prefix = "@clang-unwrapped@/bin/";
uint32_t bufsize;
struct arch_flag arch_flag;
const struct arch_flag *arch_flags, *family_arch_flag;
@@ -50,22 +50,6 @@ char **envp)
qflag = FALSE;
Qflag = FALSE;
some_input_files = FALSE;
- /*
- * Construct the prefix to the assembler driver.
- */
- bufsize = MAXPATHLEN;
- p = buf;
- i = _NSGetExecutablePath(p, &bufsize);
- if(i == -1){
- p = allocate(bufsize);
- _NSGetExecutablePath(p, &bufsize);
- }
- prefix = realpath(p, resolved_name);
- if(prefix == NULL)
- system_fatal("realpath(3) for %s failed", p);
- p = rindex(prefix, '/');
- if(p != NULL)
- p[1] = '\0';
/*
* Process the assembler flags exactly like the assembler would (except
* let the assembler complain about multiple flags, bad combinations of
@@ -362,6 +346,8 @@ char **envp)
exit(1);
}

+ prefix = "@gas@/bin/"; /* `libexec` is found relative to the assembler driver’s path. */
+
/*
* If this assembler exist try to run it else print an error message.
*/
--
2.45.2

28 changes: 28 additions & 0 deletions pkgs/by-name/cc/cctools/0005-Find-ld64-in-the-store.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
From e62f7d75380540937f24f896c82736a1e653cc75 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Mon, 22 Apr 2024 18:15:53 -0400
Subject: [PATCH 5/6] Find ld64 in the store

---
libstuff/execute.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/libstuff/execute.c b/libstuff/execute.c
index 8526ab7..abbbf1b 100644
--- a/libstuff/execute.c
+++ b/libstuff/execute.c
@@ -149,6 +149,11 @@ char *
cmd_with_prefix(
char *str)
{
+ // Return the path to ld64 in the store.
+ if (strcmp(str, "ld") == 0) {
+ return "@ld64_path@";
+ }
+
int i;
char *p;
char *prefix, buf[MAXPATHLEN], resolved_name[PATH_MAX];
--
2.45.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
From e25de788260051892b9e34177ea957cbafe6c415 Mon Sep 17 00:00:00 2001
From: Randy Eckenrode <randy@largeandhighquality.com>
Date: Thu, 2 May 2024 07:55:05 -0400
Subject: [PATCH 6/6] Support target prefixes in ranlib detection

---
misc/libtool.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/misc/libtool.c b/misc/libtool.c
index 289ec4d..8265d53 100644
--- a/misc/libtool.c
+++ b/misc/libtool.c
@@ -426,11 +426,11 @@ char **envp)
p++;
else
p = argv[0];
- if(strncmp(p, "ranlib", sizeof("ranlib") - 1) == 0) {
+ if(strncmp(p, "@targetPrefix@ranlib", sizeof("@targetPrefix@ranlib") - 1) == 0) {
cmd_flags.ranlib = TRUE;
}
else if (getenv("LIBTOOL_FORCE_RANLIB")) {
- progname = "ranlib";
+ progname = "@targetPrefix@ranlib";
cmd_flags.ranlib = TRUE;
}

--
2.45.2

Loading

0 comments on commit c3c5870

Please sign in to comment.