Jump to page: 1 2
Thread overview
[Issue 9571] New: linkage issue when using separate compilation and closures
Feb 22, 2013
deadalnix
Feb 23, 2013
Denis Shelomovskij
Mar 10, 2013
Vladimir Panteleev
Mar 10, 2013
deadalnix
Apr 02, 2013
Dicebot
Apr 10, 2013
Dicebot
Apr 10, 2013
Martin Nowak
Apr 10, 2013
Dicebot
[Issue 9571] link error due to using unique ids in anonymous funcliteral
Apr 11, 2013
Martin Nowak
Apr 11, 2013
Martin Nowak
Apr 11, 2013
Dicebot
Sep 13, 2013
Dicebot
Sep 17, 2013
Kenji Hara
Sep 17, 2013
Kenji Hara
Sep 19, 2013
Kenji Hara
Sep 19, 2013
deadalnix
February 22, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571

           Summary: linkage issue when using separate compilation and
                    closures
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: deadalnix@gmail.com


--- Comment #0 from deadalnix <deadalnix@gmail.com> 2013-02-22 10:15:07 PST ---
a.d :

import std.array;

void main() {
    import b;
    foo(new A);
}

b.d :
module b;

class C {
}

class A {
    C[] cs;
}

import std.algorithm;
auto foo(A a) {
    auto b = new B;
    a.cs.map!((C c){ return b.visit(c); });
}

class B {
    C visit(C c) {
        return c;
    }
}

compilation :
dmd -op -odobj/a -c src/a.d -m64
dmd -op -odobj/b -c src/b.d -m64

dmd -ofbin/sdc `find obj/a obj/b -type f | grep '\.o$'` -m64

Error :
obj/a/src/a.o: In function
`_D1b3fooFC1b1AZv59__T9MapResultS35_D1b3foo12__lambda1196MFC1b1CZC1b1CTAC1b1CZ9MapResult4backMFNdZC1b1C':
src/a.d:(.text._D1b3fooFC1b1AZv59__T9MapResultS35_D1b3foo12__lambda1196MFC1b1CZC1b1CTAC1b1CZ9MapResult4backMFNdZC1b1C+0x64):
undefined reference to `_D1b3fooFC1b1AZv12__lambda1196MFC1b1CZC1b1C'
obj/a/src/a.o: In function
`_D1b3fooFC1b1AZv59__T9MapResultS35_D1b3foo12__lambda1196MFC1b1CZC1b1CTAC1b1CZ9MapResult5frontMFNdZC1b1C':
src/a.d:(.text._D1b3fooFC1b1AZv59__T9MapResultS35_D1b3foo12__lambda1196MFC1b1CZC1b1CTAC1b1CZ9MapResult5frontMFNdZC1b1C+0x64):
undefined reference to `_D1b3fooFC1b1AZv12__lambda1196MFC1b1CZC1b1C'
obj/a/src/a.o: In function
`_D1b3fooFC1b1AZv59__T9MapResultS35_D1b3foo12__lambda1196MFC1b1CZC1b1CTAC1b1CZ9MapResult7opIndexMFmZC1b1C':
src/a.d:(.text._D1b3fooFC1b1AZv59__T9MapResultS35_D1b3foo12__lambda1196MFC1b1CZC1b1CTAC1b1CZ9MapResult7opIndexMFmZC1b1C+0x77):
undefined reference to `_D1b3fooFC1b1AZv12__lambda1196MFC1b1CZC1b1C'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 23, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |link-failure
                 CC|                            |verylonglogin.reg@gmail.com
           Severity|normal                      |major


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571


Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com


--- Comment #1 from Vladimir Panteleev <thecybershadow@gmail.com> 2013-03-10 17:16:46 EET ---
I'm seeing a similar error with Win64:

a.obj : error LNK2019: unresolved external symbol
_D1b3fooFC1b1AZv12__lambda1404MFC1b1CZC1b1C referenced in function
_D1b3fooFC1b1AZv59__T9MapResultS35_D1b3foo12__lambda1404MFC1b1CZC1b1CTAC1b1CZ9MapResult4backMFNdZC1b1C
a.exe : fatal error LNK1120: 1 unresolved externals
--- errorlevel 1120

Links fine on Win32, though.

Mr. deadalnix, does it happen without -m64? If not, please indicate the correct platform, since it is currently set to "All".

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571



--- Comment #2 from deadalnix <deadalnix@gmail.com> 2013-03-10 08:23:54 PDT ---
(In reply to comment #1)
> I'm seeing a similar error with Win64:
> 
> a.obj : error LNK2019: unresolved external symbol
> _D1b3fooFC1b1AZv12__lambda1404MFC1b1CZC1b1C referenced in function
> _D1b3fooFC1b1AZv59__T9MapResultS35_D1b3foo12__lambda1404MFC1b1CZC1b1CTAC1b1CZ9MapResult4backMFNdZC1b1C
> a.exe : fatal error LNK1120: 1 unresolved externals
> --- errorlevel 1120
> 
> Links fine on Win32, though.
> 
> Mr. deadalnix, does it happen without -m64? If not, please indicate the correct platform, since it is currently set to "All".

Mr. CyberShadow, I confirm the bug on 32bits as well.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 02, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571


Dicebot <m.strashun@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |m.strashun@gmail.com


--- Comment #3 from Dicebot <m.strashun@gmail.com> 2013-04-02 06:13:13 PDT ---
Want to note that it works if "auto foo" is changed to "void foo", so that it may be also somehow related to templates, exact conditions are weird though.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571



--- Comment #4 from Dicebot <m.strashun@gmail.com> 2013-04-10 07:31:40 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1882

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code@dawg.eu


--- Comment #5 from Martin Nowak <code@dawg.eu> 2013-04-10 08:47:28 PDT ---
Could you please try to reduce the test case.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 10, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571



--- Comment #6 from Dicebot <m.strashun@gmail.com> 2013-04-10 09:30:15 PDT ---
I was not able to reduce it any further than moving A variable from parameter to foo itself, leaving foo signature as void foo(). Almost any change in b module resulted in lambda marked as a weak symbol and compilation succeeding.

I have not tried to track this down really hard though as my pull solves more fundamental issue - that symbol should even be there at all, as well as several hundred phobos symbols. Still need to track down and fix special cases found by test suite though. Working on it right now.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571


Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|linkage issue when using    |link error due to using
                   |separate compilation and    |unique ids in anonymous
                   |closures                    |funcliteral


--- Comment #7 from Martin Nowak <code@dawg.eu> 2013-04-10 17:57:16 PDT ---
cat > a.d << CODE
import b;

void main()
{
    foo();
}
CODE

cat > b.d << CODE
struct MapResult(alias fun)
{
    void bar()
    {
        fun(0);
    }
}

auto foo()
{
    version (all)
    {
        alias MapResult!(function(int c) => 0) M;
    }
    else
    {
        // works because it uses a named function literal
        auto func = function(int c) => 0;
        alias MapResult!(func) M;
    }
}
CODE

dmd -c a
dmd -c b
dmd a.o b.o
--------

During the compilation of a.d semantic3 is run on auto foo() and thus
an instantiation of MapResult!(...) is added to a.o.
The problem is that the anonymous funcliteral in a.o and the one in b.o used a
different unique id suffix.
Because semantic3 on MapResult.bar() is not run during a's compilation the
funcliteral is never referenced and missing from a.o.

nm a.o | grep funcliteral
U _D1b3fooFZv14__funcliteral5FNaNbNfiZi
nm b.o | grep funcliteral
T _D1b3fooFZv14__funcliteral1FNaNbNfiZi

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
April 11, 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9571



--- Comment #8 from Martin Nowak <code@dawg.eu> 2013-04-10 18:19:57 PDT ---
(In reply to comment #7)
> Because semantic3 on MapResult.bar() is not run during a's compilation the funcliteral is never referenced and missing from a.o.
> 
That was incorrect semantic3 for the function literal and MapResult.bar is run and bar is added as a weak symbol to a.o which actually causes the link error because the funcliteral remains undefined.

We need to fix the unique id issue for anonymous literals.
We shouldn't emit an unused template instance to a.o just because we ran
semantic3 on foo, note that foo returns void.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2