From 2be2b5328c961b6fa464027c04d165fe55c0c984 Mon Sep 17 00:00:00 2001 From: Tobias Mayer Date: Wed, 27 May 2020 00:11:11 +0200 Subject: [PATCH] gcc: optimize cross-compiled libraries `libstdc++` and a few other libraries are comiled with the options set in `EXTRA_TARGET_FLAGS`. Normally, this is filled form `EXTRA_FLAGS` inside of `builder.sh`, from which it inherits its optimization option. For cross compilers `EXTRA_TARGET_FLAGS` is set by a dedicated function that does not specify any optimization, leading to sub-par runtime performance of many C++ programs. --- pkgs/development/compilers/gcc/common/extra-target-flags.nix | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkgs/development/compilers/gcc/common/extra-target-flags.nix b/pkgs/development/compilers/gcc/common/extra-target-flags.nix index f1696f182c0..62d9818ca95 100644 --- a/pkgs/development/compilers/gcc/common/extra-target-flags.nix +++ b/pkgs/development/compilers/gcc/common/extra-target-flags.nix @@ -5,9 +5,12 @@ let in { + # For non-cross builds these flags are currently assigned in builder.sh. + # It would be good to consolidate the generation of makeFlags + # ({C,CXX,LD}FLAGS_FOR_{BUILD,TARGET}, etc...) at some point. EXTRA_TARGET_FLAGS = let mkFlags = dep: langD: lib.optionals (targetPlatform != hostPlatform && dep != null && !langD) ([ - "-idirafter ${lib.getDev dep}${dep.incdir or "/include"}" + "-O2 -idirafter ${lib.getDev dep}${dep.incdir or "/include"}" ] ++ stdenv.lib.optionals (! crossStageStatic) [ "-B${lib.getLib dep}${dep.libdir or "/lib"}" ]);