This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
-shared under SunOS
- To: egcs-bugs at cygnus dot com
- Subject: -shared under SunOS
- From: Damien Neil <dneil at etak dot com>
- Date: Wed, 24 Feb 1999 09:50:29 -0800
Is the following a bug? (SunOS 4.1.4, egcs 1.1.1.)
$ cat > foo.c
int foo() { return 42; }
$ egcs -fPIC -c foo.c
$ egcs -shared -o libfoo.so foo.o
ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 3c in /usr/tmp/ccmJgnEY.o
ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 40 in /usr/tmp/ccmJgnEY.o
ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 44 in /usr/tmp/ccmJgnEY.o
ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 48 in /usr/tmp/ccmJgnEY.o
ld: /usr/tmp/ccmJgnEY.o: assert pure-text failed: reference to [offset] at 50 in /usr/tmp/ccmJgnEY.o
collect2: ld returned 2 exit status
This error does not occur with gcc 2.7.2.3. The problem appears to come
from collect2. For reasons that I do not fully understand, collect2 is
generating and compiling a small file containing some stub functions
(appended below). This file is the one generating the ld pure-text
assertion errors above, as it is not being compiled with -fPIC.
I can make the problem go away by adding -fPIC to the link line:
$ egcs -fPIC -shared -o libfoo.so foo.o
Is this what I am supposed to be doing? I would think that -fPIC would
normally be used only on compilation lines, not link lines. Shouldn't
collect automatically add -fPIC to anything it generates and compiles,
if it is destined for a shared object?
- Damien
The generated file:
#ifdef __cplusplus
extern "C" {
#endif
static int count;
typedef void entry_pt();
void _GLOBAL__FI_libfoo_so() {
++count;
}
void _GLOBAL__FD_libfoo_so() {
}
void _GLOBAL__DI() {
_GLOBAL__FI_libfoo_so();
}
void _GLOBAL__DD() {
_GLOBAL__FD_libfoo_so();
}
#ifdef __cplusplus
}
#endif