This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Bug report: objc classes linked in wrong order
- To: rth at cygnus dot com
- Subject: Re: Bug report: objc classes linked in wrong order
- From: nicola at brainstorm dot co dot uk
- Date: Fri, 26 May 2000 17:34:43 +0100 (BST)
- cc: law at cygnus dot com, hjl at lucon dot org, egcs at sourceware dot cygnus dot com, ovidiu at cup dot hp dot com, gcc at gcc dot gnu dot org
> > Anybody has any other idea about of how to have the NXConstantString class
> > from a shared library to be linked instead of the NXConstantString from a
> > shared libobjc when linking both libraries ?
>
> Make the non-preferred one weak.
Can I make an objective-C class weak ?
I found no evidence of this - because each module has a list of classes to
load, and loads them all - but I might be wrong - so please give me a hint
if I actually can in some way make a class weak.
But I liked your hint anyway, because using __attribute__((weak)) at least
can help to make the patch simpler.
--- ./init.c.orig Mon May 15 10:34:03 2000
+++ init.c Fri May 26 16:29:47 2000
@@ -26,6 +26,10 @@
#include "runtime.h"
+/* Define this to 1 if you want to provide your own version of
+ NXConstantString in your library or user code */
+int __attribute__((weak)) _user_defined_NXConstantString = 0;
+
/* The version number of this runtime. This must match the number
defined in gcc (objc-act.c) */
#define OBJC_VERSION 8
@@ -469,7 +473,34 @@
/* dummy counter */
int i;
+ /* dummy pointer */
+ const char *p;
+
DEBUG_PRINTF ("received module: %s\n", module->name);
+
+ if (_user_defined_NXConstantString == 1)
+ {
+ /* The user has overridden _user_defined_NXConstantString to
+ tell us that he doesn't want us to load the library's
+ NXConstantString implementation */
+ DEBUG_PRINTF ("Filtering out libobjc's NXConstantString at programmer's request:\n");
+
+ /* Search last occurrence of letter 'N' in the module name */
+ p = (char *)strrchr (module->name, 'N');
+ if (p)
+ {
+ /* Found; compare string starting with this last 'N' to
+ "NXConstStr.m" */
+ if (strcmp (p, "NXConstStr.m") == 0)
+ {
+ /* it matches, so it is (should be) our NXConstantString
+ module - don't load it */
+ DEBUG_PRINTF ("Module not loaded\n");
+ return;
+ }
+ }
+ DEBUG_PRINTF ("Module loaded\n");
+ }
/* check gcc version */
init_check_module_version(module);
And then GNUstep can be patched as follows:
--- NSGCString.m 2000/03/17 13:13:07 1.77
+++ NSGCString.m 2000/05/26 15:26:11
@@ -23,6 +23,12 @@
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
+/*
+ * Tell libobjc not to include its own implementation of NXConstantString
+ */
+
+int _user_defined_NXConstantString = 1;
+
#include <config.h>
#include <base/preface.h>
#include <Foundation/NSString.h>
Please notice that I already talked to the other GNUstep developers and we
agreed this solution could be acceptable.