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

grpc: work around clang limitations #253530

Merged
merged 1 commit into from
Oct 6, 2023
Merged

Conversation

reckenrode
Copy link
Contributor

Description of changes

Clang checks for a deployment target of at least 10.13 when using aligned allocations even though it has an implementaiton using posix_memalign, which is available in the 10.12 SDK. Work around this check by lying to clang about what the deployment target is.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandbox = true set in nix.conf? (See Nix manual)
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 23.11 Release Notes (or backporting 23.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

@reckenrode
Copy link
Contributor Author

Retargeting staging due to the number of rebuilds.

Copy link
Contributor

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get the same error on this branch and the staging commit it's based on.

On the staging commit without including the fix:

nix-build --pure --no-out-link --argstr system x86_64-darwin -E 'with import ./. {}; grpc.override { stdenv = llvmPackages_16.stdenv.override (let dMV = { darwinMinVersion = "10.13"; }; in old: { }); }'
error: builder for '/nix/store/mqd8c7qlz7kj8kgzn1q69daygw18d6r6-grpc-1.57.0.drv' failed with exit code 2;
       last 10 log lines:
       > make[2]: *** [CMakeFiles/grpcpp_channelz.dir/build.make:77: gens/src/proto/grpc/channelz/channelz.grpc.pb.cc] Error 1
       > make[1]: *** [CMakeFiles/Makefile2:550: CMakeFiles/grpcpp_channelz.dir/all] Error 2
       > 1 warning generated.
       > [ 99%] Linking CXX shared library libgrpc++_error_details.dylib
       > 1 warning generated.
       > [ 99%] Built target grpc++_error_details
       > 1 warning generated.
       > [ 99%] Linking CXX shared library libgrpc++_alts.dylib
       > [ 99%] Built target grpc++_alts
       > make: *** [Makefile:136: all] Error 2

And then "including" the fix:

nix-build --pure --no-out-link --argstr system x86_64-darwin -E 'with import ./. {}; grpc.override { stdenv = llvmPackages_16.stdenv.override (let dMV = { darwinMinVersion = "10.13"; }; in old: { hostPlatform = old.hostPlatform // dMV; buildPlatform = old.buildPlatform // dMV; targetPlatform = old.targetPlatform // dMV;}); }'
error: builder for '/nix/store/m343grlp9xd0z4i9ssyp5jj3gqsbic1y-grpc-1.57.0.drv' failed with exit code 2;
       last 10 log lines:
       > make[1]: *** Waiting for unfinished jobs....
       > make[1]: *** [CMakeFiles/Makefile2:550: CMakeFiles/grpcpp_channelz.dir/all] Error 2
       > 1 warning generated.
       > [ 99%] Linking CXX shared library libgrpc++_error_details.dylib
       > 1 warning generated.
       > [ 99%] Built target grpc++_error_details
       > 1 warning generated.
       > [ 99%] Linking CXX shared library libgrpc++_alts.dylib
       > [ 99%] Built target grpc++_alts
       > make: *** [Makefile:136: all] Error 2

Seems like this happens from LLVM 15 onwards.

EDIT: I think passing --argstr and then using -E with another nixpkgs import is flawed.

Fix not included:

In file included from /tmp/nix-build-grpc-1.57.0.drv-0/source/src/core/[26/1825]
el/channelz.cc:21:                                                              
In file included from /tmp/nix-build-grpc-1.57.0.drv-0/source/src/core/lib/chann
el/channelz.h:28:                                                               
In file included from /nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-
dev/include/c++/v1/map:543:                                                     
In file included from /nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-dev/include/c++/v1/__node_handle:65:                                            
In file included from /nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-
dev/include/c++/v1/optional:1583:                                               
In file included from /nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-
dev/include/c++/v1/memory:898:                                                  In file included from /nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-dev/include/c++/v1/__memory/shared_ptr.h:31:                                    
/nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-dev/include/c++/v1/__m
emory/unique_ptr.h:91:5: error: aligned deallocation function of type 'void (voi
d *, std::align_val_t) noexcept' is only available on macOS 10.13 or newer      
    delete[] __ptr;                                                                 ^                                                                           
/nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-dev/include/c++/v1/__m
emory/unique_ptr.h:504:7: note: in instantiation of function template specialization 'std::default_delete<grpc_core::channelz::PerCpuCallCountingHelper::PerCpuD
ata[]>::operator()<grpc_core::channelz::PerCpuCallCountingHelper::PerCpuData>' r
equested here                                                                         __ptr_.second()(__tmp);                                                   
      ^                                                                         
/nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-dev/include/c++/v1/__m
emory/unique_ptr.h:460:75: note: in instantiation of member function 'std::uniqu
e_ptr<grpc_core::channelz::PerCpuCallCountingHelper::PerCpuData[]>::reset' reque
sted here
  _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_SINCE_CXX23 ~unique_ptr() { reset(
); }
                                                                          ^
/tmp/nix-build-grpc-1.57.0.drv-0/source/src/core/lib/gprpp/per_cpu.h:55:7: note:
 in instantiation of member function 'std::unique_ptr<grpc_core::channelz::PerCp
uCallCountingHelper::PerCpuData[]>::~unique_ptr' requested here
class PerCpu {
      ^
/nix/store/0gxf0bjxkyx3mp7x1syxl5vh7fkj54sw-libcxx-16.0.6-dev/include/c++/v1/__m
emory/unique_ptr.h:91:5: note: if you supply your own aligned allocation functio
ns, use -faligned-allocation to silence this diagnostic
    delete[] __ptr;
    ^

I believe that's the actual failure you're fixing here.

However, with the fix "included":

nix-build --pure --no-out-link -E 'with import ./. { system = "x86_64-darwin"; }; grpc.override { stdenv = llvmPackages_16.stdenv.override (let dMV = { darwinMinVersion = "10.13"; }; in old: { hostPlatform = old.hostPlatform // dMV; buildPlatform = old.buildPlatform // dMV; targetPlatform = old.targetPlatform // dMV;}); }'
error: builder for '/nix/store/kgqrg5zz36ncr6b52dnxr1lvl6vv3ygy-grpc-1.57.0.drv' failed with exit code 2;
       last 10 log lines:
       > --grpc_out: protoc-gen-grpc: Plugin killed by signal 11.
       > make[1]: *** [CMakeFiles/Makefile2:437: CMakeFiles/grpc++_reflection.dir/all] Error 2
       > make[1]: *** Waiting for unfinished jobs....
       > make[2]: *** [CMakeFiles/grpcpp_channelz.dir/build.make:77: gens/src/proto/grpc/channelz/channelz.grpc.pb.cc] Error 1
       > make[1]: *** [CMakeFiles/Makefile2:550: CMakeFiles/grpcpp_channelz.dir/all] Error 2
       > [ 99%] Linking CXX shared library libgrpc++_error_details.dylib
       > [ 99%] Built target grpc++_error_details
       > [ 99%] Linking CXX shared library libgrpc++_alts.dylib
       > [ 99%] Built target grpc++_alts
       > make: *** [Makefile:136: all] Error 2

@reckenrode
Copy link
Contributor Author

EDIT: I think passing --argstr and then using -E with another nixpkgs import is flawed.

gRPC has dependencies written in C++, so the crash is probably due to mixing different versions of libc++ in the same process. gRPC and its dependencies all need to be built against the same libc++ (which currently means with the same clang version).

Clang checks for a deployment target of at least 10.13 when using
aligned allocations even though it has an implementation using
`posix_memalign`, which is available in the 10.12 SDK. Work around this
check by lying to clang about what the deployment target is.
Copy link
Contributor

@toonn toonn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't work out the proper override so I just merged in the LLVM bump. Reproduced both failure and success with that. So looks good to me.

I fixed a couple typos in the commit.

@toonn toonn changed the title gprc: work around clang limitations grpc: work around clang limitations Oct 6, 2023
@toonn toonn merged commit 84953fa into NixOS:staging Oct 6, 2023
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants