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

openssl: prevent -march= flags from being added on mips #244255

Merged
1 commit merged into from Jul 31, 2023
Merged

openssl: prevent -march= flags from being added on mips #244255

1 commit merged into from Jul 31, 2023

Conversation

ghost
Copy link

@ghost ghost commented Jul 19, 2023

Description of changes

Openssl assumes that CFLAGS contains all of the flags that will be passed to the compiler. This assumption fails for nixpkgs due to our cc-wrapper.

On mips platforms, openssl scans CFLAGS to see if the user passed a -march flag; if not, it adds its own:

  if ($target =~ /linux.*-mips/ && !$disabled{asm}
        && !grep { $_ =~ /-m(ips|arch=)/ } (@{$config{CFLAGS}})) {
        # minimally required architecture flags for assembly modules
        my $value;
        $value = '-mips2' if ($target =~ /mips32/);
        $value = '-mips3' if ($target =~ /mips64/);
        unshift @{$config{cflags}}, $value;
        unshift @{$config{cxxflags}}, $value if $config{CXX};
  }

Unfortunately since nixpkgs adds -march= in the wrapper, rather than the CFLAGS, openssl can't see it. The result is two conflicting -march= flags and a build failure when the user has customized hostPlatform.gcc.arch:

  openssl-mips64el-unknown-linux-gnuabin32> mips64el-unknown-linux-gnuabin32-gcc  -I. -Iinclude -Iapps/include  -fPIC -pthread -mabi=n32 -mips3 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -DOPENSSLDIR="\"/nix/store/8kwvrgwdk56ml6sz5swr71fv9mv4592w-openssl-mips64el-unknown-linux-gnuabin32-3.0.9/etc/ssl\"" -DENGINESDIR="\"/nix/store/8kwvrgwdk56ml6sz5swr71fv9mv4592w-openssl-mips64el-unknown-linux-gnuabin32-3.0.9/lib/engines-3\"" -DMODULESDIR="\"/nix/store/8kwvrgwdk56ml6sz5swr71fv9mv4592w-openssl-mips64el-unknown-linux-gnuabin32-3.0.9/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG  -MMD -MF apps/lib/libapps-lib-engine.d.tmp -MT apps/lib/libapps-lib-engine.o -c -o apps/lib/libapps-lib-engine.o apps/lib/engine.c
  cc1: error: '-mips3' conflicts with the other architecture options, which specify a mips64r2 processor
  cc1: error: '-mips3' conflicts with the other architecture options, which specify a mips64r2 processor
  make[1]: *** [Makefile:4254: apps/lib/libapps-lib-app_libctx.o] Error 1
  make[1]: *** Waiting for unfinished jobs....
  make[1]: *** [Makefile:4262: apps/lib/libapps-lib-app_params.o] Error 1
  make[1]: *** [Makefile:4270: apps/lib/libapps-lib-app_provider.o] Error 1

This commit defeats the perl code above by passing CFLAGS=-march to openssl's ./Configure script.

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.

Openssl assumes that CFLAGS contains all of the flags that will be
passed to the compiler.  This assumption fails for nixpkgs due to
our cc-wrapper.

On mips platforms, openssl scans CFLAGS to see if the user passed a
-march flag; if not, it adds its own:

  if ($target =~ /linux.*-mips/ && !$disabled{asm}
        && !grep { $_ =~ /-m(ips|arch=)/ } (@{$config{CFLAGS}})) {
        # minimally required architecture flags for assembly modules
        my $value;
        $value = '-mips2' if ($target =~ /mips32/);
        $value = '-mips3' if ($target =~ /mips64/);
        unshift @{$config{cflags}}, $value;
        unshift @{$config{cxxflags}}, $value if $config{CXX};
  }

Unfortunately since nixpkgs adds `-march=` in the wrapper, rather
than the CFLAGS, openssl can't see it.  The result is two
conflicting `-march=` flags and a build failure when the user has
customized `hostPlatform.gcc.arch`:

  openssl-mips64el-unknown-linux-gnuabin32> mips64el-unknown-linux-gnuabin32-gcc  -I. -Iinclude -Iapps/include  -fPIC -pthread -mabi=n32 -mips3 -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DOPENSSL_PIC -DOPENSSLDIR="\"/nix/store/8kwvrgwdk56ml6sz5swr71fv9mv4592w-openssl-mips64el-unknown-linux-gnuabin32-3.0.9/etc/ssl\"" -DENGINESDIR="\"/nix/store/8kwvrgwdk56ml6sz5swr71fv9mv4592w-openssl-mips64el-unknown-linux-gnuabin32-3.0.9/lib/engines-3\"" -DMODULESDIR="\"/nix/store/8kwvrgwdk56ml6sz5swr71fv9mv4592w-openssl-mips64el-unknown-linux-gnuabin32-3.0.9/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG  -MMD -MF apps/lib/libapps-lib-engine.d.tmp -MT apps/lib/libapps-lib-engine.o -c -o apps/lib/libapps-lib-engine.o apps/lib/engine.c
  cc1: error: '-mips3' conflicts with the other architecture options, which specify a mips64r2 processor
  cc1: error: '-mips3' conflicts with the other architecture options, which specify a mips64r2 processor
  make[1]: *** [Makefile:4254: apps/lib/libapps-lib-app_libctx.o] Error 1
  make[1]: *** Waiting for unfinished jobs....
  make[1]: *** [Makefile:4262: apps/lib/libapps-lib-app_params.o] Error 1
  make[1]: *** [Makefile:4270: apps/lib/libapps-lib-app_provider.o] Error 1

This commit defeats the perl code above by passing `CFLAGS=-march`
to openssl's `./Configure` script.
@ghost ghost marked this pull request as ready for review July 19, 2023 02:15
@ghost ghost requested a review from Mic92 July 29, 2023 19:53
@ghost ghost merged commit a5e3f30 into NixOS:master Jul 31, 2023
10 checks passed
@ghost ghost deleted the pr/mips/openssl-march branch July 31, 2023 21:13
This pull request was closed.
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.

0 participants