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

stdenv: Fix regression on ARM+static when enabling hardening #115363

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ in rec {
++ depsTargetTarget ++ depsTargetTargetPropagated) == 0;
dontAddHostSuffix = attrs ? outputHash && !noNonNativeDeps || (stdenv.noCC or false);
supportedHardeningFlags = [ "fortify" "stackprotector" "pie" "pic" "strictoverflow" "format" "relro" "bindnow" ];
defaultHardeningFlags = if stdenv.hostPlatform.isMusl
# Musl-based platforms will keep "pie", other platforms will not.
defaultHardeningFlags = if stdenv.hostPlatform.isMusl &&
# Except when:
# - static aarch64, where compilation works, but produces segfaulting dynamically linked binaries.
# - static armv7l, where compilation fails.
Copy link
Member Author

@samueldr samueldr Mar 7, 2021

Choose a reason for hiding this comment

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

Yes, the comment indent is weird.

It is not an error, but to keep the relevant comments close to the code.

If I didn't make the change to be the least intrusive in diffs, it would have looked like:

{/*...*/

defaultHardeningFlags =
  # Musl-based platforms will keep "pie", other platforms will not.
  if stdenv.hostPlatform.isMusl &&
    # Except when:
    #    - static aarch64, where compilation works, but produces segfaulting dynamically linked binaries.
    #    - static armv7l, where compilation fails.
    !((stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isAarch32) && stdenv.hostPlatform.isStatic)
  then supportedHardeningFlags
  else lib.remove "pie" supportedHardeningFlags;

/*...*/}

I'm not exactly sure how I should format the comments around here to keep the relevant bits at the right location.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it may be a good idea to place the condition inside an( with stdenv.hostPlatform; /* ... */ ) block, e.g.:

{/*...*/
      defaultHardeningFlags = if (with stdenv.hostPlatform; isMusl &&
                                # Except when:
                                #    - static aarch64, where compilation works, but produces segfaulting dynamically linked binaries.
                                #    - static armv7l, where compilation fails.
                                !((isAarch64 || isAarch32) && isStatic))
                              then supportedHardeningFlags
                              else lib.remove "pie" supportedHardeningFlags;
/*...*/}

!((stdenv.hostPlatform.isAarch64 || stdenv.hostPlatform.isAarch32) && stdenv.hostPlatform.isStatic)
then supportedHardeningFlags
else lib.remove "pie" supportedHardeningFlags;
enabledHardeningOptions =
Expand Down