Skip to content

Commit a4d5a7d

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 #22125
1 parent 1b24aa4 commit a4d5a7d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/ExtUtils/t/Embed.t

+15-2
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}) {
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.

0 commit comments

Comments
 (0)