Bug 25908 - [4.2 Regression] vtables with vague linkage is not being marked as vague on darwin
Summary: [4.2 Regression] vtables with vague linkage is not being marked as vague on d...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure
Depends on:
Blocks: 25925
  Show dependency treegraph
 
Reported: 2006-01-22 00:51 UTC by Erik Schnetter
Modified: 2006-03-02 02:27 UTC (History)
5 users (show)

See Also:
Host:
Target: *-*-darwin*
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-01-23 19:52:17


Attachments
Gzipped preprocessed failing source code, part 1 (25.30 KB, application/octet-stream)
2006-01-23 19:47 UTC, Erik Schnetter
Details
Gzipped preprocessed failing source code, part 2 (25.29 KB, application/octet-stream)
2006-01-23 19:47 UTC, Erik Schnetter
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Erik Schnetter 2006-01-22 00:51:07 UTC
I use gcc (GCC) 4.2.0 20060120 to compile Cactus, a large piece of code combining C, C++, and Fortran.  I receive many errors from the linker like

/usr/bin/ld: multiple definitions of symbol typeinfo for MPI::Op
/Users/eschnett/Calpha/configs/einstein-orange-gcc-debug/lib/libthorn_Carpet.a(helpers.cc.o) definition of typeinfo for MPI::Opin section (__DATA,__const)
/Users/eschnett/Calpha/configs/einstein-orange-gcc-debug/lib/libthorn_CarpetAdaptiveRegrid.a(CAR.cc.o) definition of typeinfo for MPI::Opin section (__DATA,__const)

or

/usr/bin/ld: multiple definitions of symbol vtable for MPI::Op
/Users/eschnett/Calpha/configs/einstein-orange-gcc-debug/lib/libthorn_Carpet.a(helpers.cc.o) definition of vtable for MPI::Opin section (__DATA,__const)
/Users/eschnett/Calpha/configs/einstein-orange-gcc-debug/lib/libthorn_CarpetAdaptiveRegrid.a(CAR.cc.o) definition of vtable for MPI::Opin section (__DATA,__const)

(Note that the error messages seem run-together; e.g. "MPI::OPin" seems to refer to the class "MPI::Op", which is located IN a certain section.)

These errors are not there with gcc (GCC) 4.2.0 20051129.  The code also works fine on many other architectures.  But with C++, I am not sure what the reason is.

I have looked on the web, and the gcc PR "[Bug c++/16218] Link problems with inline virtual function in multiple translation units" seems similar.  At that time, it apparently was an error in gcc that caused this problem.



I use the linker /usr/bin/ld
Apple Computer, Inc. version cctools-590.18.obj~10

and these C++ classes are defined in LAM MPI 7.0.6-11, which I installed via fink.
Comment 1 Andrew Pinski 2006-01-23 16:19:30 UTC
Do you have a simple example?
Comment 2 Erik Schnetter 2006-01-23 19:45:50 UTC
Here is a way to reproduce the error with very little source code, but still depending on the LAM MPI library.  The actual source code I used consists of two files, main.cc and sub.cc, which I include here for completeness:

main.cc:
#include <mpi.h>

int
main (int argc, char * argv[])
{
  return 0;
}

sub.cc:
#include <mpi.h>

void
sub ()
{
}



I preprocessed these with "g++ -E", and I attach the results.  When I compile the preprocessed sources, I get:

$ ~/gcc-new/bin/g++ -o lamtest main.ii sub.ii
/usr/bin/ld: multiple definitions of symbol typeinfo for MPI::Op
/var/tmp//ccFSbBVd.o definition of typeinfo for MPI::Opin section (__DATA,__const)
/var/tmp//cc8Rm38U.o definition of typeinfo for MPI::Opin section (__DATA,__const)
/usr/bin/ld: multiple definitions of symbol typeinfo for PMPI::Op
/var/tmp//ccFSbBVd.o definition of typeinfo for PMPI::Opin section (__DATA,__const)
/var/tmp//cc8Rm38U.o definition of typeinfo for PMPI::Opin section (__DATA,__const)
/usr/bin/ld: multiple definitions of symbol typeinfo for PMPI::Comm
/var/tmp//ccFSbBVd.o definition of typeinfo for PMPI::Commin section (__DATA,__const)
/var/tmp//cc8Rm38U.o definition of typeinfo for PMPI::Commin section (__DATA,__const)

(and many more warnings like that).
Comment 3 Erik Schnetter 2006-01-23 19:47:02 UTC
Created attachment 10715 [details]
Gzipped preprocessed failing source code, part 1
Comment 4 Erik Schnetter 2006-01-23 19:47:21 UTC
Created attachment 10716 [details]
Gzipped preprocessed failing source code, part 2
Comment 5 Andrew Pinski 2006-01-23 19:51:49 UTC
I think that is enough to reproduce it for now.

Thanks, when my computer (laptop) gets back up and working, I will look into this.

I think this was caused by the section changes.
Comment 6 Andrew Pinski 2006-01-24 20:04:12 UTC
Trying to reduce this failure.  (I can reproduce it on today's compiler).
Comment 7 Andrew Pinski 2006-01-24 20:14:12 UTC
Reduced testcase:
file1.cc:
class f
{
  virtual void g();
};
inline void f::g()
{}
int sub(void)
{}
file2.cc:
class f
{
  virtual void g();
};
inline void f::g()
{}
int main(void)
{}


------

Now why does this work if I add inline to the method inside the declaration of the class.
Comment 8 Andrew Pinski 2006-01-24 20:20:21 UTC
Hmm, this testcase works correctly on x86_64-linux-gnu, in that the vtable is marked as weak.
Comment 9 Andrew Pinski 2006-01-24 20:28:27 UTC
Just to clarify with "gcc (GCC) 4.2.0 20051129", you were able to compile the example you gave in comment #2?
Comment 10 Erik Schnetter 2006-01-24 21:09:18 UTC
Yes, I am able to compile the code with that version:

$ ~/gcc/bin/g++ --version
g++ (GCC) 4.2.0 20051129 (experimental)

$ ~/gcc/bin/g++ -o lamtest *.ii -L/sw/lib -llammpio -llammpi++ -lmpi -llam
Comment 11 Andrew Pinski 2006-01-24 22:53:55 UTC
It was broken before "20051231".  So we are done to a month.
Comment 12 Andrew Pinski 2006-01-25 00:04:36 UTC
It worked in "20051203".
Comment 13 Andrew Pinski 2006-01-25 01:06:34 UTC
It was broken in "20051217". so only two weeks now.
Comment 14 Andrew Pinski 2006-01-25 01:10:34 UTC
Nathan sorry for CCing you (that was accident).
Comment 15 Andrew Pinski 2006-01-25 02:14:33 UTC
Fails in "20051210".
Comment 16 Andrew Pinski 2006-01-25 03:40:22 UTC
Before the breakage:
        .globl __ZTV1f
        .weak_definition __ZTV1f
        .section __DATA,__const_coal,coalesced

After:
        .globl __ZTV1f
        .const_data

We are doing two things wrong, not marking this as weak and then not putting it into the coalesced section.
Comment 17 Andrew Pinski 2006-01-25 03:51:48 UTC
Caused by:
        (machopic_select_section): Return the selected section rather than
        emitting assembly code.  Replace the static function table with
        inline conditional expressions.  Update the tests of last_text_section
        and move them into the FUNCTION_DECL block.


I have to figure out why.
Comment 18 Andrew Pinski 2006-01-25 03:58:18 UTC
Or maybe not.  More likely the TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT changes.
Comment 19 Andrew Pinski 2006-01-25 04:07:45 UTC
I might need some C++ help on this one but I think this is valid as the virtual function is marked as inline so it is vague but can that be a key function?
Comment 20 Andrew Pinski 2006-01-25 04:39:21 UTC
Found the problem and a way to fix it.  The problem is that the key function needs to be changed to the  arm-eabi way and not the IA64 C++ ABI way.

See http://gcc.gnu.org/ml/gcc-patches/2004-08/msg02645.html for the ARM-eabi way.
Comment 21 Andrew Pinski 2006-01-25 04:44:40 UTC
To remind me, I should enable g++.dg/abi/key1.C on *-darwin.
Comment 22 Andrew Pinski 2006-01-26 15:32:49 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2006-01/msg01843.html
Comment 23 Andrew Pinski 2006-02-20 23:48:02 UTC
I am no longer going to work on this, it is too much hassle for me to get this fixed.
Comment 24 Mike Stump 2006-02-22 22:11:25 UTC
Submitted patch to fix this http://gcc.gnu.org/ml/gcc-patches/2006-02/msg01705.html
Comment 25 mrs@gcc.gnu.org 2006-03-02 02:20:58 UTC
Subject: Bug 25908

Author: mrs
Date: Thu Mar  2 02:20:54 2006
New Revision: 111632

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=111632
Log:
	PR darwin/25908
	* decl2.c (import_export_decl): Fix ABI breakage on darwin.

	* g++.dg/abi/key2.C: Add.

Added:
    trunk/gcc/testsuite/g++.dg/abi/key2.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/decl2.c
    trunk/gcc/testsuite/ChangeLog

Comment 26 Andrew Pinski 2006-03-02 02:27:16 UTC
Fixed, thanks Mike for fixing this one.