This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/17480] New: collect2 on AIX calls static constructors of unreferenced object modules


I'am working on a porting job to several unix platforms. The build process puts
(not very cleverly) all possible needed libs on the link line, and leaves it to
the linker to skip what is not needed.
This works on all platforms, except that the executables on AIX become huge, and
unexpected external libraries are needed when linking.

The problem is in collect2. It scans all objects and libraries for possible
static  objects, and generates extra c code to call the
constructors/destructors. It does that before ld has the changes to skip the
unnecessary libraries and object files.
The resulting code is not only very big, but behaves differently from other
platforms, because extra constructor calls are made.

gcc versions: 3.3.2, 3.3.3, 3.4.2

gcc -v:
Reading specs from /home/huminf/tools/lib/gcc-lib/powerpc-ibm-aix5.1.0.0/3.3.2/specs
Configured with: ../gcc-3.3.2/configure --prefix=/home/huminf/tools :
(reconfigured) ../gcc-3.3.2/configure --prefix=/home/huminf/tools
--enable-languages=c,c++
Thread model: aix
gcc version 3.3.2

A minimal example consists of the following files. The code links on non AIX
platforms, and prints 'a'.
It does not link on AIX, and the output of main2 is 'F a'.

$ cat a.cxx
#include <stdio.h>

void a() {
        printf("a\n");
}

$ cat b1.cxx
#include <stdio.h>

extern void c();

void bc() {
  printf("b\n");
  c();
}

$ cat b2.cxx
#include <stdio.h>

class F {
  public:
  F() {
        printf("F()\n");
  }
};

static F f;

$ cat makefile
#CXX=xlC
CXX=g++

all: main2 main1

# no need for b1.o (in libab.a)  so no need for c.o
main1: main.o libab1.a
        $(CXX) -o main1 main.o -L. -lab1

# no need for b2.o so static constructor should not be called
main2: main.o libab2.a
        $(CXX) -o main2 main.o -L. -lab2


%.o: %.cxx
        $(CXX) -c -o $@ $<

libab1.a: a.o b1.o
        ar r libab1.a a.o b1.o

libab2.a: a.o b2.o
        ar r libab2.a a.o b2.o

clean:
        -rm *.o
        -rm *.a
        -rm main?

-- 
           Summary: collect2 on AIX calls static constructors of
                    unreferenced object modules
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: harco dot de dot hilster at ATConsultancy dot nl
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-ibm-aix5.1.0.0
  GCC host triplet: powerpc-ibm-aix5.1.0.0
GCC target triplet: powerpc-ibm-aix5.1.0.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17480


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]