[Nix-dev] NIX_ENFORCE_NO_NATIVE

Andreas Herrmann andreash87 at gmx.ch
Thu Jun 9 10:17:37 CEST 2016


Thanks for your response.

On Wednesday 08 June 2016 22:54:04 Vladimír Čunát wrote:
> On 06/08/2016 04:14 PM, Andreas Herrmann wrote:
> > Especially, when being run outside of a nix-builder.
> 
> IIRC its' conditioned on $NIX_ENFORCE_NO_NATIVE exactly in order not to
> be filtered out when run outside a nix builder. IMO that's a good
> default. Hydra isn't the only reason; many devs use remote builds or
> nix-copy-closure.
How would you nix-copy-closure something that was compiled outside of nix?
Maybe, we're talking about different things. What I mean is using a GCC that was built by Nix directly on the command-line

    $ gcc -O3 -march=native -o thing thing.c

Or, through some build-system:

    $ make

> If you do want -march or -mtune in mkDerivation, you may either set
> NIX_ENFORCE_NO_NATIVE = false; [...]
Sure, and I'm glad that it's an easy fix.
What I'm taking issue with is that it was a quiet change, and that I'm not notified in any way that part of my compiler flags are being ignored. I only found out by chance when looking at the disassembly of some executable while profiling and optimizing. I noticed that there were no AVX instructions to be found, even though they where generated before with -march=native.

My suggestion would be to add a warning. That would seem to work well for both cases: If you're cross-compiling or remote building then you probably don't want to set -march=native and a notification would help to fix these cases. If you're compiling on the target machine and want automatic architecture specific optimization then -march=native is there specifically for that purpose. It being silently ignored is, IMHO, surprising and unexpected behavior and not really helpful.

> [...] or even better, specify it explicitly,
> e.g. -march=btver1
Well, I think, whether that's better or not depends on the use case. If you have different targets but can compile directly on the target then why not use the automatic detection? That way it's one thing less to worry about.

Again, I agree that removing -march=native is a good thing on Hydra. It makes sense to me as the default behavior when building things with nix. It's certainly better than unexpected breakage after a nix-copy-closure. But, I think in any case the user should be notified.

Best, Andreas


More information about the nix-dev mailing list