Perl-5.28 und OpenSSL

Projektleiter: Mijzelf

Eine Art FFP 2.0 mit neuen Möglichkeiten und besserem Paket-Managment.

Detaillierte Beschreibung im ersten Thread.
GerhardJ
Beiträge: 7
Registriert: So 29. Sep 2019, 08:57

Perl-5.28 und OpenSSL

Beitrag von GerhardJ »

Hallo zusammen,

ich habe auf meine NAS.5.40 (Linux NAS540 3.2.54 #1 SMP Tue May 22 01:36:44 CST 2018 armv7l GNU/Linux) seit langer Zeit entware-ng und "FHEM" am Laufen. FHEM basiert auf Perl und verlangt nach jedem Perl Update, dass ich verschiedene Module compilieren muss. Hat bisher sehr gut funktioniert:

Beschreibung: https://github.com/Entware-ng/Entware-n ... ilation%29
wget -qO- http://pkg.entware.net/binaries/armv7/i ... ude.tar.gz | tar xvz -C /opt/include
source /opt/bin/gcc_env.sh
perl -MCPAN -e shell

Nach dem letzten Update habe ich allerdings Probleme beim Perl-Modul "Net::SSLeay". Dieses benötigt libssl. Diese lib ist seit dem letzten Update in unterschiedlicher Variante vorhanden:
/opt/lib/libssl.so.1.1
und
/usr/lib/libssl.so
/usr/lib/libssl.so.1.0.0

Beim Compilieren sehe ich, dass via -L/usr und -L/usr/lib die libssl.o von /usr genommen wird. Was wohl falsch ist.

Compiler Output:

Code: Alles auswählen

arm-openwrt-linux-gnueabi-gcc -c   -D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=soft -I/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/include -I/media/ware3/Entware.2019.05/staging_dir/toolchain-arm_cortex-a9_gcc-7.4.0_glibc-2.23_eabi/include -O2   -DVERSION=\"1.88\" -DXS_VERSION=\"1.88\" -fPIC "-I/opt/lib/perl5/5.28/CORE"   SSLeay.c

rm -f blib/arch/auto/Net/SSLeay/SSLeay.so
LD_RUN_PATH="/usr/lib" arm-openwrt-linux-gnueabi-gcc  -shared -L/usr -L/usr/lib -L/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/lib  SSLeay.o  -o blib/arch/auto/Net/SSLeay/SSLeay.so  \
   -L/usr -L/usr/lib -lssl -lcrypto -lz   \
  
chmod 755 blib/arch/auto/Net/SSLeay/SSLeay.so
  CHRISN/Net-SSLeay-1.88.tar.gz
  /opt/bin/make -- OK
Soweit so gut. Die Tests gehen dann in die Hose:

Code: Alles auswählen

#     Error:  Can't load '/i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-10/blib/arch/auto/Net/SSLeay/SSLeay.so' for module Net::SSLeay: libssl.so.1.0.0: cannot open shared object file: No such file or directory at /opt/lib/perl5/5.28/DynaLoader.pm line 159.
Ich gehe mal davon aus, dass eigentlich die libssl aus "/opt/lib" korrekt wäre.

Also geforscht und folgendes gefunden:

Code: Alles auswählen

OPENSSL_PREFIX=/opt perl -MCPAN -e shell

Code: Alles auswählen

arm-openwrt-linux-gnueabi-gcc -c  -I"/opt/include" -D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=soft -I/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/include -I/media/ware3/Entware.2019.05/staging_dir/toolchain-arm_cortex-a9_gcc-7.4.0_glibc-2.23_eabi/include -O2   -DVERSION=\"1.88\" -DXS_VERSION=\"1.88\" -fPIC "-I/opt/lib/perl5/5.28/CORE"   SSLeay.c
rm -f blib/arch/auto/Net/SSLeay/SSLeay.so
LD_RUN_PATH="/opt/lib" arm-openwrt-linux-gnueabi-gcc  -shared -L/opt -L/opt/lib -L/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/lib  SSLeay.o  -o blib/arch/auto/Net/SSLeay/SSLeay.so  \
   -L/opt -L/opt/lib -lssl -lcrypto -lz   \
  
chmod 755 blib/arch/auto/Net/SSLeay/SSLeay.so
  CHRISN/Net-SSLeay-1.88.tar.gz
  /opt/bin/make -- OK
Das sieht ja mal gut aus: -L/opt -L/opt/usr ...
*ABER*:

Code: Alles auswählen

PERL_DL_NONLAZY=1 "/opt/bin/perl5.28.1" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/local/*.t t/handle/local/*.t
t/handle/local/05_use.t ................ 1/1 
#   Failed test 'use Net::SSLeay::Handle;'
#   at t/handle/local/05_use.t line 8.
#     Tried to use 'Net::SSLeay::Handle'.
#     Error:  Can't load '/i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-16/blib/arch/auto/Net/SSLeay/SSLeay.so' for module Net::SSLeay: libssl.so.1.0.0: cannot open shared object file: No such file or directory at /opt/lib/perl5/5.28/DynaLoader.pm line 159.
Warum um alles in der Welt wird versucht libssl.so.1.0.0 zu verwenden?

Folgender Aufruf - wäre wahrscheinlich korrekt - führt zu einem weiteren Problem:

Code: Alles auswählen

LD_LIBRARY_PATH=/opt/lib LD_RUN_PATH=/opt/lib OPENSSL_PREFIX=/opt perl -MCPAN -e shell

/bin/pwd: error while loading shared libraries: /opt/lib/libm.so.6: internal error
Irgendwelche Ideen?

Könnte ich evtl. ein Downgrade zu Perl-5.26 machen?

Danke und Grüße
Gerhard
Zuletzt geändert von GerhardJ am Do 3. Okt 2019, 13:50, insgesamt 1-mal geändert.

Mijzelf
Beiträge: 113
Registriert: Mi 14. Nov 2018, 19:50

Re: Perl-5.28 und OpenSSL

Beitrag von Mijzelf »

I think the compiler/linker by default doesn't address the /opt prefix. If you run

Code: Alles auswählen

ldd /i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-10/blib/arch/auto/Net/SSLeay/SSLeay.so
it will show you a 'not found' for libssl.so.1.0.0, because is searches in /lib and /usr/lib.
That seems strange, as at link time the library was findable, but not at runtime.

The output for the original linking is

Code: Alles auswählen

LD_RUN_PATH="/usr/lib" arm-openwrt-linux-gnueabi-gcc  -shared -L/usr -L/usr/lib -L/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/lib  SSLeay.o  -o blib/arch/auto/Net/SSLeay/SSLeay.so  \
   -L/usr -L/usr/lib -lssl -lcrypto -lz   \
but I think that should be

Code: Alles auswählen

LD_RUN_PATH="/opt/lib" arm-openwrt-linux-gnueabi-gcc  -shared -L/opt/lib -L/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/lib  SSLeay.o  -o blib/arch/auto/Net/SSLeay/SSLeay.so  \
   -L/opt/lib -lssl -lcrypto -lz   \
to get a valid 'Entware perl' library. Of course /opt/lib/libssl, /opt/lib/libcrypto and /opt/lib/libz should be present. An Entware compatible library should stay inside /opt.

LD_LIBRARY_PATH should be able to solve this, but unfortunately somewhere pwd is called, which is forced to use the wrong library. If /opt/bin/pwd had been used, this would have been no problem.

GerhardJ
Beiträge: 7
Registriert: So 29. Sep 2019, 08:57

Re: Perl-5.28 und OpenSSL

Beitrag von GerhardJ »

Thanks for your thoughts. /bin/pwd is a statically linked binary (in fact a symbolic link to /bin/busybox).
For completion:

Code: Alles auswählen

arm-openwrt-linux-gnueabi-gcc -c  -I"/opt/include" -D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2 -pipe -march=armv7-a -mtune=cortex-a9 -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -mfloat-abi=soft -I/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/include -I/media/ware3/Entware.2019.05/staging_dir/toolchain-arm_cortex-a9_gcc-7.4.0_glibc-2.23_eabi/include -O2   -DVERSION=\"1.88\" -DXS_VERSION=\"1.88\" -fPIC "-I/opt/lib/perl5/5.28/CORE"   SSLeay.c
rm -f blib/arch/auto/Net/SSLeay/SSLeay.so
LD_RUN_PATH="/opt/lib" arm-openwrt-linux-gnueabi-gcc  -shared -L/opt -L/opt/lib -L/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/lib  SSLeay.o  -o blib/arch/auto/Net/SSLeay/SSLeay.so  \
   -L/opt -L/opt/lib -lssl -lcrypto -lz   \
  
chmod 755 blib/arch/auto/Net/SSLeay/SSLeay.so
  CHRISN/Net-SSLeay-1.88.tar.gz
The above leads indeed to a SSLeay.so like below:

Code: Alles auswählen

ldd /i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-0/blib/arch/auto/Net/SSLeay/SSLeay.so 
        libssl.so.1.0.0 => not found
        libcrypto.so.1.0.0 => not found
        libz.so.1 => /opt/lib/libz.so.1 (0x2abc6000)
        libgcc_s.so.1 => /opt/lib/libgcc_s.so.1 (0x2abe9000)
        libc.so.6 => /opt/lib/libc.so.6 (0x2ac93000)
        /opt/lib/ld-linux.so.3 (0x2ab2f000)
And yes: libssl.so and libcrypto.so are available in /opt/lib. I don't understand, why the linker (see above) obviously uses the correct path for these libraries, but the result is crap :(

Regarding the segmentation fault in libm: Could it be that my installation is crap? The entware repository says that libc-2.27 is the latest one. Here I have 2.23 and opkg does not provide further updates..

GerhardJ
Beiträge: 7
Registriert: So 29. Sep 2019, 08:57

Re: Perl-5.28 und OpenSSL

Beitrag von GerhardJ »

Some more stuff:
As soon, as I set LD_LIBRARY_PATH=/opt/lib, the busybox tools fail with:

Code: Alles auswählen

grep: error while loading shared libraries: /opt/lib/libm.so.6: internal error
I checked the ldconfig cache and see:
libm.so.6 (libc6,soft-float, OS ABI: Linux 2.6.32) => /opt/lib/libm.so.6

Could that be an issue? The kernel running is 3.2.54.

Another statically linker binary on that box is python. When calling that one with LD_LIBRARY_PATH set,
I get:

Code: Alles auswählen

python: error while loading shared libraries: /opt/lib/libpthread.so.0: internal error
Why that? Which program-loader is involved when starting python in that case? It looks to me as my installation is corrupted and the preinstalled stuff does not work with the entware stuff :(

Mijzelf
Beiträge: 113
Registriert: Mi 14. Nov 2018, 19:50

Re: Perl-5.28 und OpenSSL

Beitrag von Mijzelf »

For completion: The above leads indeed to a SSLeay.so like below:

Code: Alles auswählen

ldd /i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-0/blib/arch/auto/Net/SSLeay/SSLeay.so
        libssl.so.1.0.0 => not found
        libcrypto.so.1.0.0 => not found
        libz.so.1 => /opt/lib/libz.so.1 (0x2abc6000)
        libgcc_s.so.1 => /opt/lib/libgcc_s.so.1 (0x2abe9000)
        libc.so.6 => /opt/lib/libc.so.6 (0x2ac93000)
        /opt/lib/ld-linux.so.3 (0x2ab2f000)
Didn't that version of SSLeay.so work in perl?
Some more stuff:
As soon, as I set LD_LIBRARY_PATH=/opt/lib, the busybox tools fail with:

Code: Alles auswählen

grep: error while loading shared libraries: /opt/lib/libm.so.6: internal error
I checked the ldconfig cache and see:
libm.so.6 (libc6,soft-float, OS ABI: Linux 2.6.32) => /opt/lib/libm.so.6

Could that be an issue? The kernel running is 3.2.54.
That behaviour is not unexpected. Busybox is not statically linked, but is linked against a certain version of libc. As in opensource world it is always possible to compile against the available libraries, the interfaces of the libraries are not rock stable, like the interfaces of -for instance- Windows libraries. And so you shouldn't be surprised when the compiled binary doesn't work well with another version of the same library.
For this reason you can't expect the firmware binaries work well with Entware libraries, and vice versa.
Using LD_LIBRARY_PATH you try to force SSLeay.so to use the libraries in /opt/lib, but because in the same session apparently firmware binaries are called, they are forced too, and that doesn't work.
Linux 2.6.32) => /opt/lib/libm.so.6

Could that be an issue? The kernel running is 3.2.54.
No. The kernel is (almost always) down compatible. The ABI used by the .so is the minimum kernel version. AFAIK all newer kernels are still compatible.

GerhardJ
Beiträge: 7
Registriert: So 29. Sep 2019, 08:57

Re: Perl-5.28 und OpenSSL

Beitrag von GerhardJ »

Hi!
Mijzelf hat geschrieben:The above leads indeed to a SSLeay.so like below:

Code: Alles auswählen

ldd /i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-0/blib/arch/auto/Net/SSLeay/SSLeay.so
        libssl.so.1.0.0 => not found
        libcrypto.so.1.0.0 => not found
        libz.so.1 => /opt/lib/libz.so.1 (0x2abc6000)
        libgcc_s.so.1 => /opt/lib/libgcc_s.so.1 (0x2abe9000)
        libc.so.6 => /opt/lib/libc.so.6 (0x2ac93000)
        /opt/lib/ld-linux.so.3 (0x2ab2f000)
Didn't that version of SSLeay.so work in perl?
Nope - the make install step checks if the new-built library works and in fact leads to this one

Code: Alles auswählen

#   Failed test 'use Net::SSLeay;'
#   at t/local/03_use.t line 8.
#     Tried to use 'Net::SSLeay'.
#     Error:  Can't load '/i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-3/blib/arch/auto/Net/SSLeay/SSLeay.so' for module Net::SSLeay: libssl.so.1.0.0: cannot open shared object file: No such file or directory at /opt/lib/perl5/5.28/DynaLoader.pm line 159.
Seems that in the past that worked by chance as long as the stock libssl and the entware libssl had the same version, which is no longer the case.
Mijzelf hat geschrieben:
Some more stuff:
As soon, as I set LD_LIBRARY_PATH=/opt/lib, the busybox tools fail with:

Code: Alles auswählen

grep: error while loading shared libraries: /opt/lib/libm.so.6: internal error
I checked the ldconfig cache and see:
libm.so.6 (libc6,soft-float, OS ABI: Linux 2.6.32) => /opt/lib/libm.so.6

Could that be an issue? The kernel running is 3.2.54.
That behaviour is not unexpected. Busybox is not statically linked, but is linked against a certain version of libc.
Well - guess you're talking about the entware Busybox - I meant the stock Busybox that resides on the NAS which is definitely statically linked. And this one cannot be launched by /opt/lib/ld-linux.so.3.
Mijzelf hat geschrieben:...
For this reason you can't expect the firmware binaries work well with Entware libraries, and vice versa.
Using LD_LIBRARY_PATH you try to force SSLeay.so to use the libraries in /opt/lib, but because in the same session apparently firmware binaries are called, they are forced too, and that doesn't work.
Okay - that is understood. So let's try it in a different way. I've also installed BusyBox from entware and did the following:

Code: Alles auswählen

usyBox v1.19.4 (2018-05-22 01:23:15 CST) built-in shell (ash)
Enter 'help' for a list of built-in commands.

/i-data/70be7240/root # /opt/bin/bash
bash-5.0# echo $PATH
/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin:/opt/sbin
bash-5.0# export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
bash-5.0# export LD_RUN_PATH=/opt/lib
bash-5.0# export LD_LIBRARY_PATH=/opt/l
lib/        libexec/    lost+found/ 
bash-5.0# export LD_LIBRARY_PATH=/opt/lib
bash-5.0# which pwd
/opt/bin/pwd
bash-5.0# OPENSSL_PREFIX=/opt PERL_READLINE_NOWARN=YES  perl -MCPAN -e shell
/bin/pwd: error while loading shared libraries: /opt/lib/libm.so.6: internal error
/bin/pwd: error while loading shared libraries: /opt/lib/libm.so.6: internal error

cpan shell -- CPAN exploration and modules installation (v2.27)
Enter 'h' for help.
I'm lost!

How can I get an environment (entware) that does not interfere with the original one?

GerhardJ
Beiträge: 7
Registriert: So 29. Sep 2019, 08:57

Re: Perl-5.28 und OpenSSL

Beitrag von GerhardJ »

Okay digged somewhat deeper and found the Perl config file @

Code: Alles auswählen

/i-data/sysvol/root/.cpan/CPAN/MyConfig.pm
This is the source of some issues I saw - means there we see some settings pointing to "/bin/" instead of "/opt/bin".
As I've already build some modules using the wrong setup, I'm going to give it a try and re-install perl-5.28 from scratch within the "/opt" environment...

Did the following now:

Code: Alles auswählen

LD_LIBRARY_PATH=/opt/lib /opt/bin/bash
bash-5.0# export PATH=/opt/bin:/opt/sbin
bash-5.0# export SHELL=/opt/bin/sh
bash-5.0# echo $LD_LIBRARY_PATH
/opt/lib
bash-5.0# ls -l /opt/bin/sh
lrwxrwxrwx    1 root     root            16 Oct  6 15:26 /opt/bin/sh -> /opt/bin/busybox

bash-5.0# OPENSSL_PREFIX=/opt perl -MCPAN -e shell                                                                                                                                                                               
Sorry, we have to rerun the configuration dialog for CPAN.pm due to                                                                                                                                                              
some missing parameters. Configuration will be written to                                                                                                                                                                        
 <</i-data/sysvol/root/.cpan/CPAN/MyConfig.pm>>                                                                                                                                                                                  
                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                 
CPAN.pm requires configuration, but most of it can be done automatically.                                                                                                                                                        
If you answer 'no' below, you will enter an interactive dialog for each                                                                                                                                                          
configuration option instead.                                                                                                                                                                                                    
                                                                                                                                                                                                                                 
Would you like to configure as much as possible automatically? [yes] 
Autoconfiguration complete.

commit: wrote '/i-data/sysvol/root/.cpan/CPAN/MyConfig.pm'

You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.

cpan shell -- CPAN exploration and modules installation (v2.20)
Enter 'h' for help.
cpan[1]> o conf shell
    shell              [/bin/sh]
Type 'o conf' to view all configuration items


cpan[2]> o conf shell /opt/bin/sh
    shell              [/opt/bin/sh]
Please use 'o conf commit' to make the config permanent! 


cpan[3]> o conf commit
commit: wrote '/i-data/sysvol/root/.cpan/CPAN/MyConfig.pm'
Even after doin' all that stuff, perl still uses "/bin/sh" - what a night-mare. Linking /bin/sh to /opt/bin/busybox the does the trick! But...

Code: Alles auswählen

LD_RUN_PATH="/opt/lib" arm-openwrt-linux-gnueabi-gcc  -shared -L/opt -L/opt/lib -L/media/ware3/Entware.2019.05/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/lib  SSLeay.o  -o blib/arch/auto/Net/SSLeay/SSLeay.so  \     
   -L/opt -L/opt/lib -lssl -lcrypto -lz   \                                                                                                                                                                                      
                                                                                                                                                                                                                                 
chmod 755 blib/arch/auto/Net/SSLeay/SSLeay.so                                                                                                                                                                                    
  CHRISN/Net-SSLeay-1.88.tar.gz                                                                                                                                                                                                  
  /opt/bin/make -- OK                                                                                           
Running make test                                                                                                                                                                                                                
"/opt/bin/perl5.28.1" -MExtUtils::Command::MM -e 'cp_nonempty' -- SSLeay.bs blib/arch/auto/Net/SSLeay/SSLeay.bs 644                                                                                                              
PERL_DL_NONLAZY=1 "/opt/bin/perl5.28.1" "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/lib', 'blib/arch')" t/local/*.t t/handle/local/*.t                               
t/handle/local/05_use.t ................ 1/1                                                                                                                                                                                     
#   Failed test 'use Net::SSLeay::Handle;'               
#   at t/handle/local/05_use.t line 8.                                                                                                                                                                                 [389/1974]
#     Tried to use 'Net::SSLeay::Handle'.                                                                                                                                                                                        
#     Error:  Can't load '/i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-0/blib/arch/auto/Net/SSLeay/SSLeay.so' for module Net::SSLeay: libssl.so.1.0.0: cannot open shared object file: No such file or directory at /opt/lib
/perl5/5.28/DynaLoader.pm line 159.
WTF? For now: No further idea :(

Mijzelf
Beiträge: 113
Registriert: Mi 14. Nov 2018, 19:50

Re: Perl-5.28 und OpenSSL

Beitrag von Mijzelf »

Well - guess you're talking about the entware Busybox - I meant the stock Busybox that resides on the NAS which is definitely statically linked.
No, it's not.

Code: Alles auswählen

admin@NAS520:/$ file /bin/busybox 
/bin/busybox: setuid, setgid ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 2.6.32, stripped
admin@NAS520:/$ ldd /bin/busybox 
	libm.so.6 => /lib/libm.so.6 (0x2acea000)
	libc.so.6 => /lib/libc.so.6 (0x2ad64000)
	/lib/ld-linux-armhf.so.3 => /lib/ld-linux.so.3 (0x2ab6c000)
It would be very strange to have a statically linked busybox in a firmware. You use busybox when your storage is limited. A statically linked busybox has a big part of libc embedded, and so it's huge compared to a dynamically linked one. And in most cases you need a seperate libc.so anyway, because other binaries need them. So a statically linked busybox is only logical when it's the only binary, or when it's not part of the firmware. (At busybox.net you can download statically linked versions, just to have a toolbox which is not dependent on any external library).

The firmware uses /lib/ld-linux-armhf.so.3 to load ELF binaries. Entware uses /opt/lib/ld-linux.so.3

Code: Alles auswählen

admin@NAS520:/$ file /opt/bin/readelf 
/opt/bin/readelf: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /opt/lib/ld-linux.so.3, for GNU/Linux 2.6.32, stripped
This lib is responsible for finding the needed libraries, while loading the binary. The firmware one searches in /lib,/usr/lib,/usr/local/lib, (unless overrided by LD_LIBRARY_PATH), and I presume the Entware one searches in /opt/lib.
And so it's strange that an Entware binary (perl), which is loaded by /opt/lib/ld-linux.so.3 can't find the right library for SSLeay.so. Unless perl uses it's own loader, somehow.

You can try to embed the right path in SSLeay.so by providing the full path, instead of -lssl, so /opt/lib/libssl.so.1.0.0 instead of -lssl. (Using -lssl the linker will search the library path for libssl.so, and link that.)

GerhardJ
Beiträge: 7
Registriert: So 29. Sep 2019, 08:57

Re: Perl-5.28 und OpenSSL

Beitrag von GerhardJ »

Hi Mijzelf!

Thanks for sharing your thoughts. I digged on and yes - you ar right, the stock BusyBox is a dynamically linked. The "op" ldd that I have used provided the wrong information - sorry for the noise.

With a fixed Perl configuration (paths to /opt/...), I started to build only the module to get its Makefile and to tweak it a bit:

Code: Alles auswählen

LD_RUN_PATH="/opt/lib" arm-openwrt-linux-gnueabi-gcc  -shared -L/opt -L/opt/lib -L/media/ware/Entware.2019.10/staging_dir/target-arm_cortex-a9_glibc-2.23_eabi/opt/lib  SSLeay.o  -o blib/arch/auto/Net/SSLeay/SSLeay.so  \
   -L/opt -L/opt/lib /opt/lib/libssl.so.1.1  /opt/lib/libcrypto.so.1.1 -lz 
The result looks as expected:

Code: Alles auswählen

root/.cpan/build/Net-SSLeay-1.88-2 # ldd blib/arch/auto/Net/SSLeay/SSLeay.so
        libssl.so.1.1 => /opt/lib/libssl.so.1.1 (0x2accb000)
        libcrypto.so.1.1 => /opt/lib/libcrypto.so.1.1 (0x2ad45000)
        libz.so.1 => /opt/lib/libz.so.1 (0x2aba6000)
        libgcc_s.so.1 => /opt/lib/libgcc_s.so.1 (0x2ab30000)
        libc.so.6 => /opt/lib/libc.so.6 (0x2af4f000)
        /opt/lib/ld-linux.so.3 (0x2ab73000)
        libdl.so.2 => /opt/lib/libdl.so.2 (0x2ac63000)
        libpthread.so.0 => /opt/lib/libpthread.so.0 (0x2ac76000)
BUT, the tests unveils another issue :(

Code: Alles auswählen

#   Failed test 'use Net::SSLeay::Handle;'
#   at t/handle/local/05_use.t line 8.
#     Tried to use 'Net::SSLeay::Handle'.
#     Error:  Can't load '/i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-2/blib/arch/auto/Net/SSLeay/SSLeay.so' for module Net::SSLeay: /i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-2/blib/arch/auto/Net/SSLeay/SSLeay.so: undefined symbol: OpenSSL_add_all_digests at /opt/lib/perl5/5.28/DynaLoader.pm line 159.
It's annoying :(

Mijzelf
Beiträge: 113
Registriert: Mi 14. Nov 2018, 19:50

Re: Perl-5.28 und OpenSSL

Beitrag von Mijzelf »

GerhardJ hat geschrieben:

Code: Alles auswählen

#   Failed test 'use Net::SSLeay::Handle;'
#   at t/handle/local/05_use.t line 8.
#     Tried to use 'Net::SSLeay::Handle'.
#     Error:  Can't load '/i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-2/blib/arch/auto/Net/SSLeay/SSLeay.so' for module Net::SSLeay: /i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-2/blib/arch/auto/Net/SSLeay/SSLeay.so: undefined symbol: OpenSSL_add_all_digests at /opt/lib/perl5/5.28/DynaLoader.pm line 159.
It's annoying :(
Is he right?

Code: Alles auswählen

strings /opt/lib/openssl.so | grep  OpenSSL_add_all_digests
strings /i-data/70be7240/root/.cpan/build/Net-SSLeay-1.88-2/blib/arch/auto/Net/SSLeay/SSLeay.so | grep OpenSSL_add_all_digests
If he is, have a look in your include files, to see if OpenSSL_add_all_digests() can be a macro, under certain circumstances.

Antworten