Skip to content

Commit b509fed

Browse files
committed
openbsd: ensure we link to the built libperl.a, not the system libperl.a
When building with gcc, lib/ExtUtils/t/Embed.t would link against the system libperl.a rather than the newly built libperl.a. Due to the limited API used by the sample code this typically didn't crash, but some configuration changes could result in a crash or a link error. For OpenBSD, change the link options to more closely match those used when building the perl executable, which results in linking against the correct library. Fixes Perl#22125
1 parent 2dd57b9 commit b509fed

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

lib/ExtUtils/t/Embed.t

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,26 @@ if ($^O eq 'VMS') {
103103
elsif ($^O eq 'os390' && $Config{usedl}) {
104104
push(@cmd,"-L$lib", ldopts());
105105
} else { # Not MSWin32 or OS/390 (z/OS) dynamic.
106-
push(@cmd,"-L$lib",'-lperl');
106+
my $ldopts = ldopts();
107+
if ($^O eq 'openbsd' && $Config{useshrplib} eq "false") {
108+
# see github #22125
109+
# with OpenBSD, the packaged gcc (tries to) link
110+
# against the system libperl, this will be fine once
111+
# this perl gets installed, but that's not so good when
112+
# testing against the uninstalled perl.
113+
# This also matches how Makefile.SH links the perl executable
114+
push @cmd, "$lib/libperl.a";
115+
$ldopts =~ s/ -lperl\b//;
116+
}
117+
else {
118+
push(@cmd,"-L$lib",'-lperl');
119+
}
107120
local $SIG{__WARN__} = sub {
108121
warn $_[0] unless $_[0] =~ /No library found for .*perl/
109122
};
110123
push(@cmd, '-Zlinker', '/PM:VIO') # Otherwise puts a warning to STDOUT!
111124
if $^O eq 'os2' and $Config{ldflags} =~ /(?<!\S)-Zomf\b/;
112-
push(@cmd,ldopts());
125+
push(@cmd, $ldopts);
113126
}
114127

115128
if ($^O eq 'aix') { # AIX needs an explicit symbol export list.
@@ -158,7 +171,7 @@ $embed_test = "run/nodebug $exe" if $^O eq 'VMS';
158171
print "# embed_test = $embed_test\n";
159172
$status = system($embed_test);
160173
print (($status? 'not ':'')."ok 10 # system returned $status\n");
161-
#unlink($exe,"embed_test.c",$obj);
174+
unlink($exe,"embed_test.c",$obj);
162175
unlink("$exe.manifest") if $cl and $Config{'ccversion'} =~ /^(\d+)/ and $1 >= 14;
163176
unlink("$exe$Config{exe_ext}") if $skip_exe;
164177
unlink("embed_test.map","embed_test.lis") if $^O eq 'VMS';
@@ -196,7 +209,7 @@ int main(int argc, char **argv, char **env) {
196209
perl_construct(my_perl);
197210
PL_exit_flags |= PERL_EXIT_WARN;
198211
199-
PERL_API_VERSION_CHECK;
212+
PERL_API_VERSION_ASSERT;
200213
201214
my_puts("ok 3");
202215

0 commit comments

Comments
 (0)