Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pkgs/build-support/cc-wrapper/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@

# the derivation at which the `-B` and `-L` flags added by `useCcForLibs` will point
, gccForLibs ? if useCcForLibs then cc else null
, fortify-headers ? null
, includeFortifyHeaders ? null
}:

with lib;
Expand All @@ -65,6 +67,10 @@ let
stdenv = stdenvNoCC;
inherit (stdenv) hostPlatform targetPlatform;

includeFortifyHeaders' = if includeFortifyHeaders != null
then includeFortifyHeaders
else targetPlatform.libc == "musl";

# Prefix for binaries. Customarily ends with a dash separator.
#
# TODO(@Ericson2314) Make unconditional, or optional but always true by
Expand Down Expand Up @@ -165,6 +171,8 @@ let
stdenv.targetPlatform.darwinMinVersionVariable;
in

assert includeFortifyHeaders' -> fortify-headers != null;

# Ensure bintools matches
assert libc_bin == bintools.libc_bin;
assert libc_dev == bintools.libc_dev;
Expand Down Expand Up @@ -414,6 +422,16 @@ stdenv.mkDerivation {

echo "${libc_lib}" > $out/nix-support/orig-libc
echo "${libc_dev}" > $out/nix-support/orig-libc-dev
''
# fortify-headers is a set of wrapper headers that augment libc
# and use #include_next to pass through to libc's true
# implementations, so must appear before them in search order.
# in theory a correctly placed -idirafter could be used, but in
# practice the compiler may have been built with a --with-headers
# like option that forces the libc headers before all -idirafter,
# hence -isystem here.
+ optionalString includeFortifyHeaders' ''
echo "-isystem ${fortify-headers}/include" >> $out/nix-support/libc-cflags
'')

##
Expand Down
34 changes: 34 additions & 0 deletions pkgs/development/libraries/fortify-headers/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{ lib
, stdenv
, fetchurl
}:

stdenv.mkDerivation {
pname = "fortify-headers";
version = "1.1alpine1";

# upstream only accessible via git - unusable during bootstrap, hence
# extract from the alpine package
src = fetchurl {
url = "https://dl-cdn.alpinelinux.org/alpine/v3.17/main/x86_64/fortify-headers-1.1-r1.apk";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't version number appear in the URL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm the one calling this 1.1alpine1 - the r1 is not an official designation, just alpine's release of the package. And it does differ from upstream's package slightly, including a patch to fix ppoll on some systems https://git.alpinelinux.org/aports/commit/main/fortify-headers?id=4f60e618352e581f7f77a3842e29141da8992d5f. r3 in fact includes patches for clang support, but I'm not using that one yet because I can't find a stable url for it, only appearing in the edge release.

name = "fortify-headers.tar.gz"; # ensure it's extracted as a .tar.gz
hash = "sha256-A67NzUv+dldARY+MTaoVnezTg+Es8ZK/b7XOxA6KzpI=";
};

installPhase = ''
runHook preInstall

mkdir -p $out
cp -r include/fortify $out/include

runHook postInstall
'';

meta = {
description = "Standalone header-based fortify-source implementation";
homepage = "https://git.2f30.org/fortify-headers";
license = lib.licenses.bsd0;
platforms = lib.platforms.all;
maintainers = with lib.maintainers; [ ris ];
};
}
3 changes: 3 additions & 0 deletions pkgs/stdenv/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ let
inherit lib;
inherit (prevStage) coreutils gnugrep;
stdenvNoCC = prevStage.ccWrapperStdenv;
fortify-headers = prevStage.fortify-headers;
}).overrideAttrs(a: lib.optionalAttrs (prevStage.gcc-unwrapped.passthru.isXgcc or false) {
# This affects only `xgcc` (the compiler which compiles the final compiler).
postFixup = (a.postFixup or "") + ''
Expand Down Expand Up @@ -568,6 +569,7 @@ in
inherit lib;
inherit (self) stdenvNoCC coreutils gnugrep;
shell = self.bash + "/bin/bash";
fortify-headers = self.fortify-headers;
};
};
extraNativeBuildInputs = [
Expand Down Expand Up @@ -645,6 +647,7 @@ in
++ [ linuxHeaders # propagated from .dev
binutils gcc gcc.cc gcc.cc.lib gcc.expand-response-params gcc.cc.libgcc glibc.passthru.libgcc
]
++ lib.optionals (localSystem.libc == "musl") [ fortify-headers ]
++ [ prevStage.updateAutotoolsGnuConfigScriptsHook prevStage.gnu-config ]
++ (with gcc-unwrapped.passthru; [
gmp libmpc mpfr isl
Expand Down
2 changes: 2 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21096,6 +21096,8 @@ with pkgs;

folks = callPackage ../development/libraries/folks { };

fortify-headers = callPackage ../development/libraries/fortify-headers { };

makeFontsConf = let fontconfig_ = fontconfig; in {fontconfig ? fontconfig_, fontDirectories}:
callPackage ../development/libraries/fontconfig/make-fonts-conf.nix {
inherit fontconfig fontDirectories;
Expand Down