[Top][All Lists]

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

.ctor section of shared libraries with PathScale compiler

From: Peter Wainwright
Subject: .ctor section of shared libraries with PathScale compiler
Date: Sun, 23 Jul 2006 22:06:36 +0100

I'm trying to compile a large existing project which uses libtool,
using the PathScale C++ compiler.
This project has several shared libraries. I found that
the constructors for the global objects in these libraries were not
being called at all. It turns out that the order of linking objects
is wrong: it goes

<my objects...> crtbeginS.o crtendS.o

instead of

crtbeginS.o <my objects...> crtendS.o

This means that the __CTOR_LIST__ and __CTOR_END__ symbols do not
enclose the constructors as they should, and the __do_global_ctors_aux
method thinks the constructor list is empty.

Tracing this problem even further back, it seems that when ./configure
generates libtool, it sets predep_objects="" and puts crtbeginS.o in
postdep_objects instead.

Tracing this problem even further back, I found that the predep_objects
and postdep_objects variables were initialized by looking at the output
of the command

output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 |
grep "\-L"'

Unfortunately, pathcc -v prints TWO lines containing -L. The latter is
the one
we want, so I suggest putting | tail -1 on the end of this command
(in /usr/share/aclocal/libtool.m4).

[ This is what pathscale prints:
First line: /usr/bin/gcc -v -L/opt/pathscale/lib/2.4
test.o -lpscrt

Second line: /usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/collect2
--eh-frame-hdr -m elf_x86_64 -Y P,/usr/lib64
-dynamic-linker /lib64/ld-linux-x86-64.so.2 
/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/crtbegin.o -L/opt/pathscale/lib/2.4 
-L/usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/../../.. -L/lib/../lib64 
-L/usr/lib/../lib64 -rpath-link /opt/pathscale/lib/2.4 test.o -lpscrt -lgcc 
-lgcc_eh -lc -lgcc -lgcc_eh /usr/lib/gcc-lib/x86_64-redhat-linux/3.2.3/crtend.o 

This patch fixes the problem:
address@hidden aclocal]$ diff -u libtool.m4{~,}
--- libtool.m4~ 2006-05-26 08:53:31.000000000 +0100
+++ libtool.m4  2006-07-23 20:41:44.000000000 +0100
@@ -2870,7 +2870,7 @@
   # Commands to make compiler produce verbose output that lists
   # what "hidden" libraries, object files and flags are used when
   # linking a shared library.
-  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1
| grep "\-L"'
+  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1
| grep "\-L" | tail -1'


Peter Wainwright

Attachment: signature.asc
Description: This is a digitally signed message part

reply via email to

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