https://github.com/Perl/perl5/commit/191f8909fa4eca1db16a91ada42dd4a065c04890.patch From 191f8909fa4eca1db16a91ada42dd4a065c04890 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Thu, 4 Oct 2018 14:41:03 +1000 Subject: [PATCH] (perl #127606) adjust dependency paths on installation on darwin SIP (System Integrity Protection) on OS X prevents the DYLD_LIBRARY_PATH environment variable from being propagated through /bin/sh, causes many tests to fail (and some more recent build issues) for -Duseshrplib builds. To avoid that, we change the way libperl.dylib is linked to perl, so for the initial build the library's id is at the build location rather than the install location, and the generated executable also expects to find libperl in that location. This obviously won't work once we copy both to the installation directory, so we adjust both the id of the library and the dependency path in the executable to point to the new location of the library. A previous attempt set -rpath and used @rpath in the id, but this made the embedding test fail. --- Makefile.SH | 34 ++++++++++++++++++++++++++++++++-- installperl | 25 +++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 2 deletions(-) diff --git Makefile.SH Makefile.SH index 6e4d5ee684f..bebe50dc131 100755 --- Makefile.SH +++ Makefile.SH @@ -67,8 +67,16 @@ true) -compatibility_version \ ${api_revision}.${api_version}.${api_subversion} \ -current_version \ - ${revision}.${patchlevel}.${subversion} \ - -install_name \$(shrpdir)/\$@" + ${revision}.${patchlevel}.${subversion}" + case "$osvers" in + 1[5-9]*|[2-9]*) + shrpldflags="$shrpldflags -install_name `pwd`/\$@ -Xlinker -headerpad_max_install_names" + exeldflags="-Xlinker -headerpad_max_install_names" + ;; + *) + shrpldflags="$shrpldflags -install_name \$(shrpdir)/\$@" + ;; + esac ;; cygwin*) shrpldflags="$shrpldflags -Wl,--out-implib=libperl.dll.a -Wl,--image-base,0x52000000" @@ -333,6 +341,14 @@ MANIFEST_SRT = MANIFEST.srt !GROK!THIS! +case "$useshrplib$osname" in +truedarwin) + $spitshell >>$Makefile <>$Makefile <>$Makefile <<'!NO!SUBS!' + $(SHRPENV) $(CC) -o perl $(PERL_EXE_LDFLAGS) $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs) +!NO!SUBS! + ;; + *) $spitshell >>$Makefile <<'!NO!SUBS!' + $(SHRPENV) $(CC) -o perl $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs) +!NO!SUBS! + ;; + esac + ;; + *) $spitshell >>$Makefile <<'!NO!SUBS!' $(SHRPENV) $(CC) -o perl $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs) !NO!SUBS! diff --git installperl installperl index 3bf79d2d6fc..6cd65a09238 100755 --- installperl +++ installperl @@ -304,6 +304,7 @@ elsif ($^O ne 'dos') { safe_unlink("$installbin/$perl_verbase$ver$exe_ext"); copy("perl$exe_ext", "$installbin/$perl_verbase$ver$exe_ext"); strip("$installbin/$perl_verbase$ver$exe_ext"); + fix_dep_names("$installbin/$perl_verbase$ver$exe_ext"); chmod(0755, "$installbin/$perl_verbase$ver$exe_ext"); } else { @@ -388,6 +389,7 @@ foreach my $file (@corefiles) { if (copy_if_diff($file,"$installarchlib/CORE/$file")) { if ($file =~ /\.(\Q$so\E|\Q$dlext\E)$/) { strip("-S", "$installarchlib/CORE/$file") if $^O eq 'darwin'; + fix_dep_names("$installarchlib/CORE/$file"); chmod($SO_MODE, "$installarchlib/CORE/$file"); } else { chmod($NON_SO_MODE, "$installarchlib/CORE/$file"); @@ -834,4 +836,27 @@ sub strip } } +sub fix_dep_names { + my $file = shift; + + $^O eq "darwin" && $Config{osvers} =~ /^(1[5-9]|[2-9])/ + && $Config{useshrplib} + or return; + + my @opts; + my $so = $Config{so}; + my $libperl = "$Config{archlibexp}/CORE/libperl.$Config{so}"; + if ($file =~ /\blibperl.\Q$Config{so}\E$/a) { + push @opts, -id => $libperl; + } + else { + push @opts, -change => getcwd . "/libperl.$so", $libperl; + } + push @opts, $file; + + $opts{verbose} and print " install_name_tool @opts\n"; + system "install_name_tool", @opts + and die "Cannot update $file dependency paths\n"; +} + # ex: set ts=8 sts=4 sw=4 et: