Skip to content

Implement the betterC switch like DMD does. #1872

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

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

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 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
Copy link
Contributor Author

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 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 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we require __dmd_personality_v0 in the first place?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, good idea.

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

extern(C) __gshared void* _d_dso_registry;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Namely, don't emit the ModuleInfo.
@9il
Copy link

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 commented Nov 13, 2016

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

@dnadlinger
Copy link
Member

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

-betterC omit generating some runtime information and helper functions

@kinke
Copy link
Member

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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants