-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Fix GCC compilation on MacOS 10.15 #82921
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
Conversation
MacOS 10.15 now includes "aligned_alloc". Disagreement between the headers and the binaries about whether aligned_alloc exists leads to a compilation failure (see NixOS#73319 and the detailed comment in this commit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable
# regardless of their actual version. (Nix uses version 10.12 headers.) | ||
# - Nix uses the native standard library binaries for the build system. That | ||
# means the standard library binaries may not exactly match the standard | ||
# library headers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which library does this symbol come from? While we do use the native Libsystem we only export a subset of it's symbols to avoid problems like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't declared in any of the libsystem libraries in the store. It sneaks in from outside the store: libSystem.B.dylib
is linked to /usr/lib/system/libsystem_malloc.dylib
, which contains aligned_alloc
.
$ DYLD_PRINT_LIBRARIES=1 ./result/bin/alignedalloc-test
dyld: loaded: /Users/loncaric/Desktop/alignedalloc/./result/bin/alignedalloc-test
dyld: loaded: /opt/nix/store/b8xv2cjbqlpngwn3fx3hf5pdkaym8f0q-Libsystem-osx-10.12.6/lib/libSystem.B.dylib
dyld: loaded: /opt/nix/store/b8xv2cjbqlpngwn3fx3hf5pdkaym8f0q-Libsystem-osx-10.12.6/lib/system/libsystem_c.dylib
dyld: loaded: /opt/nix/store/b8xv2cjbqlpngwn3fx3hf5pdkaym8f0q-Libsystem-osx-10.12.6/lib/system/libsystem_kernel.dylib
dyld: loaded: /opt/nix/store/b8xv2cjbqlpngwn3fx3hf5pdkaym8f0q-Libsystem-osx-10.12.6/lib/libSystem_internal.dylib
[...]
dyld: loaded: <00190446-C6A8-3EA6-92D1-850EA85C84CE> /usr/lib/system/libsystem_malloc.dylib
[...]
allocated memory at 0x294017a0
$ fgrep -ir aligned_alloc /usr/lib/system/libsystem_malloc.dylib
Binary file /usr/lib/system/libsystem_malloc.dylib matches
I don't have a good mental model of how linkers work, but I'm not terribly surprised that one might discover aligned_alloc
through this transitive link.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's the test case I put together, which compiles on Catalina but not on earlier versions of MacOS:
$ cat alignedalloc.c
int main() {
void* p = aligned_alloc(16, 64);
printf("allocated memory at %p\n", p);
return p ? 0 : 1;
}
$ cat default.nix
with import <nixpkgs> {};
stdenv.mkDerivation rec {
name = "alignedalloc-test";
src = ./.;
buildPhase = ''
cc -v alignedalloc.c -o a.out
'';
doCheck = true;
checkPhase = ''
./a.out
'';
installPhase = ''
mkdir -p $out/bin
mv a.out $out/bin/alignedalloc-test
'';
}
$ nix-build
[...]
/opt/nix/store/b203gi34fvm1y5v26i4h3vgav9cdqgp8-alignedalloc-test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LnL7 Any remaining concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess, a slightly more robust way to address this impurity would be to come up with a common list of symbols for libsystem_malloc and plug it into the https://github.com/NixOS/nixpkgs/blob/master/pkgs/os-specific/darwin/apple-source-releases/Libsystem/default.nix . A while I made a tool for doing this using travis https://github.com/veprbl/libsystem_symbol_list , it may come useful.
This needs to target staging branch |
Thanks for catching that; I've changed the target branch from master to staging. |
This seems to have fallen through the cracks. Can it be merged? |
@GrahamcOfBorg eval |
I'm not sure how to interpret the automated test output. It failed, but the failure looks unrelated to this change. Is there some action I should be taking here? |
@GrahamcOfBorg eval |
Motivation for this change
Fix #73319 (GCC libstdc++ does not compile on MacOS 10.15 Catalina).
I left a comment in the diff with details about the fix.
This is a "quick-n-dirty" fix: there may be other derivations that suffer from the same issue, and this won't do anything to help them. The right change is probably going to be somewhere in the Darwin stdenv code, but I don't understand it well enough to know what to do.
Things done
sandbox
innix.conf
on non-NixOS linux)nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
./result/bin/
)nix path-info -S
before and after)