diff options
Diffstat (limited to 'nixpkgs/pkgs/build-support')
7 files changed, 97 insertions, 18 deletions
diff --git a/nixpkgs/pkgs/build-support/appimage/default.nix b/nixpkgs/pkgs/build-support/appimage/default.nix index 6db626464fb7..c17274295c96 100644 --- a/nixpkgs/pkgs/build-support/appimage/default.nix +++ b/nixpkgs/pkgs/build-support/appimage/default.nix @@ -23,7 +23,7 @@ rec { buildCommand = '' install $src ./appimage patchelf \ - --set-interpreter $(cat $NIX_CC/nix-support/dynamic-linker) \ + --set-interpreter ${stdenv.cc.bintools.dynamicLinker} \ --replace-needed libz.so.1 ${zlib}/lib/libz.so.1 \ ./appimage @@ -33,7 +33,7 @@ rec { ''; }; - wrapAppImage = { name, src, extraPkgs }: buildFHSUserEnv (defaultFhsEnvArgs // { + wrapAppImage = args@{ name, src, extraPkgs, ... }: buildFHSUserEnv (defaultFhsEnvArgs // { inherit name; targetPkgs = pkgs: defaultFhsEnvArgs.targetPkgs pkgs ++ extraPkgs pkgs; @@ -46,17 +46,17 @@ rec { cd $APPDIR exec ./AppRun "$@" ''; - }); + } // (removeAttrs args (builtins.attrNames (builtins.functionArgs wrapAppImage)))); - wrapType1 = args@{ name, src, extraPkgs ? pkgs: [] }: wrapAppImage { + wrapType1 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // { inherit name extraPkgs; src = extractType1 { inherit name src; }; - }; + }); - wrapType2 = args@{ name, src, extraPkgs ? pkgs: [] }: wrapAppImage { + wrapType2 = args@{ name, src, extraPkgs ? pkgs: [], ... }: wrapAppImage (args // { inherit name extraPkgs; src = extractType2 { inherit name src; }; - }; + }); defaultFhsEnvArgs = { name = "appimage-env"; diff --git a/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix b/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix index 964ff1175538..e1ec09bc95a1 100644 --- a/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix +++ b/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix @@ -191,7 +191,8 @@ stdenv.mkDerivation { else if targetPlatform.isAvr then "avr" else if targetPlatform.isAlpha then "alpha" else throw "unknown emulation for platform: ${targetPlatform.config}"; - in targetPlatform.platform.bfdEmulation or (fmt + sep + arch); + in if targetPlatform.useLLVM or false then "" + else targetPlatform.platform.bfdEmulation or (fmt + sep + arch); strictDeps = true; depsTargetTargetPropagated = extraPackages; diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/add-flags.sh b/nixpkgs/pkgs/build-support/cc-wrapper/add-flags.sh index 9762894607ac..1358b167f6ec 100644 --- a/nixpkgs/pkgs/build-support/cc-wrapper/add-flags.sh +++ b/nixpkgs/pkgs/build-support/cc-wrapper/add-flags.sh @@ -6,6 +6,7 @@ var_templates_list=( NIX+CFLAGS_COMPILE + NIX+CFLAGS_COMPILE_BEFORE NIX+CFLAGS_LINK NIX+CXXSTDLIB_COMPILE NIX+CXXSTDLIB_LINK @@ -43,5 +44,9 @@ if [ -e @out@/nix-support/cc-ldflags ]; then NIX_@infixSalt@_LDFLAGS+=" $(< @out@/nix-support/cc-ldflags)" fi +if [ -e @out@/nix-support/cc-cflags-before ]; then + NIX_@infixSalt@_CFLAGS_COMPILE_BEFORE="$(< @out@/nix-support/cc-cflags-before) $NIX_@infixSalt@_CFLAGS_COMPILE_BEFORE" +fi + # That way forked processes will not extend these environment variables again. export NIX_CC_WRAPPER_@infixSalt@_FLAGS_SET=1 diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh b/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh index 8003fe1d8f38..bb7890100087 100644 --- a/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh +++ b/nixpkgs/pkgs/build-support/cc-wrapper/cc-wrapper.sh @@ -135,7 +135,7 @@ source @out@/nix-support/add-hardening.sh # Add the flags for the C compiler proper. extraAfter=($NIX_@infixSalt@_CFLAGS_COMPILE) -extraBefore=(${hardeningCFlags[@]+"${hardeningCFlags[@]}"}) +extraBefore=(${hardeningCFlags[@]+"${hardeningCFlags[@]}"} $NIX_@infixSalt@_CFLAGS_COMPILE_BEFORE) if [ "$dontLink" != 1 ]; then diff --git a/nixpkgs/pkgs/build-support/cc-wrapper/default.nix b/nixpkgs/pkgs/build-support/cc-wrapper/default.nix index 9569c6e78c8a..cf2d38cd9978 100644 --- a/nixpkgs/pkgs/build-support/cc-wrapper/default.nix +++ b/nixpkgs/pkgs/build-support/cc-wrapper/default.nix @@ -63,6 +63,25 @@ let then import ../expand-response-params { inherit (buildPackages) stdenv; } else ""; + # older compilers (for example bootstrap's GCC 5) fail with -march=too-modern-cpu + isGccArchSupported = arch: + if cc.isGNU or false then + { skylake = versionAtLeast ccVersion "6.0"; + skylake-avx512 = versionAtLeast ccVersion "6.0"; + cannonlake = versionAtLeast ccVersion "8.0"; + icelake-client = versionAtLeast ccVersion "8.0"; + icelake-server = versionAtLeast ccVersion "8.0"; + knm = versionAtLeast ccVersion "8.0"; + }.${arch} or true + else if cc.isClang or false then + { cannonlake = versionAtLeast ccVersion "5.0"; + icelake-client = versionAtLeast ccVersion "7.0"; + icelake-server = versionAtLeast ccVersion "7.0"; + knm = versionAtLeast ccVersion "7.0"; + }.${arch} or true + else + false; + in # Ensure bintools matches @@ -279,23 +298,56 @@ stdenv.mkDerivation { export hardening_unsupported_flags="${builtins.concatStringsSep " " (cc.hardeningUnsupportedFlags or [])}" '' - + optionalString hostPlatform.isCygwin '' - hardening_unsupported_flags+=" pic" + # Machine flags. These are necessary to support + + # TODO: We should make a way to support miscellaneous machine + # flags and other gcc flags as well. + + # Always add -march based on cpu in triple. Sometimes there is a + # discrepency (x86_64 vs. x86-64), so we provide an "arch" arg in + # that case. + + optionalString ((targetPlatform ? platform.gcc.arch) && + isGccArchSupported targetPlatform.platform.gcc.arch) '' + echo "-march=${targetPlatform.platform.gcc.arch}" >> $out/nix-support/cc-cflags-before '' - + optionalString targetPlatform.isMinGW '' - hardening_unsupported_flags+=" stackprotector" + # -mcpu is not very useful. You should use mtune and march + # instead. It’s provided here for backwards compatibility. + + optionalString (targetPlatform ? platform.gcc.cpu) '' + echo "-mcpu=${targetPlatform.platform.gcc.cpu}" >> $out/nix-support/cc-cflags-before '' - + optionalString targetPlatform.isAvr '' - hardening_unsupported_flags+=" stackprotector pic" + # -mfloat-abi only matters on arm32 but we set it here + # unconditionally just in case. If the abi specifically sets hard + # vs. soft floats we use it here. + + optionalString (targetPlatform ? platform.gcc.float-abi) '' + echo "-mfloat-abi=${targetPlatform.platform.gcc.float-abi}" >> $out/nix-support/cc-cflags-before + '' + + optionalString (targetPlatform ? platform.gcc.fpu) '' + echo "-mfpu=${targetPlatform.platform.gcc.fpu}" >> $out/nix-support/cc-cflags-before + '' + + optionalString (targetPlatform ? platform.gcc.mode) '' + echo "-mmode=${targetPlatform.platform.gcc.mode}" >> $out/nix-support/cc-cflags-before + '' + + optionalString (targetPlatform ? platform.gcc.tune && + isGccArchSupported targetPlatform.platform.gcc.tune) '' + echo "-mtune=${targetPlatform.platform.gcc.tune}" >> $out/nix-support/cc-cflags-before '' - + optionalString targetPlatform.isNetBSD '' + # TODO: categorize these and figure out a better place for them + + optionalString hostPlatform.isCygwin '' + hardening_unsupported_flags+=" pic" + '' + optionalString targetPlatform.isMinGW '' + hardening_unsupported_flags+=" stackprotector" + '' + optionalString targetPlatform.isAvr '' + hardening_unsupported_flags+=" stackprotector pic" + '' + optionalString (targetPlatform.libc == "newlib") '' + hardening_unsupported_flags+=" stackprotector fortify pie pic" + '' + optionalString targetPlatform.isNetBSD '' hardening_unsupported_flags+=" stackprotector fortify" '' - + optionalString (targetPlatform.libc == "newlib") '' + + optionalString targetPlatform.isWasm '' hardening_unsupported_flags+=" stackprotector fortify pie pic" '' diff --git a/nixpkgs/pkgs/build-support/fetchgit/nix-prefetch-git b/nixpkgs/pkgs/build-support/fetchgit/nix-prefetch-git index fa4e504c908f..c681be8e4c35 100755 --- a/nixpkgs/pkgs/build-support/fetchgit/nix-prefetch-git +++ b/nixpkgs/pkgs/build-support/fetchgit/nix-prefetch-git @@ -68,7 +68,7 @@ for arg; do --leave-dotGit) leaveDotGit=true;; --fetch-submodules) fetchSubmodules=true;; --builder) builder=true;; - --help) usage; exit;; + -h|--help) usage; exit;; *) : $((++argi)) case $argi in diff --git a/nixpkgs/pkgs/build-support/libredirect/libredirect.c b/nixpkgs/pkgs/build-support/libredirect/libredirect.c index ba1e6c57e12e..dcf3a2016bc2 100644 --- a/nixpkgs/pkgs/build-support/libredirect/libredirect.c +++ b/nixpkgs/pkgs/build-support/libredirect/libredirect.c @@ -91,6 +91,20 @@ int open64(const char * path, int flags, ...) return open64_real(rewrite(path, buf), flags, mode); } +int openat(int dirfd, const char * path, int flags, ...) +{ + int (*openat_real) (int, const char *, int, mode_t) = dlsym(RTLD_NEXT, "openat"); + mode_t mode = 0; + if (flags & O_CREAT) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + char buf[PATH_MAX]; + return openat_real(dirfd, rewrite(path, buf), flags, mode); +} + FILE * fopen(const char * path, const char * mode) { FILE * (*fopen_real) (const char *, const char *) = dlsym(RTLD_NEXT, "fopen"); @@ -152,3 +166,10 @@ int execv(const char *path, char *const argv[]) char buf[PATH_MAX]; return execv_real(rewrite(path, buf), argv); } + +void *dlopen(const char *filename, int flag) +{ + void * (*__dlopen_real) (const char *, int) = dlsym(RTLD_NEXT, "dlopen"); + char buf[PATH_MAX]; + return __dlopen_real(rewrite(filename, buf), flag); +} |