Merge pull request #256525 from K900/auto-patchelf-flags

autoPatchelfHook: add `patchelfFlags` option

authored by K900 and committed by GitHub 03fddbfb 3bf47679

+20 -23
+3 -16
pkgs/applications/networking/browsers/firefox-bin/default.nix
··· 20 , runtimeShell 21 , systemLocale ? config.i18n.defaultLocale or "en_US" 22 , patchelfUnstable # have to use patchelfUnstable to support --no-clobber-old-sections 23 - , makeWrapper 24 }: 25 26 let ··· 58 source = lib.findFirst (sourceMatches mozLocale) defaultSource sources; 59 60 pname = "firefox-${channel}-bin-unwrapped"; 61 - 62 - # FIXME: workaround for not being able to pass flags to patchelf 63 - # Remove after https://github.com/NixOS/nixpkgs/pull/256525 64 - wrappedPatchelf = stdenv.mkDerivation { 65 - pname = "patchelf-wrapped"; 66 - inherit (patchelfUnstable) version; 67 - 68 - nativeBuildInputs = [ makeWrapper ]; 69 - 70 - buildCommand = '' 71 - mkdir -p $out/bin 72 - makeWrapper ${patchelfUnstable}/bin/patchelf $out/bin/patchelf --append-flags "--no-clobber-old-sections" 73 - ''; 74 - }; 75 in 76 77 stdenv.mkDerivation { ··· 79 80 src = fetchurl { inherit (source) url sha256; }; 81 82 - nativeBuildInputs = [ wrapGAppsHook autoPatchelfHook wrappedPatchelf ]; 83 buildInputs = [ 84 gtk3 85 adwaita-icon-theme ··· 95 appendRunpaths = [ 96 "${pipewire.lib}/lib" 97 ]; 98 99 installPhase = 100 ''
··· 20 , runtimeShell 21 , systemLocale ? config.i18n.defaultLocale or "en_US" 22 , patchelfUnstable # have to use patchelfUnstable to support --no-clobber-old-sections 23 }: 24 25 let ··· 57 source = lib.findFirst (sourceMatches mozLocale) defaultSource sources; 58 59 pname = "firefox-${channel}-bin-unwrapped"; 60 in 61 62 stdenv.mkDerivation { ··· 64 65 src = fetchurl { inherit (source) url sha256; }; 66 67 + nativeBuildInputs = [ wrapGAppsHook autoPatchelfHook patchelfUnstable ]; 68 buildInputs = [ 69 gtk3 70 adwaita-icon-theme ··· 80 appendRunpaths = [ 81 "${pipewire.lib}/lib" 82 ]; 83 + # Firefox uses "relrhack" to manually process relocations from a fixed offset 84 + patchelfFlags = [ "--no-clobber-old-sections" ]; 85 86 installPhase = 87 ''
+14 -6
pkgs/build-support/setup-hooks/auto-patchelf.py
··· 174 found: bool = False # Whether it was found somewhere 175 176 177 - def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = []) -> list[Dependency]: 178 try: 179 with open_elf(path) as elf: 180 ··· 213 if file_is_dynamic_executable: 214 print("setting interpreter of", path) 215 subprocess.run( 216 - ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()], 217 check=True) 218 rpath += runtime_deps 219 ··· 250 if rpath: 251 print("setting RPATH to:", rpath_str) 252 subprocess.run( 253 - ["patchelf", "--set-rpath", rpath_str, path.as_posix()], 254 check=True) 255 256 return dependencies ··· 262 runtime_deps: List[Path], 263 recursive: bool = True, 264 ignore_missing: List[str] = [], 265 - append_rpaths: List[Path] = []) -> None: 266 267 if not paths_to_patch: 268 sys.exit("No paths to patch, stopping.") ··· 275 dependencies = [] 276 for path in chain.from_iterable(glob(p, '*', recursive) for p in paths_to_patch): 277 if not path.is_symlink() and path.is_file(): 278 - dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths) 279 280 missing = [dep for dep in dependencies if not dep.found] 281 ··· 333 type=Path, 334 help="Paths to append to all runtime paths unconditionally", 335 ) 336 337 print("automatically fixing dependencies for ELF files") 338 args = parser.parse_args() ··· 344 args.runtime_dependencies, 345 args.recursive, 346 args.ignore_missing, 347 - append_rpaths=args.append_rpaths) 348 349 350 interpreter_path: Path = None # type: ignore
··· 174 found: bool = False # Whether it was found somewhere 175 176 177 + def auto_patchelf_file(path: Path, runtime_deps: list[Path], append_rpaths: List[Path] = [], extra_args: List[str] = []) -> list[Dependency]: 178 try: 179 with open_elf(path) as elf: 180 ··· 213 if file_is_dynamic_executable: 214 print("setting interpreter of", path) 215 subprocess.run( 216 + ["patchelf", "--set-interpreter", interpreter_path.as_posix(), path.as_posix()] + extra_args, 217 check=True) 218 rpath += runtime_deps 219 ··· 250 if rpath: 251 print("setting RPATH to:", rpath_str) 252 subprocess.run( 253 + ["patchelf", "--set-rpath", rpath_str, path.as_posix()] + extra_args, 254 check=True) 255 256 return dependencies ··· 262 runtime_deps: List[Path], 263 recursive: bool = True, 264 ignore_missing: List[str] = [], 265 + append_rpaths: List[Path] = [], 266 + extra_args: List[str] = []) -> None: 267 268 if not paths_to_patch: 269 sys.exit("No paths to patch, stopping.") ··· 276 dependencies = [] 277 for path in chain.from_iterable(glob(p, '*', recursive) for p in paths_to_patch): 278 if not path.is_symlink() and path.is_file(): 279 + dependencies += auto_patchelf_file(path, runtime_deps, append_rpaths, extra_args) 280 281 missing = [dep for dep in dependencies if not dep.found] 282 ··· 334 type=Path, 335 help="Paths to append to all runtime paths unconditionally", 336 ) 337 + parser.add_argument( 338 + "--extra-args", 339 + nargs="*", 340 + type=str, 341 + help="Extra arguments to pass to patchelf" 342 + ) 343 344 print("automatically fixing dependencies for ELF files") 345 args = parser.parse_args() ··· 351 args.runtime_dependencies, 352 args.recursive, 353 args.ignore_missing, 354 + append_rpaths=args.append_rpaths, 355 + extra_args=args.extra_args) 356 357 358 interpreter_path: Path = None # type: ignore
+3 -1
pkgs/build-support/setup-hooks/auto-patchelf.sh
··· 63 64 local appendRunpathsArray=($appendRunpaths) 65 local runtimeDependenciesArray=($runtimeDependencies) 66 @pythonInterpreter@ @autoPatchelfScript@ \ 67 ${norecurse:+--no-recurse} \ 68 --ignore-missing "${ignoreMissingDepsArray[@]}" \ ··· 70 --libs "${autoPatchelfLibs[@]}" \ 71 "${extraAutoPatchelfLibs[@]}" \ 72 --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \ 73 - --append-rpaths "${appendRunpathsArray[@]}" 74 } 75 76 # XXX: This should ultimately use fixupOutputHooks but we currently don't have
··· 63 64 local appendRunpathsArray=($appendRunpaths) 65 local runtimeDependenciesArray=($runtimeDependencies) 66 + local patchelfFlagsArray=($patchelfFlags) 67 @pythonInterpreter@ @autoPatchelfScript@ \ 68 ${norecurse:+--no-recurse} \ 69 --ignore-missing "${ignoreMissingDepsArray[@]}" \ ··· 71 --libs "${autoPatchelfLibs[@]}" \ 72 "${extraAutoPatchelfLibs[@]}" \ 73 --runtime-dependencies "${runtimeDependenciesArray[@]/%//lib}" \ 74 + --append-rpaths "${appendRunpathsArray[@]}" \ 75 + --extra-args "${patchelfFlagsArray[@]}" 76 } 77 78 # XXX: This should ultimately use fixupOutputHooks but we currently don't have