Bug 51832 - [4.7 regression] Rev.182970 causes LTO link errors (multiple definitions of allocator_traits)
Summary: [4.7 regression] Rev.182970 causes LTO link errors (multiple definitions of a...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P1 normal
Target Milestone: 4.7.0
Assignee: Jason Merrill
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-12 01:24 UTC by Markus Trippelsdorf
Modified: 2012-01-22 20:57 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-01-14 00:00:00


Attachments
testcase patch (1.51 KB, text/plain)
2012-01-14 07:48 UTC, Markus Trippelsdorf
Details
libxul link error log (4.96 KB, text/plain)
2012-01-19 09:34 UTC, Markus Trippelsdorf
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2012-01-12 01:24:15 UTC
Rev.182970 causes LTO link errors because of multiple definitions that all start with '_ZNSt16allocator_traits', e.g.:

c++ -o elfhack -fno-rtti -Wall -Wpointer-arith -Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wcast-align -Wno-invalid-offsetof -Wno-variadic-macros -Werror=return-type -Wno-long-long -march=native -flto=4 -fno-fat-lto-objects -Wno-delete-non-virtual-dtor -fno-strict-aliasing -std=gnu++0x -pthread -ffunction-sections -pipe -fexceptions  -DNDEBUG -DTRIMMED -Os -freorder-blocks  -fomit-frame-pointer -lpthread -fuse-linker-plugin -Wl,-O1,--hash-style=gnu,--as-needed,--no-keep-memory,--gc-sections -Wl,--icf=safe  -Wl,-rpath-link,/var/tmp/mozilla-central/moz-build-dir/dist/bin -Wl,-rpath-link,/usr/lib  host_elf.o host_elfhack.o  
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: host_elfhack.o: multiple definition of '_ZNSt16allocator_traitsISaIP10ElfSegmentEE18__construct_helperIS1_JRKS1_EE5valueE'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: host_elf.o: previous definition here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: host_elfhack.o: multiple definition of '_ZNSt16allocator_traitsISaIN17ElfStrtab_Section13table_storageEEE18__construct_helperIS1_JS1_EE5valueE'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: host_elf.o: previous definition here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: host_elfhack.o: multiple definition of '_ZNSt16allocator_traitsISaI7Elf_RelEE18__construct_helperIS0_JRKS0_EE5valueE'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: host_elf.o: previous definition here
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: host_elfhack.o: multiple definition of '_ZNSt16allocator_traitsISaI8Elf_RelaEE18__construct_helperIS0_JRKS0_EE5valueE'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: host_elf.o: previous definition here
collect2: error: ld returned 1 exit status
make[1]: *** [elfhack] Error 1

2d847c181ef6fc581d0c915678dedd66e3fdaa15 is the first bad commit
commit 2d847c181ef6fc581d0c915678dedd66e3fdaa15
Author: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Date:   Fri Jan 6 21:39:43 2012 +0000

        PR c++/6057
        PR c++/48051
        PR c++/50855
        PR c++/51322
    gcc/cp/
        * mangle.c (write_expression): Support NEW_EXPR, DELETE_EXPR,
        THROW_EXPR, CONSTRUCTOR, OVERLOAD.  Fix PREINCREMENT_EXPR and
        PREDECREMENT_EXPR.
        (write_template_arg): Fix mangling of class-scope functions and
        argument packs.
        (mangle_decl): Update suggested -fabi-version argument.
        * operators.def: Add DOTSTAR_EXPR, REINTERPRET_CAST_EXPR,
        DYNAMIC_CAST_EXPR; correct CONST_CAST_EXPR, STATIC_CAST_EXPR.
        * tree.c (dependent_name): No longer static.
        * cp-tree.h: Declare it.
        * pt.c (unify): Defer handling of unconverted functions.
    include/
        * demangle.h (enum demangle_component_type): Add
        DEMANGLE_COMPONENT_INITIALIZER_LIST, DEMANGLE_COMPONENT_NULLARY.
    libiberty/
        * cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_NULLARY and
        DEMANGLE_COMPONENT_INITIALIZER_LIST.
        (d_make_comp): Likewise.  Allow null right arg for
        DEMANGLE_COMPONENT_TRINARY_ARG2.
        (cplus_demangle_operators): Adjust new/delete; add .*, :: and throw.
        (d_template_args, d_template_arg): Handle 'J' for argument packs.
        (d_exprlist): Add terminator parm.
        (d_expression, d_print_comp): Handle initializer lists, nullary
        expressions, prefix/suffix operators, and new.
        (d_print_subexpr): Avoid parens around DEMANGLE_COMPONENT_QUAL_NAME
        and DEMANGLE_COMPONENT_INITIALIZER_LIST.
        * testsuite/demangle-expected: Add tests.
    
    git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182970 138bc75d-0d04-0410-961f-82ee72b054a4
Comment 1 Richard Biener 2012-01-12 08:54:23 UTC
Can you attach preprocessed sources to reproduce this?
Comment 2 Markus Trippelsdorf 2012-01-12 09:06:57 UTC
(In reply to comment #1)
> Can you attach preprocessed sources to reproduce this?

I've reduced it to this snipped:

 % cat foo.cpp
#include <vector>

struct foo
{
  void bar ()
  {
    s.push_back (0);
  }
  std::vector <int> s;
};

 % g++ foo.cpp foo.cpp -flto -std=gnu++0x
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: /tmp/ccZEKdVj.o: multiple definition of '_ZNSt16allocator_traitsISaIiEE18__construct_helperIiJiEE5valueE'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/cc1lLTi3.o: previous definition here
../sysdeps/x86_64/elf/start.S:109: error: undefined reference to 'main'
collect2: error: ld returned 1 exit statu
Comment 3 Markus Trippelsdorf 2012-01-12 12:11:03 UTC
g++ -fabi-version=6 -shared foo.cpp foo.cpp -flto -std=c++11
is fine BTW.
Comment 4 Jason Merrill 2012-01-12 15:25:55 UTC
(In reply to comment #2)
> error: /tmp/ccZEKdVj.o: multiple definition of
> '_ZNSt16allocator_traitsISaIiEE18__construct_helperIiJiEE5valueE'

That symbol is an extra-name alias for

std::allocator_traits<std::allocator<int> >::__construct_helper<int, int>::value

created by mangle_decl for forward ABI compatibility.

But I can't reproduce the bug; that variable isn't emitted at all when I compile the reduced testcase with r183124.
Comment 5 Markus Trippelsdorf 2012-01-12 16:15:32 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > error: /tmp/ccZEKdVj.o: multiple definition of
> > '_ZNSt16allocator_traitsISaIiEE18__construct_helperIiJiEE5valueE'
> 
> That symbol is an extra-name alias for
> 
> std::allocator_traits<std::allocator<int> >::__construct_helper<int,
> int>::value
> 
> created by mangle_decl for forward ABI compatibility.
> 
> But I can't reproduce the bug; that variable isn't emitted at all when I
> compile the reduced testcase with r183124.

Hmm, that's strange.

I've updated binutils and gcc just to double-check and it still fails:

(Please note that foo.cpp occurs _twice_ below)
 % g++ -shared foo.cpp foo.cpp -flto -std=c++11 --save-temps
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: foo.o: multiple definition of 'std::allocator_traits<std::allocator<int> >::__construct_helper<int, int>::value'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: foo.o: previous definition here
[Leaving LTRANS /tmp/ccXhj6nz.args]
[Leaving LTRANS /tmp/ccLh8B76.ltrans.out]
[Leaving LTRANS /tmp/ccIB53Wt.args]
[Leaving LTRANS /tmp/ccLh8B76.ltrans0.o]
collect2: error: ld returned 1 exit status

 % < foo.res
2
foo.o 2
164 ac8416e1b427b8aa PREVAILING_DEF_IRONLY_EXP _ZNSt16allocator_traitsISaIiEE18__construct_helperIiJiEE5valueE
170 ac8416e1b427b8aa UNDEF _ZNSt16allocator_traitsISaIiEE18__construct_helperIiIiEE5valueE
foo.o 2
164 ac8416e1b427b8aa PREEMPTED_IR _ZNSt16allocator_traitsISaIiEE18__construct_helperIiJiEE5valueE
170 ac8416e1b427b8aa UNDEF _ZNSt16allocator_traitsISaIiEE18__construct_helperIiIiEE5valueE

 % gcc -v
Using built-in specs.
COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.0/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.0 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.0 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.0/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.0/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-lto --enable-nls --without-included-gettext --with-system-zlib --disable-werror --enable-initfini-array --with-gold --enable-secureplt --disable-multilib --enable-libmudflap --disable-libssp --enable-libgomp --enable-cld --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.7.0/python --enable-checking=release --disable-libgcj --enable-languages=c,c++ --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --with-build-config=bootstrap-lto --with-boot-ldflags=-Wl,-O1,--hash-style=gnu,--as-needed,--gc-sections,--icf=all,--icf-iterations=3 --enable-version-specific-runtime-libs --disable-libstdcxx-pch --enable-libstdcxx-time=yes
Thread model: posix
gcc version 4.7.0 20120112 (experimental) (GCC) 

 % ld -v
GNU gold (GNU Binutils 2.22.51.20120112) 1.11
Comment 6 Jason Merrill 2012-01-13 18:55:24 UTC
I still can't reproduce this on x86_64-pc-linux-gnu.  I notice that you have a lot of configure flags in your gcc -v output; mine is just

/home/jason/src/trunk/configure -v --with-mpfr=/opt/cfarm/mpfr --with-gmp=/opt/cfarm/gmp --with-mpc=/opt/cfarm/mpc --with-libelf=/opt/cfarm/libelf --enable-languages=all,obj-c++ --enable-checking

Can you try rebuilding the compiler with different configure flags and see if one of them is causing this difference?  I tried building the compiler with all your configure flags, but it seems to result in a broken stage1 compiler for me.
Comment 7 Markus Trippelsdorf 2012-01-13 21:25:48 UTC
(In reply to comment #6)
> I still can't reproduce this on x86_64-pc-linux-gnu.  I notice that you have a
> lot of configure flags in your gcc -v output; mine is just
> 
> /home/jason/src/trunk/configure -v --with-mpfr=/opt/cfarm/mpfr
> --with-gmp=/opt/cfarm/gmp --with-mpc=/opt/cfarm/mpc
> --with-libelf=/opt/cfarm/libelf --enable-languages=all,obj-c++
> --enable-checking
> 
> Can you try rebuilding the compiler with different configure flags and see if
> one of them is causing this difference?  I tried building the compiler with all
> your configure flags, but it seems to result in a broken stage1 compiler for
> me.

Even the most minimal config fails on my machine:
 gcc_build_dir % ../gcc/configure --disable-multilib --enable-checking --enable-languages=c,c++
 gcc_build_dir % make -j4

My gcc git clone is clean:
 gcc % git status
# On branch master
nothing to commit (working directory clean)

Can anybody else except Jason reproduce this issue?
Comment 8 Markus Trippelsdorf 2012-01-14 07:48:35 UTC
Created attachment 26320 [details]
testcase patch

I've attached the original reduced testcase.

markus@x4 allocator_lto_testcase % patch -p0 < testcase.patch
patching file foo.cpp
patching file Makefile
patching file test2.ii
patching file test.ii
markus@x4 allocator_lto_testcase % make
g++ -shared test.ii test2.ii -flto -std=gnu++0x
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: error: /tmp/cc16CrQE.o: multiple definition of 'std::allocator_traits<std::allocator<ElfSegment*> >::__construct_helper<ElfSegment*, ElfSegment* const&>::value'
/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.0/../../../../x86_64-pc-linux-gnu/bin/ld: /tmp/ccd65lbL.o: previous definition here
collect2: error: ld returned 1 exit status
make: *** [all] Error 1
Comment 9 Marc Glisse 2012-01-14 09:56:20 UTC
(In reply to comment #7)
> Can anybody else except Jason reproduce this issue?

It does happen with the gcc I built yesterday on an up-to-date debian testing box (using the testcase from comment #2). Just so you know you're not the only one...

stedding /tmp $ /tmp/gcc-2012-01-13/inst/bin/g++ foo.cpp foo.cpp -flto -std=gnu++0x -v
Using built-in specs.
COLLECT_GCC=/tmp/gcc-2012-01-13/inst/bin/g++
COLLECT_LTO_WRAPPER=/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /data/repos/gcc/trunk/configure --prefix=/tmp/gcc-2012-01-13/inst --enable-languages=c,c++ --with-system-zlib --disable-nls --enable-libstdcxx-time=yes
Thread model: posix
gcc version 4.7.0 20120113 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-flto' '-std=gnu++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/cc1plus -quiet -v -D_GNU_SOURCE foo.cpp -quiet -dumpbase foo.cpp -mtune=generic -march=x86-64 -auxbase foo -std=gnu++11 -version -flto -o /tmp/ccsHpwDx.s
GNU C++ (GCC) version 4.7.0 20120113 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.0 20120113 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/x86_64-unknown-linux-gnu
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/backward
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include
 /usr/local/include
 /tmp/gcc-2012-01-13/inst/include
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.7.0 20120113 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.0 20120113 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: fd54b59ce46d25c505f29ce3b2761268
COLLECT_GCC_OPTIONS='-flto' '-std=gnu++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as --64 -o /tmp/ccYykeUv.o /tmp/ccsHpwDx.s
COLLECT_GCC_OPTIONS='-flto' '-std=gnu++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/cc1plus -quiet -v -D_GNU_SOURCE foo.cpp -quiet -dumpbase foo.cpp -mtune=generic -march=x86-64 -auxbase foo -std=gnu++11 -version -flto -o /tmp/ccsHpwDx.s
GNU C++ (GCC) version 4.7.0 20120113 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.0 20120113 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
ignoring nonexistent directory "/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../x86_64-unknown-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/x86_64-unknown-linux-gnu
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../include/c++/4.7.0/backward
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include
 /usr/local/include
 /tmp/gcc-2012-01-13/inst/include
 /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/include-fixed
 /usr/include
End of search list.
GNU C++ (GCC) version 4.7.0 20120113 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.0 20120113 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: fd54b59ce46d25c505f29ce3b2761268
COLLECT_GCC_OPTIONS='-flto' '-std=gnu++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 as --64 -o /tmp/ccsaZaCu.o /tmp/ccsHpwDx.s
COMPILER_PATH=/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-flto' '-std=gnu++11' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/collect2 -plugin /tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/liblto_plugin.so -plugin-opt=/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper -plugin-opt=-fresolution=/tmp/cch9gflt.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -flto --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/x86_64-linux-gnu/crt1.o /usr/lib/x86_64-linux-gnu/crti.o /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/crtbegin.o -L/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0 -L/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../.. /tmp/ccYykeUv.o /tmp/ccsaZaCu.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/crtend.o /usr/lib/x86_64-linux-gnu/crtn.o
/tmp/ccsaZaCu.o (symbol from plugin): In function `_ZNSt16allocator_traitsISaIiEE18__construct_helperIiJiEE5valueE':
(.text+0x0): multiple definition of `_ZNSt16allocator_traitsISaIiEE18__construct_helperIiJiEE5valueE'
/tmp/ccYykeUv.o (symbol from plugin):(.text+0x0): first defined here
 /tmp/gcc-2012-01-13/inst/bin/g++ @/tmp/ccBqjU1Y.args

*** HERE ***

Using built-in specs.
COLLECT_GCC=/tmp/gcc-2012-01-13/inst/bin/g++
COLLECT_LTO_WRAPPER=/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /data/repos/gcc/trunk/configure --prefix=/tmp/gcc-2012-01-13/inst --enable-languages=c,c++ --with-system-zlib --disable-nls --enable-libstdcxx-time=yes
Thread model: posix
gcc version 4.7.0 20120113 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-c' '-fexceptions' '-mtune=generic' '-march=x86-64' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-fltrans-output-list=/tmp/ccuNACe0.ltrans.out' '-fwpa' '-fresolution=/tmp/cch9gflt.res' '-shared-libgcc'
 /tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto1 -quiet -dumpbase ccYykeUv.o -mtune=generic -march=x86-64 -mtune=generic -march=x86-64 -auxbase ccYykeUv -version -fexceptions -fltrans-output-list=/tmp/ccuNACe0.ltrans.out -fwpa -fresolution=/tmp/cch9gflt.res @/tmp/ccerJ79Z
GNU GIMPLE (GCC) version 4.7.0 20120113 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.0 20120113 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU GIMPLE (GCC) version 4.7.0 20120113 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.0 20120113 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
COMPILER_PATH=/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/../lib64/:/lib/../lib64/../lib64/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/:/lib/../lib64/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/:/lib/../lib64/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../:/lib/:/usr/lib/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-c' '-fexceptions' '-mtune=generic' '-march=x86-64' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-fltrans-output-list=/tmp/ccuNACe0.ltrans.out' '-fwpa' '-fresolution=/tmp/cch9gflt.res' '-shared-libgcc'
 /tmp/gcc-2012-01-13/inst/bin/g++ @/tmp/ccUCMFEW.args
Using built-in specs.
COLLECT_GCC=/tmp/gcc-2012-01-13/inst/bin/g++
COLLECT_LTO_WRAPPER=/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /data/repos/gcc/trunk/configure --prefix=/tmp/gcc-2012-01-13/inst --enable-languages=c,c++ --with-system-zlib --disable-nls --enable-libstdcxx-time=yes
Thread model: posix
gcc version 4.7.0 20120113 (experimental) (GCC) 
COLLECT_GCC_OPTIONS='-c' '-fexceptions' '-mtune=generic' '-march=x86-64' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-fltrans-output-list=/tmp/ccuNACe0.ltrans.out' '-fltrans' '-o' '/tmp/ccuNACe0.ltrans0.ltrans.o' '-shared-libgcc'
 /tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto1 -quiet -dumpbase ccuNACe0.ltrans0.o -mtune=generic -march=x86-64 -mtune=generic -march=x86-64 -auxbase-strip /tmp/ccuNACe0.ltrans0.ltrans.o -version -fexceptions -fltrans-output-list=/tmp/ccuNACe0.ltrans.out -fltrans @/tmp/cc43FwAY -o /tmp/ccZ2MaqX.s
GNU GIMPLE (GCC) version 4.7.0 20120113 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.0 20120113 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU GIMPLE (GCC) version 4.7.0 20120113 (experimental) (x86_64-unknown-linux-gnu)
	compiled by GNU C version 4.7.0 20120113 (experimental), GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
COLLECT_GCC_OPTIONS='-c' '-fexceptions' '-mtune=generic' '-march=x86-64' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-fltrans-output-list=/tmp/ccuNACe0.ltrans.out' '-fltrans' '-o' '/tmp/ccuNACe0.ltrans0.ltrans.o' '-shared-libgcc'
 as --64 -o /tmp/ccuNACe0.ltrans0.ltrans.o /tmp/ccZ2MaqX.s
COMPILER_PATH=/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/libexec/gcc/x86_64-unknown-linux-gnu/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/
LIBRARY_PATH=/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/../lib64/:/lib/../lib64/../lib64/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/:/lib/../lib64/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/:/lib/../lib64/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../../lib64/:/lib/../lib64/:/usr/lib/x86_64-linux-gnu/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../:/lib/:/usr/lib/:/tmp/gcc-2012-01-13/inst/lib/gcc/x86_64-unknown-linux-gnu/4.7.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-c' '-fexceptions' '-mtune=generic' '-march=x86-64' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-fltrans-output-list=/tmp/ccuNACe0.ltrans.out' '-fltrans' '-o' '/tmp/ccuNACe0.ltrans0.ltrans.o' '-shared-libgcc'
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 0 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 1 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 2 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 3 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 4 has invalid symbol index 11
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 5 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 6 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 7 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 8 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 9 has invalid symbol index 2
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 10 has invalid symbol index 12
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 11 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 12 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 13 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 14 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 15 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 16 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 17 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 18 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 19 has invalid symbol index 13
/usr/bin/ld: /usr/lib/debug/usr/lib/x86_64-linux-gnu/crt1.o(.debug_info): relocation 20 has invalid symbol index 20
/usr/lib/x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

(the relocation errors at the end are just because of the missing "main")

stedding /tmp $ ld -v
GNU ld (GNU Binutils for Debian) 2.22
Comment 10 Richard Biener 2012-01-16 10:53:48 UTC
I can't reproduce it with the reduced testcase but _can_ reproduce it with
test.ii test2.ii from the attachment.

trunk-g/gcc> ./g++ -B. /tmp/test.ii /tmp/test2.ii -std=gnu++0x -B ../x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/ -flto 
/tmp/ccaH7unB.o (symbol from plugin): In function `_ZNSt16allocator_traitsISaIP10ElfSegmentEE18__construct_helperIS1_JRKS1_EE5valueE':
(.text+0x0): multiple definition of `_ZNSt16allocator_traitsISaIP10ElfSegmentEE18__construct_helperIS1_JRKS1_EE5valueE'
/tmp/ccsJ08q0.o (symbol from plugin):(.text+0x0): first defined here
/usr/lib/../lib64/crt1.o: In function `_start':
/usr/src/packages/BUILD/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
collect2: error: ld returned 1 exit status


trunk-g/gcc> ./g++ -B. /tmp/test.ii /tmp/test2.ii -std=gnu++0x -B ../x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs/ 
/usr/lib/../lib64/crt1.o: In function `_start':
/usr/src/packages/BUILD/glibc-2.9/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
collect2: error: ld returned 1 exit status


It does not reproduce when not using the linker plugin though and I am
using a linker that uses the v2 interface with the fancy COMDAT support
(the 2.22 release).
Comment 11 Jason Merrill 2012-01-16 22:17:42 UTC
This wasn't fixed by my patch for PR 51827, was it?
Comment 12 Markus Trippelsdorf 2012-01-16 22:52:09 UTC
(In reply to comment #11)
> This wasn't fixed by my patch for PR 51827, was it?

No, unfortunately not.
Comment 13 Markus Trippelsdorf 2012-01-19 09:34:07 UTC
Created attachment 26375 [details]
libxul link error log

BTW I've first observed this bug while building 
a PGO-LTO Firefox. The errors of the final libxul
link are attached (unrelated warnings have been deleted).
As you can see there are ~350 (closely related) errors altogether.
Comment 14 Jason Merrill 2012-01-19 15:16:04 UTC
I still can't reproduce this, either on my Fedora 14 i686 laptop or on gcc20.
Comment 15 Markus Trippelsdorf 2012-01-19 15:56:50 UTC
(In reply to comment #14)
> I still can't reproduce this, either on my Fedora 14 i686 laptop or on gcc20.

What binutils version are you running on both machines?
(is PREVAILING_DEF_IRONLY_EXP already supported?)

Is gcc20 a 64bit machine running a 64bit gcc?
Comment 16 Markus Trippelsdorf 2012-01-19 17:54:43 UTC
I've just checked my Fedora 15 image in KVM.
Here ld.bfd is fine and only ld.gold fails:

$ ld -v
GNU ld version 2.21.51.0.6-6.fc15 20110118
$ /home/markus/gcc/usr/local/bin/g++ test.ii test2.ii -flto -std=gnu++0x
/usr/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status

$ sudo ln -f /usr/bin/ld.gold /usr/bin/ld
$ ld -v
GNU gold (version 2.21.51.0.6-6.fc15 20110118) 1.10

$ /home/markus/gcc/usr/local/bin/g++ test.ii test2.ii -flto -std=gnu++0x
/usr/bin/ld: error: /tmp/ccOfbqWY.o: multiple definition of '_ZNSt16allocator_traitsISaIP10ElfSegmentEE18__construct_helperIS1_JRKS1_EE5valueE'
/usr/bin/ld: /tmp/ccQ2J7XR.o: previous definition here
/usr/bin/ld: /usr/lib/../lib64/crt1.o:(.text+0x20): error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
Comment 17 Markus Trippelsdorf 2012-01-19 18:18:03 UTC
I ran git bisected on ld.bfd. Since this commit my testcase fails:

4b96312bb623ba76b035ac3b3c5afe583bebca76 is the first bad commit
commit 4b96312bb623ba76b035ac3b3c5afe583bebca76
Author: Alan Modra <amodra@bigpond.net.au>
Date:   Sun Apr 17 23:15:11 2011 +0000

        PR ld/12365
        PR ld/12672
    bfd/
        * bfd.c (BFD_PLUGIN): Define.
        (BFD_FLAGS_SAVED, BFD_FLAGS_FOR_BFD_USE_MASK): Add BFD_PLUGIN.
        * bfd-in2.h: Regenerate.
        * elflink.c (elf_link_output_extsym): Strip undefined plugin syms.
        * opncls.c (bfd_make_readable): Don't lose original bfd flags.
    ld/
        * ldfile.c (ldfile_try_open_bfd): Don't attempt any plugin action
        when no_more_claiming.
        * ldmain.c (add_archive_element): Likewise.
        (multiple_definition): Remove plugin_multiple_definition call.
        (notice): Remove plugin_notice call.
        * ldlang.c (lang_list_insert_after, void lang_list_remove_tail): Move.
        Delete prototype.
        (plugin_insert): New static var.
        (open_input_bfds): Only rescan libs after plugin insert point.
        (lang_gc_sections): Omit plugin claimed files.
        (lang_process): Set plugin_insert.  Only rescan when plugin adds
        objects.
        * plugin.h (no_more_claiming): Declare.
        (plugin_notice, plugin_multiple_definition): Don't declare.
        * plugin.c: Formatting.
        (orig_notice_all, orig_allow_multiple_defs, orig_callbacks,
        plugin_callbacks): New static vars.
        (no_more_claiming): Make global.
        (plugin_cached_allow_multiple_defs): Delete.
        (plugin_get_ir_dummy_bfd): Set SEC_EXCLUDE on dummy .text section,
        use newer bfd_make_section variant.  Make COMMON section too.
        Error handling.  Correct setting of gp size.
        (asymbol_from_plugin_symbol): Properly cast last arg of concat.
        (message): Likewise for ACONCAT.
        (asymbol_from_plugin_symbol): Use our COMMON section.
        (get_symbols): When report_plugin_symbols, show visibility too.
        (init_non_ironly_hash): Move.  Don't test non_ironly_hash.
        (plugin_load_plugins): Save state of linker callbacks, set up to
        call plugin_notice instead.  Call init_non_ironly_hash here.
        (plugin_call_all_symbols_read): Set plugin_multiple_definition in
        plugin callbacks.
        (plugin_notice): Rewrite.
        (plugin_multiple_definition): Make static, call original callback.
    ld/testsuite/
        * ld-plugin/plugin-7.d: Adjust for plugin changes.
        * ld-plugin/plugin-8.d: Likewise.
        * ld-plugin/plugin.exp: Pass --verbose=2 for visibility test, and
        compare ld output to..
        * ld-plugin/plugin-12.d: New
Comment 18 Jason Merrill 2012-01-19 23:31:16 UTC
OK, I can reproduce it by adding binutils to the source tree.
Comment 19 Jason Merrill 2012-01-20 20:04:39 UTC
Patch posted to http://gcc.gnu.org/ml/gcc-patches/2012-01/msg01025.html
Comment 20 Jason Merrill 2012-01-22 20:56:37 UTC
Author: jason
Date: Sun Jan 22 20:56:34 2012
New Revision: 183396

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=183396
Log:
	PR c++/51832
	* varpool.c (varpool_analyze_pending_decls): Copy DECL_EXTERNAL
	for extra name aliases.

Added:
    trunk/gcc/testsuite/g++.dg/lto/pr51832.h
    trunk/gcc/testsuite/g++.dg/lto/pr51832_0.C
    trunk/gcc/testsuite/g++.dg/lto/pr51832_1.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/varpool.c
Comment 21 Jason Merrill 2012-01-22 20:57:06 UTC
Fixed.