Added no-main detection #1178

Merged
merged 5 commits into from Oct 21, 2012

6 participants

@carlor

Reads linker error output, and gives a "no main function specified" error when proper.

@alexrp
D Programming Language member

This seems reasonable to me and is sorely needed - a lot of people are confused when they see a bunch of seemingly nonsensical linker errors just because they forgot main.

This does make some assumptions about the output of the linker, but I don't think that's a problem for all practical purposes. Though, is this tested on all the platforms listed in that #if?

@carlor

@alexrp I've only tested it on my OSX machine. However, it's all POSIX, so any standards-compliant platform should work.

EDIT: now that I think about it, ld isn't POSIX. So no.

@alexrp
D Programming Language member

I was more curious whether the error detection works everywhere than anything else.

@carlor

@alexrp If it doesn't detect the error, it outputs the linker error as it's always done.

@alexrp
D Programming Language member

Sure, and that's fine; I'm just wondering if it will actually catch the missing main error on all three POSIXes that we currently support (Linux, OS X, FreeBSD) or if this was only tested on a particular system.

@carlor

@alexrp I tested it on Debian, there's a different error message. I'll try and make it check for that.

@carlor

Testing on other platforms, will reopen when done.

@carlor carlor closed this Oct 19, 2012
@carlor

Tested on Debian, modified so that error messages on other platforms can be easily added in.

@carlor carlor reopened this Oct 20, 2012
@WalterBright
D Programming Language member

Clever!

@WalterBright WalterBright merged commit f58578f into dlang:master Oct 21, 2012

1 check passed

Details default Pass: 9
@WalterBright WalterBright added a commit that referenced this pull request Oct 21, 2012
@WalterBright WalterBright merge D2 pull #1178 b14eebf
@andralex
D Programming Language member

The strategy of this is great, but the implementation is awkward and deviates (I think) a bit from dmd's usual style as I'll note inline.

@andralex This is an earlier commit; I fixed some of the issues you mentioned, but not all of them. The ones I still need to work on:

  • style stuff (variable definitions, 1/0 -> true/false)
  • error handling (I miss D here)
  • fread/fwrite

I don't want to return true when nmeFound, because I still need to forward the rest of the error message. In later commits I break to the no-checking forwarding loop.

How would converting the last loop to using fread work? I'm assuming read/write a buffer. What should its size be?

Should I create another pull request which handles these three things?

D Programming Language member

Thanks for your understanding. Sorry for misinterpreting the logic where I did. For fread/fwrite, just use a stack-allocated 64 KB buffer. Feel free to create an additional pull request - aside from the error checking issue, there's no urgency.

@andralex
D Programming Language member

move definition to point of initialization

@andralex
D Programming Language member

move definition to point of initialization

@andralex
D Programming Language member

move to after the test against stream

@andralex
D Programming Language member

must return here!

@andralex
D Programming Language member

static const char nmeErrorMessage[] = " \"__Dmain\", referenced from:";

@andralex
D Programming Language member

must check for errors

@andralex
D Programming Language member

move definition to initialization

@andralex
D Programming Language member

This fgetc/fputc approach is very slow. Should we invest in switching to fread/fwrite?

@andralex
D Programming Language member

return true;

@andralex
D Programming Language member

return false;

@CyberShadow
D Programming Language member

Ooh. Can we use the linker pipe to also demangle D symbols from linker errors on the fly?

@andralex
D Programming Language member

@CyberShadow What a great idea!!!

@MartinNowak
D Programming Language member

Calling waitpid without emptying the pipe buffer causes a deadlock for huge error messages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment