Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 27 - Undefined interface functions when inheriting from two sources.
Summary: Undefined interface functions when inheriting from two sources.
Status: RESOLVED FIXED
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: development
Hardware: x86 Linux
: --- normal
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2012-12-04 03:08 CET by Daniel Green
Modified: 2015-04-08 22:00 CEST (History)
0 users

See Also:


Attachments
A.s - Assembly output of A.d (4.26 KB, text/plain)
2012-12-04 03:09 CET, Daniel Green
Details
B.s - Assembly output of B.d (3.12 KB, text/plain)
2012-12-04 03:09 CET, Daniel Green
Details
main.s - Assembly output of main.d (7.09 KB, text/plain)
2012-12-04 03:09 CET, Daniel Green
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Green 2012-12-04 03:08:55 CET
When an interface is inherited from multiple sources this will result in undefined functions.

This occurs when a class inherits an interface from another class and from another class and from the interface itself.  See the source for the when this occurs.

This will also only occur when the inheritance is separated.  If all definitions reside in the same file then the undefined reference goes away.  

This looks like it may be thunk related.

$ gdc A.d B.d
/tmp/ccg0h4le.o:(.data+0x180): undefined reference to `_DT24_D1A3C_A1aMFZb'
collect2: error: ld returned 1 exit status

$ nm -A *.o | grep D1A3C_A1aMFZb
A.o:0000000000000000 T _D1A3C_A1aMFZb
A.o:000000000000006c T _DT16_D1A3C_A1aMFZb
B.o:                 U _D1A3C_A1aMFZb
B.o:                 U _DT24_D1A3C_A1aMFZb

$ gdc main.d
$ # Success

$ nm -A main.o | grep A1aMFZb
main.o:0000000000000000 T _D4main3C_A1aMFZb
main.o:0000000000000072 T _DT16_D4main3C_A1aMFZb
main.o:000000000000006c T _DT24_D4main3C_A1aMFZb


=== B.d === 
module B;

import A;

interface I_B : I_A
{
    void b();
}

abstract class C_B : C_A, I_B
{
        abstract void b();
}

// required to get it to try linking.
void main(){}

=== A.d ===

module A;

interface I_A
{
        bool a();
}


class C_A : I_A
{
        bool a()
        { return false; }
}


=== main.d ===
interface I_A
{
        bool a();
}


class C_A : I_A
{
        bool a()
        { return false; }
}

interface I_B : I_A
{
    void b();
}

abstract class C_B : C_A, I_B
{
        abstract void b();
}

void main(){}
Comment 1 Daniel Green 2012-12-04 03:09:22 CET
Created attachment 16 [details]
A.s - Assembly output of A.d
Comment 2 Daniel Green 2012-12-04 03:09:42 CET
Created attachment 17 [details]
B.s - Assembly output of B.d
Comment 3 Daniel Green 2012-12-04 03:09:58 CET
Created attachment 18 [details]
main.s - Assembly output of main.d
Comment 4 Daniel Green 2012-12-04 03:10:31 CET
This error occurs with head using GCC 4.8 on linux.
Comment 5 Daniel Green 2012-12-04 03:10:50 CET
This occurs with head on GCC 4.8 on linux.
Comment 6 Daniel Green 2013-01-08 18:41:52 CET
This is identical to the thunk issue we had a while ago.  It broke with this change.

https://github.com/D-Programming-GDC/GDC/commit/cd8bb6d03ae3134a4976689eab312e2bb57701fc#gcc/d/d-objfile.cc

weakref allowed the Thunk symbol to be associated with the actual symbol.  Switching to WEAK provides no such association.

Additionally, the weakref solution doesn't work for MinGW resulting in rather interesting crashes.  Mostly an issue with binutils and some obscure interaction I couldn't trace.

The solution is the same as before and a pull request has been made.  https://github.com/D-Programming-GDC/GDC/pull/42
Comment 7 Iain Buclaw 2013-03-13 10:48:42 CET
https://github.com/D-Programming-GDC/GDC/commit/1526e44f38f888531c1032e17068dcef9fdd0df8


Does the weakref solution still produce phantom crashes in binutils for MinGW?
Comment 8 Daniel Green 2013-03-13 15:42:08 CET
> Does the weakref solution still produce phantom crashes in binutils for MinGW?

Looks good.  Couldn't reproduce the weakref crashes and some more complicated testcases passed.
Comment 9 Iain Buclaw 2013-03-13 16:23:16 CET
Wicked, thanks Daniel.
Comment 10 Iain Buclaw 2013-08-07 14:35:45 CEST
Re-opening bug report.