in reply to Re^3: Devel::NYTProf: "undefined symbol: PL_stack_sp" error
in thread Devel::NYTProf: "undefined symbol: PL_stack_sp" error
How do module directories get associated with specific installation locations of perl? When I install a module, I just do the following (as an example):
cd /home/user/perl_modules cpanm -L$PWD Devel::NYTProf
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: Devel::NYTProf: "undefined symbol: PL_stack_sp" error
by afoken (Chancellor) on Aug 28, 2021 at 00:14 UTC | |
How do module directories get associated with specific installation locations of perl? Easy: The library paths are compiled into the perl binary. In case of Linux, most of the library paths are actually in libperl.so, the perl executable is barely more than a stub that contains just enough code to load libperl.so, and the directory where libperl.so can be found:
The CPAN utilities (or, to be more precise: the module build utilties) install into the directories that were choosen when perl was configured. That information is available via Config, and is actually stored in Config_heavy.pl:
The build modules simply load and query Config, simply by using use or require. Config.pm and Config_heavy.pl are created when perl is compiled, and installed into one of the directories compiled into the binaries. Because each perl has its own set of include directories, simply loading Config.pm is sufficient (unless someone has messed with @INC or the data in Config.pm or Config_heavy.pl - see the warning in Config). (All examples from Slackware Linux 14.2 64 bit, using the system perl.) Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] [select] |
by Special_K (Pilgrim) on Aug 31, 2021 at 19:35 UTC | |
It seems I have multiple sources of confusion here. First of all, the Devel::NYTProf module directory contains the following file (referenced in the error message in my OP):
Which appears to be called using this line in /user/perl_modules/lib/perl5/x86_64-linux/Devel/NYTProf/Core.pm:
Based on a cursory search this appears to be a way to include a library of separate C/C++ functions and access them from within perl. Is that correct? If so, then that probably explains why I've never run into this error until now - other modules I've installed and referenced from /user/perl_modules/lib/perl5 didn't have dynamic libraries.
whereas "ldd /tool/bin/perl" returns the following:
Note that neither perl installation has /user/perl_modules/lib/perl5/x86_64-linux/Devel/auto/Devel/NYTProf/ in its list of ldd paths, so how was /tool/bin/perl able to find NYTProf.so but /usr/bin/perl was not?
| [reply] [d/l] [select] |
by afoken (Chancellor) on Aug 31, 2021 at 21:44 UTC | |
Yes, that's the XS mechanism. (See perlxs for far more information than you want to know now.) The actual C library is loaded by DynaLoader or the simplified XSLoader, and that's where the next part is anwered: neither perl installation has /user/perl_modules/lib/perl5/x86_64-linux/Devel/auto/Devel/NYTProf/ in its list of ldd paths, so how was /tool/bin/perl able to find NYTProf.so but /usr/bin/perl was not? Also the ldd paths for a given perl installation are completely separate from the paths contained in @INC when that perl executable is run, correct? In case of Devel::NYTProf, the XS library is searched in @INC, not in the system's library path, because Devel::NYTProf uses XSLoader:
What happens is that perl tries to load Devel::NYTProf from files named Devel/NYTProf.pmc or Devel/NYTProf.pm, in all paths in @INC, stopping at the first found. That's normal behaviour of use/require/do. Devel::NYTProf loads Devel::NYTProf::Core, and perl tries to load it from files named Devel/NYTProf/Core.pmc or Devel/NYTProf/Core.pm. Then Devel::NYTProf::Core calls XSLoader::load("Devel::NYTProf",...). That's a tiny bit more complicated than shown in XSLoader, where load() is just called as XSLoader::load(__PACKAGE__,...). Usually, Devel::NYTProf would directly call XSLoader, but it seems to have grown so far that it needed to be split in two parts. Not really relevant here. What happens is that XSLoader::load() more or less just replaces :: by / in the package name, prefixes auto/, and appends the name of the bootstrap and library files. So it tries to find auto/Devel/NYTProf/NYTProf.bs and auto/Devel/NYTProf/NYTProf.so. It tries to search only where the matching *.pm file was found (which makes sense, because that's where the installation tools will place it), but may revert to searching in @INC. See https://metacpan.org/dist/XSLoader/source/XSLoader.pm. Note that XSLoader actually searches the directory where the calling module was loaded from, not the one for the module name passed as argument. Usually, that's the same file, so it usually makes sense. In case of Devel::NYTProf, it looks a little bit confusing because it uses the directory containing Devel/NYTProf/Core.pm instead of the directory containing Devel/NYTProf.pm to load the XS library for Devel::NYTProf, but again, the installation tools placed all of them below the same directory. So it does not really matter and is right in the common case. You usually don't have two completely different modules A and B, installed below different directories, and have module B load the XS for module A or vice versa. Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] [select] |
Re^5: Devel::NYTProf: "undefined symbol: PL_stack_sp" error
by ikegami (Patriarch) on Aug 28, 2021 at 00:08 UTC | |
It's not so much associated with a specific install location, but the version and settings of a specific build of perl. The perl that was used to install them. (head -n 1 "$( type -p cpanm )" ) Upd: Added missing -p. Seeking work! You can reach me at ikegami@adaelis.com | [reply] [d/l] [select] |
by bliako (Abbot) on Aug 28, 2021 at 05:10 UTC | |
type or which? | [reply] [d/l] [select] |
by eyepopslikeamosquito (Archbishop) on Aug 28, 2021 at 05:44 UTC | |
type or which?See also: Re^3: [OT] 'perl' is not the 'perl' reported by 'which perl' (which vs type References) (updated with extra references including KornShell whence command and POSIX command command [sic]). | [reply] [d/l] [select] |
by bliako (Abbot) on Aug 28, 2021 at 06:01 UTC | |
by eyepopslikeamosquito (Archbishop) on Aug 31, 2021 at 07:41 UTC | |
by ikegami (Patriarch) on Aug 30, 2021 at 22:39 UTC | |
Re^5: Devel::NYTProf: "undefined symbol: PL_stack_sp" error
by swl (Prior) on Aug 27, 2021 at 23:58 UTC | |
This stackoverflow post looks relevant: https://stackoverflow.com/questions/41903944/what-is-the-default-path-for-cpanm-to-install-perl-modules. It links to the cpanm docs at https://metacpan.org/pod/App::cpanminus#Where-does-this-install-modules-to?-Do-I-need-root-access? . | [reply] |