python312Packages.linear-operator: 0.5.3 -> 0.6
[NixPkgs.git] / pkgs / development / compilers / gcc / common / libgcc-buildstuff.nix
blob5c72e0dbdf05d94c402ef092dbf81aa08a26692a
2   lib,
3   stdenv,
4 }:
6 # Trick to build a gcc that is capable of emitting shared libraries *without* having the
7 # targetPlatform libc available beforehand.  Taken from:
8 #   https://web.archive.org/web/20170222224855/http://frank.harvard.edu/~coldwell/toolchain/
9 #   https://web.archive.org/web/20170224235700/http://frank.harvard.edu/~coldwell/toolchain/t-linux.diff
10 let
11   # crt{i,n}.o are the first and last (respectively) object file
12   # linked when producing an executable.  Traditionally these
13   # files are delivered as part of the C library, but on GNU
14   # systems they are in fact built by GCC.  Since libgcc needs to
15   # build before glibc, we can't wait for them to be copied by
16   # glibc.  At this early pre-glibc stage these files sometimes
17   # have different names.
18   crtstuff-ofiles =
19     if stdenv.targetPlatform.isPower then "ecrti.o ecrtn.o ncrti.o ncrtn.o" else "crti.o crtn.o";
21   # Normally, `SHLIB_LC` is set to `-lc`, which means that
22   # `libgcc_s.so` cannot be built until `libc.so` is available.
23   # The assignment below clobbers this variable, removing the
24   # `-lc`.
25   #
26   # On PowerPC we add `-mnewlib`, which means "libc has not been
27   # built yet".  This causes libgcc's Makefile to use the
28   # gcc-built `{e,n}crt{n,i}.o` instead of failing to find the
29   # versions which have been repackaged in libc as `crt{n,i}.o`
30   #
31   SHLIB_LC = lib.optionalString stdenv.targetPlatform.isPower "-mnewlib";
35   echo 'libgcc.a: ${crtstuff-ofiles}' >> libgcc/Makefile.in
36   echo 'SHLIB_LC=${SHLIB_LC}' >> libgcc/Makefile.in
39 # Meanwhile, crt{i,n}.S are not present on certain platforms
40 # (e.g. LoongArch64), resulting in the following error:
42 # No rule to make target '../../../gcc-xx.x.x/libgcc/config/loongarch/crti.S', needed by 'crti.o'.  Stop.
44 # For LoongArch64 and S390, a hacky workaround is to simply touch them,
45 # as the platform forces .init_array support.
47 # https://www.openwall.com/lists/musl/2022/11/09/3
49 # 'parsed.cpu.family' won't be correct for every platform.
51   lib.optionalString
52     (
53       stdenv.targetPlatform.isLoongArch64 || stdenv.targetPlatform.isS390 || stdenv.targetPlatform.isAlpha
54     )
55     ''
56       touch libgcc/config/${stdenv.targetPlatform.parsed.cpu.family}/crt{i,n}.S
57     ''