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

gnats: format hardened flag isn't supported #107435

Merged
merged 1 commit into from Dec 24, 2020

Conversation

flokli
Copy link
Contributor

@flokli flokli commented Dec 23, 2020

When invoking a simple Ada program with gcc from gnats10, the
following warnings are shown:

$ gcc -c conftest.adb
gnat1: warning: command-line option ‘-Wformat=1’ is valid for C/C++/ObjC/ObjC++ but not for Ada
gnat1: warning: command-line option ‘-Wformat-security’ is valid for C/C++/ObjC/ObjC++ but not for Ada
gnat1: warning: ‘-Werror=’ argument ‘-Werror=format-security’ is not valid for Ada
$ echo $?
0

This is only spammy when compiling Ada programs inside a Nix derivation,
but certain configure scripts (such as the ./configure script from the
gcc that's built by coreboot's make crossgcc command) fail entirely
when getting that warning output.

https://nixos.wiki/wiki/Coreboot currently suggests manually running

NIX_HARDENING_ENABLE="${NIX_HARDENING_ENABLE/ format/}" make crossgcc

… but actually teaching the nixpkgs-provided cc wrapper that format
isn't supported as a hardening flag seems to be the more canonical way
to do this in nixpgks.

After this, Ada programs still compile:

$ gcc -c conftest.adb
$ echo $?
0

And the compiler output is empty.

cc @ajs124 due to the nixos wiki edit and @petabyteboy due to coreboot-utils :-)

This shouldn't be a scary rebuild, as the default gcc doesn't have ada support enabled.

Motivation for this change

Build Coreboot on NixOS

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.

When invoking a simple Ada program with `gcc` from `gnats10`, the
following warnings are shown:

```
$ gcc -c conftest.adb
gnat1: warning: command-line option ‘-Wformat=1’ is valid for C/C++/ObjC/ObjC++ but not for Ada
gnat1: warning: command-line option ‘-Wformat-security’ is valid for C/C++/ObjC/ObjC++ but not for Ada
gnat1: warning: ‘-Werror=’ argument ‘-Werror=format-security’ is not valid for Ada
$ echo $?
0
```

This is only spammy when compiling Ada programs inside a Nix derivation,
but certain configure scripts (such as the ./configure script from the
gcc that's built by coreboot's `make crossgcc` command) fail entirely
when getting that warning output.

https://nixos.wiki/wiki/Coreboot currently suggests manually running

> NIX_HARDENING_ENABLE="${NIX_HARDENING_ENABLE/ format/}" make crossgcc

… but actually teaching the nixpkgs-provided cc wrapper that `format`
isn't supported as a hardening flag seems to be the more canonical way
to do this in nixpgks.

After this, Ada programs still compile:

```
$ gcc -c conftest.adb
$ echo $?
0
```

And the compiler output is empty.
@SuperSandro2000
Copy link
Member

SuperSandro2000 commented Dec 23, 2020

Result of nixpkgs-review pr 107435 run on x86_64-linux 1

6 packages built:
  • ghdl (ghdl-mcode)
  • ghdl-llvm
  • gnat (gnat9)
  • gnat10
  • gnat6
  • gnatboot

Only took 4 hours to build...

@SuperSandro2000
Copy link
Member

nixos.wiki/wiki/Coreboot currently suggests manually running

NIX_HARDENING_ENABLE="${NIX_HARDENING_ENABLE/ format/}" make crossgcc

Can you update this after the PR got merged?

@ajs124
Copy link
Member

ajs124 commented Dec 23, 2020

cc @ajs124 due to the nixos wiki edit

I have no memory of doing this, but it seems hacky. This is probably a better solution, but I'm not really an expert in any of this.

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Dec 23, 2020

This is only spammy when compiling Ada programs inside a Nix derivation,
but certain configure scripts (such as the ./configure script from the
gcc that's built by coreboot's make crossgcc command) fail entirely
when getting that warning output.

Ah, what a coincidence! I'm trying to make a Nix expression for coreboot and have found this issue just a few hours ago.

Copy link
Contributor

@rnhmjoj rnhmjoj left a comment

Choose a reason for hiding this comment

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

The solution is definitely correct and I can confirm it fixes the gcc configure script.

@ajs124
Copy link
Member

ajs124 commented Dec 24, 2020

Ah, what a coincidence! I'm trying to make a Nix expression for coreboot and have found this issue just a few hours ago.

@petabyteboy already has something for that: https://git.petabyte.dev/petabyteboy/corenix

@flokli flokli merged commit 8f5c939 into NixOS:master Dec 24, 2020
@flokli flokli deleted the gnats-cc-wrapper-format-unsupported branch December 24, 2020 01:26
@flokli
Copy link
Contributor Author

flokli commented Dec 24, 2020

I updated the wiki and removed the hack there.

@rnhmjoj
Copy link
Contributor

rnhmjoj commented Dec 24, 2020

@petabyteboy already has something for that: https://git.petabyte.dev/petabyteboy/corenix

Nice, I'll take a look.

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.

None yet

4 participants