Switch -g disables optimizations.

Marco Leise via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Fri Oct 9 12:41:36 PDT 2015


Am Fri, 09 Oct 2015 09:24:05 +0200
schrieb David Nadlinger via digitalmars-d-ldc
<digitalmars-d-ldc at puremagic.com>:

> On 9 Oct 2015, at 7:46, Joakim via digitalmars-d-ldc wrote:
> > On Friday, 9 October 2015 at 04:22:51 UTC, Marco Leise wrote:
> >> push   rbp
> >> mov    rbp,rsp
> >> xor    eax,eax
> >> pop    rbp
> >> ret
> > Optimization is turned off in debug mode, with a comment claiming 
> > debug info doesn't work with optimization:
> >
> > https://github.com/ldc-developers/ldc/blob/9d3dd1f609e08f001aeec2cacb1c55707f37884b/gen/optimizer.cpp#L179
> 
> We should actually look into re-enabling that. I don't know the story 
> behind that comment, and I'm not sure who does.
> 
> In this particular case, though, the reason for the "ugly" codegen is 
> that LDC enables -disable-fp-elim (the equivalent of GCC's 
> -fno-omit-frame-pointer) by default when -g is passed. I suppose the 
> reason for this was that all the druntime backtracing code (inherited 
> from DMD) relies on a full call frame being set up for each function.
> 
>   — David
 
Then this was all intentional. It's just that neither Clang
nor GDC do this and I generalized "-g" to be adding debug
info to an otherwise unchanged compile. Maybe the other
compilers also change to some saner defaults when -g is used.

The stack unwinding code in druntime used to blow up anyways
as soon as you call through GCC compiled functions, with
-fomit-frame-pointer as default (on amd64). It's rather
surprising when the default system ABI causes unexpected
runtime crashes.

-- 
Marco



More information about the digitalmars-d-ldc mailing list