Article View: gnu.gcc.bug
Article #6268gcc-2.7.2, hpux-10.01: -shared can't build shared libraries
From: Christopher Hylands
Date: Sun, 31 Dec 1995 00:00
Date: Sun, 31 Dec 1995 00:00
125 lines
6233 bytes
6233 bytes
When I try to create a shared library under HPUX10.01 and gcc-2.7.2,
I get the message:
/usr/bin/ld: DP-Relative Code in file /var/tmp/cca04159.o - Shared Library must be Position-Independent
I believe that the problem is with collect, where the .o file that
collect builds is not being built with -fpic or -fPIC.
Here's how to reproduce this bug.
Create a trivial file:
cxh@hewlett 21% echo "int f() { return 1;}" > fn.c
Create a .o file with -fPIC
cxh@hewlett 22% gcc -fPIC -v -c fn.c
Reading specs from /users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/specs
gcc version 2.7.2
/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/cpp -lang-c -v -undef -D__GNUC__=2 -D__GNUC_MINOR__=7 -Dhppa -Dhp9000s800 -D__hp9000s800 -Dhp9k8 -DPWB -Dhpux -Dunix -D_HPUX_SOURCE -D__hppa__ -D__hp9000s800__ -D__hp9000s800 -D__hp9k8__ -D__PWB__ -D__hpux__ -D__unix__ -D_HPUX_SOURCE -D__hppa -D__hp9000s800 -D__hp9k8 -D__PWB -D__hpux -D__unix -Asystem(unix) -Asystem(hpux) -Acpu(hppa) -Amachine(hppa) -D__hp9000s700 -D_PA_RISC1_1 fn.c /tmp/cca04211.i
GNU CPP version 2.7.2 (hppa)
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/users/ptdesign/gnu/hppa/hppa1.1-hp-hpux10.01/include
/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/include
/usr/include
End of search list.
/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/cc1 /tmp/cca04211.i -quiet -dumpbase fn.c -version -fPIC -o /tmp/cca04211.s
GNU C version 2.7.2 (hppa) compiled by GNU C version 2.7.2.
/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/as -o fn.o /tmp/cca04211.s
Try to create a shared library:
cxh@hewlett 23% gcc -v -shared -Wl,-debug -o /tmp/libfn.sl fn.o
Reading specs from /users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/specs
gcc version 2.7.2
/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/ld -b -o /tmp/libfn.sl -L/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2 -L/users/ptdesign/gnu/hppa/lib -debug fn.o
collect2 version 2.7.2 (hppa)
ld_file_name = /usr/bin/ld
c_file_name = /users/ptdesign/bin.hppa/gcc
nm_file_name = /usr/sww/bin/gnm
ldd_file_name = /usr/bin/chatr
strip_file_name = /usr/sww/bin/gstrip
c_file = /tmp/cca04216.c
o_file = /tmp/cca04216.o
COLLECT_NAMES = /users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/ld
COLLECT_GCC_OPTIONS = -v -shared -o /tmp/libfn.sl
COLLECT_GCC = gcc
COMPILER_PATH = /users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/:/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/:/usr/lib/gcc/hppa1.1-hp-hpux10.01/2.7.2/:/usr/lib/gcc/hppa1.1-hp-hpux10.01/:/users/ptdesign/gnu/hppa/hppa1.1-hp-hpux10.01/bin/hppa1.1-hp-hpux10.01/2.7.2/:/users/ptdesign/gnu/hppa/hppa1.1-hp-hpux10.01/bin/
LIBRARY_PATH = /users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2/:/usr/lib/gcc/hppa1.1-hp-hpux10.01/2.7.2/:/users/ptdesign/gnu/hppa/hppa1.1-hp-hpux10.01/lib/hppa1.1-hp-hpux10.01/2.7.2/:/users/ptdesign/gnu/hppa/hppa1.1-hp-hpux10.01/lib/:/users/ptdesign/gnu/hppa/lib/hppa1.1-hp-hpux10.01/2.7.2/:/users/ptdesign/gnu/hppa/lib/:/lib/hppa1.1-hp-hpux10.01/2.7.2/:/lib/:/usr/lib/hppa1.1-hp-hpux10.01/2.7.2/:/usr/lib/
/usr/bin/ld -b -o /tmp/libfn.sl -L/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2 -L/users/ptdesign/gnu/hppa/lib fn.o
/usr/sww/bin/gnm -p /tmp/libfn.sl
nm output with constructors/destructors.
/usr/bin/chatr /tmp/libfn.sl
ldd output with constructors/destructors.
0 constructor(s) found
0 destructor(s) found
[Leaving /tmp/libfn.sl]
write_c_file - output name is /tmp/libfn.sl, prefix is libfn_sl
========== output_file = /tmp/libfn.sl, c_file = /tmp/cca04216.c
write_c_file - output name is /tmp/libfn.sl, prefix is libfn_sl
static int count;
typedef void entry_pt();
void _GLOBAL__FI_libfn_sl() {
++count;
}
void _GLOBAL__FD_libfn_sl() {
}
void _GLOBAL__DI() {
_GLOBAL__FI_libfn_sl();
}
void _GLOBAL__DD() {
_GLOBAL__FD_libfn_sl();
}
========== end of c_file
/users/ptdesign/bin.hppa/gcc -c -o /tmp/cca04216.o /tmp/cca04216.c
/usr/bin/ld -b -o /tmp/libfn.sl -L/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2 -L/users/ptdesign/gnu/hppa/lib fn.o /tmp/cca04216.o
/usr/bin/ld: DP-Relative Code in file /tmp/cca04216.o - Shared Library must be Position-Independent
collect2: ld returned 1 exit status
[Leaving /tmp/cca04216.c]
[Leaving /tmp/cca04216.o]
[Leaving /tmp/cca04216.x]
[Leaving /tmp/cca04216.ld]
[Leaving /tmp/libfn.sl]
cxh@hewlett 24%
As a workaround, compile the interim .c file that collect produced with -fPIC:
cxh@hewlett 24% /users/ptdesign/bin.hppa/gcc -fPIC -c -o /tmp/cca04216.o /tmp/cca04216.c
Run the linker by hand:
cxh@hewlett 25% /usr/bin/ld -b -o /tmp/libfn.sl -L/users/ptdesign/gnu/hppa/lib/gcc-lib/hppa1.1-hp-hpux10.01/2.7.2 -L/users/ptdesign/gnu/hppa/lib fn.o /tmp/cca04216.o
The shared library is produced:
cxh@hewlett 26% file libfn.sl
libfn.sl: s800 shared library -not stripped
From collect.c, I can see that collect reads environment variables
that get passed from the parent gcc, but I can't seem to override
them.
Am I dropping a bit here? The same commands work with gcc-2.7.2 under
Solaris2.4, which does not use collect, and SunOS4.1.3, which does use
collect.
-Christopher
Christopher Hylands, Ptolemy Project Manager University of California
cxh@eecs.berkeley.edu US Mail: 558 Cory Hall #1770
ph: (510)643-9841 fax:(510)642-2739 Berkeley, CA 94720-1770
home: (510)526-4010 (if busy -4068) (Office: 493 Cory)
Technical Details
Message-ID:
<199601010024.QAA21629@watson.eecs.berkeley.edu>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,d05c50de2ef6ca8,start X-Google-Attributes: gid113d02,public From: cxh@eecs.berkeley.edu (Christopher Hylands) Subject: gcc-2.7.2, hpux-10.01: -shared can't build shared libraries Date: 1995/12/31 Message-ID: <199601010024.QAA21629@watson.eecs.berkeley.edu> X-Deja-AN: 133616619 distribution: gnu sender: daemon@cis.ohio-state.edu organization: GNUs Not Usenet newsgroups: gnu.gcc.bug