Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
(perl #127606) adjust dependency paths on installation on darwin
Browse files Browse the repository at this point in the history
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.

(cherry picked from commit 191f890)

cperl: keep dsymutil logic, needs testing.
  • Loading branch information
tonycoz authored and rurban committed Apr 13, 2019
1 parent a9800c9 commit 2d73f16
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
42 changes: 34 additions & 8 deletions Makefile.SH
Expand Up @@ -71,8 +71,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*)
pkg=$package
Expand Down Expand Up @@ -356,6 +364,14 @@ MANIFEST_SRT = MANIFEST.srt
!GROK!THIS!

case "$useshrplib$osname" in
truedarwin)
$spitshell >>$Makefile <<!GROK!THIS!
PERL_EXE_LDFLAGS=$exeldflags
!GROK!THIS!
;;
esac

case "$usecrosscompile$perl" in
define?*)
$spitshell >>$Makefile <<!GROK!THIS!
Expand Down Expand Up @@ -1124,16 +1140,26 @@ $(PERL_EXE): $& $(perlmain_dep) $(LIBPERL) $(static_ext) ext.libs $(PERLEXPORT)
$(SHRPENV) $(LD) -o perl $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(LLIBPERL) $(static_ext) `cat ext.libs` $(libs)
!NO!SUBS!
;;
darwin) $spitshell >>$Makefile <<'!NO!SUBS!'

darwin)
case "$useshrplib$osvers" in
true1[5-9]*|true[2-9]*) $spitshell >>$Makefile <<'!NO!SUBS!'
$(SHRPENV) $(LD) -o perl $(PERL_EXE_LDFLAGS) $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
!NO!SUBS!
;;
*) $spitshell >>$Makefile <<'!NO!SUBS!'
$(SHRPENV) $(LD) -o perl $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
!NO!SUBS!
case "$ccflags" in
*-DDEBUGGING*) $spitshell >>$Makefile <<'!NO!SUBS!'
;;
esac
case "$ccflags" in
*-DDEBUGGING*) $spitshell >>$Makefile <<'!NO!SUBS!'
dsymutil $@
!NO!SUBS!
;;
esac
;;
;;
esac
;;

*) $spitshell >>$Makefile <<'!NO!SUBS!'
$(SHRPENV) $(LD) -o perl $(CLDFLAGS) $(CCDLFLAGS) $(perlmain_objs) $(static_ext) $(LLIBPERL) `cat ext.libs` $(libs)
!NO!SUBS!
Expand Down
25 changes: 25 additions & 0 deletions installperl
Expand Up @@ -342,6 +342,7 @@ elsif ($^O ne 'dos') {
chmod(0755, $exe);
copy($exe, "$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 {
Expand Down Expand Up @@ -426,6 +427,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' and !$debug;
fix_dep_names("$installarchlib/CORE/$file");
chmod($SO_MODE, "$installarchlib/CORE/$file");
} else {
strip("$installarchlib/CORE/$file");
Expand Down Expand Up @@ -852,4 +854,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:

0 comments on commit 2d73f16

Please sign in to comment.