Skip to content
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

equivalent for dmd's -gx option (add stack stomp code) ? #2489

Closed
timotheecour opened this issue Jan 11, 2018 · 11 comments
Closed

equivalent for dmd's -gx option (add stack stomp code) ? #2489

timotheecour opened this issue Jan 11, 2018 · 11 comments

Comments

@timotheecour
Copy link

  • what's the equivalent for dmd's -gx option (add stack stomp code) ? (for ldmd2 and ldc2)
  • is ldc2's -disable-fp-elim (Disable frame pointer elimination optimization) equivalent to ldmd2's -gs (always emit stack frame)?
@kinke
Copy link
Member

kinke commented Jan 11, 2018

  1. There is none, at least none that I know of.
  2. Should be.

Please post questions in the forum, the issue tracker is for issues.

@kinke
Copy link
Member

kinke commented Jan 16, 2018

Are you asking this because you're still pursuing mixing code compiled by different compilers?

@timotheecour
Copy link
Author

timotheecour commented Jan 16, 2018

was trying to debug a crash and was searching for an equivalent of dmd's -gx which could've helped with that.

Are you asking this because you're still pursuing mixing code compiled by different compilers?

that was unrelated to that effort. But I was indeed able to mix code produced by ldc and dmd in some example program, using proper symbol hiding (eg: only un-hide symbols for critical hot path functions). This is useful for combining compilation speed of dmd with runtime speed of ldc (for hot functions which don't need to be recompiled often)

@kinke
Copy link
Member

kinke commented Jan 16, 2018

I'd say LDC's answer to -gx is -fsanitize. ;)

Wrt. mixing the code, did it pay off, compile-time wise? ;)
[DMD with enabled inlining may not be faster than LDC with optimizations; on the contrary, building an optimized DMD itself takes significantly longer with DMD, as recently posted by Rainer.]

@dnadlinger
Copy link
Member

Yep, check out the different sanitizers for help with that sort of corruption issue (AddressSanitizer might be able to help you in that particular case). There are probably some more Clang/LLVM ideas we could steal if there is a concrete need.

@JohanEngelen
Copy link
Member

-gx stack stomp = overwrite stack with zeros, right?
That is different behavior from sanitizing, so none of the sanitizers will offer that. I've looked for an LLVM equivalent, but haven't found it yet. I would think this is behavior desirable for some security folks, so probably it exists somewhere in LLVM.

@timotheecour
Copy link
Author

-gx stack stomp = overwrite stack with zeros, right?

with a special value (but not 0 IIRC)

DMD with enabled inlining may not be faster than LDC with optimizations

why enabled inlining? my use case is to combine fast recompilation (dmd with no optimizations) with fast runtime speed (ldc with optmizations, for parts of the program i'm not editing)

@kinke
Copy link
Member

kinke commented Jan 18, 2018

why enabled inlining? my use case is to combine fast recompilation (dmd with no optimizations) with fast runtime speed (ldc with optmizations, for parts of the program i'm not editing)

Just saying that DMD isn't generally faster. I'm wondering how many seconds you'd hope to gain by compiling the non-optimized active parts by DMD instead of LDC.

@timotheecour
Copy link
Author

I've looked for an LLVM equivalent, but haven't found it yet. I would think this is behavior desirable for some security folks, so probably it exists somewhere in LLVM.

clang has -fstack-protector is that it?

@dnadlinger
Copy link
Member

That uses canary values to make stack buffer overflows non-exploitable. I'm not sure whether there is a direct analogon to -gx in LLVM, but AddressSanitizer should catch use-after-return issues just fine (in fact, in a much more useful fashion).

Hence the above comment - the answer to your original question is "no", but that's not really actionable. If you have a particular debugging situation where the sanitisers are not enough, we can see what else LLVM has to offer to help.

@JohanEngelen
Copy link
Member

but AddressSanitizer should catch use-after-return issues just fine

Currently that does not work for LDC, because it is non-trivial to make detect_stack_use_after_return work.
See also http://johanengelen.github.io/ldc/2017/12/25/LDC-and-AddressSanitizer.html and #2470
It's something I have worked on, and plan to work on more, but ... time...
I agree that -gx shouldn't be used to catch those kind of bugs.

The other use case of -gx that I can think of is security related. For C++, I can't find much on stack cleansing or overwriting the stack with zeros/random values to prevent the caller to read function local data after the callee returns. It's also massive overkill, and thus useless in practice, to do -gx for every function. So an attribute feels more suitable.

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

No branches or pull requests

4 participants