Re: .ctor section of shared libraries with PathScale compiler
Noah -- Awesome; thanks! (you code is a bit simpler than mine, which is good) I think the only difference is that the C++ library must be a shared library. It will always work fine if the library is static. I saw some references in some of the other .at files that there is a way to figure out if Libtool was built with shared library support, but I didn't figure that part out before I sent my original patch. On Apr 25, 2007, at 10:58 PM, Noah Misch wrote: On Wed, Apr 25, 2007 at 12:36:23PM -0400, Jeff Squyres wrote: I'm told that I can describe the patch in implementation-free terms in the hope that someone else can implement it who either can setup to transfer copyright to the FSF or already has such a transfer agreement in place. The patch is very simple. It's a test that makes a shared library containing a single instance of a class in the global scope. The class has a specific constructor that should be invoked before main() (since the instance is in the global scope). It is easy enough to test whether the constructor has run before main(); if it has, the test passes. If it has not, the test fails. Does the test this patch adds exercise the bug affecting your compiler? 2007-04-25 Noah Misch [EMAIL PROTECTED] * tests/ctor.at: New file. * Makefile.am (TESTSUITE_AT): Add tests/ctor.at. diff -NurpX dontdiff lt-bootstrap/Makefile.am lt-ctortest/Makefile.am --- lt-bootstrap/Makefile.am2007-04-24 16:46:17.0 -0400 +++ lt-ctortest/Makefile.am 2007-04-25 22:52:10.0 -0400 @@ -448,6 +448,7 @@ TESTSUITE_AT= tests/testsuite.at \ tests/nonrecursive.at \ tests/recursive.at \ tests/template.at \ + tests/ctor.at \ tests/early-libtool.at \ tests/deplibs-ident.at \ tests/stresstest.at \ diff -NurpX dontdiff lt-bootstrap/tests/ctor.at lt-ctortest/tests/ ctor.at --- lt-bootstrap/tests/ctor.at 1969-12-31 19:00:00.0 -0500 +++ lt-ctortest/tests/ctor.at 2007-04-25 22:54:19.0 -0400 @@ -0,0 +1,66 @@ +# ctor.at -- Test constructors via C++-*- Autotest -*- +# +# Copyright (C) 2007 Free Software Foundation, Inc. +# Written by Noah Misch, 2007 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# GNU Libtool is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, +# or obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +AT_BANNER([Constructors.]) + +AT_SETUP([C++ static constructors]) +LT_AT_TAG([CXX]) +AT_KEYWORDS([libtool]) + +AT_DATA(class.h, +[[class Foo { +public: + Foo() { bar = 0xaabbccdd; } + unsigned bar; +}; + +extern Foo instance; +]]) + +AT_DATA(libctor.cpp, +[[#include class.h +Foo instance; +]]) + +AT_DATA(main.cpp, +[[#include class.h + +int main(int argc, char **argv) +{ + return instance.bar != 0xaabbccdd; +} +]]) + +AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS \ + -c libctor.cpp -o libctor.lo], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS \ + -c main.cpp -o main.lo], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS \ + libctor.lo -o libctor.la -rpath /none], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS \ + main.lo libctor.la -o main], [0], [ignore], [ignore]) + +LT_AT_EXEC_CHECK([./main], [0]) + +AT_CLEANUP -- Jeff Squyres Cisco Systems ___ Bug-libtool mailing list Bug-libtool@gnu.org http://lists.gnu.org/mailman/listinfo/bug-libtool
Re: .ctor section of shared libraries with PathScale compiler
Thanks Noah. I installed that, but changed the constant to be a #define in the header file. To ease Jeff's concerns about -shared: if libtool supports shared libraries for the system/compiler in question, then they will be preferred over static libs. So -shared is not needed in order for the test to be effective. And we don't want it to fail in the static-only case. Cheers, Ralf 2007-04-27 Noah Misch [EMAIL PROTECTED] * tests/ctor.at: New file. * Makefile.am (TESTSUITE_AT): Add tests/ctor.at. Index: Makefile.am === RCS file: /cvsroot/libtool/libtool/Makefile.am,v retrieving revision 1.217 diff -u -r1.217 Makefile.am --- Makefile.am 24 Apr 2007 20:46:17 - 1.217 +++ Makefile.am 26 Apr 2007 22:32:48 - @@ -448,6 +448,7 @@ tests/nonrecursive.at \ tests/recursive.at \ tests/template.at \ + tests/ctor.at \ tests/early-libtool.at \ tests/deplibs-ident.at \ tests/stresstest.at \ --- /dev/null 2007-04-15 17:46:43.220064750 +0200 +++ tests/ctor.at 2007-04-27 00:31:36.0 +0200 @@ -0,0 +1,67 @@ +# ctor.at -- Test constructors via C++-*- Autotest -*- +# +# Copyright (C) 2007 Free Software Foundation, Inc. +# Written by Noah Misch, 2007 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# GNU Libtool is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, +# or obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +AT_BANNER([Constructors.]) + +AT_SETUP([C++ static constructors]) +LT_AT_TAG([CXX]) +AT_KEYWORDS([libtool]) + +AT_DATA(class.h, +[[#define magic 0xaabbccdd +class Foo { +public: + Foo() { bar = magic; } + unsigned bar; +}; + +extern Foo instance; +]]) + +AT_DATA(libctor.cpp, +[[#include class.h +Foo instance; +]]) + +AT_DATA(main.cpp, +[[#include class.h + +int main(int argc, char **argv) +{ + return instance.bar != magic; +} +]]) + +AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS \ + -c libctor.cpp -o libctor.lo], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS \ + -c main.cpp -o main.lo], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS \ + libctor.lo -o libctor.la -rpath /none], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS \ + main.lo libctor.la -o main], [0], [ignore], [ignore]) + +LT_AT_EXEC_CHECK([./main], [0]) + +AT_CLEANUP ___ Bug-libtool mailing list Bug-libtool@gnu.org http://lists.gnu.org/mailman/listinfo/bug-libtool
Re: .ctor section of shared libraries with PathScale compiler
After some more off-list mails with Ralf, I found that non-trivial patches to Libtool must be accompanied by a copyright transfer to the FSF (this is FSF policy). I understand the rationale for this policy, but I'm told by Cisco lawyers that we cannot do this, unfortunately (long, uninteresting reasons). So the patch that I sent will not make it into Libtool. I'm told that I can describe the patch in implementation-free terms in the hope that someone else can implement it who either can setup to transfer copyright to the FSF or already has such a transfer agreement in place. The patch is very simple. It's a test that makes a shared library containing a single instance of a class in the global scope. The class has a specific constructor that should be invoked before main() (since the instance is in the global scope). It is easy enough to test whether the constructor has run before main(); if it has, the test passes. If it has not, the test fails. Hope that helps. On Apr 23, 2007, at 10:28 AM, Jeff Squyres wrote: With some off-list help from Ralf, I was able to create a .at test that shows the problem (see attached). I'm sure you guys will want to tweak it a bit more (e.g., it blindly uses -shared and doesn't check to see if Libtool has shared library support). The test itself is pretty simple: - a shared library is created with a global instance of a class that has a static constructor. This constructor should fire before main(). - a trivial application is linked against this library and simply checks to see if the constructor for the global object has fired. The C++ portion of the test could probably be made a little more simple if desired -- I was testing for something slightly different when we Googled and found the old libtool posting. The specific cause for the failure is what Peter originally posted -- Libtool is not properly snarfing all the extra libraries/flags from pathCC that it needs (e.g., the library that ensures to call static initializer constructors on global objects). If you configure libtool with the pathscale suite, you'll see the problem, and test 50 will fail (at least, it's test 50 for me): % ./configure CC=pathcc CXX=pathCC FC=pathf90 F77=pathf77 [...lots of output...] % make TESTSUITEFLAGS=50 check-local abs_srcdir=`CDPATH=${ZSH_VERSION+.}: cd . pwd`; cd tests; \ CONFIG_SHELL=/bin/sh /bin/sh $abs_srcdir/tests/testsuite \ MAKE=make CC=pathcc CFLAGS=-g -O2 CPP=pathcc -E CPPFLAGS= LD=/usr/bin/ld -m elf_x86_64 LDFLAGS= LIBS=-ldl LN_S=ln -s NM=/usr/bin/nm -B RANLIB=ranlib OBJEXT=o EXEEXT= SHELL=/bin/sh CONFIG_SHELL=/bin/sh CXX=pathCC CXXFLAGS=-g -O2 CXXCPP=pathCC -E F77=pathf77 FFLAGS= FC=pathf90 FCFLAGS=-g -O2 GCJ=gcj GCJFLAGS=-g -O2 _lt_pkgdatadir=/home/jsquyres/cvs/libtool LIBTOOLIZE=/home/ jsquyres/cvs/libtool/libtoolize LIBTOOL=/home/jsquyres/cvs/ libtool/libtool tst_aclocaldir=/home/jsquyres/cvs/libtool/libltdl/ m4 50 ## ## ## libtool 2.1a test suite. ## ## ## 50: simple test FAILED (pathscale-ctor.at:69) ...etc. With gcc, it works fine. Hope this test is helpful. pathscale-ctor.at On Apr 23, 2007, at 1:26 AM, Ralf Wildenhues wrote: [ http://thread.gmane.org/gmane.comp.gnu.libtool.bugs/5697 http://thread.gmane.org/gmane.comp.gnu.libtool.bugs/5465 ] Hello all, and apologies for the huge delay, * Peter Wainwright wrote on Sun, Jul 23, 2006 at 11:06:36PM CEST: 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 [...] * Jeff Squyres wrote on Sat, Apr 21, 2007 at 03:09:45AM CEST: Greetings Libtool! Long-time Libtool fan here, reporting that we ran into the exact same bug as described on this list about 8 months ago by Peter Wainwright: http://www.mail-archive.com/bug-libtool@gnu.org/msg00899.html There was no reply to Peter's post on the list; did anyone have a chance to look at his patch, perchance? It was still sitting in my ever-longer queue; sorry. I think a fix for this issue would be a lot easier for me together with a testcase (along the lines of HEAD's tests/template.at) that exposes this issue. A small self-contained (portable!) example would be a good start. This helps ensure that we don't regress with other unrelated compilers. (And testing will then allow me to evaluate whether the patch Peter suggested is good enough.) Thanks, Ralf -- Jeff Squyres Cisco Systems -- Jeff Squyres Cisco Systems ___ Bug-libtool mailing list Bug-libtool@gnu.org
Re: .ctor section of shared libraries with PathScale compiler
On Wed, Apr 25, 2007 at 12:36:23PM -0400, Jeff Squyres wrote: I'm told that I can describe the patch in implementation-free terms in the hope that someone else can implement it who either can setup to transfer copyright to the FSF or already has such a transfer agreement in place. The patch is very simple. It's a test that makes a shared library containing a single instance of a class in the global scope. The class has a specific constructor that should be invoked before main() (since the instance is in the global scope). It is easy enough to test whether the constructor has run before main(); if it has, the test passes. If it has not, the test fails. Does the test this patch adds exercise the bug affecting your compiler? 2007-04-25 Noah Misch [EMAIL PROTECTED] * tests/ctor.at: New file. * Makefile.am (TESTSUITE_AT): Add tests/ctor.at. diff -NurpX dontdiff lt-bootstrap/Makefile.am lt-ctortest/Makefile.am --- lt-bootstrap/Makefile.am2007-04-24 16:46:17.0 -0400 +++ lt-ctortest/Makefile.am 2007-04-25 22:52:10.0 -0400 @@ -448,6 +448,7 @@ TESTSUITE_AT= tests/testsuite.at \ tests/nonrecursive.at \ tests/recursive.at \ tests/template.at \ + tests/ctor.at \ tests/early-libtool.at \ tests/deplibs-ident.at \ tests/stresstest.at \ diff -NurpX dontdiff lt-bootstrap/tests/ctor.at lt-ctortest/tests/ctor.at --- lt-bootstrap/tests/ctor.at 1969-12-31 19:00:00.0 -0500 +++ lt-ctortest/tests/ctor.at 2007-04-25 22:54:19.0 -0400 @@ -0,0 +1,66 @@ +# ctor.at -- Test constructors via C++-*- Autotest -*- +# +# Copyright (C) 2007 Free Software Foundation, Inc. +# Written by Noah Misch, 2007 +# +# This file is part of GNU Libtool. +# +# GNU Libtool is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of +# the License, or (at your option) any later version. +# +# GNU Libtool is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Libtool; see the file COPYING. If not, a copy +# can be downloaded from http://www.gnu.org/licenses/gpl.html, +# or obtained by writing to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +AT_BANNER([Constructors.]) + +AT_SETUP([C++ static constructors]) +LT_AT_TAG([CXX]) +AT_KEYWORDS([libtool]) + +AT_DATA(class.h, +[[class Foo { +public: + Foo() { bar = 0xaabbccdd; } + unsigned bar; +}; + +extern Foo instance; +]]) + +AT_DATA(libctor.cpp, +[[#include class.h +Foo instance; +]]) + +AT_DATA(main.cpp, +[[#include class.h + +int main(int argc, char **argv) +{ + return instance.bar != 0xaabbccdd; +} +]]) + +AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS \ + -c libctor.cpp -o libctor.lo], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=compile $CXX $CPPFLAGS $CXXFLAGS \ + -c main.cpp -o main.lo], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS \ + libctor.lo -o libctor.la -rpath /none], [0], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --tag=CXX --mode=link $CXX $CXXFLAGS $LDFLAGS \ + main.lo libctor.la -o main], [0], [ignore], [ignore]) + +LT_AT_EXEC_CHECK([./main], [0]) + +AT_CLEANUP ___ Bug-libtool mailing list Bug-libtool@gnu.org http://lists.gnu.org/mailman/listinfo/bug-libtool
Re: .ctor section of shared libraries with PathScale compiler
With some off-list help from Ralf, I was able to create a .at test that shows the problem (see attached). I'm sure you guys will want to tweak it a bit more (e.g., it blindly uses -shared and doesn't check to see if Libtool has shared library support). The test itself is pretty simple: - a shared library is created with a global instance of a class that has a static constructor. This constructor should fire before main(). - a trivial application is linked against this library and simply checks to see if the constructor for the global object has fired. The C++ portion of the test could probably be made a little more simple if desired -- I was testing for something slightly different when we Googled and found the old libtool posting. The specific cause for the failure is what Peter originally posted -- Libtool is not properly snarfing all the extra libraries/flags from pathCC that it needs (e.g., the library that ensures to call static initializer constructors on global objects). If you configure libtool with the pathscale suite, you'll see the problem, and test 50 will fail (at least, it's test 50 for me): % ./configure CC=pathcc CXX=pathCC FC=pathf90 F77=pathf77 [...lots of output...] % make TESTSUITEFLAGS=50 check-local abs_srcdir=`CDPATH=${ZSH_VERSION+.}: cd . pwd`; cd tests; \ CONFIG_SHELL=/bin/sh /bin/sh $abs_srcdir/tests/testsuite \ MAKE=make CC=pathcc CFLAGS=-g -O2 CPP=pathcc -E CPPFLAGS= LD=/usr/bin/ld -m elf_x86_64 LDFLAGS= LIBS=-ldl LN_S=ln -s NM=/usr/bin/nm -B RANLIB=ranlib OBJEXT=o EXEEXT= SHELL=/bin/sh CONFIG_SHELL=/bin/sh CXX=pathCC CXXFLAGS=-g -O2 CXXCPP=pathCC -E F77=pathf77 FFLAGS= FC=pathf90 FCFLAGS=-g - O2 GCJ=gcj GCJFLAGS=-g -O2 _lt_pkgdatadir=/home/jsquyres/cvs/ libtool LIBTOOLIZE=/home/jsquyres/cvs/libtool/libtoolize LIBTOOL=/ home/jsquyres/cvs/libtool/libtool tst_aclocaldir=/home/jsquyres/cvs/ libtool/libltdl/m4 50 ## ## ## libtool 2.1a test suite. ## ## ## 50: simple test FAILED (pathscale- ctor.at:69) ...etc. With gcc, it works fine. Hope this test is helpful. pathscale-ctor.at Description: Binary data On Apr 23, 2007, at 1:26 AM, Ralf Wildenhues wrote: [ http://thread.gmane.org/gmane.comp.gnu.libtool.bugs/5697 http://thread.gmane.org/gmane.comp.gnu.libtool.bugs/5465 ] Hello all, and apologies for the huge delay, * Peter Wainwright wrote on Sun, Jul 23, 2006 at 11:06:36PM CEST: 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 [...] * Jeff Squyres wrote on Sat, Apr 21, 2007 at 03:09:45AM CEST: Greetings Libtool! Long-time Libtool fan here, reporting that we ran into the exact same bug as described on this list about 8 months ago by Peter Wainwright: http://www.mail-archive.com/bug-libtool@gnu.org/msg00899.html There was no reply to Peter's post on the list; did anyone have a chance to look at his patch, perchance? It was still sitting in my ever-longer queue; sorry. I think a fix for this issue would be a lot easier for me together with a testcase (along the lines of HEAD's tests/template.at) that exposes this issue. A small self-contained (portable!) example would be a good start. This helps ensure that we don't regress with other unrelated compilers. (And testing will then allow me to evaluate whether the patch Peter suggested is good enough.) Thanks, Ralf -- Jeff Squyres Cisco Systems ___ Bug-libtool mailing list Bug-libtool@gnu.org http://lists.gnu.org/mailman/listinfo/bug-libtool