D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5215 - Crash with empty program
Summary: Crash with empty program
Status: RESOLVED MOVED
Alias: None
Product: D
Classification: Unclassified
Component: tools (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: Optlink
: 12340 (view as issue list)
Depends on:
Blocks:
 
Reported: 2010-11-13 14:46 UTC by bearophile_hugs
Modified: 2020-04-09 08:31 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-11-13 14:46:08 UTC
This simple wrong D2 program generates expected linker errors and then an unexpected crash on Windows:


void main();
Comment 1 Don 2010-11-13 18:01:25 UTC
(In reply to comment #0)
> This simple wrong D2 program generates expected linker errors and then an
> unexpected crash on Windows:

> void main();

What do you mean, 'unexpected'? It complains that there's no main(). Passing an empty file does exactly the same thing.
(The annoying thing is that it makes an exe anyway, even though the exe is corrupt).
Comment 2 bearophile_hugs 2010-11-13 18:46:45 UTC
(In reply to comment #1)

> What do you mean, 'unexpected'? It complains that there's no main(). Passing an
> empty file does exactly the same thing.
> (The annoying thing is that it makes an exe anyway, even though the exe is
> corrupt).

You are right, sorry. The crash is not caused by the compiler/linker, but by the corrupt exe.
Comment 3 Walter Bright 2012-01-20 02:12:34 UTC
The linker is supposed to create an exe file, even if there are errors. This is handy for some special purposes.
Comment 4 Brad Roberts 2012-01-20 10:19:27 UTC
What circumstances?  I don't have a lot of experience with windows, but binutils ld doesn't leave broken turds when linking fails like that.  I can see having a linker option to force it to leave the output alone on error, but not having that as the default behavior.  Would you treat dmd leaving a .obj file around if there are syntax errors in the .d being built?
Comment 5 Andrej Mitrovic 2012-01-20 10:31:54 UTC
Optlink has a /DELEXECUTABLE flag for deleting the exe if there are linker errors, but it doesn't work (I assume because optlink creates warnings instead of errors for OPs code).

Additionally optlink creates executables even if you don't pass anything to it, e.g.:

$ link.exe
creates .exe

The linker gives you warnings and creates a `.exe` file. Pretty stupid behavior if you ask me. Every modern console app would display a list of arguments you can pass to it, or a sane warning instead of "OPTLINK : Warning 134: No Start Address" when you didn't pass a single file to it.
Comment 6 Walter Bright 2012-01-20 12:47:06 UTC
The special purposes are when parts of your program are missing, but you want to link and run the rest of it.

I'm not sure why /delexecutable is not working, though.
Comment 7 Mathias LANG 2020-04-09 03:16:47 UTC
Transferred the issue to OPTLINK Github repository: https://github.com/DigitalMars/optlink/issues/24
Comment 8 Mathias LANG 2020-04-09 08:31:01 UTC
*** Issue 12340 has been marked as a duplicate of this issue. ***