Jump to page: 1 2
Thread overview
What exactly does the compiler switch -betterC do?
Jun 19, 2016
Gary Willoughby
Jun 20, 2016
docandrew
Jun 20, 2016
Jacob Carlborg
Sep 19, 2016
Gary Willoughby
Sep 20, 2016
Jacob Carlborg
Sep 26, 2016
Gary Willoughby
Oct 05, 2016
Martin Nowak
Oct 05, 2016
Jacob Carlborg
Oct 06, 2016
Martin Nowak
Sep 21, 2016
Anonymouse
Sep 21, 2016
Jacob Carlborg
June 19, 2016
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?
June 20, 2016
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
June 20, 2016
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
September 19, 2016
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

September 20, 2016
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
September 21, 2016
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?


September 21, 2016
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
September 26, 2016
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
October 05, 2016
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.
October 05, 2016
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
« First   ‹ Prev
1 2