www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7745] New: Regression (1.x git-415e48a) Methods defined in external object files when a pointer to it is taken

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7745

           Summary: Regression (1.x git-415e48a) Methods defined in
                    external object files when a pointer to it is taken
           Product: D
           Version: D1
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: regression
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: leandro.lucarella sociomantic.com



2012-03-21 05:25:44 PDT ---
How to reproduce:

---
echo 'class C { void asdfg() {} }' > inc.d
echo 'import inc; void f(C c) { auto x = &c.asdfg; }' > m.d
dmd -c -release -inline m.d ; nm m.o
---

This prints:
---
00000000 t 
         U _D10ModuleInfo6__vtblZ
00000000 D _D1m12__ModuleInfoZ
00000000 T _D1m1fFC3inc1CZv
00000000 T _D3inc1C5asdfgMFZv
         U _Dmodule_ref
---

Which means that _D3inc1C5asdfgMFZv (AKA inc.asdfg()) is included in the text
(code) section of m.o, but it shouldn't, it should only be in inc.d (which I
didn't even compile), otherwise when linking both inc.o and m.o you'll get a
"multiple definition" error. Symbol D3inc1C5asdfgMFZv should have U (undefined)
or maybe at most v/W (weak linkage).

Please note that the compiler flags -inline -release has to be used to
reproduce the bug, removing either makes it go away. -O is irrelevant.

This regression was introduced by commit
415e48ac4703ffab94cd6ce5a3211625099c637a in D1, which is the fix for bug 4820.

This bug prevents using Tango, so I guess it should be high priority among
regressions (reverting the fix for bug 4820 in the latest dmd-1.x branch fixes
the problem, and I think is even better to leave that bug unfixed instead of
introducing this new regression).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 21 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7745


Leandro Lucarella <leandro.lucarella sociomantic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |link-failure, rejects-valid
           Priority|P2                          |P1
           See Also|                            |http://d.puremagic.com/issu
                   |                            |es/show_bug.cgi?id=4820


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7745


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au



I haven't been able to reproduce this. If I change it from:
-auto x = &c.asdfg;
+auto x = &C.asdfg;

then I get a U symbol for _D3inc1C5asdfgMFZv, otherwise I can't get it to
appear at all. I guess it is changed into an index into the vtable.
Further investigation required.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 21 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7745




Now able to reproduce it. The cause was this line added to e2ir.c, line 3129.

   //printf("DelegateExp::toElem() '%s'\n", toChars());

+    if (func->semanticRun == PASSsemantic3done)
+        irs->deferToObj->push(func);

The fact that EVERY delegate expression gets deferred, seems like overkill for
the bug being fixed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7745


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D1                          |D1 & D2



Reduced test case (actually much longer, but doesn't require -inline -release,
and also fails on D2).

inc.d ---------------
struct C { void asdfg() {} }

m.d-----------------------
import inc;

bool forceSemantic7745()
{
   C c;
   c.asdfg();
  return true;
}
static assert(forceSemantic7745());

void f(C c) { auto x = &c.asdfg; }
void main() {}
----
dmd -c inc.d
dmd -c m.d
dmd m.o inc.o
----
inc.o: In function `_D3inc1C5asdfgMFZv':
inc.d:(.text._D3inc1C5asdfgMFZv+0x0): multiple definition of
`_D3inc1C5asdfgMFZv'
m.o:m.d:(.text._D3inc1C5asdfgMFZv+0x0): first defined here

It happens because this has forced asdfg() to be semantically analyzed. I'm
using CTFE to do this, there are probably more direct ways.

PATCH (D2, also works for D1):
-- a/src/e2ir.c
+++ b/src/e2ir.c
   -3422,7 +3422,8    elem *DelegateExp::toElem(IRState *irs)

     //printf("DelegateExp::toElem() '%s'\n", toChars());

-    if (func->semanticRun == PASSsemantic3done)
+     if (func->semanticRun == PASSsemantic3done
+         && func->parent == irs->m ) // bug 7745
     {
         irs->deferToObj->push(func);
     }

The idea of the patch is that it should only write to the obj file if the
parent of the function belongs to this module.
Not sure if this is correct, but at least it still fixes the test case in 4820.
Perhaps it should run through all parents until it gets to the module.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 22 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7745




Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/3eee94d6116abfe437303f8495067bf32d3b7023


Fix issue 7745 Regression(2.059beta) Methods defined in external object ...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 28 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7745


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 29 2012