Skip to content

Commit 191f890

Browse files
committed
(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.
1 parent 86c170d commit 191f890

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

Makefile.SH

+32-2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ true)
6767
-compatibility_version \
6868
${api_revision}.${api_version}.${api_subversion} \
6969
-current_version \
70-
${revision}.${patchlevel}.${subversion} \
71-
-install_name \$(shrpdir)/\$@"
70+
${revision}.${patchlevel}.${subversion}"
71+
case "$osvers" in
72+
1[5-9]*|[2-9]*)
73+
shrpldflags="$shrpldflags -install_name `pwd`/\$@ -Xlinker -headerpad_max_install_names"
74+
exeldflags="-Xlinker -headerpad_max_install_names"
75+
;;
76+
*)
77+
shrpldflags="$shrpldflags -install_name \$(shrpdir)/\$@"
78+
;;
79+
esac
7280
;;
7381
cygwin*)
7482
shrpldflags="$shrpldflags -Wl,--out-implib=libperl.dll.a -Wl,--image-base,0x52000000"
@@ -339,6 +347,14 @@ MANIFEST_SRT = MANIFEST.srt
339347
340348
!GROK!THIS!
341349

350+
case "$useshrplib$osname" in
351+
truedarwin)
352+
$spitshell >>$Makefile <<!GROK!THIS!
353+
PERL_EXE_LDFLAGS=$exeldflags
354+
!GROK!THIS!
355+
;;
356+
esac
357+
342358
case "$usecrosscompile$perl" in
343359
define?*)
344360
$spitshell >>$Makefile <<!GROK!THIS!
@@ -1050,6 +1066,20 @@ $(PERL_EXE): $& $(perlmain_dep) $(LIBPERL) $(static_ext) ext.libs $(PERLEXPORT)
10501066
$(SHRPENV) $(CC) -o perl $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(LLIBPERL) $(static_ext) `cat ext.libs` $(libs)
10511067
!NO!SUBS!
10521068
;;
1069+
1070+
darwin)
1071+
case "$useshrplib$osvers" in
1072+
true1[5-9]*|true[2-9]*) $spitshell >>$Makefile <<'!NO!SUBS!'
1073+
$(SHRPENV) $(CC) -o perl $(PERL_EXE_LDFLAGS) $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
1074+
!NO!SUBS!
1075+
;;
1076+
*) $spitshell >>$Makefile <<'!NO!SUBS!'
1077+
$(SHRPENV) $(CC) -o perl $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
1078+
!NO!SUBS!
1079+
;;
1080+
esac
1081+
;;
1082+
10531083
*) $spitshell >>$Makefile <<'!NO!SUBS!'
10541084
$(SHRPENV) $(CC) -o perl $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
10551085
!NO!SUBS!

installperl

+25
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ elsif ($^O ne 'dos') {
304304
safe_unlink("$installbin/$perl_verbase$ver$exe_ext");
305305
copy("perl$exe_ext", "$installbin/$perl_verbase$ver$exe_ext");
306306
strip("$installbin/$perl_verbase$ver$exe_ext");
307+
fix_dep_names("$installbin/$perl_verbase$ver$exe_ext");
307308
chmod(0755, "$installbin/$perl_verbase$ver$exe_ext");
308309
}
309310
else {
@@ -388,6 +389,7 @@ foreach my $file (@corefiles) {
388389
if (copy_if_diff($file,"$installarchlib/CORE/$file")) {
389390
if ($file =~ /\.(\Q$so\E|\Q$dlext\E)$/) {
390391
strip("-S", "$installarchlib/CORE/$file") if $^O eq 'darwin';
392+
fix_dep_names("$installarchlib/CORE/$file");
391393
chmod($SO_MODE, "$installarchlib/CORE/$file");
392394
} else {
393395
chmod($NON_SO_MODE, "$installarchlib/CORE/$file");
@@ -791,4 +793,27 @@ sub strip
791793
}
792794
}
793795

796+
sub fix_dep_names {
797+
my $file = shift;
798+
799+
$^O eq "darwin" && $Config{osvers} =~ /^(1[5-9]|[2-9])/
800+
&& $Config{useshrplib}
801+
or return;
802+
803+
my @opts;
804+
my $so = $Config{so};
805+
my $libperl = "$Config{archlibexp}/CORE/libperl.$Config{so}";
806+
if ($file =~ /\blibperl.\Q$Config{so}\E$/a) {
807+
push @opts, -id => $libperl;
808+
}
809+
else {
810+
push @opts, -change => getcwd . "/libperl.$so", $libperl;
811+
}
812+
push @opts, $file;
813+
814+
$opts{verbose} and print " install_name_tool @opts\n";
815+
system "install_name_tool", @opts
816+
and die "Cannot update $file dependency paths\n";
817+
}
818+
794819
# ex: set ts=8 sts=4 sw=4 et:

0 commit comments

Comments
 (0)