python312Packages.linear-operator: 0.5.3 -> 0.6
[NixPkgs.git] / pkgs / development / compilers / gcc / common / strip-attributes.nix
blob3871d8466495956b4b687961997d0ff923b29c8c
2   lib,
3   stdenv,
4   langJit,
5 }:
8   # Note [Cross-compiler stripping]
9   # gcc requires delicate stripping as it installs ELF files for both
10   # HOST and TARGET platforms. It requires according strip tool otherwise
11   # strip could remove sections it's not aware of.
12   # Example ARM breakage by x86_64 strip: https://bugs.gentoo.org/697428
13   #
14   # Let's recap the file layout for directories with object files for a
15   # cross-compiler:
16   #
17   # $out (host != target)
18   # `- bin: HOST
19   #    lib/*.{a,o}: HOST
20   #      `- gcc/<TARGET>/<VERSION>/*.{a,o}: TARGET
21   #                               `- plugin/: HOST
22   #  `- lib{,32,64,x32}: symlink to lib or identical layout
23   #  `- libexec/: HOST
24   #  `- <TARGET>/: TARGET
25   #
26   # $out (host == target) has identical directory layout.
27   #
28   # $lib (host != target):
29   # `- <TARGET>/lib/*.{la,so}: TARGET
30   #
31   # $lib (host == target):
32   # `- lib/*.{la,so}: HOST
34   # The rest of stripDebugList{Host,Target} will be populated in
35   # postInstall to disambiguate lib/ object files.
36   stripDebugList = [
37     "bin"
38     "libexec"
39   ];
40   stripDebugListTarget = [ stdenv.targetPlatform.config ];
42   preFixup =
43     ''
44       # Populate most delicated lib/ part of stripDebugList{,Target}
45       updateDebugListPaths() {
46         local oldOpts
47         oldOpts="$(shopt -p nullglob)" || true
48         shopt -s nullglob
50         pushd $out
51         local -ar outHostFiles=(
52           lib{,32,64}/*.{a,o,so*}
53           lib{,32,64}/gcc/${stdenv.targetPlatform.config}/*/plugin
54         )
55         local -ar outTargetFiles=(
56           lib{,32,64}/gcc/${stdenv.targetPlatform.config}/*/*.{a,o,so*}
57         )
58         popd
59     ''
60     + lib.optionalString (!langJit) ''
61       ${
62         # keep indentation
63         ""
64       }
65         pushd $lib
66         local -ar libHostFiles=(
67           lib{,32,64}/*.{a,o,so*}
68         )
69         local -ar libTargetFiles=(
70           lib{,32,64}/${stdenv.targetPlatform.config}/*.{a,o,so*}
71         )
72         popd
74     ''
75     + ''
76         eval "$oldOpts"
78         stripDebugList="$stripDebugList ''${outHostFiles[*]} ''${libHostFiles[*]}"
79         stripDebugListTarget="$stripDebugListTarget ''${outTargetFiles[*]} ''${libTargetFiles[*]}"
80       }
81       updateDebugListPaths
82     '';