GCC 2.95.1 and HP-UX 10.20 and shared libraries
Eric Z. Ayers
ericATcompgen.com
Wed Sep 15 14:10:00 GMT 1999
Hello,
I've been having a frustrating time with compiling a shared library
with GCC 2.7.2.3. I got an error from the linker as follows:
/usr/local/lib/gcc-lib/hppa1.0-hp-hpux10.20/2.7.2.3/ld: Target of unconditional branch is out of range
Reference from: /obj/dcs/dcs/obj/dcs_dportal_filename.o(0x3ff7c)
This is a pretty big source file with a few exported routines at the
top, and a lot of small static subroutines at the bottom. We
looked at the assmebly and saw that it was the bl <xxx> instructions
that were causing the problem as the source file got bigger.
"No problem," I think. "I'll just upgrade to GCC 2.95.1"
When I try to create a shared library, I get an error from the linker:
/usr/ccs/bin/ld: DP relative code in file /var/tmp/cciKnbLv.o - shared library must be position
independent. Use +z or +Z to recompile.
I AM compiling with -fPIC as a command line flag. I configured
gcc-2.95.1 as follows:
../gcc-2.95.1/configure --with-gnu-as hppa1.1-hp-hpux10.20
I had to override the architecture which was originally detected as
hppa1.0-hp-hpux10.20 , but I had some problems compiling.
When I look at the link line, it runs:
$ gcc -v -shared -o /obj/dcs/dcs/lib/libdcs_dp.sl /obj/dcs/dcs/obj/dcs_dportal_dump.o /obj/dcs/dcs/obj/dcs_dportal_api.o /obj/dcs/dcs/obj/dcs_dportal_filename.o /obj/dcs/dcs/obj/dcs_dportal_filename_routines.o /obj/dcs/dcs/obj/dcs_dportal_internal.o /obj/dcs/dcs/obj/dcs_dportal_dupblock.o /obj/dcs/dcs/obj/dcs_dportal_lock.o
Reading specs from /usr/local/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/specs
gcc version 2.95.1 19990816 (release)
/usr/local/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/collect2 -z -b -o /obj/dcs/dcs/lib/libdcs_dp.sl -L/usr/local/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1 -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/lib /obj/dcs/dcs/obj/dcs_dportal_dump.o /obj/dcs/dcs/obj/dcs_dportal_api.o /obj/dcs/dcs/obj/dcs_dportal_filename.o /obj/dcs/dcs/obj/dcs_dportal_filename_routines.o /obj/dcs/dcs/obj/dcs_dportal_internal.o /obj/dcs/dcs/obj/dcs_dportal_dupblock.o /obj/dcs/dcs/obj/dcs_dportal_lock.o -lgcc -lgcc
/usr/ccs/bin/ld: DP relative code in file /var/tmp/ccmaBbdw.o - shared library must be position
independent. Use +z or +Z to recompile.
collect2: ld returned 1 exit status
The wEiRd thing is that if I run this command by itself, I don't get
this problem:
$ /usr/local/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/collect2 -z -b -o /obj/dcs/dcs/lib/libdcs_dp.sl -L/usr/local/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1 -L/usr/ccs/bin -L/usr/ccs/lib -L/usr/local/lib /obj/dcs/dcs/obj/dcs_dportal_dump.o /obj/dcs/dcs/obj/dcs_dportal_api.o /obj/dcs/dcs/obj/dcs_dportal_filename.o /obj/dcs/dcs/obj/dcs_dportal_filename_routines.o /obj/dcs/dcs/obj/dcs_dportal_internal.o /obj/dcs/dcs/obj/dcs_dportal_dupblock.o /obj/dcs/dcs/obj/dcs_dportal_lock.o -lgcc -lgcc
$ echo $?
0
I don't understand what I did wrong here, or why the linker is
complaining. Most frighteningly, I am reading the man page and am
concerned that there is something that will keep the compiler from
working right when working with shared libraries
-mshared-libs
Generate code that can be linked against HP-UX shared libraries.
This option is not fully function yet, and is not on by default
for any PA target. Using this option can cause incorrect code to
be generated by the compiler.
-mno-shared-libs
Don't generate code that will be linked against shared libraries.
This is the default for all PA targets.
But the man page is the only place I see this constraint referenced? Is
gcc-2.95.1 a no-go when compiling software with shared libraries under
HP-UX?
more info:
$ uname -a
HP-UX eel B.10.20 B 9000/871 2008545387 16-user license
/usr/local/lib/gcc-lib/hppa1.1-hp-hpux10.20/2.95.1/specs
*asm:
*asm_final:
*cpp:
%{!mpa-risc-1-0:%{!mnosnake:%{!msoft-float:-D__hp9000s700 -D_PA_RISC1_1}}} %{!a
nsi: -D_HPUX_SOURCE -D_HIUX_SOURCE} %{threads:-D_REENTRANT -D_DCE_THREADS}
*cc1:
%{pg:} %{p:}
*cc1plus:
*endfile:
*link:
%{!mpa-risc-1-0:%{!shared:-L/lib/pa1.1 -L/usr/lib/pa1.1 }} -z %{mlinker-opt:-O}
%{!shared:-u main} %{static:-a archive} %{shared:-b}
*lib:
%{!shared: %{!p: %{!pg: %{!threads:-lc} %{threads:-lcm
a -lc_r}} %{p: -L/lib/libp/ -lc} %{pg: -L/lib/libp/ -lc}}}
*libgcc:
-lgcc
*startfile:
%{!shared:%{pg:gcrt0%O%s}%{!pg:%{p:mcrt0%O%s}%{!p:crt0%O%s}}}
*switches_need_spaces:
*signed_char:
%{funsigned-char:-D__CHAR_UNSIGNED__}
*predefines:
-Dhppa -Dhp9000s800 -D__hp9000s800 -Dhp9k8 -DPWB -Dhpux -Dunix -Asystem(unix) -A
system(hpux) -Acpu(hppa) -Amachine(hppa)
*cross_compile:
0
*version:
2.95.1
*multilib:
. ;
*multilib_defaults:
*multilib_extra:
*multilib_matches:
*linker:
collect2
*link_command:
%{!fsyntax-only: %{!c:%{!M:%{!MM:%{!E:%{!S:%(linker) %l %X %{o*} %{A} %{d} %{e*
} %{m} %{N} %{n} %{r} %{s} %{t} %{u*} %{x} %{z} %{Z}
%{!A:%{!nostdlib:%{!nostartfiles:%S}}} %{static
:} %{L*} %D %o %{!nostdlib:%{!nodefaultlibs:%G %L %G}}
%{!A:%{!nostdlib:%{!nostartfiles:%E}}} %{T*}
}}}}}}
More information about the Gcc-bugs
mailing list