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



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



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



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




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




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





 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 -- 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



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



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




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



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




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




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


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



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





 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




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





 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




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



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