Operating System - HP-UX
1751695 Members
4956 Online
108781 Solutions
New Discussion юеВ

Re: dld.sl: Bad magic number for shared library

 
Arjen Visser
Occasional Advisor

dld.sl: Bad magic number for shared library

I have seen this error on many forums, but I have not been able to fix the issue.
I am trying to compile a Perl module in a 64bit PA-RISC2.0 11.11 HP-UX environment.

The make command is successful:
$ make
gcc -c -I. -D_HPUX_SOURCE -mpa-risc-2-0 -DNO_HASH_SEED -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O -DVERSION=\"2.023\" -DXS_VERSION=\"2.023\" -fPIC "-I/usr/local/perl2exe/perl5/lib/5.10.0/PA-RISC2.0/CORE" -Wall -Wno-comment -DBZ_NO_STDIO -DUSE_PPPORT_H blocksort.c
gcc -c -I. -D_HPUX_SOURCE -mpa-risc-2-0 -DNO_HASH_SEED -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O -DVERSION=\"2.023\" -DXS_VERSION=\"2.023\" -fPIC "-I/usr/local/perl2exe/perl5/lib/5.10.0/PA-RISC2.0/CORE" -Wall -Wno-comment -DBZ_NO_STDIO -DUSE_PPPORT_H huffman.c
gcc -c -I. -D_HPUX_SOURCE -mpa-risc-2-0 -DNO_HASH_SEED -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O -DVERSION=\"2.023\" -DXS_VERSION=\"2.023\" -fPIC "-I/usr/local/perl2exe/perl5/lib/5.10.0/PA-RISC2.0/CORE" -Wall -Wno-comment -DBZ_NO_STDIO -DUSE_PPPORT_H crctable.c
gcc -c -I. -D_HPUX_SOURCE -mpa-risc-2-0 -DNO_HASH_SEED -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O -DVERSION=\"2.023\" -DXS_VERSION=\"2.023\" -fPIC "-I/usr/local/perl2exe/perl5/lib/5.10.0/PA-RISC2.0/CORE" -Wall -Wno-comment -DBZ_NO_STDIO -DUSE_PPPORT_H randtable.c
gcc -c -I. -D_HPUX_SOURCE -mpa-risc-2-0 -DNO_HASH_SEED -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O -DVERSION=\"2.023\" -DXS_VERSION=\"2.023\" -fPIC "-I/usr/local/perl2exe/perl5/lib/5.10.0/PA-RISC2.0/CORE" -Wall -Wno-comment -DBZ_NO_STDIO -DUSE_PPPORT_H compress.c
gcc -c -I. -D_HPUX_SOURCE -mpa-risc-2-0 -DNO_HASH_SEED -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O -DVERSION=\"2.023\" -DXS_VERSION=\"2.023\" -fPIC "-I/usr/local/perl2exe/perl5/lib/5.10.0/PA-RISC2.0/CORE" -Wall -Wno-comment -DBZ_NO_STDIO -DUSE_PPPORT_H decompress.c
gcc -c -I. -D_HPUX_SOURCE -mpa-risc-2-0 -DNO_HASH_SEED -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O -DVERSION=\"2.023\" -DXS_VERSION=\"2.023\" -fPIC "-I/usr/local/perl2exe/perl5/lib/5.10.0/PA-RISC2.0/CORE" -Wall -Wno-comment -DBZ_NO_STDIO -DUSE_PPPORT_H bzlib.c
gcc -c -I. -D_HPUX_SOURCE -mpa-risc-2-0 -DNO_HASH_SEED -DDEBUGGING -fno-strict-aliasing -pipe -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g -O -DVERSION=\"2.023\" -DXS_VERSION=\"2.023\" -fPIC "-I/usr/local/perl2exe/perl5/lib/5.10.0/PA-RISC2.0/CORE" -Wall -Wno-comment -DBZ_NO_STDIO -DUSE_PPPORT_H Bzip2.c
Running Mkbootstrap for Compress::Raw::Bzip2 ()
chmod 644 Bzip2.bs
rm -f blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl
/usr/bin/ld -b blocksort.o huffman.o crctable.o randtable.o compress.o decompress.o bzlib.o Bzip2.o -o blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl \
\

chmod 755 blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl
cp Bzip2.bs blib/arch/auto/Compress/Raw/Bzip2/Bzip2.bs
chmod 644 blib/arch/auto/Compress/Raw/Bzip2/Bzip2.bs
Manifying blib/man3/Compress::Raw::Bzip2.3

The compiled shared libraries are all 64bit, and so is the Perl executable.

But when I run make test, I get the following:
Manifying blib/man3/Compress::Raw::Bzip2.3
$ make test
PERL_DL_NONLAZY=1 /usr/local/perl2exe/perl5/bin/perl "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib/lib', 'blib/arch')" t/*.t
t/000prereq........ok
t/01bzip2........../usr/lib/dld.sl: Bad magic number for shared library: /opt/oracle/orabase/cpan/Compress-Raw-Bzip2-2.023/blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl
/usr/lib/dld.sl: Exec format error
/usr/lib/dld.sl: Bad magic number for shared library: /opt/oracle/orabase/cpan/Compress-Raw-Bzip2-2.023/blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl
/usr/lib/dld.sl: Exec format error

The shared library is 64bit:
$ file /opt/oracle/orabase/cpan/Compress-Raw-Bzip2-2.023/blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl
/opt/oracle/orabase/cpan/Compress-Raw-Bzip2-2.023/blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl: ELF-64 shared object file - PA-RISC 2.0 (LP64)

So as far as I can see the issue is that it calls the 32bit linker /usr/lib/dld.sl. It should be calling the 64bit linker: /usr/lib/pa20_64/dld.sl

The linker is patched to the latest version:
# ld -V
92453-07 linker command s800.sgs ld PA64 B.11.68 REL 090514
ld: 92453-07 linker linker ld B.11.68 090514

My settings:
LD_LIBRARY_PATH=/usr/lib/pa20_6a:/usr/ccs/lib/pa20_644
SHLIB_PATH=/usr/lib/

Anyone has any ideas how to force the 64 bit linker /usr/lib/pa20_64/dld.sl?

Thanks

16 REPLIES 16
Shinji Teragaito_1
Respected Contributor

Re: dld.sl: Bad magic number for shared library

If you want to generate
blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl with ELF-64, it's very
easy to use /usr/local/pa64/bin/gcc which can be installed from
http://hp.com/go/gcc as "HP-GCC 4.4.0-1 PA-RISC LP64".

% which gcc
/usr/local/bin/gcc
% gcc -o hello hello.c -mpa-risc-2-0
% file hello
hello: PA-RISC2.0 shared executable dynamically linked -not stripped
% /usr/local/pa64/bin/gcc -o hello hello.c
% file hello
hello: ELF-64 executable object file - PA-RISC 2.0 (LP64)
%

Hope this helps you !!
Arjen Visser
Occasional Advisor

Re: dld.sl: Bad magic number for shared library

Thank you for your reply. It is already using 64bit gcc:

$ which gcc
/opt/hp-gcc/bin/gcc
$ file /opt/hp-gcc/bin/gcc
/opt/hp-gcc/bin/gcc: ELF-64 executable object file - PA-RISC 2.0 (LP64)
Arjen Visser
Occasional Advisor

Re: dld.sl: Bad magic number for shared library

$ gcc -v
Using built-in specs.
Target: hppa64-hp-hpux11.11
Configured with: /tmp/gcc-4.4.0.tar.gz/gcc-4.4.0/configure --host=hppa64-hp-hpux11.11 --target=hppa64-hp-hpux11.11 --build=hppa64-hp-hpux11.11 --prefix=/opt/hp-gcc64-4.4.0 --with-gnu-as --without-gnu-ld --enable-threads=posix --enable-languages=c,c++ --with-gmp=/proj/opensrc/be/hppa64-hp-hpux11.11 --with-mpfr=/proj/opensrc/be/hppa64-hp-hpux11.11
Thread model: posix
gcc version 4.4.0 (GCC)
Dennis Handly
Acclaimed Contributor

Re: dld.sl: Bad magic number for shared library

>I am trying to compile a Perl module in a 64bit PA-RISC2.0 11.11 HP-UX environment.

Then you have to use HP's gcc compiler to get 64 bit mode. (Or build your own.)

>The compiled shared libraries are all 64bit, and so is the Perl executable.
>the issue is that it calls the 32bit linker /usr/lib/dld.sl. It should be calling the 64bit linker: /usr/lib/pa20_64/dld.sl

If it invokes /usr/lib/dld.sl, it's 32 bit.
(This is the dynamic loader, not linker.)

>LD_LIBRARY_PATH=/usr/lib/pa20_6a:/usr/ccs/lib/pa20_644

You have typos here? And there are no shlibs in /usr/ccs/lib/, so remove that.

>SHLIB_PATH=/usr/lib/

This is the default, so remove this too.

>$ file /opt/hp-gcc/bin/gcc
/opt/hp-gcc/bin/gcc: ELF-64 executable object file - PA-RISC 2.0 (LP64)

This may not be telling us the right thing. You need to run file(1) on a binary produced by the compiler. (HP's compilers can produce both 32 and 64 bit with the same executable.)

>But when I run make test, I get the following:

Is this using the right gcc?
Arjen Visser
Occasional Advisor

Re: dld.sl: Bad magic number for shared library

Thank you for the reply Dennis.

>>LD_LIBRARY_PATH=/usr/lib/pa20_6a:/usr/ccs/lib/pa20_644

>You have typos here? And there are no shlibs in /usr/ccs/lib/, so remove that.

Thanks for pointing this out, I have removed the typo but still get the same result.

> This may not be telling us the right thing. You need to run file(1) on a binary produced by the compiler. (HP's compilers can produce both 32 and 64 bit with the same executable.)

The resulting binary is 64 bit as far as I can tell:
$ file /opt/oracle/orabase/cpan/Compress-Raw-Bzip2-2.023/blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl
/opt/oracle/orabase/cpan/Compress-Raw-Bzip2-2.023/blib/arch/auto/Compress/Raw/Bzip2/Bzip2.sl: ELF-64 shared object file - PA-RISC 2.0 (LP64)

>>But when I run make test, I get the following:

>Is this using the right gcc?
How can I tell if make uses the right gcc.

>Then you have to use HP's gcc compiler to get 64 bit mode. (Or build your own.)
I used the HP gcc compiler from the DSPP HP website.
Dennis Handly
Acclaimed Contributor

Re: dld.sl: Bad magic number for shared library

>but still get the same result.

Naturally since you are still in 32 bit mode.

>The resulting binary is 64 bit as far as I can tell:

Yes, you showed that elsewhere. But my comment was directed at using file(1) on gcc.

>How can I tell if make uses the right gcc?

Do you see the make macro CC defined anywhere?
Typically you can use:
gmake ... CC=/opt/hp-gcc/bin/gcc ...
Arjen Visser
Occasional Advisor

Re: dld.sl: Bad magic number for shared library

Compiled a sample C program to test if the resulting executable:

$ ls
sample.c
$ gcc -Wall -o sample sample.c
$ ./sample
sum = 55
$ file sample
sample: ELF-64 executable object file - PA-RISC 2.0 (LP64)

$ gcc -v
Using built-in specs.
Target: hppa64-hp-hpux11.11
Configured with: /tmp/gcc-4.4.0.tar.gz/gcc-4.4.0/configure --host=hppa64-hp-hpux11.11 --target=hppa64-hp-hpux11.11 --build=hppa64-hp-hpux11.11 --prefix=/opt/hp-gcc64-4.4.0 --with-gnu-as --without-gnu-ld --enable-threads=posix --enable-languages=c,c++ --with-gmp=/proj/opensrc/be/hppa64-hp-hpux11.11 --with-mpfr=/proj/opensrc/be/hppa64-hp-hpux11.11
Thread model: posix
gcc version 4.4.0 (GCC)

I also set CC=/opt/hp-gcc/bin/gcc and ran gmake with CC=/opt/hp-gcc/bin/gcc, but still get the same results.
Arjen Visser
Occasional Advisor

Re: dld.sl: Bad magic number for shared library

This is part of the Makefile:
AR = ar
CC = gcc
CCCDLFLAGS = -fPIC
CCDLFLAGS = -Wl,-E -Wl,-B,deferred
DLEXT = sl
DLsrc=dl_hpux.xs
EXE_EXT =
FULL_AR = /usr/bin/ar
LD = /usr/bin/ld
LDDLFLAGS = -b
LDFLAGS =
LIBC = /lib/libc.sl
LIB_EXT = .a
OBJ_EXT = .o
OSNAME = hpux
OSVERS = 11.11
RANLIB = :
SITELIBEXP = /usr/local/perl2exe/perl5/lib/site_perl/5.10.0
SITEARCHEXP = /usr/local/perl2exe/perl5/lib/site_perl/5.10.0/PA-RISC2.0
SO = sl

Anything there I can try to get this resolved?

Thanks
Dennis Handly
Acclaimed Contributor

Re: dld.sl: Bad magic number for shared library

>Compiled a sample C program to test if the resulting executable:

Now, this is a valid test.

>CC=/opt/hp-gcc/bin/gcc, but still get the same results.

Then you need to do makefile debugging. Try removing every stinkin' "@" at the beginning of lines so you see what's happening.
Also make has -d.

>Anything there I can try to get this resolved?

You need to find out the name of the executable when it aborts.

>so is the Perl executable

Is /usr/local/perl2exe/perl5/bin/perl 64 bit?

If you can't debug your makefiles you need to give up and just use "tusc -fp -ae -o tusc.out make test".