www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10833] New: DMD puts mixin's source code in the binary

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

           Summary: DMD puts mixin's source code in the binary
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: temtaime gmail.com


--- Comment #0 from Temtaime <temtaime gmail.com> 2013-08-16 15:23:12 PDT ---
import std.stdio;

string foo()() {
    return `void main() { writefln("hello world"); }`;
}

mixin(foo);

Compiled with -O -release

Copy from IDA PRO strings window:
.CRT$XIA:0043F100 00000029 C void main() { writefln(\"hello world\"); }

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 16 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10833


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-16
15:40:45 PDT ---
W.r.t. -O and -release, if this feature is implemented I think it would be
better if it was a separate switch (e.g. -security), rather than have to depend
on security features based on what optimization some compiler implements.
Sometimes you can't even compile with -release or -O (due to bugs), so you
shouldn't be forced to lose security features because of optimization bugs. (+
maybe D could standardize on these security features).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10833



--- Comment #2 from Temtaime <temtaime gmail.com> 2013-08-17 04:21:59 PDT ---
I think there is no need to have any switches.

If D debugger requires mixin's source - then source in binary should to be only
when -g flag specified.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 17 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10833


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |enhancement


--- Comment #3 from Don <clugdbug yahoo.com.au> 2013-08-19 05:01:21 PDT ---
The mixin source isn't put into the binary. What you're seeing is the
executable code of the template that you instantiated. It's exactly as if you
wrote:

string foo() {
    return `void main() { writefln("hello world"); }`;
}

There's a possible optimisation: templates instantiated only in a compile-time
context don't need to be put into the binary. Unfortunately the linker isn't
smart enough to detect they are never used. This should be fixable, but it's
not actually a bug.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10833


Vladimir Panteleev <thecybershadow gmail.com> changed:

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


--- Comment #4 from Vladimir Panteleev <thecybershadow gmail.com> 2013-08-19
15:05:42 EEST ---
 This should be fixable, but it's not actually a bug.
FWIW, it can be a serious issue for closed-source software products, where details about the source code must not be present in executables. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10833



--- Comment #5 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-19
06:45:42 PDT ---
(In reply to comment #4)
 This should be fixable, but it's not actually a bug.
FWIW, it can be a serious issue for closed-source software products, where details about the source code must not be present in executables.
Yeah. This is why I propose a -security switch to add guarantees about what the compiler does, rather than rely on compiler optimizations. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 19 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10833


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx


--- Comment #6 from hsteoh quickfur.ath.cx 2013-08-19 12:58:15 PDT ---
IMO DMD should somehow keep track of which template instantiations actually
require code to be emitted. If a template function only runs in CTFE but not at
runtime, that code shouldn't even be emitted in the first place.

Tho I understand that separate compilation may make this tricky. :)

One possible approach is to emit all template instantiations in a separate
static library that the linker can then selectively pull from. Linkers are
designed to only pull parts of the library that are actually referenced, so
this won't require massive compiler changes. Then we can both reduce template
bloat and avoid security issues like this one.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 19 2013