Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the betterC switch like DMD does. #1872

Closed
wants to merge 1 commit into from

Conversation

@LemonBoy
Copy link
Contributor

@LemonBoy LemonBoy commented Nov 9, 2016

Namely, don't emit the ModuleInfo.
Additionally, for the following code we emit less symbols than dmd (28 vs 38) and the resulting executable actually runs as we don't emit any dso section (which explains the former) and no code that fondles with _d_dso_registry (which explains the latter).

module main;

extern(C) __gshared int __dmd_personality_v0;
extern(C) __gshared void* _d_dso_registry;

extern (C) int printf(in char*, ...);

extern (C) int main()
{
    printf("asd\n");
    return 0;
}
@JohanEngelen
Copy link
Member

@JohanEngelen JohanEngelen commented Nov 9, 2016

No tests!

Can you try to include a test that shows that the resulting object file can be linked without druntime?

@9il
Copy link

@9il 9il commented Nov 9, 2016

Other issues:

  1. switch errors
  2. asserts
  3. cast between arrays
  4. Type info
  5. Check that DRuntime is 100% does not required by generated code.
@LemonBoy LemonBoy force-pushed the LemonBoy:betterc branch from d41c74f to f3ef9ef Nov 9, 2016
@LemonBoy
Copy link
Contributor Author

@LemonBoy LemonBoy commented Nov 9, 2016

IR + Linking test has been attached.
@9il This PR implements betterC a'la dmd, it's not an effort to have a better betterC :) See here for more details.

@9il
Copy link

@9il 9il commented Nov 9, 2016

@9il This PR implements betterC a'la dmd, it's not an effort to have a better betterC :) See here for more details.

OK )

@kinke
Copy link
Member

@kinke kinke commented Nov 9, 2016

@9il: Is it just that you'd like -betterC to imply -release, getting rid of all assertions, bounds checks, contracts etc.?

Copy link
Member

@dnadlinger dnadlinger left a comment

Should be okay as a DMD compatibility thing. We might want to sit down and properly discuss our "minimal runtime" to come up with a sensible and flexible design rather than Walter's one-off hack.

// CHECK-NOT: ModuleInfoZ
// CHECK-NOT: ModuleRefZ
// CHECK-NOT: call void @ldc.register_dso
extern(C) __gshared int __dmd_personality_v0;

This comment has been minimized.

@dnadlinger

dnadlinger Nov 9, 2016
Member

Why would we require __dmd_personality_v0 in the first place?

This comment has been minimized.

@LemonBoy

LemonBoy Nov 9, 2016
Author Contributor

That's a leftover from the testing against dmd, can be safely removed.
Appveyor shows that _mainCRTStartup can't be found though, don't know why since I expect the MSVC crt to provide that anyway.

This comment has been minimized.

@kinke

kinke Nov 9, 2016
Member

The MSVC libs are pulled in exclusively via the C parts in druntime lib. :/

This comment has been minimized.

@LemonBoy

LemonBoy Nov 9, 2016
Author Contributor

That's very bare metal we're running on then heh
Adding a stub declaration in a version(CRuntime_Microsoft) would do the trick, no ?

This comment has been minimized.

@kinke

kinke Nov 9, 2016
Member

Yep, good idea.

@LemonBoy LemonBoy force-pushed the LemonBoy:betterc branch 2 times, most recently from f264531 to 7c6cc42 Nov 9, 2016
extern(C) void mainCRTStartup() { }
}

extern(C) __gshared void* _d_dso_registry;

This comment has been minimized.

@JohanEngelen

JohanEngelen Nov 9, 2016
Member

Why is this needed? Doesn't that mean that more code emission needs to be disabled with -betterC?

@LemonBoy LemonBoy force-pushed the LemonBoy:betterc branch from 7c6cc42 to 69fa490 Nov 9, 2016
Namely, don't emit the ModuleInfo.
@LemonBoy LemonBoy force-pushed the LemonBoy:betterc branch from 69fa490 to d355414 Nov 10, 2016
@9il
Copy link

@9il 9il commented Nov 12, 2016

@9il: Is it just that you'd like -betterC to imply -release, getting rid of all assertions, bounds checks, contracts etc.?

betterC (in my vision) should verify that compiled code does not depend on Druntime. A code can still use some generic code from Phobos. assertions in non release mode should be replaced with inlined checks that use libc to exit from the program.

@kinke
Copy link
Member

@kinke kinke commented Nov 13, 2016

Please document the new switch in LDMD's usage output too.

@dnadlinger
Copy link
Member

@dnadlinger dnadlinger commented Nov 24, 2016

Could you add the description from DMD to -help, please?

-betterC omit generating some runtime information and helper functions

@kinke
Copy link
Member

@kinke kinke commented Nov 25, 2016

I amended the LDMD addition and pushed it directly to master (62a2252), so that it can be part of beta 4.

@kinke kinke closed this Nov 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.