From fbdb9a76798ae34a7b53f664e77aaaf1f4040f2f Mon Sep 17 00:00:00 2001
From: zhangzikang <zhangzikang@kylinos.cn>
Date: Wed, 20 Mar 2024 17:44:51 +0800
Subject: [PATCH] perl-5.38.0-Link-XS-modules-to-libperl.so-with-EU-MM-on-Linux

---
 MANIFEST                                      |  1 +
 .../lib/ExtUtils/MM_Unix.pm                   |  8 +++++-
 .../lib/ExtUtils/CBuilder/Platform/linux.pm   | 26 +++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletion(-)
 create mode 100644 dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/linux.pm

diff --git a/MANIFEST b/MANIFEST
index 6bc115b..0775b2f 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -3855,6 +3855,7 @@ dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/android.pm	CBuilder method
 dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/cygwin.pm		CBuilder methods for cygwin
 dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/darwin.pm		CBuilder methods for darwin
 dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/dec_osf.pm	CBuilder methods for OSF
+dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/linux.pm		CBuilder methods for Linux
 dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/os2.pm		CBuilder methods for OS/2
 dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/Unix.pm		CBuilder methods for Unix
 dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/VMS.pm		CBuilder methods for VMS
diff --git a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm
index 1761380..4e82dda 100644
--- a/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm
+++ b/cpan/ExtUtils-MakeMaker/lib/ExtUtils/MM_Unix.pm
@@ -32,6 +32,7 @@ BEGIN {
     $Is{IRIX}    = $^O eq 'irix';
     $Is{NetBSD}  = $^O eq 'netbsd';
     $Is{Interix} = $^O eq 'interix';
+    $Is{Linux}   = $^O eq 'linux';
     $Is{SunOS4}  = $^O eq 'sunos';
     $Is{Solaris} = $^O eq 'solaris';
     $Is{SunOS}   = $Is{SunOS4} || $Is{Solaris};
@@ -1074,7 +1075,7 @@ sub xs_make_dynamic_lib {
     push(@m,"	\$(RM_F) \$\@\n");
 
     my $libs = '$(LDLOADLIBS)';
-    if (($Is{NetBSD} || $Is{Interix} || $Is{Android}) && $Config{'useshrplib'} eq 'true') {
+    if (($Is{Linux} || $Is{NetBSD} || $Is{Interix} || $Is{Android}) && $Config{'useshrplib'} eq 'true') {
         # Use nothing on static perl platforms, and to the flags needed
         # to link against the shared libperl library on shared perl
         # platforms.  We peek at lddlflags to see if we need -Wl,-R
@@ -1087,6 +1088,11 @@ sub xs_make_dynamic_lib {
             # The Android linker will not recognize symbols from
             # libperl unless the module explicitly depends on it.
             $libs .= ' "-L$(PERL_INC)" -lperl';
+        } else {
+            if ($ENV{PERL_CORE}) {
+                $libs .= ' "-L$(PERL_INC)"';
+            }
+            $libs .= ' -lperl';
         }
     }
 
diff --git a/dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/linux.pm b/dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/linux.pm
new file mode 100644
index 0000000..582339b
--- /dev/null
+++ b/dist/ExtUtils-CBuilder/lib/ExtUtils/CBuilder/Platform/linux.pm
@@ -0,0 +1,26 @@
+package ExtUtils::CBuilder::Platform::linux;
+
+use strict;
+use ExtUtils::CBuilder::Platform::Unix;
+use File::Spec;
+
+use vars qw($VERSION @ISA);
+$VERSION = '0.280230';
+our @ISA = qw(ExtUtils::CBuilder::Platform::Unix);
+
+sub link {
+  my ($self, %args) = @_;
+  my $cf = $self->{config};
+
+  # Link XS modules to libperl.so explicitly because multiple
+  # dlopen(, RTLD_LOCAL) hides libperl symbols from XS module.
+  local $cf->{lddlflags} = $cf->{lddlflags};
+  if ($ENV{PERL_CORE}) {
+    $cf->{lddlflags} .= ' -L' . $self->perl_inc();
+  }
+  $cf->{lddlflags} .= ' -lperl';
+
+  return $self->SUPER::link(%args);
+}
+
+1;
-- 
2.33.0

