Bug 16547 – -betterC switch no longer removes druntime symbols
Status
RESOLVED
Resolution
DUPLICATE
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2016-09-26T19:57:00Z
Last change time
2016-10-07T21:10:46Z
Assigned to
nobody
Creator
dev
Comments
Comment #0 by dev — 2016-09-26T19:57:12Z
Example program:
import core.stdc.stdio;
extern(C) void main()
{
printf("Hello World!\n");
}
When building an executable and using the -betterC flag using DMD v2.070.0 the symbols emitted from the above program are thus:
0000000000000000 T _main
U _printf
Starting from DMD v2.071.0 the druntime information is not omitted from the executable and there are over two thousand symbols inside.
Reference thread: http://forum.dlang.org/thread/[email protected]
Comment #1 by dlang-bugzilla — 2016-09-30T15:17:54Z
(In reply to Gary Willoughby from comment #0)
> When building an executable and using the -betterC flag using DMD v2.070.0
> the symbols emitted from the above program are thus:
>
> 0000000000000000 T _main
> U _printf
I can't reproduce this.
$ uname -a
Linux home.thecybershadow.net 4.7.4-1-ARCH #1 SMP PREEMPT Thu Sep 15 15:24:29 CEST 2016 x86_64 GNU/Linux
$ dmd --version
DMD64 D Compiler v2.070.0
Copyright (c) 1999-2015 by Digital Mars written by Walter Bright
$ cat test.d
import core.stdc.stdio;
extern(C) void main()
{
printf("Hello World!\n");
}
$ dmd -betterC test
$ nm test | wc -l
1814
Comment #2 by code — 2016-10-05T09:42:07Z
Can't reproduce any significant different among 2.069.x - 2.070.2-b1 either.
Guess this is a confusion b/c the program was still linked w/ phobos.
Also see issue 11881 for a few shortcomings w/ the current -betterC state.
Comment #3 by doob — 2016-10-05T12:42:51Z
$ 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
Comment #4 by code — 2016-10-07T16:18:31Z
Apparently happens b/c of __dmd_personality_v0 being emitted with -betterC.
A simple workaround is to add a dummy personality symbol to your binary, e.g. in the same object file as main.
extern(C) __gshared int __dmd_personality_v0;
Not sure if we did disable EH for -betterC. Would make sense, right?
Comment #5 by doob — 2016-10-07T17:42:07Z
(In reply to Martin Nowak from comment #4)
> Apparently happens b/c of __dmd_personality_v0 being emitted with -betterC.
> A simple workaround is to add a dummy personality symbol to your binary,
> e.g. in the same object file as main.
>
> extern(C) __gshared int __dmd_personality_v0;
Yeah, that works.
> Not sure if we did disable EH for -betterC. Would make sense, right?
I guess. Unless we can limit it to something like Errors which cannot be caught. Or somehow use what the C++ runtime provides, if that would help.
BTW, how did this work in DMD 2.070.0? It didn't have anything similar to __dmd_personality_v0?
Comment #6 by code — 2016-10-07T20:18:19Z
(In reply to Jacob Carlborg from comment #5)
> > Not sure if we did disable EH for -betterC. Would make sense, right?
>
> I guess. Unless we can limit it to something like Errors which cannot be
> caught. Or somehow use what the C++ runtime provides, if that would help.
It's exactly this native EH that drags in so much stuff.
Did we excluded EH when introducing -betterC? Without TypeInfo it would hardly work anyhow.
> BTW, how did this work in DMD 2.070.0? It didn't have anything similar to
> __dmd_personality_v0?
Yes, it's part of the native DWARF EH implementation, which was extended to OSX w/ 2.071.0.
I'm inclined to merge this with issue 11881 b/c it's just another backend mechanism, that we're not correctly disabling with -betterC.
Also if the binary weren't linked with phobos/druntime, this would have properly errored as undefined symbol. BetterC should always be used with -defaultlib=, maybe we should make that the default.
Comment #7 by code — 2016-10-07T21:10:46Z
Merging w/ issue 11881.
Until this get's fixed, please use
extern(C) __gshared int __dmd_personality_v0;
as a workaround and remember to not link -betterC code with phobos using the
-defaultlib=
compiler switch.
*** This issue has been marked as a duplicate of issue 11881 ***