Skip to content

Comments

Preserve the __debug_line section on macOS in the final executable#8168

Merged
dlang-bot merged 2 commits intodlang:masterfrom
jacob-carlborg:debug-line-macos
Apr 18, 2018
Merged

Preserve the __debug_line section on macOS in the final executable#8168
dlang-bot merged 2 commits intodlang:masterfrom
jacob-carlborg:debug-line-macos

Conversation

@jacob-carlborg
Copy link
Contributor

The linker on macOS will remove any debug info, i.e. every section with the S_ATTR_DEBUG flag, this includes everything in the __DWARF section. By using the S_REGULAR flag the linker will not remove this section. This allows to get the filenames and line numbers for backtraces from the executable.

Normally the linker removes all the debug info but adds a reference to the object files. The debugger can then read the object files to get filename and line number information. It's also possible to use an additional tool that generates a separate .dSYM file. This file can then later be deployed with the application if debug info is needed when the application is deployed.

All calls to this function are guarded with and #if for EFL.
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @jacob-carlborg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Your 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 locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub fetch digger
dub run digger -- build "master + dmd#8168"

@jacob-carlborg
Copy link
Contributor Author

I've not included a changelog entry here because it's not a user facing change.

@WalterBright
Copy link
Member

Please add your opening comment in as a comment in the code.

@jacob-carlborg
Copy link
Contributor Author

Please add your opening comment in as a comment in the code.

It's already in the commit message, do you want it in the code as well?

The linker on macOS will remove any debug info, i.e. every section
with the `S_ATTR_DEBUG` flag, this includes everything in the
`__DWARF` section. By using the `S_REGULAR` flag the linker will not
remove this section. This allows to get the filenames and line numbers
for backtraces from the executable.

Normally the linker removes all the debug info but adds a reference to
the object files. The debugger can then read the object files to get
filename and line number information. It's also possible to use an
additional tool that generates a separate `.dSYM` file. This file can
then later be deployed with the application if debug info is needed
when the application is deployed.
@jacob-carlborg
Copy link
Contributor Author

Please add your opening comment in as a comment in the code.

@WalterBright added comment to the code and added a test as well.

@jacob-carlborg
Copy link
Contributor Author

Is the failing DAutoTest related to this change? Nothing else fails.

@wilzbach
Copy link
Contributor

Yeah the error is

Test the D Language specification
../dmd/generated/linux/release/64/dmd -run tools/dspec_tester.d --compiler=../dmd/generated/linux/release/64/dmd
---
void main() {
import std.stdio;
        struct S { int x; float y; }

        int foo(S s) { return s.x; }

        foo( S(1, 2) ); // set field x to 1, field y to 2
        
}
---
/usr/bin/ld: error in __stdin.o(.eh_frame); no .eh_frame_hdr table will be created.
/usr/bin/ld: __stdin.o: invalid string offset 1096055152 >= 528 for section `.strtab'
/usr/bin/ld: unknown operator '(' in complex symbol
/usr/bin/ld: final link failed: Invalid operation
collect2: error: ld returned 1 exit status
Error: linker exited with status 1

But it's unrelated to this PR.

@wilzbach
Copy link
Contributor

Is the failing DAutoTest related to this change? Nothing else fails.

-> dlang/dlang.org#2345

@jacob-carlborg
Copy link
Contributor Author

Everything is green.

@jacob-carlborg
Copy link
Contributor Author

Ping, this is pretty trivial.

@jacob-carlborg
Copy link
Contributor Author

@wilzbach @JinShil ping

@dlang-bot dlang-bot merged commit 7fa85b6 into dlang:master Apr 18, 2018
@WalterBright
Copy link
Member

@jacob-carlborg
Copy link
Contributor Author

@WalterBright

There are a couple of options:

  • You can choose to revert this. Then filenames and line numbers will not be available in stack traces of exceptions (unless LDC has upstreamed its changes in druntime. The changes require an external tool, shipped with Xcode, which might not be available when an application is deployed)
  • Try to fix the alignment (don't know if that's possible)
  • Revert this change but duplicate the debug info in a custom section. I don't know if the linker will strip custom sections with the S_ATTR_DEBUG attribute

@WalterBright
Copy link
Member

@jacob-carlborg I'd prefer to fix the problem rather than revert this. Except nobody seems to know what to do about it.

@WalterBright
Copy link
Member

Can you try fixing the alignment and see if it works?

@jacob-carlborg
Copy link
Contributor Author

Can you try fixing the alignment and see if it works?

Unfortunately that's out of my league. It would be more suitable for someone that actually knows the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants