diff --git a/nix/checks.nix b/nix/checks.nix index 3fdd5ba2c0..8ed069bb1f 100644 --- a/nix/checks.nix +++ b/nix/checks.nix @@ -954,6 +954,25 @@ postgresql_17_src ; psql_orioledb-17_exts_orioledb_debug = self'.legacyPackages.psql_orioledb-17.exts.orioledb.debug; + glibc-floor = + let + checkScript = pkgs.writers.writeNuBin "check-glibc-floor" { + makeWrapperArgs = [ + "--prefix" + "PATH" + ":" + "${lib.makeBinPath [ pkgs.binutils ]}" + ]; + } (builtins.readFile ./tools/check-glibc-floor.nu); + in + pkgs.runCommand "glibc-floor-check" + { + paths = lib.collect lib.isDerivation (self'.legacyPackages // self'.packages); + } + '' + ${lib.getExe checkScript} 2.31 $paths + touch $out + ''; }; }; } diff --git a/nix/tools/check-glibc-floor.nu b/nix/tools/check-glibc-floor.nu new file mode 100644 index 0000000000..4fde55b689 --- /dev/null +++ b/nix/tools/check-glibc-floor.nu @@ -0,0 +1,40 @@ +# Fails if any file under the given paths requires a glibc symbol version +# above the allowed floor. + +def ver-key [ver: string] { + $ver | split row "." | each { into int } +} + +def is-elf []: string -> bool { + ($in | path type) == file and (open --raw $in | bytes at 0..<4) == 0x[7f454c46] +} + +def main [max_allowed: string, ...paths: string] { + let max_key = (ver-key $max_allowed) + + let offenders = ( + $paths + | each { |p| glob $"($p)/**/*" } + | flatten + | where { is-elf } + | par-each { |file| + { + file: $file, + version: ( + ^objdump -T $file | complete | get stdout + | parse -r 'GLIBC_(?[0-9.]+)' | get ver + | sort-by { |v| ver-key $v } | last + ), + } + } + | where { |h| $h.version != null and (ver-key $h.version) > $max_key } + ) + + if ($offenders | is-empty) { + print $"glibc floor OK \(<= ($max_allowed)\)" + exit 0 + } + + print $offenders + exit 1 +}