www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4854] New: writefln Segmentation fault if no globals

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

           Summary: writefln Segmentation fault if no globals
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Mac OS X
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: alexibu mac.com


--- Comment #0 from Alex Burton <alexibu mac.com> 2010-09-11 14:29:49 PDT ---
Hi,

I have dmd version 2.048, OS X 10.5.8

If I compile this :

import std.stdio;
int main()
{
    writefln("%d",0);
    return 0;
}

with "dmd file.d"

and then run it

I get segmentation fault in writefln

if I then compile this :

import std.stdio;
int x;
int main()
{
    writefln("%d",0);
    return 0;
}

and run it, it works.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 11 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854


wresch <wresch drgang.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wresch drgang.net


--- Comment #1 from wresch <wresch drgang.net> 2010-10-15 16:51:44 PDT ---
I have the exact same issue.  In the code below the segfault happens in
writefln.

Setup:
Digital Mars D Compiler v2.049
OS X 10.5.3
2.26 MHz Core2 duo (macbook pro)

[510]dmd2 >  cat hello.d
import std.stdio;
//int x;

void main() {
    writeln("hello world!");
    writefln("foo = %d", 10);
}
[511]dmd2 >  ./hello
Segmentation fault
[515]dmd2 >  cat hello2.d
import std.stdio;
int x;

void main() {
    writeln("hello world!");
    writefln("foo = %d", 10);
}
[
[514]dmd2 >  ./hello2
hello world!
foo = 10

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854


Kyle Kilpatrick <garfieldrules sbcglobal.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |garfieldrules sbcglobal.net


--- Comment #2 from Kyle Kilpatrick <garfieldrules sbcglobal.net> 2010-10-15
17:04:55 PDT ---
I have the same problem.  In my OS X 10.5.8 installation, any program in my 
with a writef or writefln statement in DMD >= 2.047 segfaults.  Oddly, this
problem is NOT present in DMD 2.046.  Readf in >= 2.047 also causes trouble.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854



--- Comment #3 from Kyle Kilpatrick <garfieldrules sbcglobal.net> 2010-10-15
17:08:27 PDT ---
My setup:

Digital Mars D 2.049
OS X 10.5.8
MacBook Black early 2008
Core 2 Duo 2.4ghz

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 15 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Summary|writefln Segmentation fault |Regression(2.047, Mac only)
                   |if no globals               |writefln Segmentation fault
                   |                            |if no globals
           Severity|major                       |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 18 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854



--- Comment #4 from Don <clugdbug yahoo.com.au> 2010-11-07 13:51:01 PST ---
Can somebody please help to track this down further?
Does it crash with: import std.stdio;  void main() { writeln("abc", 0);}   ?
Does it crash with: import std.string; void main() { format("%d", 0); } ?
Does it crash with: import std.string; void main() { writefln("abc"); } ?

If it crashes with writeln, it's probably a compiler code generation bug,
related to varargs.

And can you get a stack trace?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 07 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854



--- Comment #5 from Alex Burton <alexibu mac.com> 2010-11-08 01:51:46 PST ---
(In reply to comment #4)
 Can somebody please help to track this down further?
 Does it crash with: import std.stdio;  void main() { writeln("abc", 0);}   ?
YES
 Does it crash with: import std.string; void main() { format("%d", 0); } ?
NO
 Does it crash with: import std.string; void main() { writefln("abc"); } ?
assume you meant import std.stdio: YES
 
 If it crashes with writeln, it's probably a compiler code generation bug,
 related to varargs.
 
 And can you get a stack trace?
Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: 13 at address: 0x00000000 0x0000a7b9 in __tls_get_addr () (gdb) bt #0 0x0000a7b9 in __tls_get_addr () #1 0x000073a1 in _moduleTlsCtor () #2 0x0000fbfd in D2rt6dmain24mainUiPPaZi6runAllMFZv () #3 0x0000fb06 in D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv () #4 0x0000fa93 in main () -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Nov 08 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com


--- Comment #6 from Walter Bright <bugzilla digitalmars.com> 2010-11-08
09:59:18 PST ---
I cannot reproduce this problem with OS X 10.6.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854


Jacob Carlborg <doob me.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |doob me.com


--- Comment #7 from Jacob Carlborg <doob me.com> 2010-11-08 12:34:49 PST ---
I can reproduce it on Mac OS X 10.5.8 using dmd 2.050.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854



--- Comment #8 from Walter Bright <bugzilla digitalmars.com> 2010-11-08
14:11:18 PST ---
I've had a lot of problems with the 10.5 linker screwing up on empty sections.
I suspect the solution is for, a module that defines main(), to output 4 bytes
of dummy data into the tls section if it is blank.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854


nfxjfg gmail.com changed:

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


--- Comment #9 from nfxjfg gmail.com 2010-11-08 14:19:29 PST ---
I'm curious: why you need to rely on (obviously) not guaranteed linker
behaviour?
Btw. gcc supports TLS variables via extensions, if that is the problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854



--- Comment #10 from Jacob Carlborg <doob me.com> 2010-11-09 00:09:39 PST ---
TLS is not supported by GCC on Mac OS X.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854



--- Comment #11 from Jacob Carlborg <doob me.com> 2010-11-20 03:14:21 PST ---
Created an attachment (id=823)
Patch

I'm adding my patch here as well so it doesn't get lost.

I've created a patch but I'm not completely sure if it solves the problem or
not. I don't get an error in __tls_get_addr now but instead I get this:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x97655133 in strncmp ()
(gdb) bt
#0  0x97655133 in strncmp ()
#1  0x0000101c in ?? ()
Previous frame inner to this frame (gdb could not unwind past this frame)
(gdb)

Maybe someone else can look at the patch and see if I did something wrong or
maybe the solution we thought of couldn't fix the problem.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 20 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854


Andrei Alexandrescu <andrei metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com


--- Comment #12 from Andrei Alexandrescu <andrei metalanguage.com> 2012-01-31
14:57:11 PST ---
Can this be still reproduced? The code works for me on OSX 10.7.2.

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



--- Comment #13 from Jacob Carlborg <doob me.com> 2012-01-31 23:32:45 PST ---
(In reply to comment #12)
 Can this be still reproduced? The code works for me on OSX 10.7.2.
As the title say, it's only for Mac OS X 10.5. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 31 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854



--- Comment #14 from Walter Bright <bugzilla digitalmars.com> 2012-02-06
19:58:16 PST ---
Is anyone still running 10.5? That's two OSX versions ago.

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



--- Comment #15 from Jacob Carlborg <doob me.com> 2012-02-07 04:21:38 PST ---
I (In reply to comment #14)
 Is anyone still running 10.5? That's two OSX versions ago.
I don't know. But I see now reason why we shouldn't support 10.5 as long as it doesn't cause too much problem. We're still supporting Windows XP which is two versions ago as well and is far older than Mac OS X 10.5. And yes, I know you can't really compare Mac OS X and Windows in this case. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 07 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4854



--- Comment #16 from github-bugzilla puremagic.com 2012-03-07 18:33:23 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/druntime

https://github.com/D-Programming-Language/druntime/commit/73cf2c150665cb17d9365a6e3d6cf144d76312d6
fix Issue 4854 - Regression(2.047, Mac 10.5 only) writefln Segmentation fault
if no globals

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


--- Comment #17 from Walter Bright <bugzilla digitalmars.com> 2012-03-07
18:34:28 PST ---
I don't have 10.5 to test it on, but this should fix it.

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