www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Several segmentation faults

reply Josh <strattonbrazil gmail.com> writes:
Has anyone had segmentation faults running the tutorials?  This segfaults on my
computer (Ubuntu 8.04) using dgc.  It's taken from one of the tutorials, but
several similar tutorials also fail.  

import std.stdio;

int magicNumber = 42;
char[] password = "sesame";

void main() {
  writefln("Magic number: ", magicNumber);
  writefln("Password: ", password);
}
May 28 2008
next sibling parent reply BCS <ao pathlink.com> writes:
Reply to Josh,

 Has anyone had segmentation faults running the tutorials?  This
 segfaults on my computer (Ubuntu 8.04) using dgc.  It's taken from one
 of the tutorials, but several similar tutorials also fail.
 
 import std.stdio;
 
 int magicNumber = 42;
 char[] password = "sesame";
 void main() {
 writefln("Magic number: ", magicNumber);
 writefln("Password: ", password);
 }

does the compiler seg-v or does the compiled program?
May 28 2008
parent Josh <strattonbrazil gmail.com> writes:
 does the compiler seg-v or does the compiled program?

The compiled program
May 28 2008
prev sibling next sibling parent reply downs <default_357-line yahoo.de> writes:
Josh wrote:
 Has anyone had segmentation faults running the tutorials?  This segfaults on
my computer (Ubuntu 8.04) using dgc.  It's taken from one of the tutorials, but
several similar tutorials also fail.  
 
 import std.stdio;
 
 int magicNumber = 42;
 char[] password = "sesame";
 
 void main() {
   writefln("Magic number: ", magicNumber);
   writefln("Password: ", password);
 }

All I can say is there is nothing in there that I could possibly imagine segfaulting. Ergo it has to be a problem with your system. If you have too much free time, try to build GDC from sources. Out of curiosity, could you gdb the crashing program? --downs
May 28 2008
parent Chris Wright <dhasenan gmail.com> writes:
downs wrote:
 Josh wrote:
 Has anyone had segmentation faults running the tutorials?  This segfaults on
my computer (Ubuntu 8.04) using dgc.  It's taken from one of the tutorials, but
several similar tutorials also fail.  

 import std.stdio;

 int magicNumber = 42;
 char[] password = "sesame";

 void main() {
   writefln("Magic number: ", magicNumber);
   writefln("Password: ", password);
 }

All I can say is there is nothing in there that I could possibly imagine segfaulting. Ergo it has to be a problem with your system. If you have too much free time, try to build GDC from sources. Out of curiosity, could you gdb the crashing program? --downs

I've tried using gdc as installed from the Ubuntu repositories. The programs it produces always segfault on vararg calls.
May 29 2008
prev sibling parent reply Lars <public kyllingen.net> writes:
Josh Wrote:

 Has anyone had segmentation faults running the tutorials?  This segfaults on
my computer (Ubuntu 8.04) using dgc.  It's taken from one of the tutorials, but
several similar tutorials also fail.  
 
 import std.stdio;
 
 int magicNumber = 42;
 char[] password = "sesame";
 
 void main() {
   writefln("Magic number: ", magicNumber);
   writefln("Password: ", password);
 }

I was searching for the answer to the exact same question. It seems that writef and writefln segfault whenever additional arguments are passed. Consider the following (modified) Hello World: import std.stdio; void main { writefln("Hello %s!", "world"); } When I compile this on my system (also running Ubuntu 8.04) with GDC and run it, it immediately segfaults without displaying the message. Just using writefln("Hello world!"); works perfectly, however. Some more testing shows that writing to other streams (files, etc.) doesn't work either. The printf() function works fine. Something wrong with the newest Ubuntu build of GDC, then? I tried running my hello-world program through GDB, this is the output I got: Starting program: /home/lars/development/programming/d/test/helloworld [Thread debugging using libthread_db enabled] [New Thread 0x7f0871deb6e0 (LWP 16622)] Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7f0871deb6e0 (LWP 16622)] 0x000000000040cfe9 in _D3std6format11doFormatPtrFDFwZvAC8TypeInfoG1S6object13__va_list_tagPvZv9formatA gMFaZv6putstrMFAaZv () Current language: auto; currently asm Regards, Lars
May 29 2008
parent reply Urban Hafner <urban bettong.net> writes:
Lars wrote:
 When I compile this on my system (also running Ubuntu 8.04) with GDC and run
it, it immediately segfaults without displaying the message. Just using

Which GDC build are you using? There's one built using GCC 4.1 and one using GCC 4.2, IIRC. The latter one also didn't work for me (on other more complex code). Urban
May 29 2008
parent reply Lars Kyllingstad <public kyllingen.net> writes:
Urban Hafner Wrote:

 Lars wrote:
 When I compile this on my system (also running Ubuntu 8.04) with GDC and run
it, it immediately segfaults without displaying the message. Just using

Which GDC build are you using? There's one built using GCC 4.1 and one using GCC 4.2, IIRC. The latter one also didn't work for me (on other more complex code). Urban

In the repository it is listed as 0.25-4.2.3-2ubuntu2. -Lars
May 29 2008
parent reply Urban Hafner <urban bettong.net> writes:
Lars Kyllingstad wrote:
 Urban Hafner Wrote:
 
 Lars wrote:
 When I compile this on my system (also running Ubuntu 8.04) with GDC and run
it, it immediately segfaults without displaying the message. Just using

using GCC 4.2, IIRC. The latter one also didn't work for me (on other more complex code). Urban

In the repository it is listed as 0.25-4.2.3-2ubuntu2.

I just checked. I'm using 0.25-4.1.2-16ubuntu1. And the package is called gdc-4.1. Maybe this works for you. The only thing is that you have to create a few symlinks, as the executable is called gdc-4.1 instead of gdc (the same for gdmd and maybe others). Urban
May 29 2008
parent reply Josh <strattonbrazil gmail.com> writes:
Urban Hafner Wrote:

 Lars Kyllingstad wrote:
 Urban Hafner Wrote:
 
 Lars wrote:
 When I compile this on my system (also running Ubuntu 8.04) with GDC and run
it, it immediately segfaults without displaying the message. Just using

using GCC 4.2, IIRC. The latter one also didn't work for me (on other more complex code). Urban

In the repository it is listed as 0.25-4.2.3-2ubuntu2.

I just checked. I'm using 0.25-4.1.2-16ubuntu1. And the package is called gdc-4.1. Maybe this works for you. The only thing is that you have to create a few symlinks, as the executable is called gdc-4.1 instead of gdc (the same for gdmd and maybe others). Urban

Just to confirm, I tried compiling the same code on Ubuntu 8.04 using gdc-4.1 instead of gdc-4.2. The program ran fine. Thanks.
May 29 2008
parent Lars Kyllingstad <public kyllingen.net> writes:
Josh Wrote:
 
 Just to confirm, I tried compiling the same code on Ubuntu 8.04 using gdc-4.1
instead of gdc-4.2.  The program ran fine.  Thanks.  
 

That would explain why this started happening after I upgraded to Ubuntu 8.04. I guess the 4.1 build was the default in Ubuntu 7.10. Anyway, I have reported this as a bug on Launchpad. Feel free to add "me too"s. :) https://bugs.launchpad.net/ubuntu/+source/gdc-4.2/+bug/235955 Thanks, Lars
May 29 2008