gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple _OBJC_Module in the same shared library/framework, not so g


From: David Chisnall
Subject: Re: Multiple _OBJC_Module in the same shared library/framework, not so good
Date: Tue, 3 Jan 2012 23:25:34 +0000

Hi Nat,

This is, unfortunately, a limitation imposed on us by the old GCC ABI.  

With the non-fragile ABI (and clang's transitional ABI), classes all export a 
public symbol, so it is possible for us to initialise the isa pointer as a weak 
reference to the public symbol for the NSConstantString class so that the fixup 
in the runtime becomes redundant.  This is done in clang r147493 and your test 
case now passes for me.  It should work as long as GNUstep-base is compiled 
with clang.  If it was not, then the weak symbol will be resolved to null at 
link time and you will see the same crash.

David

P.S.  'irregardless' still isn't a word...


On 3 Jan 2012, at 20:38, Nat! wrote:

> Hi
> 
> there is a problem I ran into with static NSStrings in frameworks +load 
> methods, which I wanted to share. 
> 
> If I read the gnu runtime correctly, then for every struct objc_module 
> (_OBJC_Module), there is eventually a call to __objc_exec_class.
> 
> __objc_exec_class does in succession a couple of initialization steps 
> 
> o) on the first run, one big time objc init
> 
> o) add classes/prototypes
> o) hack static strings 
> o) call +load
> 
> I suppose there is one _OBJC_Module per compile unit (i.e. file), but even if 
> not, irregardless, currently multiple _OBJC_Module can appear in a .so file 
> and then this otherwise harmless looking code will crash:
> 
> a.m:  
> #import <Foundation/Foundation.h>
> 
> NSString  *A = @"A";
> 
> 
> @implementation ATest
> 
> + (void) load
> {
>  extern NSString  *Z;
> 
>  printf( "+[ATest load]\n");
>  printf( "Z=%s\n", [Z cString]);
> }
> 
> @end
> 
> 
> z.m:
> #import <Foundation/Foundation.h>
> 
> NSString  *Z = @"Z";
> 
> 
> @implementation ZTest
> 
> + (void) load
> {
>  extern NSString  *A;
> 
>  printf( "+[ZTest load]\n");   
>  printf( "%s\n", [A cString]);
> }
> 
> @end
> 
> 
> It will crash, because one of the +load is happening before the external 
> NXConstantString is fixed up.
> 
> This is not optimal. Optimally, the linker should combine multiple 
> _OBJC_Modules into one for each shared library.
> 
> The workaround is to not use static NSStrings that are defined outside the 
> current file in the same framework/library/tool during +load. static 
> NSStrings in dependent linkage should be fine. (e.g. gui linking with base or 
> so)
> 
> Ciao
>  Nat!
> ---------------------------------------------------------
> Any one who thinks about the future must live in fear and
> terror. This is due to the fact that the intelligence and
> character of the masses are incomparably lower than the 
> intelligence and character of the few who produce some 
> thing valuable for the community.  -- A. Einstein
> 
> 
> _______________________________________________
> Gnustep-dev mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/gnustep-dev


-- Sent from my IBM 1620




reply via email to

[Prev in Thread] Current Thread [Next in Thread]