[omniORB] Static build with GCC 3.4

Vladimir Panov gbr at voidland.org
Sun Oct 22 01:53:26 BST 2006


Duncan Grisby wrote:
> On Thursday 10 February, Vladimir Panov wrote:
>
>   
>> When omniORB 4.0.5 (or any 4.0 version, actually) is built with GCC
>> 3.4, then a statically linked program against it segfaults on
>> startup. The reason is that the static initializers of the code sets
>> are not executed (even the ones from libomniORB4.a, not only the ones
>> from libomniCodeSets4.a). The reason seems to be a new optimization in
>> GCC 3.4 called "unit-at-a-time" which is on by default when using -O2.
>>     
>
> Thanks for your patch. I've checked it in. Have you reported the problem
> to the GCC developers?
>
> Cheers,
>
> Duncan.
>
>   
Hi, Duncan.

I have found that there are more cases to fix (because of using 
"CXXOPTIONS =" rather than "CXXOPTIONS +="), for example Darwin.
I have attached a patch against omniORB 4.0.7 
(omniORB-4.0.7-EXTRA_GCC_CXXFLAGS.patch).

However, -fno-unit-at-a-time is not enough when using GCC 4. It ignores 
unused static global variables and functions. I have found two solutions:
a) Use non-static variables to reference the export symbol. We have to 
ensure a unique-per-source-file name for the variable but I couldn't 
figure out how to do it automatically. Manually doing this is not 
possible because OMNI_FORCE_LINK is used indirectly (in headers).
b) Do something on the export symbol, like ++. This way, the compiler 
will still ignore the unused global static variable but because code 
must be generated for the ++ operator it won't discard the reference. 
The downside is that the code will actually be executed. I have attached 
a patch against omniORB 4.0.7 (omniORB-4.0.7-linkHacks.patch). If it is 
applied then -fno-unit-at-a-time is not required and 
OMNI_CHECK_NO_UNIT_AT_A_TIME can be removed from configure.ac.

Vlado

-------------- next part --------------
diff -u -r -u -N omniORB-4.0.7-orig/mk/beforeauto.mk.in omniORB-4.0.7/mk/beforeauto.mk.in
--- omniORB-4.0.7-orig/mk/beforeauto.mk.in	2005-03-22 15:53:41.000000000 +0200
+++ omniORB-4.0.7/mk/beforeauto.mk.in	2006-10-21 00:17:55.000000000 +0300
@@ -870,7 +870,7 @@
 #                    /opt/aCC/lbin/ld: Unsatisfied symbols:
 #                    fstreambase::cma_close(void)(code)
 CXXOPTIONS    =  -fhandle-exceptions -Wall -Wno-unused \
-                 -D_CMA_NOWRAPPERS_
+                 -D_CMA_NOWRAPPERS_ @EXTRA_GCC_CXXFLAGS@
 endif
 
 ifdef Compiler_aCC
@@ -958,7 +958,7 @@
 OMNITHREAD_POSIX_CPPFLAGS = -DPthreadDraftVersion=10 \
                             -DPthreadSupportThreadPriority -DNoNanoSleep
 
-CXXOPTIONS = -fno-common -bind_at_load
+CXXOPTIONS = -fno-common -bind_at_load @EXTRA_GCC_CXXFLAGS@
 SHAREDLIB_SUFFIX = dylib
 
 SharedLibraryFullNameTemplate = lib$$1$$2.$$3.$$4.$(SHAREDLIB_SUFFIX)



-------------- next part --------------
diff -u -r -N omniORB-4.0.7-orig/include/omniORB4/linkHacks.h omniORB-4.0.7/include/omniORB4/linkHacks.h
--- omniORB-4.0.7-orig/include/omniORB4/linkHacks.h	2003-02-17 04:03:07.000000000 +0200
+++ omniORB-4.0.7/include/omniORB4/linkHacks.h	2006-10-21 22:39:48.000000000 +0300
@@ -63,8 +63,8 @@
 
 #define OMNI_FORCE_LINK(modname) \
   extern int _omni_ ## modname ## _should_be_linked_but_is_not_; \
-  static int* _omni_ ## modname ## _forcelink_ = \
-                         &_omni_ ## modname ## _should_be_linked_but_is_not_; \
+  static int _omni_ ## modname ## _forcelink_ = \
+                         _omni_ ## modname ## _should_be_linked_but_is_not_++; \
   static int _omni_ ## modname ## _value_ () { \
     return *(_omni_ ## modname ## _forcelink_); \
   }
@@ -73,8 +73,8 @@
 
 #define OMNI_FORCE_LINK(modname) \
   extern int _omni_ ## modname ## _should_be_linked_but_is_not_; \
-  static int* _omni_ ## modname ## _forcelink_ = \
-                         &_omni_ ## modname ## _should_be_linked_but_is_not_
+  static int _omni_ ## modname ## _forcelink_ = \
+                         _omni_ ## modname ## _should_be_linked_but_is_not_++
 
 #endif
 



More information about the omniORB-list mailing list