Jump to page: 1 2
Thread overview
[Issue 14894] mangling of mixins and lambdas is not unique and depends on compilation flags
[Issue 14894] [Reg 2.068.0-rc1] linkage error with mixin template in std.net.curl
Aug 09, 2015
Martin Nowak
Aug 09, 2015
Martin Nowak
Aug 10, 2015
Martin Nowak
Aug 10, 2015
Walter Bright
[Issue 14894] mangling of mixins and lambdas can change w/ -unittest or other versions
Aug 10, 2015
Martin Nowak
Aug 30, 2015
Martin Nowak
Jan 08, 2017
Martin Nowak
Jan 08, 2017
Martin Nowak
Jun 14, 2017
Martin Nowak
Oct 20, 2017
Martin Nowak
Oct 26, 2017
Walter Bright
Aug 22, 2018
Mike Franklin
Dec 17, 2022
Iain Buclaw
August 09, 2015
https://issues.dlang.org/show_bug.cgi?id=14894

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|nobody@puremagic.com        |code@dawg.eu

--
August 09, 2015
https://issues.dlang.org/show_bug.cgi?id=14894

--- Comment #1 from Martin Nowak <code@dawg.eu> ---
Happens b/c the mangling is determined by the number of member in the parent scope. This number can vary between compilations w/ and w/o -unittest.

cat > main.d << CODE
import bug;

void main()
{
    Foo foo;
    foo.onReceive();
}
CODE

cat > bug.d << CODE
mixin template Protocol()
{
    void onReceive() {}
}

struct Foo
{
    mixin Protocol!();

    unittest
    {
    }
}
CODE
----
dmd -c bug
dmd -unittest main bug.o
----

The manifestation of this bug is caused by skipping unittest parsing [¹], but
the underlying problem can also be triggered by any other version/debug block
member.
The code to derive a unique mixin mangling was already added with 2.065.0 [²]
and is also used for lambdas.

[¹]: https://github.com/D-Programming-Language/dmd/pull/4704 [²]: https://github.com/D-Programming-Language/dmd/pull/3019

--
August 10, 2015
https://issues.dlang.org/show_bug.cgi?id=14894

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #2 from Martin Nowak <code@dawg.eu> ---
https://github.com/D-Programming-Language/dmd/pull/4871

--
August 10, 2015
https://issues.dlang.org/show_bug.cgi?id=14894

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--
August 10, 2015
https://issues.dlang.org/show_bug.cgi?id=14894

--- Comment #3 from github-bugzilla@puremagic.com ---
Commits pushed to stable at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/d10bd6c88426b3566c25f42d7194bf5c98a90a38 workaround Issue 14894 - linkage error with mixin template in std.net.curl

https://github.com/D-Programming-Language/dmd/commit/24214150e3463c94709f55c4ade912b974bbf911 Merge pull request #4871 from MartinNowak/workaround14894

workaround Issue 14894 - linkage error with mixin template in std.net.curl

--
August 10, 2015
https://issues.dlang.org/show_bug.cgi?id=14894

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|pull                        |
            Summary|[Reg 2.068.0-rc1] linkage   |mangling of mixins and
                   |error with mixin template   |lambdas can change w/
                   |in std.net.curl             |-unittest or other versions
           Severity|regression                  |normal

--- Comment #4 from Martin Nowak <code@dawg.eu> ---
We still need a long-term solution to make the mangling not dependent on flags
like -unittest or -release.
Using source position (line and col) doesn't work b/c the position might
differ, e.g. in a .di file or when editing a comment.

--
August 10, 2015
https://issues.dlang.org/show_bug.cgi?id=14894

--- Comment #5 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/d10bd6c88426b3566c25f42d7194bf5c98a90a38 workaround Issue 14894 - linkage error with mixin template in std.net.curl

https://github.com/D-Programming-Language/dmd/commit/24214150e3463c94709f55c4ade912b974bbf911 Merge pull request #4871 from MartinNowak/workaround14894

--
August 30, 2015
https://issues.dlang.org/show_bug.cgi?id=14894

--- Comment #6 from Martin Nowak <code@dawg.eu> ---
(In reply to Martin Nowak from comment #4)
> We still need a long-term solution to make the mangling not dependent on
> flags like -unittest or -release.
> Using source position (line and col) doesn't work b/c the position might
> differ, e.g. in a .di file or when editing a comment.

This is very similar to the -debug issues we have with template instantiation. The bottom line would be that only libs with the same flags are linkable.

BTW, g++ counts the number of lambdas per function and assigns them an increasing id. Using separate counters per scope per entity at least mitigates the issue.

--
January 08, 2017
https://issues.dlang.org/show_bug.cgi?id=14894

Martin Nowak <code@dawg.eu> changed:

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

--- Comment #7 from Martin Nowak <code@dawg.eu> ---
*** Issue 16994 has been marked as a duplicate of this issue. ***

--
January 08, 2017
https://issues.dlang.org/show_bug.cgi?id=14894

Martin Nowak <code@dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|mangling of mixins and      |mangling of mixins and
                   |lambdas can change w/       |lambdas is not unique and
                   |-unittest or other versions |depends on compilation
                   |                            |flags
           Severity|normal                      |critical

--- Comment #8 from Martin Nowak <code@dawg.eu> ---
Apparently can also cause calls of the wrong function instead of linker errors,
see issue 16994.
Different compilations end up with instances of the same mangling.

cat > lib.d << CODE
alias min = (a, b) => a < b ? a : b;
alias max = (a, b) => a > b ? a : b;

auto reduce(alias func, T...)(T args)
{
    return func(args);
}
CODE
cat > a.d << CODE
import lib;

unittest
{
    assert(reduce!min(1, 2) == 1);
}
CODE
cat > b.d << CODE
import lib;

unittest
{
    assert(reduce!max(1, 2) == 2);
}
CODE

# works
dmd -main -unittest -ofmain a.d b.d
./main

# fails
dmd -unittest -c a.d
dmd -unittest -c b.d
dmd -main -ofmain a.o b.o // one of the tests calls the wrong reduce
./main

----

$ dmd -unittest -c a.d
$ nm a.o | grep lambda
0000000000000000 W _D3lib18__T9__lambda5TiTiZ9__lambda5FNaNbNiNfiiZi
0000000000000000 W _D3lib32__T6reduceS143lib9__lambda5TiTiZ6reduceFNaNbNiNfiiZi
$ dmd -unittest -c b.d
$ nm b.o | grep lambda
0000000000000000 W _D3lib18__T9__lambda5TiTiZ9__lambda5FNaNbNiNfiiZi
0000000000000000 W _D3lib32__T6reduceS143lib9__lambda5TiTiZ6reduceFNaNbNiNfiiZi

--
« First   ‹ Prev
1 2