[Vxl-maintainers] RE: [Cmake] command to build dynamic lib changed causing my VXL b uild to brea k

William A. Hoffman billlist at nycap . rr . com
Sun, 13 Jan 2002 11:41:07 -0500


This could be a bad installation of gcc on your solaris machine.
The only thing that changed was the creation of shared libraries.
You are right in saying that the .o files are created in the same way.

With the -shared option the compiler knows it is creating a shared library, 
so it can put
calls to initialize global objects in the init section of the shared library.
The compilation of .o files has not been changed.  The -nostdlib tells the 
compiler not
to link in libstdc++ or libc as these are often not shared libraries and 
linking in static ones
with a shared library would cause link errors.

So you are getting a crash in an object initialization which was not 
happening before.

Does it matter what is in the shared library.

You said this crashed:
c++ -v $OPT -g -O2 -o /tmp/libvcl.so \
   vcl_ostream_iterator+int-.o \
   vcl_vector+bool-.o


What about:

foo.o
where foo has one function in it.

If that crashes, I am suspecting your gcc installation.   VTK is working 
fine with these flags.


One more thing, can you leave off the -O2 -g and just use -g, that compiler 
option has caused me trouble
before, also you might get a call stack in the debugger.

-Bill
At 10:01 AM 1/13/2002 -0500, Wheeler, Fred (CRD) wrote:
>Brad, Peter,
>
>Thanks for your replies.  Brad's idea that I might have a mixed batch of 
>.o files is a good one, but
>I guarded against that.  I can demo the problem I am seeing with the 
>commands below.  I'm finding
>some more strange behavior described in the comments that start with 
>"!!!". Note that optimization
>(whether -O2 is used or not) affects this, and that the problem only 
>happens when I use both objects
>in the demo below.
>
>Brad noted that the compiler should know whether the object file it is 
>creating will go in a shared
>or non-shared library.  Makes sense to me, but it looks to me like cmake 
>started using "-shared
>-nostdlib" for creating the shared lib, but did not change the command 
>line for creating object
>files.  Right?
>
># demo
>cd /tmp
>VXLSRC=/no_backup/wheeler/prj/sr/vxl_src
>
># !!! the problem does not occur if either of these object files is 
>removed from the library
>
># build vcl_ostream_iterator+int-.o
>c++ -g -O2 -Wall -Dvcl_EXPORTS -fPIC -I$VXLSRC/vcl 
>-I/no_backup/wheeler/prj/sr/vxl_bld/vcl
>-I/no_backup/wheeler/prj/sr/vxl_bld/vxl -I$VXLSRC/vcl -DVXL_WARN_DEPRECATED
>-DVXL_WARN_DEPRECATED_ONCE -c 
>$VXLSRC/vcl/Templates/vcl_ostream_iterator+int-.cxx -o
>vcl_ostream_iterator+int-.o
>
># build vcl_vector+bool-.o
># !!! if I remove the -O2 option - no bus error
>c++ -g -O2 -Wall -Dvcl_EXPORTS -fPIC -I$VXLSRC/vcl 
>-I/no_backup/wheeler/prj/sr/vxl_bld/vcl
>-I/no_backup/wheeler/prj/sr/vxl_bld/vxl -I$VXLSRC/vcl -DVXL_WARN_DEPRECATED
>-DVXL_WARN_DEPRECATED_ONCE -c $VXLSRC/vcl/Templates/vcl_vector+bool-.cxx 
>-o vcl_vector+bool-.o
>
># a minimal main
>cat<<EOF >| foo.cxx
>int main() { return 0; }
>EOF
>
>c++ -g -O2 -c foo.cxx -o foo.o
>
># with this option there is no bus error
>OPT="-Wl,-G"
># with this option the exec will produce a bus error
>OPT="-shared -nostdlib"
>
># build vcl library with only two objects
>c++ -v $OPT -g -O2 -o /tmp/libvcl.so \
>   vcl_ostream_iterator+int-.o \
>   vcl_vector+bool-.o
>
># link
>c++ foo.o -L/tmp -lvcl -Wl,-R,/tmp: -o foo
>
># run, bus error will occur here is "-shared -nostdlib" was used
>./foo
>
># if there was a bus error, gdb yeilds garbage (otherwise it works)
>138% gdb foo
>GNU gdb 5.1
>(gdb) break main
>Breakpoint 1 at 0x10700: file foo.cxx, line 1.
>(gdb) run
>Starting program: /tmp/foo
>
>Program received signal SIGSEGV, Segmentation fault.
>0xff3c9e84 in ?? ()
>(gdb) where
>#0  0xff3c9e84 in ?? ()
>#1  0xff3c3bdc in ?? ()
>#2  0xff3b2ea0 in ?? ()
>#3  0xff3ba8cc in ?? ()
>#4  0xff3c4da0 in ?? ()
>#5  0xff3b2958 in ?? ()
>(gdb)