@@ -413,7 +413,7 @@ def download_stage0(self):
413413 lib_dir = "{}/lib" .format (self .bin_root ())
414414 for lib in os .listdir (lib_dir ):
415415 if lib .endswith (".so" ):
416- self .fix_bin_or_dylib ("{}/{}" . format (lib_dir , lib ))
416+ self .fix_bin_or_dylib (os . path . join (lib_dir , lib ), rpath_libz = True )
417417 with output (self .rustc_stamp ()) as rust_stamp :
418418 rust_stamp .write (self .date )
419419
@@ -451,10 +451,15 @@ def download_stage0(self):
451451 "{}/src/bootstrap/download-ci-llvm-stamp" .format (top_level ),
452452 ]).decode (sys .getdefaultencoding ()).strip ()
453453 llvm_assertions = self .get_toml ('assertions' , 'llvm' ) == 'true'
454+ llvm_root = self .llvm_root ()
455+ llvm_lib = os .path .join (llvm_root , "lib" )
454456 if self .program_out_of_date (self .llvm_stamp (), llvm_sha + str (llvm_assertions )):
455457 self ._download_ci_llvm (llvm_sha , llvm_assertions )
456458 for binary in ["llvm-config" , "FileCheck" ]:
457- self .fix_bin_or_dylib ("{}/bin/{}" .format (self .llvm_root (), binary ))
459+ self .fix_bin_or_dylib (os .path .join (llvm_root , "bin" , binary ), rpath_libz = True )
460+ for lib in os .listdir (llvm_lib ):
461+ if lib .endswith (".so" ):
462+ self .fix_bin_or_dylib (os .path .join (llvm_lib , lib ), rpath_libz = True )
458463 with output (self .llvm_stamp ()) as llvm_stamp :
459464 llvm_stamp .write (llvm_sha + str (llvm_assertions ))
460465
@@ -501,7 +506,7 @@ def _download_ci_llvm(self, llvm_sha, llvm_assertions):
501506 match = "rust-dev" ,
502507 verbose = self .verbose )
503508
504- def fix_bin_or_dylib (self , fname ):
509+ def fix_bin_or_dylib (self , fname , rpath_libz = False ):
505510 """Modifies the interpreter section of 'fname' to fix the dynamic linker,
506511 or the RPATH section, to fix the dynamic library search path
507512
@@ -571,20 +576,22 @@ def fix_bin_or_dylib(self, fname):
571576 self .nix_deps_dir = nix_deps_dir
572577
573578 patchelf = "{}/patchelf/bin/patchelf" .format (nix_deps_dir )
579+ patchelf_args = []
574580
575- if fname . endswith ( ".so" ) :
576- # Dynamic library, patch RPATH to point to system dependencies.
581+ if rpath_libz :
582+ # Patch RPATH to add `zlib` dependency that stems from LLVM
577583 dylib_deps = ["zlib" ]
578584 rpath_entries = [
579585 # Relative default, all binary and dynamic libraries we ship
580586 # appear to have this (even when `../lib` is redundant).
581587 "$ORIGIN/../lib" ,
582588 ] + ["{}/{}/lib" .format (nix_deps_dir , dep ) for dep in dylib_deps ]
583- patchelf_args = ["--set-rpath" , ":" .join (rpath_entries )]
584- else :
589+ patchelf_args += ["--set-rpath" , ":" .join (rpath_entries )]
590+ if not fname .endswith (".so" ):
591+ # Finally, set the corret .interp for binaries
585592 bintools_dir = "{}/stdenv.cc.bintools" .format (nix_deps_dir )
586593 with open ("{}/nix-support/dynamic-linker" .format (bintools_dir )) as dynamic_linker :
587- patchelf_args = ["--set-interpreter" , dynamic_linker .read ().rstrip ()]
594+ patchelf_args + = ["--set-interpreter" , dynamic_linker .read ().rstrip ()]
588595
589596 try :
590597 subprocess .check_output ([patchelf ] + patchelf_args + [fname ])
0 commit comments