Add -gu compiler flag to enforce unwind table generation (including for -betterC)#22818
Add -gu compiler flag to enforce unwind table generation (including for -betterC)#22818IDONTUSEGH wants to merge 5 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @IDONTUSEGH! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#22818" |
|
I had to remove
I don't see a
What is the error when removing that flag? If you're already linking a custom -betterC compatible druntime then removing |
I agree that avoiding a new flag is ideal. Initially, I considered enabling this by default for debug builds, but I wanted to avoid changing existing behavior/assumptions for users.
I may have confused it with Clang's Since C doesn't support EH, and
We've tried removing the flag, but there are too many assumptions baked into the codebase. Since this project is a shared environment with C and strictly embedded constraints, it isn't feasible to resolve every errors without -betterC. |
But .eh_frame is not only used for throwing Exceptions, and C compilers emit it by default just like LDC. I don't think users will mind when dmd becomes consistent with them.
But which kind of errors, can you post one of them? -betterC is supposed to enforce a subset, so if a codebase compiles under those restrictions, and then you lift the restriction, then that's not supposed to generate new errors. |
|
C compilers do not emit .eh_frame by default on all platforms. For instance, my testing on Alpine Linux (musl) confirms they are omitted by default. I believe maintaining the current default behavior is valuable to avoid upsetting existing users or regressing on binary size. Regarding the errors: I cannot share specific project details due to confidentiality. However, the issue is that removing -betterC introduces issues that the target environment isn't configured to handle. I am currently working on a PR for dmd to help address a few of them. |
Okay, but they still can because it's useful. I interpreted your argument as "users of
Don't worry, users don't expect dmd to generate optimized or small executables, that's what ldc and gdc get used for. (And LDC incidentally still emits .eh_info so unless there's people complaining about that it should be fine) |
GDC has """ |
|
To remind everyone, the -betterC switch should be split into its constituent parts to match gdc. So instead of saying I want unwinding tables, you say I don't want TypeInfo/ModuleInfo, druntime linked, exceptions. |
What this PR is asking for is |
| else if (arg == "-gs") // https://dlang.org/dmd.html#switch-gs | ||
| driverParams.alwaysframe = true; | ||
| else if (arg == "-gu") // generate unwind tables for stack tracing | ||
| else if (arg == "-gu") // https://dlang.org/dmd.html#switch-gu |
There was a problem hiding this comment.
BTW that needs an update to src/dmd/cli.d
Adds a new compiler flag
-gu(generate unwind tables) that enables stack backtracing in betterC.The motive of the PR was working on a client's project that uses -betterC for deployment scenarios with a tweaked D runtime. When debugging crashes, I couldn't generate meaningful backtraces with DMD, the backtrace() function would only return a single frame. Switching to LDC worked around the issue, and disabling -betterC was not an option due to the runtime requirements of the target environment.
This flag allows DMD to emit the necessary unwind tables that backtrace() needs to walk the stack, matching LDC's behavior (and C compilers).