-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Don't let .debug_gdb_scripts become loadable into memory. #41627
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"by the linker" - you mean the compiler, right? The linker doesn't know or care about llvm.used stuff but likely it has some special case to preserve the .debug_gdb_scripts section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, by the linker. I thought that too, and started writing a comment, but turns out that it's not true; LLVM has a separate
!llvm.compiler.used
for what you say, and!llvm.used
is defined to keep the symbol through the linking process as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Upon further investigation, on ELF,
!llvm.used
doesn't actually change anything in the object file, so LangRef is blatantly lying. On MachO, it uses a.no_dead_strip
directive. On ELF...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To add to this, the default linker script on x86_64 Linux has no mention of
.debug_gdb_scripts
(or a wildcard over all.debug*
sections), and the logic of --gc-sections does not appear to special-case any of that either (it only really special-cases.eh_frame
, in general; the rest is handled by traversing the graph). So this is interesting.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I only modified the part of the comment that was obviously wrong to me. Is it possible
--gc-sections
will strip this section, making it useless?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have confirmed that the linker, called with
--gc-sections
, will, in fact, remove.debug_gdb_scripts
(whether or not!llvm.used
is used, of course). Not only that, but it will also gladly remove this section even when used exactly as directed by the gcc manual, and building with gcc and binutils ld!My conclusion is that, I suppose not completely unexpectedly, this feature is poorly thought out and is not widely supported by toolchains, and Rust's original solution is gross but undeniably effective. Ideally, linker scripts (on ELF platforms) would be updated to do something like...
... but unfortunately, this doesn't work! Without the directive above, the section shows in objdump as:
which is of course not what we want because it's LOAD. With
(NOLOAD)
, however, it's another story entirely:So in a direct contradiction with the ld manual, which claims that:
the contents of the section does not, in fact, appear in the output file at all.
I'd like to be proven wrong but I am afraid it's not possible to implement this feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I have proven myself wrong. If I use the extremely obscure output section type of
INFO
in the linker script, then exactly the thing that I expect happens!I do not believe it is viable to integrate this into upstream rustc and so this PR and its parent issue may be closed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So incidentally I was curious where did the DEBUGGING bit appear, since that's not something gcc (or gas) can do, and I looked at the binutils source code. It looks like all
.debug*
sections should have their SEC_ALLOC bit removed (and SEC_DEBUGGING bit added)...... but this is evidently not happening for
.debug_gdb_scripts
for some reason that I have no doubt is deeply unsettling in more than one way. There's really a large amount of logic in binutils that touchesSEC_DEBUGGING
, most of which is almost but not exactly identical platform code, and the more I look into it, the less I want to be aware of it. Or be conscious.