Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

darwin.xnu: update and restructure #110840

Draft
wants to merge 2 commits into
base: staging
Choose a base branch
from
Draft

Conversation

holymonson
Copy link
Contributor

Motivation for this change

Updating darwin.xnu, this should fix most header issues in #101229.
It contains part of #109368 and #110685 , only last commit is really related to this PR.

cc @matthewbauer @veprbl @siraben @SuperSandro2000 , could some one call ofborg test darwin.xnu darwin.Libsystem ?

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

@SuperSandro2000
Copy link
Member

SuperSandro2000 commented Jan 26, 2021

could some one call ofborg test darwin.xnu darwin.Libsystem ?

You can do that yourself.

Also I don't think that ofborg currently has any darwin builder.

@holymonson
Copy link
Contributor Author

You can do that yourself.

Also I don't think that ofborg currently has any darwin builder.

Oh, I could only call on linux, no privilege on darwin. Last time I saw veprbl did it, thought you trusted_users could do the magic.

@siraben
Copy link
Member

siraben commented Jan 27, 2021

@GrahamcOfBorg test darwin.xnu darwin.Libsystem

@r-burns

This comment has been minimized.

@holymonson
Copy link
Contributor Author

Thanks @r-burns , we will add it to list in next amend, after #109368 merged.

@r-burns
Copy link
Contributor

r-burns commented Feb 6, 2021

stdenv build failure:

building '/nix/store/djb0wihi87bm6677jjy9jr00s83dwn0w-libc++abi-7.1.0.drv'...
building '/nix/store/wim1fc280lby704qdkviprvqbkixr486-libiconv-50.drv'...
building '/nix/store/yii1whm14cqbnpylgpi1b06cm6wkf2g2-expand-response-params.drv'...
building '/nix/store/gp8w5ryzglbq9swbndbl2r8kfg6ixj31-pcre-8.44.drv'...
building '/nix/store/y0yjxpwbg60vv43kr89b5bwrf693a7hy-texinfo-6.7.drv'...
unpacking sources
unpacking sources
unpacking sources
unpacking sources
unpacking source archive /nix/store/fkhcwf3vy1bbb5c5d2aky2bxpxf0wa7d-libiconv-50.tar.gz
unpacking source archive /nix/store/zpf0j0qqw8bhm1knfr1x29zzq8pc85wj-pcre-8.44.tar.bz2
unpacking source archive /nix/store/p1fp0amkcrkgax7nnw22snnxil4akngv-libcxxabi-7.1.0.src.tar.xz
patching sources
configuring
no configure script, doing nothing
building
unpacking sources
unpacking source archive /nix/store/qz3xm3v88flpwpsa06czmj3jzn01z9bx-texinfo-6.7.tar.xz
source root is libcxxabi-7.1.0.src
unpacking source archive /nix/store/l3q1583896dzv9x4pjak17mm7w37dxwm-libcxx-7.1.0.src.tar.xz
source root is libiconv-50
setting SOURCE_DATE_EPOCH to timestamp 1445557872 of file libiconv-50/libiconv/lib/loop_unicode.h
patching sources
configuring
fixing libtool script ./build-aux/ltmain.sh
fixing libtool script ./libcharset/build-aux/ltmain.sh
configure flags: --disable-static --disable-dependency-tracking --prefix=/nix/store/8sx1aknfsj8mw5q89jnpyxxmzcng6q0q-libiconv-50 --disable-static --enable-shared
source root is pcre-8.44
In file included from expand-response-params.c:3:
/nix/store/4xa22msw94rmm6knhpdbfvnb77m4gz5f-Libsystem-1238.60.2/include/stdio.h:242:81: error: expected function body after function declarator
FILE    *fopen(const char * __restrict __filename, const char * __restrict __mode) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fopen));
                                                                                   ^
/nix/store/4xa22msw94rmm6knhpdbfvnb77m4gz5f-Libsystem-1238.60.2/include/sys/cdefs.h:654:53: note: expanded from macro '__DARWIN_ALIAS_STARTING'
#define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   __DARWIN_ALIAS_STARTING_MAC_##_mac(x)
                                                    ^
<scratch space>:261:1: note: expanded from here
__DARWIN_ALIAS_STARTING_MAC___MAC_10_6
^
In file included from expand-response-params.c:3:
/nix/store/4xa22msw94rmm6knhpdbfvnb77m4gz5f-Libsystem-1238.60.2/include/stdio.h:303:33: error: expected function body after function declarator
FILE    *fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen));
                                   ^
/nix/store/4xa22msw94rmm6knhpdbfvnb77m4gz5f-Libsystem-1238.60.2/include/sys/cdefs.h:654:53: note: expanded from macro '__DARWIN_ALIAS_STARTING'
#define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   __DARWIN_ALIAS_STARTING_MAC_##_mac(x)
                                                    ^
<scratch space>:266:1: note: expanded from here
__DARWIN_ALIAS_STARTING_MAC___MAC_10_6
^
In file included from expand-response-params.c:3:
/nix/store/4xa22msw94rmm6knhpdbfvnb77m4gz5f-Libsystem-1238.60.2/include/stdio.h:325:41: error: expected function body after function declarator
FILE    *popen(const char *, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(popen)) __swift_unavailable_on("Use posix_spawn APIs or NSTask instead.", "Process spawning is unavailable.");
                                           ^
/nix/store/4xa22msw94rmm6knhpdbfvnb77m4gz5f-Libsystem-1238.60.2/include/sys/cdefs.h:654:53: note: expanded from macro '__DARWIN_ALIAS_STARTING'
#define __DARWIN_ALIAS_STARTING(_mac, _iphone, x)   __DARWIN_ALIAS_STARTING_MAC_##_mac(x)
                                                    ^
<scratch space>:268:1: note: expanded from here
__DARWIN_ALIAS_STARTING_MAC___MAC_10_6
^
setting SOURCE_DATE_EPOCH to timestamp 1581528922 of file pcre-8.44/config.h.generic
expand-response-params.c:49:38: warning: implicitly declaring library function 'fopen' with type 'FILE *(const char *, const char *)' (aka 'struct __sFILE *(const char *, const char *)') [-Wimplicit-function-declaration]
    if (arg->data[0] != '@' || !(f = fopen(&arg->data[1], "r"))) {
                                     ^
expand-response-params.c:49:38: note: include the header <stdio.h> or explicitly provide a declaration for 'fopen'
1 warning and 3 errors generated.
patching sources
applying patch /nix/store/m2qc8a9c4yr5xmqck50fpzzwzpqggbbw-stacksize-detection.patch
builder for '/nix/store/yii1whm14cqbnpylgpi1b06cm6wkf2g2-expand-response-params.drv' failed with exit code 1
cannot build derivation '/nix/store/ypg2b9bhcx7yx95pf5j883mh8v4b16vr-binutils-wrapper-2.35.1.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/m6gwv01ksrf48cz8x78s35269avm5xfk-bootstrap-stage0-clang-wrapper-7.1.0.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/gfn770l0dbs1mdsdm7g0w52ixx7ffnfm-bootstrap-stage3-stdenv-darwin.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/shd40lpir947gh33hi68x1fdxxlri8cy-bootstrap-stage3-stdenv-darwin.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/33v0w0w37yjqp2nikmwqhi5c5lasbs3n-bash-4.4-p23.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/k47ikmhjj7cmh6yhsl7p2290f8crwabf-bzip2-1.0.6.0.1.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/i3xxsb4pmvs7j845gfk2n35nb46rr5iz-clang-7.1.0.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/akchgz5a3qjkgl26v8k8fh8hs1r2si2w-clang-wrapper-7.1.0.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/8iv1b7zl0wjp1a16aa0ybnqn5myka33h-compiler-rt-7.1.0.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/hf1zaygskd1k0jh47b3q1p3v7k63k055-coreutils-8.32.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/nddqpr820zw68j3md0dz6p579zgg6y8j-diffutils-3.7.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/zirlw9fypkh83sgghr2r6y6ilzvchz5z-ed-1.17.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/cmab8aqg3dp9f6qzm7vj5lwy2kq7wm2p-findutils-4.7.0.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/3609kk2axwpz6ag70qkgcc4pakv2crzr-gawk-5.1.0.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/wh6hasfg06dzxp54w0cd8kmwavh32q1p-gmp-6.2.1.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/f722qvba7d5phmvcapxrphplxcs6ij6a-gnugrep-3.6.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/338n8lvfd6a06ypgl4bgj4sz2311p097-gnumake-4.3.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/m8g218216jl2gw2q27l9xvjpw7g42lx3-gnused-4.8.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/swgdq5dgrm6h5fv884rknkv252i4iv0l-gzip-1.10.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/xij03ikr8nc1v1274hmd3z72xyh9rf9p-libffi-3.3.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/0v3rbb1xwsrxzd13yx09g2zy6c8rs4c0-libxml2-2.9.10.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/drd1xympdbij68vf6kxm4bdcsmwrdgsi-llvm-7.1.0.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/8y8286k3w6wbsh0gn0kljig0s5ryffrk-ncurses-6.2.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/z2i0pv4fzxp41dzrianhn7pxgmwa0yrv-patch-2.7.6.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/ssamw6iywr1aa49gb9sk4yk5yxzx1712-pcre-8.44.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/8inp724bhjjbwabpa3s8dn6vnb9axndz-swift-corefoundation.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/vm69ih3qlpx7zwrgx7h4nx1z2bdj84ln-xz-5.2.5.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/9i4jn20vhy0vh0l0v9q41p5xyij9qpvq-zlib-1.2.11.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/hlzy2nhzpdirm5rwdn0b6akallpx9dqi-stdenv-darwin.drv': 1 dependencies couldn't be built
error: build of '/nix/store/hlzy2nhzpdirm5rwdn0b6akallpx9dqi-stdenv-darwin.drv' failed

@r-burns
Copy link
Contributor

r-burns commented Feb 18, 2021

(Never mind, I think I was mistaken)

Oh haha, the expand-response-params failure is a really easy fix, was just missing an include.

diff --git a/pkgs/build-support/expand-response-params/expand-response-params.c b/pkgs/build-support/expand-response-params/expand-response-params.c
index 05b9c62b1e8..e569d539260 100644
--- a/pkgs/build-support/expand-response-params/expand-response-params.c
+++ b/pkgs/build-support/expand-response-params/expand-response-params.c
@@ -1,6 +1,7 @@
 #include <assert.h>
 #include <ctype.h>
 #include <stdio.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>

@r-burns
Copy link
Contributor

r-burns commented Feb 19, 2021

Ok I was able to get stdenv to build using a highly sophisticated approach. Idk if any of this will actually be useful, but I guess I'll post it here anyway.

I think this patch fixes the first issue I was running into:

--- a/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/xnu/default.nix
@@ -5,9 +5,9 @@ let
   # This could be found as /System/DriverKit/usr/local/libexec/availability.pl
   # TODO: update below output when new macOS SDK released.
   availability_pl = writeShellScript "availability.pl" ''
-    if [ "\$1" == "--macosx" ]; then
+    if [ "$1" == "--macosx" ]; then
       echo 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.10.2 10.10.3 10.11 10.11.2 10.11.3 10.11.4 10.12 10.12.1 10.12.2 10.12.4 10.13 10.13.1 10.13.2 10.13.4 10.14 10.14.1 10.14.4 10.14.5 10.14.6 10.15 10.15.1
-    elif [ "\$1" == "--ios" ]; then
+    elif [ "$1" == "--ios" ]; then
       echo 2.0 2.1 2.2 3.0 3.1 3.2 4.0 4.1 4.2 4.3 5.0 5.1 6.0 6.1 7.0 7.1 8.0 8.1 8.2 8.3 8.4 9.0 9.1 9.2 9.3 10.0 10.1 10.2 10.3 11.0 11.1 11.2 11.3 11.4 12.0 12.1 12.2 12.3 12.4 13.0 13.1 13.2 13.3 13.4 13.5 13.6
     fi
   '';
@@ -130,6 +130,13 @@ appleDerivation ({
     )
   '';
 
+  doInstallCheck = true;
+  # Sanity check. Make sure darwin availability macros work.
+  installCheckPhase = ''
+    echo 'checking darwin symbol aliases... '
+    grep __DARWIN_ALIAS_STARTING_MAC___MAC_10_6 $out/include/sys/_symbol_aliasing.h
+  '';

The extra backslashes broke the availability script, causing it to exit and output nothing. The return status was not checked so the build "succeeded" and produced an empty symbol aliasing header, causing seemingly unrelated failures later. So maybe a sanity check is warranted here.

After that, I run into this error later on when building bash:

 clang -L./builtins -L./lib/readline -L./lib/readline -L./lib/glob -L./lib/tilde  -L./lib/sh    -g -O2 -Wno-parentheses -Wno-format-security -o bash shell.o eval.o y.tab.o general.o make_cmd.o print_cmd.o  dispose_cmd.o execute_cmd.o variables.o copy_cmd.o error.o expr.o flags.o jobs.o subst.o hashcmd.o hashlib.o mailcheck.o trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o alias.o array.o arrayfunc.o assoc.o braces.o bracecomp.o bashhist.o bashline.o  list.o stringlib.o locale.o findcmd.o redir.o pcomplete.o pcomplib.o syntax.o xmalloc.o  -lbuiltins -lglob -lsh  -lhistory  -ltilde  lib/intl/libintl.a    -ldl
Undefined symbols for architecture x86_64:
  "___darwin_check_fd_set_overflow", referenced from:
      _input_avail in libsh.a(input_avail.o)
ld: symbol(s) not found for architecture x86_64
clang-7: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [Makefile:573: bash] Error 1
builder for '/nix/store/hvr310gj50rrw4mnlrxnipajpc8ajjm8-bash-4.4-p23.drv' failed with exit code 2

I don't know what ___darwin_check_fd_set_overflow is but it's marked 10.16+ so I just patched it out of Libsystem, lol:

--- a/include/sys/_types/_fd_def.h
+++ b/include/sys/_types/_fd_def.h
@@ -51,55 +51,29 @@ typedef struct fd_set {
 	__int32_t       fds_bits[__DARWIN_howmany(__DARWIN_FD_SETSIZE, __DARWIN_NFDBITS)];
 } fd_set;
 
-int __darwin_check_fd_set_overflow(int, const void *, int) __API_AVAILABLE(macosx(10.16), ios(14.0), tvos(14.0), watchos(7.0));
 __END_DECLS
 
 __header_always_inline int
 __darwin_check_fd_set(int _a, const void *_b)
 {
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunguarded-availability-new"
-#endif
-	if ((uintptr_t)&__darwin_check_fd_set_overflow != (uintptr_t) 0) {
-#if defined(_DARWIN_UNLIMITED_SELECT) || defined(_DARWIN_C_SOURCE)
-		return __darwin_check_fd_set_overflow(_a, _b, 1);
-#else
-		return __darwin_check_fd_set_overflow(_a, _b, 0);
-#endif
-	} else {
-		return 1;
-	}
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
+    return 1;
 }
 
 /* This inline avoids argument side-effect issues with FD_ISSET() */
 __header_always_inline int
 __darwin_fd_isset(int _fd, const struct fd_set *_p)
 {
-	if (__darwin_check_fd_set(_fd, (const void *) _p)) {
-		return _p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] & ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS)));
-	}
-
 	return 0;
 }
 
 __header_always_inline void
 __darwin_fd_set(int _fd, struct fd_set *const _p)
 {
-	if (__darwin_check_fd_set(_fd, (const void *) _p)) {
-		(_p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] |= ((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS))));
-	}
 }
 
 __header_always_inline void
 __darwin_fd_clr(int _fd, struct fd_set *const _p)
 {
-	if (__darwin_check_fd_set(_fd, (const void *) _p)) {
-		(_p->fds_bits[(unsigned long)_fd / __DARWIN_NFDBITS] &= ~((__int32_t)(((unsigned long)1) << ((unsigned long)_fd % __DARWIN_NFDBITS))));
-	}
 }

Later on I ran into issues with __SPI_AVAILABLE, which doesn't seem to be applicable for macOS, so I defined it to nothing:

--- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
@@ -68,6 +69,11 @@ appleDerivation {
       #define API_UNAVAILABLE(...)
 
     #endif
+
+    #if !defined(__SPI_AVAILABLE)
+      #define __SPI_AVAILABLE(...)
+    #endif

The next issue was error: use of undeclared identifier 'strcasecmp' during LLVM 7 compilation. Turns out there are multiple headers named strings.h in the apple sources and Libsystem is using the wrong one (internal strings.h from xnu, rather than the one we want from Libc).

--- a/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
+++ b/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix
@@ -30,7 +31,6 @@ appleDerivation {
         gethostuuid.h
         libproc.h
         spawn.h
-        strings.h
       ")
     )

@veprbl
Copy link
Member

veprbl commented Feb 19, 2021

Removing functions behind the FD_* macros will break any code that uses the select() system call.

@r-burns
Copy link
Contributor

r-burns commented Mar 20, 2021

@holymonson still interested? I posted some kludges I used to build stdenv - if you have more principled fixes for these, maybe we can move forward with this PR?

@holymonson
Copy link
Contributor Author

All my work on updating darwin has paused because of #111988, we may extract headers directly from sdk itself instead of assembled from different libs. I'm not sure if core maintainers still want moving on this way.

@veprbl veprbl marked this pull request as draft July 3, 2021 07:37
@stale
Copy link

stale bot commented Jan 3, 2022

I marked this as stale due to inactivity. → More info

@stale stale bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Staging
  
WIP
Development

Successfully merging this pull request may close these issues.

None yet

5 participants