perlapp --bind LD_LIBRARY_PATH not working for use statments module load inside application

Posted by halak on 2016-07-08 04:05
Forums: PDK discussion | OS: Solaris SPARC

In trying to make an application which uses XML::LibXML portable in regards to system shared libs version I installed the XML::LibXML module and built is against my own version of the libxml2 shared library.
here is the test perl snippet (with some pause for user input for troubleshooting) :
-----------------------------------------
print "ENV = \n";
foreach my $key (keys(%ENV)) {

printf("%-s: $ENV{$key}\n", $key);

}
print STDERR "Hit Enter > "; scalar ;

use XML::LibXML;
##use XML::Parser;
print STDERR "Hit Enter > "; scalar ;
---------------------------------------------------
my command to build application:
/opt/perlutils/Perl32/PDK/bin/perlapp --bind libxml2.so.2[file=/opt/perlutils/Perl32/my-libs/lib/libxml2.so.2,extract] --bind libz.so[file=/opt/perlutils/Perl32/my-libs/lib/libz.so,extract] --bind liblzma.so.5[file=/opt/perlutils/Perl32/my-libs/lib/liblzma.so.5,extract] --bind libgcc_s.so.1[file=/opt/perlutils/Perl32/my-libs/lib/libgcc_s.so.1,extract] --perl /opt/perlutils/Perl32/bin/perl --force --tmpdir ./Temp test.pm --exe testbind --info CompanyName="Blah Blah" --info ProductName="testbind" --info InternalName="testcs" --info OriginalFilename="test" --info Language="English" --info FileDescription="testbind" --info Comments="DEV" --info FileVersion="2.0.0" --info ProductVersion="2.0.0"
----------------------------------------------------------------
Here is my env:
SSH_CLIENT=10.0.0.2 36167 22
OLDPWD=/opt/test-perlapp/Temp/pdk-root-3894
SSH_TTY=/dev/pts/1
USER=root
PATH=/usr/sbin:/usr/bin
MAIL=/var/mail//root
PWD=/opt/test-perlapp
LANG=en_US.UTF-8
TZ=US/Eastern
SHLVL=1
HOME=/
LOGNAME=root
SSH_CONNECTION=10.0.0.2 36167 10.0.2.14 22 _=/usr/bin/env
---------
When I execute:
bash-3.2# ./testcscc
Warning: program compiled against libxml 209 using older 206
Warning: XML::LibXML compiled against libxml2 20902, but runtime libxml2 is older 20623 ENV =
USER: root
LD_LIBRARY_PATH: ./Temp/pdk-root-4066/:
TERM: xterm
HOME: /
SSH_TTY: /dev/pts/1
LOGNAME: root
LANG: en_US.UTF-8
PATH: ./Temp/pdk-root-4066/:/opt/test-perlapp:/usr/sbin:/usr/bin
PWD: /opt/test-perlapp
_: ./testcscc
SSH_CONNECTION: 10.0.0.2 36167 10.0.2.14 22
OLDPWD: /opt/test-perlapp/Temp/pdk-root-3894
SSH_CLIENT: 10.0.0.2 36167 22
SHLVL: 1
SHELL: /sbin/sh
MAIL: /var/mail//root
TZ: US/Eastern
Hit Enter > ^Z
---> at the pause I hit ^z so I can now:
[1]+ Stopped ./testbind
---->I set LD_LIBRARY_PATH to ./Temp/pdk-root-4066 (where the libs were extracted by perlapp)
----> and run again:
bash-3.2# export LD_LIBRARY_PATH=./Temp/pdk-root-4066/
bash-3.2# ./testbind
ENV
SSH_TTY: /dev/pts/1
SSH_CLIENT: 10.0.0.2 36167 22
USER: root
SHELL: /sbin/sh
_: ./testcscc
LD_LIBRARY_PATH: ./Temp/pdk-root-4067/:./Temp/pdk-root-4066/
LANG: en_US.UTF-8
LOGNAME: root
PATH: ./Temp/pdk-root-4067/:/opt/test-perlapp:/usr/sbin:/usr/bin
OLDPWD: /opt/test-perlapp/Temp/pdk-root-3894
TZ: US/Eastern
HOME: /
PWD: /opt/test-perlapp
MAIL: /var/mail//root
TERM: xterm
SHLVL: 1
SSH_CONNECTION: 10.0.0.2 36167 10.0.2.14 22 Hit Enter >
----------------------------
It then finds the libxml2.so library.
It seems that perlapp is applying the LD_LIBRARY_PATH too late.

Don

grahams
ActiveState Staff
Fri, 2016-07-08 08:10

The best way to ensure you use a specific version of a library is to compile the Perl module that uses the library with static linking. No other way gives you a 100% certainty that a system library won't be found, and used, first.

If the library you want to use has a license that won't allow static linking, then you're better off not wrapping.

halak | Mon, 2016-07-11 05:16

I appreciate your fast response.

1. Why is LD_LIBRARY_PATH set and then not used until too late. It makes no sense as to why a feature is included and documented flat out does not work as documented.
2. I am unsure about statically linking a .a file to a shared (.so) file. Now
Or are you recomending installing the XML::LibXML (LibXML.so) as a static lib (LibXML.a ?)

we are talking about messing with the CPAN Makefile.PL, etc. If this is a requirement for AS perl, then shouldn't it be the default?

halak | Fri, 2016-07-08 08:46

Thank you for your fast response.

I understand. Bu
Why is it not documented that --bind files or the LD_LIBRARY_PATH are not available until after compile time....
In which case I am not sure I see the usefulness of --bind and LD_LIBRARY_PATH being set at all.

Don

grahams
ActiveState Staff
Tue, 2016-07-12 08:54

http://docs.activestate.com/pdk/7.3/PerlApp.html#perlapp_environment

File binding is mentioned as being available at runtime, not at compile time.

Make sure you understand what the implications of the Environment section are, as they also answer one of your earlier questions. In order to keep the code secure, a wrapped application runs in a controlled environment that can't be accessed, or easily altered. You cannot alter LD_LIBRARY_PATH inside the application. Whatever you change will be locked out by the mechanics of PerlApp.

Also see the -bind documentation:
http://docs.activestate.com/pdk/7.3/PerlApp.html#perlapp_options
http://docs.activestate.com/pdk/7.3/PerlApp.html#perlapp_functions

Notice that there is a difference between what happens with extract_bound_file and get_bound_file, and that the default is get_bound_file.

There is an example for using --bind+extract with the PerlEz.dll (notice that PerlEz is not a module dependency library), but most example code in the docs, and in the sample application, use --bind for additional non-Perl text or data files. It's quite dependable for plain files, but there are still some edge-cases where the way a module has been written will defeat it (such as feeding in files intended to seed or configure some kind of back-end on the fly).

halak | Tue, 2016-07-12 09:31

I absolutely understand not altering LD_LIBRARY_PATH inside the application. But if the binaries are unavailable at compile time, what is the point of --bind . extract.
Also the doc says available at run time. There is no mention of compile time. I was referring of course to Perl compile when modules are loaded, not the perlapp build time.
"extract
The bound file is extracted into the TEMP directory upon application start. It is deleted when the application terminates. The extraction directory is added to the PATH environment variable (as well as to the LD_LIBRARY_PATH variable on Unix). It is also added to the front of @INC"
I see "The bound file is extracted into the TEMP directory upon application start." it is unclear that the implication is after Perl compile time.
Perhaps the documentation could be clearer that this is not useful to ensure application determinism.