Commit Graph

498 Commits

Author SHA1 Message Date
Sergei Trofimovich
4763533cca build-support/cc-wrapper: add libstdc++fs into default library path for clang
After https://github.com/NixOS/nixpkgs/pull/210004 `usbmuxd2` started
failing to build as:

    usbmuxd2-unstable> .../ld: cannot find -lstdc++fs: No such file or directory
    usbmuxd2-unstable> clang-11: error: linker command failed with exit code 1 (use -v to see invocation)

This started happening because #210004 exposed a long-standing bug in
`gcc` derivation: `cc.lib` is missing `libstdc++fs` library:

    $ find $(nix-build --no-link -A stdenv.cc.cc.lib) | fgrep libstdc | unnix

    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++fs.la

    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++.la
    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++.so.6.0.29
    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++.so
    /<<NIX>>/gcc-11.3.0-lib/lib/libstdc++.so.6

It was not moved from `cc.out` output:

    $ find $(nix-build --no-link -A stdenv.cc.cc) | fgrep libstdc | unnix
    /<<NIX>>/gcc-11.3.0/lib/libstdc++.a
    /<<NIX>>/gcc-11.3.0/lib/libstdc++fs.a

This change adds `cc` library lookup path back to `staging-next` until
`gcc` is fixed.`
2023-01-28 07:30:33 +00:00
github-actions[bot]
c47e4b69a3
Merge master into staging-next 2023-01-25 00:02:20 +00:00
Robert Scott
00aadf0bf7 cc-wrapper: add support for fortify3 flag 2023-01-24 21:52:10 +00:00
Alyssa Ross
2ae30c9f45 llvmPackages: use libcxxrt on FreeBSD
FreeBSD doesn't use LLVM's cxxabi implementation, for backwards
compatibility reasons.  Software expects the libcxxrt API when
building on FreeBSD.  This fixes the build of
pkgsCross.x86_64-freebsd.boost.
2023-01-24 21:18:39 +00:00
Sergei Trofimovich
b9b1d958d0 Merge remote-tracking branch 'origin/staging-next' into staging
Conflicts:
	pkgs/development/libraries/qt-6/modules/qtbase.nix
	pkgs/stdenv/linux/make-bootstrap-tools.nix
2023-01-20 21:56:57 +00:00
Yureka
7a05f9de7d
gccgo: wrap go binary (#207670) 2023-01-20 14:31:54 +01:00
Sergei Trofimovich
ca4da963f8 Merge remote-tracking branch 'origin/staging-next' into staging
Conflicts:
    pkgs/development/libraries/audio/roc-toolkit/default.nix
2023-01-14 11:07:42 +00:00
Sergei Trofimovich
67a3a14f24
Merge pull request #210004 from trofi/cc-fake-sysroot
build-support/cc-wrapper: pass in non-existent --sysroot= to untangle…
2023-01-14 08:18:56 +00:00
github-actions[bot]
49722fd14a
Merge master into staging-next 2023-01-13 18:01:34 +00:00
Vladimír Čunát
befc83905c
Merge #209423: gnat12: add for x86_64-darwin 2023-01-13 18:32:21 +01:00
Martin Weinelt
c1e6c6af69 Merge remote-tracking branch 'origin/master' into staging-next 2023-01-11 03:51:33 +01:00
Adam Joseph
dfa3f14493 cc-wrapper: -march= is not allowed on powerpc
Gcc does not allow `-march=` on PowerPC:

  https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/RS_002f6000-and-PowerPC-Options.html#RS_002f6000-and-PowerPC-Options

Instead, `-mcpu=` should be used to set the minimum instruction set
and `-mtune=` is used to optimize instruction scheduling for a
specific processor.  Both flags take the same set of valid values,
which includes `native`.

This commit causes `isGccArchSupported` to return `false` for PowerPC
targets so we never pass an `-march=` flag, since that will always be
rejected by gcc.
2023-01-10 14:05:03 +01:00
Sergei Trofimovich
8c80bd08b7 build-support/cc-wrapper: pass in non-existent --sysroot= to untangle from libc
I would like to add an extra `gcc` build step during linux bootstrap
(https://github.com/NixOS/nixpkgs/issues/208412). This makes it early
bootstrap compiler linked and targeted against `bootstrapTools` `glibc`
including it's headers.

Without this change `gcc`'s spec files always prefer `bootstrapTools` `glibc`
for header search path (passed in as --with-native-system-header-dir=). We'can't
override it with:

- `-I` option as it gets stacked before gcc-specific headers, we need to keep
  glibc headers after gcc as gcc cleans namespace up for C standard by using
  #include_next and by undefining system macros.
- `-idirafter` option as it gets appended after existing `glibc`-includes

This `--sysroot=/nix/store/does/not/exist` hack allows us to remove existing
`glibc` headers and add new ones with `-idirafter`.

We use `cc-cflags-before` instead of `libc-cflags` to allow user to define
their own `--sysroot=` (like `firefox` does).

To keep it working prerequisite cross-symlink in gcc.libs is required:
https://github.com/NixOS/nixpkgs/pull/209153
2023-01-10 07:54:13 +00:00
Boey Maun Suang
a584587bea cc-wrapper: Wrap/link all other GNAT commands 2023-01-07 18:32:12 +11:00
Boey Maun Suang
c1308ac58c cc-wrapper: Fix gnatmake wrapper
Switches that gnatmake needs to pass to gcc must be given as
"-cargs <gcc_switches>" after at least the files to compile (see the
gnatmake docs for all the subtleties).  This commit makes that happen,
in a way that triggers rebuilds only for things that actually depend on
GNAT, and not the other compilers contained in GCC.
2023-01-07 18:32:12 +11:00
Artturin
adc8900df1 treewide: fix some core package structuredAttrs 2022-12-08 21:05:28 +02:00
Artturin
734d7df235 allow derivation attributes in env
derivations can be coerced to their output paths
2022-12-08 06:13:19 +02:00
Nick Cao
994deb2bf1 cc-wrapper: fix path to libcxx includes for cross compilers 2022-11-30 18:46:16 +01:00
John Ericson
0c09b3d17c
Merge pull request #197937 from danielbarter/cc-wrapper-hook
cc-wrapper: adding a cc-wrapper-hook to the cc-wrapper
2022-10-28 17:30:03 +01:00
Vladimír Čunát
6890557c17
Revert "Merge #191724: cc-wrapper: remove duplicate include flags"
Let's redo this later, with more testing and less bugs.
This reverts commits 4f6e99870b and d700d8e8a2.
2022-10-28 10:28:12 +02:00
Daniel Barter
77bd639c4c cc-wrapper: adding a cc-wrapper-hook to the cc-wrapper 2022-10-26 09:33:43 -07:00
Sergei Trofimovich
8480f40236
Merge pull request #191134 from Et7f3/remove-duplicate-code-cc-wrapper
cc-wrapper: remove duplicate C{C,XX}${role_post}
2022-10-16 21:02:04 +01:00
Vladimír Čunát
d700d8e8a2
stdenv cc-wrapper: revert a problematic change for non-Linux
The change from 0bea4a194f (PR #191724) broke stdenv bootstap
on *-darwin, and I didn't want to drop the *-linux binaries
that we have already.
2022-10-14 09:40:48 +02:00
Sergei Trofimovich
7d7030c6d5
Merge pull request #193871 from trofi/FORTIFY-unset-and-set
cc-wrapper/add-hardening.sh: always unset _FORTIFY_SOURCE before re-s…
2022-10-08 07:30:17 +01:00
Vladimír Čunát
4f6e99870b
Merge #191724: cc-wrapper: remove duplicate include flags
...into staging
2022-10-05 20:01:34 +02:00
Sergei Trofimovich
2a9fc04635 cc-wrapper/add-hardening.sh: always unset _FORTIFY_SOURCE before re-setting it
On darwin clang driver always sets -D_FORTIFY_SOURCE=0 under asan.
This causes -Werror to trip over macro redefinition:

    <command line>:1:9: error: '_FORTIFY_SOURCE' macro redefined [-Werror,-Wmacro-redefined]
    #define _FORTIFY_SOURCE 2
            ^

To avoid it let's always explicitly undefine it first before redefining.
2022-10-01 08:30:11 +01:00
Daniel Barter
0bea4a194f cc-wrapper/setup-hook.sh: remove duplicate flags in NIX_CFLAGS_COMPILE 2022-09-28 13:24:42 -07:00
Yang, Bo
b51302ed47 Add stdenv.cc.libcxx to detect the standard C++ library 2022-09-26 12:52:19 -07:00
Daniel Fullmer
2946b819c2 cc-wrapper: fix linking against GCC libs for non-GCC
Currently, clang++ statically links against libstdc++ instead of
dynamically links, because the -L path included in the cc-wrapper is
incorrect. The gccForLibs.lib output only contains the architecture
subdirectory if the target and host platform are not the same. (See
targetConfig set in gcc/<version>/default.nix and the gcc/builder.nix)

This fixes the incorrect linking by using the correct path for both the
cross and native cases. This also matches the cc_solib set above in
cc-wrapper/default.nix

Tested by compiling a simple cpp binary and noting that it now correctly
dynamically links against libstdc++, natively on x86_64 and arm64, as
well as x86_64 -> arm64 cross compilation.

Co-Authored-By: Sebastian Ullrich <sebasti@nullri.ch>
2022-09-22 09:41:40 -07:00
Theodore Ni
c319d8ae3b
cc-wrapper: comment explaining C++ stdlib order
There is context here that I needed when resolving an issue in which
libc was added to NIX_CFLAGS_COMPILE before the C++ stdlib that took
me awhile to understand.

It was suggested to me that this context be included as a comment,
since it is not obvious and could help others in the future.
2022-09-20 12:14:51 +02:00
Et7f3
d937f6fc2f
cc-wrapper: remove duplicate C{C,XX}${role_post}
This might be typo but I don't know which other variable was intended to be named. This can also come from a merge conflict.
2022-09-14 02:41:05 +02:00
github-actions[bot]
efe19ddf3b
Merge staging-next into staging 2022-08-25 18:01:48 +00:00
Minijackson
bec06f5bba
cc-wrapper: disable stackprotector for MicroBlaze
This option doesn't seem to be supported in the cross-compiler
2022-08-25 16:00:49 +02:00
Theodore Ni
1f6366d38c
cc-wrapper: fortran: enable stackprotector on M1
Was failing due to https://github.com/iains/gcc-darwin-arm64/issues/54,
fix picked up in https://github.com/NixOS/nixpkgs/pull/186477.
2022-08-19 16:41:36 -07:00
github-actions[bot]
67f5b5a85d
Merge staging-next into staging 2022-08-08 18:02:11 +00:00
adisbladis
5cc12aa8cb
Merge pull request #182187 from adisbladis/newlib-nano-cc
newlib-nano: Set same flags as regular newlib in cc-wrapper/gcc config
2022-08-08 22:07:57 +08:00
Sergei Trofimovich
549e08c8e8 bintools-wrapper, cc-wrapper: avoid invalid export of 'expand-response-params'
POSIX sh (and `bash`) impose a restriction on environment variable name
format and disallow hypheps in the names. Normally it's not a problem
as nothing usually tries to refer nyphenated names.

One exception is `nix develop` (https://github.com/NixOS/nix/issues/6848):

    $ nix develop -f. gcc -L
    gcc-wrapper> ...-get-env.sh: line 70: expand-response-params: bad substitution

Note that bash usually uses explicitly created `expandResponseParams`
variant of the same variable.

To work the problem around let's avoid environment variable export and move
it to `passthru` for `cc` (used ina  few places) and remove it completely for
`binutils` (does not seem to be used at all).
2022-07-31 16:31:13 +01:00
Vladimír Čunát
5b5843e2b2
Merge #151983: wrapper: Fortran: disable stackprotector
...hardening on darwin aarch64 (merge into staging)
2022-07-29 19:27:34 +02:00
adisbladis
d5fb429c7d cc-wrapper: Set correct hardening_unsupported_flags for newlib-nano 2022-07-20 16:41:48 +08:00
Semion Nadezhdin
b060076e21 cc-wrapper: broaden explicit libc++abi linking for LLVM stdenv 2022-07-13 21:19:12 +03:00
Dmitry Kalinkin
daa77caf9b
cc-wrapper: disable response files for ccache
The problem is that the ccache wrapper does not work with response
files (it seems like the fd doesn't survive after exec in the
makeWrapper wrapper).
2022-06-19 17:38:59 -04:00
Dmitry Bogatov
6eb689d490
cc-wrapper: fix typo in shell script
Noticed this bug when was trying to bootstrap m4 on darwin. That fixes

	line 163: no such file or directory error

That does not solve all problems staging has on darwin.
2022-06-17 20:25:27 -04:00
John Ericson
e23e71f9e4
Merge pull request #176152 from mmlb/cc-wrapper-allow-target-override
cc-wrapper: Allow user to override -target for clang
2022-06-15 15:09:27 -04:00
Manuel Mendez
0fdc72b7e9 cc-wrapper: Add clang specific options to clang specific file
This way gcc doesn't need to be rebuilt because of clang. This also avoids
rebuilding clang when only the wrapper needs to be tweaked.
2022-06-15 11:34:53 -04:00
Manuel Mendez
19b6ccd9ac cc-wrapper: Allow for override of -target for clang/clang++
This enables users to make use of clang's multi-platform/target support
without having to go through full cross system setup. This is especially useful
for generating bpf object files, I'm not even usre what would a no-userland
cross compile system tuple even look like to even try going that route.

Fixes #176128
2022-06-09 16:57:15 -04:00
Manuel Mendez
e91b5670e3 cc-wrapper: Use case statements instead of bunch of if/elif checks
Makes for easier to read code imo, case-in-point there was a duplicate test for
`$p = -E` before. While doing this little bit of refactor I changed rest ->
kept because that makes more sense, rest sounds like its the rest of params
while kept says these are the params that we've kept.

I tested for no change in behavior using the following bash script:

```
reset() {
	cInclude=1
	cxxInclude=1
	cxxLibrary=1
	dontLink=0
	isCxx=0
	nonFlagArgs=0
	params=()
}

parseParams() {
	declare -i n=0
	nParams=${#params[@]}
	while (("$n" < "$nParams")); do
		p=${params[n]}
		p2=${params[n + 1]:-} # handle `p` being last one

		case "$p" in
		-[cSEM] | -MM) dontLink=1 ;;
		-cc1) cc1=1 ;;
		-nostdinc) cInclude=0 cxxInclude=0 ;;
		-nostdinc++) cxxInclude=0 ;;
		-nostdlib) cxxLibrary=0 ;;
		-x)
			case "$p2" in
			*-header) dontLink=1 ;;
			c++*) isCxx=1 ;;
			esac
			;;
		-?*) ;;
		*) nonFlagArgs=1 ;; # Includes a solitary dash (`-`) which signifies standard input; it is not a flag
		esac
		n+=1
	done
}

for p in c S E M MM; do
	reset
	params=-$p
	parseParams
	[[ $dontLink != 1 ]] && echo "expected dontLink=1 for params:${params[@]}" >&2 && exit 1
done

reset
params=(-x foo-header)
parseParams
[[ $dontLink != 1 ]] && echo "expected dontLink=1 for params:${params[@]}" >&2 && exit 1

reset
params=(-x c++-foo)
parseParams
[[ $isCxx != 1 ]] && echo "expected isCxx=1 for params:${params[@]}" >&2 && exit 1

reset
params=-nostdlib
parseParams
[[ $cxxLibrary != 0 ]] && echo "expected cxxLibrary=0 for params:${params[@]}" >&2 && exit 1

reset
params=-nostdinc
parseParams
[[ $cInclude != 0 ]] && echo "expected cInclude=0 for params:${params[@]}" >&2 && exit 1
[[ $cxxInclude != 0 ]] && echo "expected cxxInclude=0 for params:${params[@]}" >&2 && exit 1

reset
params=-nostdinc++
parseParams
[[ $cxxInclude != 0 ]] && echo "expected cxxInclude=0 for params:${params[@]}" >&2 && exit 1

reset
params=-cc1
parseParams
[[ $cc1 != 1 ]] && echo "expected cc1=1 for params:${params[@]}" >&2 && exit 1

reset
params=-
parseParams
[[ $nonFlagArgs != 1 ]] && echo "expected nonFlagArgs=1 for params:${params[@]}" >&2 && exit 1

reset
params=bleh
parseParams
[[ $nonFlagArgs != 1 ]] && echo "expected nonFlagArgs=1 for params:${params[@]}" >&2 && exit 1

reset
params=-?
parseParams
[[ $nonFlagArgs != 0 ]] && echo "expected nonFlagArgs=0 for params:${params[@]}" >&2 && exit 1

exit 0
```
2022-06-09 16:57:15 -04:00
FliegendeWurst
7b185e04a9 cc-wrapper: Fortran: disable format hardening
Otherwise, these warnings are emitted:
command-line option '-Wformat=1' is valid for C/C++/ObjC/ObjC++ but not for Fortran
command-line option '-Wformat-security' is valid for C/C++/ObjC/ObjC++ but not for Fortran
'-Werror=' argument '-Werror=format-security' is not valid for Fortran

Fixes part of #27218
2022-05-26 12:29:35 +02:00
Artturin
1d44ac176c treewide: add enableParallelBuilding's to bootstrap packages so hashes stay the same
when enableParallelBuildingByDefault is enabled

verified with
`nix-diff $(nix eval ".#gcc-unwrapped.drvPath") $(nix eval --expr 'with import ./. { config = { enableParallelBuildingByDefault = true; }; }; gcc-unwrapped.drvPath' --impure)`
2022-05-25 16:03:14 +03:00
Janne Heß
c911240e9c
Revert "Add mingwW64-llvm cross-system." 2022-05-18 13:50:23 +02:00
Shea Levy
0f68ed163c
Merge branch 'mingwW64-clang' into staging 2022-05-18 06:30:21 -04:00
Shea Levy
078a07708a
libunwind: Fix build against compiler-rt-using clang 2022-05-09 10:05:47 -04:00
Shea Levy
4b503b2a58
cc-wrapper: clang doesn't support -fPIC on Windows 2022-05-06 10:54:52 -04:00
Emery Hemingway
89a0dd2414 wrapCCWith: structured argument for wrapper flags
Take a "nixSupport" argument that is an attrset of lists to append
to "$out/nix-support/${name}" where name is the name of the
attribute. This attrset is available from the passthru of the
wrapped compiler.

This is an alternative to imperatively issuing flags with
extraBuildCommands and makes it possible to append or filter
flags with an override.
2022-04-30 21:21:41 -05:00
Doron Behar
2cc754a7ba cc-wrapper: Fortran: disable stackprotector hardening on darwin aarch64 2022-04-16 11:11:26 +03:00
Sergei Trofimovich
649ebfbed6 cc-wrapper: change cflags order from cc/crt1/libc to crt1/libc/cc
In https://github.com/NixOS/nixpkgs/issues/158042 I noticed order
mismatch as a bootstrap build failure when building x86_64-linux
against glibc-2.35 in nixpkgs (bootstrap libs has glibc-2.27):

    expand-response-params> ld: /nix/store/p4s4jf7aq6v6z9iazll1aiqwb34aqxq9-bootstrap-tools/lib/crt1.o: in function `_start':
    expand-response-params> /build/glibc-2.27/csu/../sysdeps/x86_64/start.S:101: undefined reference to `__libc_csu_fini'
    expand-response-params> ld: /build/glibc-2.27/csu/../sysdeps/x86_64/start.S:102: undefined reference to `__libc_csu_init'
    expand-response-params> collect2: error: ld returned 1 exit status

Here crt1.o from glibc-2.27 links against libc.so.6 from glibc-2.35.

This happens because ordering of `-L` (influences `libc.so` lookup) and
`-B` (influences `crt1.o` lookup) flags differs:

    expand-response-params>   -B/...-bootstrap-tools/lib
    expand-response-params>   -B/...-glibc-2.35/lib/
    ...
    expand-response-params>   -L/...-glibc-2.35/lib
    expand-response-params>   -L/...-bootstrap-tools/lib

The change makes consistent ordering of `-L`/`-B` and allows getting to
stage4 for `glibc-2.35` target.
2022-02-20 10:45:45 +00:00
Moritz Angermann
14996789a1
Check link type based on expanded parameters
So far we've ignored response files in arguments, and did not
check linkType against expanded parameters.  This means if
we have `-static` in a @reponse-file, linkType will not be
set to `-static` as we never check against the expanded arguments
from response files.
2022-01-01 20:30:56 +08:00
r-burns
16728283c3
Merge pull request #135619 from r-burns/fpie-musl-fixes
[staging] {cc,binutils}-wrapper: fixes for PIE hardening
2021-09-23 17:55:08 -07:00
Ryan Burns
37d089c1af {cc,binutils}-wrapper: match leading/trailing arguments
fixes e.g.:
pkgsMusl.libfsm
pkgsMusl.libiscsi
pkgsMusl.nsjail
pkgsMusl.pv

match strings have whitespace on either side, which wasn't
matching leading/trailing arguments previously
2021-09-20 17:24:04 -07:00
Ryan Burns
bd8258a389 cc-wrapper: ensure PIE flags precede PIC flags
fixes:
pkgsMusl.bulletml
pkgsMusl.proot
pkgsMusl.python3

Debian explains this issue well in the dpkg-buildflags manpage:

-fPIE
    Can be linked into any program, but not a shared library (recommended).
-fPIC
    Can be linked into any program and shared library.

On projects that build both programs and shared libraries you might need to
make sure that when building the shared libraries -fPIC is always passed last
(so that it overrides any previous -PIE) to compilation flags such as CFLAGS.

(from https://manpages.debian.org/bullseye/dpkg-dev/dpkg-buildflags.1.en.html#hardening)
2021-09-20 11:03:42 -07:00
John Ericson
d3407f1a3b cc-wrapper: Add support for -mthumb / -marm 2021-09-17 17:12:54 +00:00
Shea Levy
9ecfbe0c5b
mingw: Disalbe FORTIFY_SOURCE by default.
In newer versions of mingw, programs compiled with FORTIFY_SOURCE need
to link to libssp or they will have link-time errors.

gmp has been broken since @pstn updated mingw-64 in c60a0b0447
2021-08-11 05:07:42 -04:00
sternenseemann
c3c4ef859a gprbuild, xmlada: init at 21.0.0
GPRbuild is a multi language build system developed by AdaCore which
is mostly used for build Ada-related projects using GNAT.

Since GPRbuild is used to build itself and its dependency library
XML/Ada we first build a bootstrap version of it using the provided
bash build script bootstrap.sh as the gprbuild-boot derivation.
gprbuild-boot is then used to build xmlada and the proper gprbuild
derivation.

GPRbuild has its own search path mechanism via GPR_PROJECT_PATH which
we address via a setupHook. It currently works quite similar to the
pkg-config one: It accumulates all inputs into GPR_PROJECT_PATH,
GPR_PROJECT_PATH_FOR_BUILD etc. However this is quite limited at the
moment as we don't have a gprbuild wrapper yet which understands the
_FOR_BUILD suffix. However, we'll need to address this in the future
as it is currently basically impossible to test since the distinction
only affects cross-compilation, but it is not possible to build a GNAT
cross-compiler in nixpkgs at the moment (I'm working on changing that,
however).

Another issue we had to solve was GPRbuild not finding the right GNAT
via its gprconfig tool: GPRbuild has a knowledge base with compiler
definitions which run some checks and collect info about binaries
which are in PATH. In the end the first compiler in PATH that supports
the desired language is selected.

We want GPRbuild to discover our wrapped GNAT since the unwrapped one
is incapable of producing working binaries since it won't find the
crt*.o objects distributed with libc. GPRbuild however needs to find
the Ada runtime distributed with GNAT which is not part of the wrapper
derivation, so it will skip the wrapper and select the unwrapped GNAT.
Symlinking the unwrapped's lib directory into the wrapper fixes this
problem, but breaks linking in some cases (e. g. when linking against
OMP from gcc, the runtime variant will shadow the problem dynamic lib
from buildInputs). Additionally it uses gnatls as an indicator it has
found GNAT which is not part of the wrapper.

The solution we opted to adopt here is to install a custom compiler
description into gprbuild's knowledge base which properly detects the
nixpkgs GNAT wrapper: It uses gnatmake to detect GNAT instead of
gnatls and discovers the runtime via a symlink we add to
`$out/nix-support`. This additional definition is enough to properly
detect GNAT, since the plain wrapped gcc detection works out of the
box. It may, however, be necessary to add special definitions for
other languages in the future where gprbuild also needs to discover
the runtime.

One future improvement would be to install libgpr into a separate
output or split it into a separate derivation (which would require to
link gprbuild statically always since otherwise we end up with a
cyclical dependency).
2021-08-03 14:58:49 +02:00
Jörg Thalheim
166948d479 cc-wrapper: don't set rpath on static-pie executables 2021-05-23 17:38:17 +00:00
John Ericson
18c38f8aee treewide: All the linker to be chosen independently
This will begin the process of breaking up the `useLLVM` monolith. That
is good in general, but I hope will be good for NetBSD and Darwin in
particular.

Co-authored-by: sterni <sternenseemann@systemli.org>
2021-05-14 21:29:51 +00:00
John Ericson
912c8262b4
Merge pull request #117591 from s1341/android_non_prebuilt
treewide: Support aarch64-android using minimal prebuilt components
2021-05-11 12:49:53 -04:00
s1341
1e1d29c2af treewide: Support aarch64-android using minimal prebuilt components
This PR adds a new aarch64 android toolchain, which leverages the
existing crossSystem infrastructure and LLVM builders to generate a
working toolchain with minimal prebuilt components.

The only thing that is prebuilt is the bionic libc. This is because it
is practically impossible to compile bionic outside of an AOSP tree. I
tried and failed, braver souls may prevail. For now I just grab the
relevant binaries from https://android.googlesource.com/.

I also grab the msm kernel sources from there to generate headers. I've
included a minor patch to the existing kernel-headers derivation in
order to expose an internal function.

Everything else, from binutils up, is using stock code. Many thanks to
@Ericson2314 for his help on this, and for building such a powerful
system in the first place!

One motivation for this is to be able to build a toolchain which will
work on an aarch64 linux machine. To my knowledge, there is no existing
toolchain for an aarch64-linux builder and an aarch64-android target.
2021-05-11 15:39:08 +00:00
Vladimír Čunát
8eabe2ecc5
Merge #115235: gcc: native aarch64-darwin support 2021-05-11 12:12:04 +02:00
Ivan Babrou
4aa95e3312 gcc: native aarch64-darwin support 2021-05-10 19:07:30 -07:00
Dmitry Kalinkin
11b744b59c
cc-wrapper.sh: make -nostdlib disable the standard C++ library, but not its includes
Should be the correct fix for #111970
2021-05-02 14:07:00 -04:00
Dmitry Kalinkin
d9bad0eae6
cc-wrapper.sh: rename variables cpp -> cxx
CPP is the C PreProcessor
CXX is C++
2021-05-02 14:03:51 -04:00
Dmitry Kalinkin
96bbe339d4
Revert "cc-wrapper: -nostdlib does not imply -nostdinc++"
This made C++ standard headers passed to be passed when C compiler is
executed, which is not a correct fix.

This reverts commit 54c7a0f422.
2021-05-02 14:00:37 -04:00
Andrew Childs
7869d16545 llvmPackages: Multuple outputs for everythting
Also begin to start work on cross compilation, though that will have to
be finished later.

The patches are based on the first version of
https://reviews.llvm.org/D99484. It's very annoying to do the
back-porting but the review has uncovered nothing super major so I'm
fine sticking with what I've got.

Beyond making the outputs work, I also strove to re-sync the packages,
as they have been drifting pointlessly apart for some time.

----

Other misc notes, highly incomplete

- lvm-config-native and llvm-config are put in `dev` because they are
  tools just for build time.

- Clang no longer has an lld dep. That was introduced in
  db29857eb3, but if clang needs help
  finding lld when it is used we should just pass it flags / put in the
  resource dir. Providing it at build time increases critical path
  length for no good reason.

----

A note on `nativeCC`:

`stdenv` takes tools from the previous stage, so:

1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.stdenv.cc`: `(?0, ?1, x)`

while:

1. `pkgsBuildBuild`: `(?1, x, x)`
2. `pkgsBuildBuild.targetPackages`: `(x, x, ?2)`
3. `pkgsBuildBuild.targetPackages.stdenv.cc`: `(?1, x, x)`
2021-04-30 05:41:00 +00:00
Luke Granger-Brown
08b22e605b Merge remote-tracking branch 'upstream/staging-next' into down-integrate-staging 2021-04-12 18:49:01 +00:00
Andrew Childs
6c4ce7960e bintools-wrapper, cc-wrapper: parameterize darwin min version variable
These variables are the ones that the standard toolchain uses, so we
should use those and not always use MACOSX_DEPLOYMENT_TARGET.

See 236a426c12/cctools/ld64/src/ld/PlatformSupport.cpp (L54-L55)
2021-04-11 09:47:10 +09:00
Andrew Childs
2a9b3b4943 cc-wrapper, bintools-wrapper: support MACOSX_DEPLOYMENT_TARGET with roles
In a typical build environment the toolchain will use the value of the
MACOSX_DEPLOYMENT_TARGET environment variable to determine the version
of macOS to support. When cross compiling there are two distinct
toolchains, but they will look at this single environment variable. To
avoid contamination, we always set the equivalent command line flag
which effectively disables the toolchain's internal handling.

Prior to this change, the MACOSX_DEPLOYMENT_TARGET variable was
ignored, and the toolchains always used the Nix platform
definition (`darwinMinVersion`) unless overridden with command line
arguments.

This change restores support for MACOSX_DEPLOYMENT_TARGET, and adds
nix-specific MACOSX_DEPLOYMENT_TARGET_FOR_BUILD and
MACOSX_DEPLOYMENT_TARGET_FOR_TARGET for cross compilation.
2021-04-11 09:47:10 +09:00
Andrew Childs
8b59d52ca3 cc-wrapper: use legacy -mmacosx-version-min for gcc
See https://github.com/NixOS/nixpkgs/pull/105026#discussion_r587169144
2021-04-11 09:47:10 +09:00
Andrew Childs
362cb82b75 cc-wrapper: specify default -mmacos-version-min
This avoids contamination via MACSOX_DEPLOYMENT_TARGET when cross
compiling.
2021-04-11 09:47:10 +09:00
arcnmx
2f1131cff7 cc-wrapper: match useGccForLibs conditional order
This breaks an evaluation cycle between `cc` and `gccForLibs` for cross
builds, fixing an infinite recursion error.
2021-04-10 10:39:07 -07:00
Thomas Tuegel
54c7a0f422 cc-wrapper: -nostdlib does not imply -nostdinc++
The check for including the C++ standard library headers was nested inside the
check for linking with the C++ standard library. As a result, the `-nostdlib`
flag incorrectly implied `-nostdinc++`, which made it virtually impossible to
partially link C++ objects.
2021-03-20 09:26:04 +01:00
Andrew Childs
86e962a41a cc-wrapper: remove quoting of response file
Fixes build failures with clang:

    clang-7: error: unknown argument: '-fPIC                -target'
    clang-7: error: no such file or directory: '@<(printf %qn        -O2'
    clang-7: error: no such file or directory: 'x86_64-apple-darwin'

Introduced by 60c5cf9cea in #112449
2021-03-09 14:01:34 +09:00
John Ericson
6979a72840
Merge pull request #112449 from angerman/angerman/response-files
Add response file support when compiling with clang
2021-03-06 11:24:32 -05:00
Jan Tojnar
6d1958ad2d
Merge branch 'staging-next' into staging 2021-03-04 22:16:45 +01:00
s1341
aee60bef7a android_prebuilt: Fix eval 2021-03-04 18:17:39 +00:00
Andrew Childs
fc0456bed1 cc-wrapper: set -arch on darwin 2021-03-02 17:21:08 +09:00
Moritz Angermann
60c5cf9cea
Update pkgs/build-support/cc-wrapper/cc-wrapper.sh
Co-authored-by: Matthew Bauer <mjbauer95@gmail.com>
2021-02-26 10:07:27 +08:00
Walter Franzini
eabb56ac6c identify musl32 using x86_32 instead of i686 2021-02-12 21:11:16 +01:00
Walter Franzini
87e35291a5 disable stackprotector on target platform musl32 2021-02-12 11:06:29 +01:00
Moritz Angermann
11b4d6c633
responsie file logic 2021-02-09 09:46:47 +08:00
Ben Siraphob
aa8868c7cc pkgs/build-support: stdenv.lib -> lib 2021-01-24 19:07:54 -08:00
John Ericson
0710308402 clang, cc-wrapper: Move --gcc-toolchain logic into CC wrapper
Take 2, after #94582 had to be reverted.

This reverts commit ac03cfa3c5.
2021-01-24 15:49:32 -05:00
John Ericson
9c213398b3 lib: Clean up how linux and gcc config is specified
Second attempt of 8929989614589ee3acd070a6409b2b9700c92d65; see that
commit for details.

This reverts commit 0bc275e634.
2021-01-23 10:01:28 -05:00
Jonathan Ringer
0bc275e634
Revert "lib: Clean up how linux and gcc config is specified"
This is a stdenv-rebuild, and should not be merged
into master

This reverts commit 8929989614.
2021-01-22 14:07:06 -08:00
John Ericson
8929989614 lib: Clean up how linux and gcc config is specified
The `platform` field is pointless nesting: it's just stuff that happens
to be defined together, and that should be an implementation detail.

This instead makes `linux-kernel` and `gcc` top level fields in platform
configs. They join `rustc` there [all are optional], which was put there
and not in `platform` in anticipation of a change like this.

`linux-kernel.arch` in particular also becomes `linuxArch`, to match the
other `*Arch`es.

The next step after is this to combine the *specific* machines from
`lib.systems.platforms` with `lib.systems.examples`, keeping just the
"multiplatform" ones for defaulting.
2021-01-21 22:44:09 -05:00
Steven Pease
b766673c6f Move disabling of gccForLibs for iOS to build-support cc-wrapper 2021-01-20 10:14:46 -08:00
Jörg Thalheim
61bbbcd1af
bintools-wrapper: skip dynamic linker for static binaries 2020-12-27 16:42:11 +01:00
John Ericson
fb875dcf6f
Merge pull request #107507 from LibreCybernetics/add-zen-info
lib.systems: update processor architecture info
2020-12-24 10:23:10 -05:00
Fabián Heredia Montiel
2a9ac172c1 lib.systems: update processor architecture info 2020-12-23 18:57:59 -06:00
Florian Klink
07c4056179 gnats: format hardened flag isn't supported
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.
2020-12-23 01:51:14 +01:00
Matthew Bauer
989b403c7f
Merge pull request #96318 from matthewbauer/provide-patchelf-in-native-stdenv
stdenv/native: provide patchelf on linux
2020-10-30 13:32:13 -05:00
Matthew Bauer
4830967736 Fix cc-wrapper in native stdenv 2020-08-26 14:36:26 -05:00
Frederik Rietdijk
d59c57f8a6
Merge pull request #92412 from matthewbauer/blas-cross
Blas/Lapack cross fixes
2020-08-15 08:55:57 +02:00
John Ericson
b5f7ed6846
Merge pull request #91293 from Ericson2314/cxx-wrapper-debt-part-2
treewide: Get rid of `cc.gcc`
2020-08-02 20:42:20 -04:00
John Ericson
92f96f47b0 treewide: Get rid of cc.gcc
Instead, we have a new `gccForLibs`, which has the appropriate
definition for e.g. avoiding `x86_32` linking problems.
2020-08-02 17:12:05 +00:00
Jörg Thalheim
96092dc936
stdenv: make -nostdinc work as intended
Right now we add glibc to search path also -nostdinc was provided,
which breaks projects providing their own gcc.
2020-07-23 08:39:46 +01:00
Matthew Bauer
f42aa7e1d7 cc-wrapper: set FC when langFortran is on
We need to set FC so that CMake and other tools can find the fortran
compiler. Also we need to limit the hardening flags since fortify and
format don’t work with fortran.

Fixes #88449
2020-07-06 00:22:19 -04:00
John Ericson
704daf7a6e {bintools,cc}-wrapper: Ensure nix-support/*-flags files exist
This will unbreak firefox and a few other packages which try to grab
some of the libcxx flags.
2020-06-30 18:26:37 +00:00
John Ericson
1085403acd {cc,bintools}-wrapper: Comments no longer spliced
This means we can freely keep the comments up to date without the
penalty of a mass rebuild.
2020-06-30 15:04:10 +00:00
John Ericson
f3f7612a40 C++ Compilers: Systematize handling of standard libraries 2020-06-22 04:24:44 +00:00
Lars Jellema
7ea5b08cfc gnat: fix build 2020-09-19 20:54:27 -07:00
Vladimír Čunát
e88e14ec8d
Merge branch 'master' into staging-next
A few thousand rebuilds per platform have arrived in the meantime.
2020-09-11 14:24:13 +02:00
John Ericson
5fd27509cf
Merge pull request #97387 from Ericson2314/fix-android-prebuilt
cc-wrapper: Fix for prebuilt android
2020-09-08 20:24:50 -04:00
John Ericson
204dc3a88b cc-wrapper: Fix for prebuilt android
We don't want to use Nix-built GCC's libs with prebuilt clang in this
case.
2020-09-07 15:08:11 -04:00
Frederik Rietdijk
5ceea5705a Revert "utils.bash: also "fix" cc-wrapper and pkg-config-wrapper"
Follow up to the revert in e560459c5b.

This reverts commit 1936b11f63.
2020-09-07 16:31:59 +02:00
Frederik Rietdijk
1936b11f63 utils.bash: also "fix" cc-wrapper and pkg-config-wrapper 2020-09-07 07:19:26 +02:00
John Ericson
1965a241fc
Merge pull request #61019 from volth/gcc.arch-amd
platform.gcc.arch: support for AMD CPUs
2020-09-01 22:31:16 -04:00
volth
cf7b63df5b gcc.arch: refactor, move tables under lib/ 2020-08-05 11:18:26 +00:00
volth
463db72e63 platform.gcc.arch: support for AMD CPUs 2020-08-05 02:32:48 +00:00
Frederik Rietdijk
d578248611 Merge staging-next into staging 2020-05-24 10:10:06 +02:00
Stefan Frijters
fc9b93d2fc gdc: init at 9.3.0 2020-05-19 23:06:52 +02:00
John Ericson
1ac5398589 *-wrapper; Switch from infixSalt to suffixSalt
I hate the thing too even though I made it, and rather just get rid of
it. But we can't do that yet. In the meantime, this brings us more
inline with autoconf and will make it slightly easier for me to write a
pkg-config wrapper, which we need.
2020-05-12 00:44:44 -04:00
Lars Jellema
8e79583510 gnat: init at 9.3.0 2020-04-20 14:41:22 +02:00
John Ericson
204d710405 treewide: Get rid of -dumpmachine in favor of static info 2020-04-13 19:26:19 -04:00
John Ericson
19a0b38cbe
Merge pull request #82882 from obsidiansystems/armv6-embedded
Misc fixes for armv6 bare metal cross
2020-03-19 10:38:22 -04:00
John Ericson
bc054004ac cc-wrapper, clang: libstdcxxHook should a propagated build input
Lumping it in with the target platform libraries was incorrect, and
caused eval failures when gcc couldn't be built for the target platform.
2020-03-18 11:28:52 -04:00
Vladimír Čunát
1d9c10c8de
stdenv cc-wrapper: deal with edge-case regressions
Regression introduced in PR #81191 80729b6787.  The file does not exist
somewhere during bootstrap of pkgsStatic.busybox which is used in nix
(by default).

I tested the builds.
2020-03-10 11:09:26 +01:00
John Ericson
5c4dd08a03
Merge pull request #81191 from clkamp/stdenv-multi-line-libc-cflags
stdenv: Fix gcc multi line libc-cflags
2020-03-07 21:28:33 -05:00
Christian Lütke-Stetzkamp
80729b6787 stdenv: Fix gcc multi line libc-cflags
which broke at least libstdc++5.

Closes #79761
2020-03-06 10:34:57 +01:00
Ben Wolsieffer
e1831ebea3 gcc: move target-specific runtime libraries to separate output 2020-03-04 16:12:36 -05:00
John Ericson
cfd013813e
Merge pull request #74090 from obsidiansystems/ghcjs-cross-without-cc
stdenv, haskell: bonafied GHCJS cross compilation without stdenv.cc
2019-12-30 16:40:43 -08:00
Matthew Bauer
162a935d3c
Merge pull request #74226 from bhpdt/fix/idirafter-stdenv
stdenv: Fix gcc -idirafter shell glob in cc-wrapper
2019-12-02 13:41:28 -05:00
David Wood
4d26c18306 cc-wrapper: expose wrapper script as overridable attribute (#65813) 2019-11-27 14:15:56 -05:00
Ben Hipple
5f589d8d5d stdenv: Fix gcc -idirafter shell glob in cc-wrapper
If an empty string is passed to `-idirafter`, it breaks gcc. This commit makes
the stdenv less fragile by expanding out the shell glob and ensuring no empty
arguments get passed.
2019-11-26 00:55:16 +00:00
John Ericson
6bc456c91c Merge remote-tracking branch 'upstream/master' into ghcjs-cross-without-cc 2019-11-25 00:23:07 +00:00
John Ericson
63bd851e95 stdenv: Introduce hasCC attribute
Before, we'd always use `cc = null`, and check for that. The problem is
this breaks for cross compilation to platforms that don't support a C
compiler.

It's a very subtle issue. One might think there is no problem because we
have `stdenvNoCC`, and presumably one would only build derivations that
use that. The problem is that one still wants to use tools at build-time
that are themselves built with a C compiler, and those are gotten via
"splicing". The runtime version of those deps will explode, but the
build time / `buildPackages` versions of those deps will be fine, and
splicing attempts to work this by using `builtins.tryEval` to filter out
any broken "higher priority" packages (runtime is the default and
highest priority) so that both `foo` and `foo.nativeDrv` works.

However, `tryEval` only catches certain evaluation failures (e.g.
exceptions), and not arbitrary failures (such as `cc.attr` when `cc` is
null). This means `tryEval` fails to let us use our build time deps, and
everything comes apart.

The right solution is, as usually, to get rid of splicing. Or, baring
that, to make it so `foo` never works and one has to explicitly do
`foo.*`. But that is a much larger change, and certaily one unsuitable
to be backported to stable.

Given that, we instead make an exception-throwing `cc` attribute, and
create a `hasCC` attribute for those derivations which wish to
condtionally use a C compiler: instead of doing `stdenv.cc or null ==
null` or something similar, one does `stdenv.hasCC`. This allows quering
without "tripping" the exception, while also allowing `tryEval` to work.

No platform without a C compiler is yet wired up by default. That will
be done in a following commit.
2019-11-25 00:12:38 +00:00
John Ericson
6d3b7458cc
Merge pull request #74065 from Ericson2314/cc-versions
compilers, binutils: Add version and pname
2019-11-24 18:35:13 -05:00
Craig Hall
da3c053482 {cc,bintools}-wrapper: Inherit compiler version 2019-11-24 18:32:26 +00:00
John Ericson
d0d5136cce Merge remote-tracking branch 'upstream/master' into wrapper-pname-support 2019-11-24 17:25:07 +00:00
Craig Hall
99537e994f {cc,bintools}-wrapper: use cc pname/version if set 2019-11-24 16:33:21 +00:00
John Ericson
fae8d2627d cc-wrapper, bintools-wrapper: Remove now unneeded set {+,-}u 2019-11-04 19:57:14 -05:00
Craig Hall
0b7494ed2b cc-wrapper: add (partial) support for clang -cc1
We need this for intel-compute-runtime, see #63705
2019-09-01 16:53:06 +01:00
Matthew Bauer
f496357585 cc-wrapper: use -iframework instead of -F
This avoids dumping -Wall warnings when they appear in framework
headers. As a result, we are closer to how regular headers are
included (via -isystem).

Also remove ccIncludeFlag lookup, this was unused & not very useful.
2019-06-28 16:27:27 -04:00
Matthew Bauer
23c520d95e cc-wrapper: only set -march when platform.gcc.arch is specified
We want to make sure this value is explicitly set. Infering it for
every arch leads to annoying failures like:

https://hydra.nixos.org/build/92583832/

Perhaps we can enable it in the future with some smarter handling of
cc-wrapper.sh.
2019-04-26 22:30:45 -04:00
volth
dba65df034 kernel: fix cross-build
Fix for #59225 regression proposed by @matthewbauer
https://github.com/NixOS/nixpkgs/pull/59225#issuecomment-486398003

(cherry picked from commit a6ea72a77d1f8e794244b063a7e9780c1b47486d)
2019-04-25 14:14:48 -04:00
Matthew Bauer
7488a367af
Merge pull request #56555 from matthewbauer/wasm
Initial WebAssembly/WASI cross-compilation support
2019-04-23 22:44:33 -04:00
Matthew Bauer
6948ffd398 wasilibc: use .imports file for lld
instead of passing in the --allow-undefined-file, we can just let lld
find the file.
2019-04-23 21:48:58 -04:00
Matthew Bauer
9abff4af4f wasm: init cross target
Adds pkgsCross.wasm32 and pkgsCross.wasm64. Use it to build Nixpkgs
with a WebAssembly toolchain.

stdenv/cross: use static overlay on isWasm

isWasm doesn’t make sense dynamically linked.
2019-04-23 21:48:57 -04:00
volth
5d87bc2650 fix bootstrap when platform.gcc.arch=="skylake" 2019-04-21 16:37:49 +00:00
Matthew Bauer
d180cb9850 cc-wrapper: make machine configuration configurable
It is useful to make these dynamic and not bake them into gcc. This
means we don’t have to rebuild gcc to change these values. Instead, we
will pass cflags to gcc based on platform values. This was already
done hackily for android gcc (which is multi-target), but not for our
own gccs which are single target.

To accomplish this, we need to add a few things:

- add ‘arch’ to cpu
- add NIX_CFLAGS_COMPILE_BEFORE flag (goes before args)
- set -march everywhere
- set mcpu, mfpu, mmode, and mtune based on targetPlatform.gcc flags

cc-wrapper: only set -march when it is in the cpu type

Some architectures don’t have a good mapping of -march. For instance
POWER architecture doesn’t support the -march flag at all!

https://gcc.gnu.org/onlinedocs/gcc/RS_002f6000-and-PowerPC-Options.html#RS_002f6000-and-PowerPC-Options
2019-04-20 20:05:51 -04:00
Matthew Bauer
d453273fbf llvm8: support c++ in cross case
this adds libc++ to the LLVM cross, giving us access to the full
Nixpkgs set. This requires 4 stages of wrapped compilers:

- Clang with no libraries
- Clang with just compiler-rt
- Clang with Libc, and compiler-rt
- Clang with Libc++, Libc, and compiler-rt
2019-04-11 21:28:51 -04:00
Matthew Bauer
aab8c7ba43 netbsd: add cross target 2019-02-26 15:55:47 -05:00