D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6790 - buildPath using std.path.curdir segfaults
Summary: buildPath using std.path.curdir segfaults
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86 Linux
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-07 21:37 UTC by Jonathan Sternberg
Modified: 2012-04-19 08:14 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan Sternberg 2011-10-07 21:37:46 UTC
I am using the dmd compiler and phobos library at version 2.055. This is on Linux Mint 11 with x86 architecture. To repeat the bug is a bit weird. It seems to only happen when using std.path.curdir, and only when not in the main module. The following will NOT produce the error:

import std.path; import std.stdio;
int main() {
writeln(buildPath(curdir, "a.out"));
return 0;
}

This WILL produce the error:

-- main.d
static import foobar;
int main() {
foobar.crash();
return 0;
}

-- foobar.d
module foobar;
import std.path; import std.stdio;
void crash() {
writeln(buildPath(curdir, "a.out"));
}

Compiling and running this results in a segfault. No idea why.

Workaround that seems to work is to use std.path.curdir.idup instead.
Comment 1 Jonathan Sternberg 2011-11-10 16:18:31 UTC
As of dmd 2.056, this now throws "core.exception.OutOfMemoryError". No recompilation was needed, but recompilation resulted in the same thing.

This is probably some error in druntime.
Comment 2 Lars T. Kyllingstad 2011-11-28 15:14:39 UTC
I am using the latest revisions of DMD, druntime and Phobos, and I can't reproduce this.

curdir is a string enum, and the only thing that happens to it in buildPath is the following:

    return cast(string)(curdir ~ dirSeparator ~ "a.out");

This should be perfectly OK, as concatenation always allocates a new string.  Therefore, I agree with Jacob that it is/was a bug in druntime, or perhaps DMD, but it seems to have been fixed now.
Comment 3 Lars T. Kyllingstad 2011-11-28 15:21:19 UTC
(In reply to comment #2)
> Therefore, I agree with Jacob [...]

Why on earth did I say Jacob? :)  I meant Jonathan, of course.
Comment 4 Jonathan Sternberg 2011-11-28 19:53:11 UTC
Lars, for completeness, can you give your OS/architecture? As I said, it still happens on x86 Linux for me.
Comment 5 Lars T. Kyllingstad 2011-11-29 13:15:35 UTC
I am on 64-bits Ubuntu Linux.  However, I have tried compiling the entire toolchain (DMD, druntime and Phobos, all fresh from the Github repositories) with -m32, and used it to compile your test case, and I still can't reproduce it.
Comment 6 Lars T. Kyllingstad 2012-02-01 14:41:35 UTC
Have you tried this with DMD 2.057, and if so, are you still experiencing the same problem?
Comment 7 SomeDude 2012-04-19 07:37:35 UTC
I think this one should be closed as "Can't reproduce". We'll reopen it if it happens again.
Comment 8 Lars T. Kyllingstad 2012-04-19 08:14:23 UTC
I agree.