This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: detecting non-PIC in shared lib on Darwin?

Andrew is referring to the following:
[shantonu@macboo]$ cat foo.c
extern int a;
int foo(void) { return a; }
[shantonu@macboo]$ cat bar.c
int a = 1;
[shantonu@macboo]$ cc -mdynamic-no-pic -c foo.c -arch ppc
[shantonu@macboo]$ cc -mdynamic-no-pic -c bar.c -arch ppc
[shantonu@macboo]$ cc -dynamiclib -o libfoo.dylib foo.o bar.o -arch ppc
ld: foo.o has local relocation entries in non-writable section (__TEXT,__text)
/usr/bin/libtool: internal link edit command failed

Instead of going through stubs in the data segment, -mdynamic-no-pic puts relocations directly in the text segment on the assumption that the final linked image will be an executable at a fixed address and the relocations will be resolved to absolute addresses. If you do the same experiment with -arch ppc64, you will not get a static linker error, but instead the program will crash at runtime. Some may consider that a bug that should be reported to Apple.

I don't believe there's a general way of detecting non-dylib-safe object files, except trying to link it into a dylib and see if it fails (for ppc32)


On Apr 26, 2006, at 6:45 PM, Jack Howarth wrote:

    What on earth would make you think that the linker on Darwin would
reject non-PIC code in linking a shared library. The linker on Linux
doesn't do any such thing (hence the discussion on the Debian mailing
list of adopting this as check on their builds).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]