www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What exactly does the compiler switch -betterC do?

reply Gary Willoughby <dev nomad.so> writes:
When compiling, what exactly does the -betterC flag do? The 
command help says "omit generating some runtime information and 
helper functions" but what does this really mean? Is there any 
specifics somewhere?
Jun 19 2016
next sibling parent docandrew <x x.com> writes:
On Sunday, 19 June 2016 at 19:53:46 UTC, Gary Willoughby wrote:
 When compiling, what exactly does the -betterC flag do? The 
 command help says "omit generating some runtime information and 
 helper functions" but what does this really mean? Is there any 
 specifics somewhere?
My understanding was that -betterC was not fully implemented yet, due mostly to tight compiler integration with the runtime. (old info?) I'm not super smart on the DMD source, but it looks like betterC prevents genhelpers() and genModuleInfo() from being called, with "helpers" appearing to be array checking, asserts and unit tests. A comparison of object files compiled with and without the flags shows just a small reduction in the size of the code, but grepping for bounds checking, unit tests and ModuleInfo in the -betterC generated object file shows they are missing. Hope this helps, -Jon
Jun 19 2016
prev sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2016-06-19 21:53, Gary Willoughby wrote:
 When compiling, what exactly does the -betterC flag do? The command help
 says "omit generating some runtime information and helper functions" but
 what does this really mean? Is there any specifics somewhere?
It is intended to allow you to link an application without druntime. A Hello World using "extern(C) main" and printing using "printf" contains the following symbols on OS X: 00000000000000a8 S _D4main12__ModuleInfoZ 0000000000000068 T _D4main15__unittest_failFiZv 0000000000000018 T _D4main7__arrayZ 0000000000000040 T _D4main8__assertFiZv 00000000000000b5 s _TMP1 U __d_arraybounds U __d_assert U __d_unittest 0000000000000000 T _main U _printf If compiled with -betterC, it contains these: 0000000000000000 T _main U _printf -- /Jacob Carlborg
Jun 19 2016
next sibling parent reply Gary Willoughby <dev nomad.so> writes:
On Monday, 20 June 2016 at 06:35:32 UTC, Jacob Carlborg wrote:
 On 2016-06-19 21:53, Gary Willoughby wrote:
 When compiling, what exactly does the -betterC flag do? The 
 command help
 says "omit generating some runtime information and helper 
 functions" but
 what does this really mean? Is there any specifics somewhere?
It is intended to allow you to link an application without druntime. A Hello World using "extern(C) main" and printing using "printf" contains the following symbols on OS X: 00000000000000a8 S _D4main12__ModuleInfoZ 0000000000000068 T _D4main15__unittest_failFiZv 0000000000000018 T _D4main7__arrayZ 0000000000000040 T _D4main8__assertFiZv 00000000000000b5 s _TMP1 U __d_arraybounds U __d_assert U __d_unittest 0000000000000000 T _main U _printf If compiled with -betterC, it contains these: 0000000000000000 T _main U _printf
I get significantly more symbols than that when compiling the following program any idea why? import core.stdc.stdio; extern(C) void main() { printf("Hello World!\n"); } $ rdmd --build-only --force -betterC -de -O -inline -release -w test.d $ nm test
Sep 19 2016
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2016-09-19 23:09, Gary Willoughby wrote:

 $ rdmd --build-only --force -betterC -de -O -inline -release -w test.d
 $ nm test
Indeed. I just noticed now that there's a difference between 2.070.0 and 2.071.0. I get 4 symbols with 2.070.0 and 2428 with 2.071.0. I would say it's a bug. -- /Jacob Carlborg
Sep 20 2016
parent Gary Willoughby <dev nomad.so> writes:
On Tuesday, 20 September 2016 at 13:23:35 UTC, Jacob Carlborg 
wrote:
 On 2016-09-19 23:09, Gary Willoughby wrote:

 $ rdmd --build-only --force -betterC -de -O -inline -release 
 -w test.d
 $ nm test
Indeed. I just noticed now that there's a difference between 2.070.0 and 2.071.0. I get 4 symbols with 2.070.0 and 2428 with 2.071.0. I would say it's a bug.
Filed: https://issues.dlang.org/show_bug.cgi?id=16547
Sep 26 2016
prev sibling parent reply Martin Nowak <code dawg.eu> writes:
On Monday, 19 September 2016 at 21:09:39 UTC, Gary Willoughby 
wrote:
 On Monday, 20 June 2016 at 06:35:32 UTC, Jacob Carlborg wrote:
 On 2016-06-19 21:53, Gary Willoughby wrote:
 If compiled with -betterC, it contains these:

 0000000000000000 T _main
                  U _printf
I get significantly more symbols than that when compiling the following program any idea why?
Because you're linking with druntime/phobos which drags in plenty of symbols (including a GC). Also Jakob is showing the symbols of the object file, not executable.
Oct 05 2016
parent reply Jacob Carlborg <doob me.com> writes:
On 2016-10-05 11:39, Martin Nowak wrote:

 Because you're linking with druntime/phobos which drags in plenty of
 symbols (including a GC). Also Jakob is showing the symbols of the
 object file, not executable.
No. There's a difference between DMD 2.070.0 and 2.071.0: $ cat main.d module main; extern (C) int printf(in char*, ...); extern (C) void main() { printf("asd\n"); } $ dvm use 2.070.0 $ dmd --version DMD64 D Compiler v2.070.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright $ dmd -betterC main.d $ nm main | wc -l 4 $ dvm use 2.071.0 $ dmd --version DMD64 D Compiler v2.071.0 Copyright (c) 1999-2015 by Digital Mars written by Walter Bright $ dmd -betterC main.d $ nm main | wc -l 2428 Note that "main" is declared as "extern (C)", which makes all the difference. -- /Jacob Carlborg
Oct 05 2016
parent Martin Nowak <code dawg.eu> writes:
On Wednesday, 5 October 2016 at 12:42:14 UTC
On Wednesday, 5 October 2016 at 12:42:14 UTC, Jacob Carlborg 
wrote:
 No. There's a difference between DMD 2.070.0 and 2.071.0:
OK, I'll retry on OSX, the bug report said Linux though. Seems like we're dragging in all of the _Dmain stuff. IIRC _Dmain is marked as weak in some extra C file, but the problem might be unrelated to that. https://issues.dlang.org/show_bug.cgi?id=16547
Oct 06 2016
prev sibling parent reply Anonymouse <asdf asdf.net> writes:
On Monday, 20 June 2016 at 06:35:32 UTC, Jacob Carlborg wrote:
 On 2016-06-19 21:53, Gary Willoughby wrote:
 When compiling, what exactly does the -betterC flag do? The 
 command help
 says "omit generating some runtime information and helper 
 functions" but
 what does this really mean? Is there any specifics somewhere?
It is intended to allow you to link an application without druntime. [...]
What is the equavilent in gdc and ldc?
Sep 20 2016
parent Jacob Carlborg <doob me.com> writes:
On 2016-09-21 02:25, Anonymouse wrote:
 On Monday, 20 June 2016 at 06:35:32 UTC, Jacob Carlborg wrote:
 It is intended to allow you to link an application without druntime.
 [...]
What is the equavilent in gdc and ldc?
No idea, try ldc/gdc --help ;) -- /Jacob Carlborg
Sep 20 2016