This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Solaris, Objective-C, and shared libraries
- To: egcs at cygnus dot com
- Subject: Solaris, Objective-C, and shared libraries
- From: David McWherter <dtm at water dot waterw dot com>
- Date: Thu, 11 Sep 1997 16:35:56 -0400 (EDT)
I think (but I'm not sure) that there's a bug in gcc-2.7.2.1
for Solaris, that causes objective-c object code that is
compiled as a shared library to fail (because some of its
data is shoved into a .text section, causing symbol resolving
to fail when the shared library is loaded). The gcc code
seems to indicate that it does this to keep the variable
in question read-only, just for the fun of it.
My question is whether or not this bug still exists in egcs
for Solaris (I don't have free reign on a Solaris box to
experiment).
Code that can replicate this looks like this:
printer.m
=============
#import "printer.h"
#import <stdio.h>
@implementation Printer
- init
{
[super init];
printf ("hello, printer\n");
return self;
}
@end
=============
printer.h
=============
#import <objc/Object.h>
@interface Printer : Object
{
}
- init;
@end
=============
main.m
=============
#import <stdio.h>
#import "printer.h"
int main () {
id p = [[Printer alloc] init];
printf("Hello, world\n");
return 0;
}
=============
Compiled like so:
gcc printer.m -o printer.o -c -Wno-import -fPIC
gcc printer.o -fPIC -shared -o libP.so.1.0
gcc main.m -o x.sun4 -L. -lP -Wno-import -fPIC -lobjc
For me, the compile fails on the generation of the libP.so.1.0
file, because of "assert pure-text failed" errors on the symbol
___objc_class_name_Object.
gcc -v turns up:
Reading specs from
/vol/gnu/pkgs/gcc/2.7.2.1/sun4/lib/gcc-lib/sparc-sun-sunos4.1.3_U1/2.7.2.1/specs
gcc version 2.7.2.1
The assembler output surrounding the definition in question looks
like so:
ret
restore
.align 4
.word ___objc_class_name_Object
.global ___objc_class_name_Printer
___objc_class_name_Printer:
.data
.align 8
__OBJC_CLASS_NAME_0:
.ascii "Printer\0"
.align 8
__OBJC_CLASS_NAME_1:
.ascii "Object\0"
.align 8
Moving the '.data' declaration up three lines, just before the
'.word ___objc_class_name_Object' line allows things to link and run
(seemingly) properly.
I think that ___objc_class_name_Object is put into the
.text section in objc-act.c in the handle_class_ref function by
code that looks like so:
>>
/* Make following constant read-only (why not)? */
readonly_data_section ();
<<
which I think should be data_section() instead...
-David