-
Notifications
You must be signed in to change notification settings - Fork 503
Use a DWARF version consistent with rustc #694
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,13 +214,17 @@ enum ToolFamily { | |
|
||
impl ToolFamily { | ||
/// What the flag to request debug info for this family of tools look like | ||
fn add_debug_flags(&self, cmd: &mut Tool) { | ||
fn add_debug_flags(&self, cmd: &mut Tool, dwarf_version: Option<u32>) { | ||
match *self { | ||
ToolFamily::Msvc { .. } => { | ||
cmd.push_cc_arg("-Z7".into()); | ||
} | ||
ToolFamily::Gnu | ToolFamily::Clang => { | ||
cmd.push_cc_arg("-g".into()); | ||
cmd.push_cc_arg( | ||
dwarf_version | ||
.map_or_else(|| "-g".into(), |v| format!("-gdwarf-{}", v)) | ||
.into(), | ||
); | ||
} | ||
} | ||
} | ||
|
@@ -1589,7 +1593,7 @@ impl Build { | |
cmd.args.push("-G".into()); | ||
} | ||
let family = cmd.family; | ||
family.add_debug_flags(cmd); | ||
family.add_debug_flags(cmd, self.get_dwarf_version()); | ||
} | ||
|
||
if self.get_force_frame_pointer() { | ||
|
@@ -2848,6 +2852,25 @@ impl Build { | |
}) | ||
} | ||
|
||
fn get_dwarf_version(&self) -> Option<u32> { | ||
// Tentatively matches the DWARF version defaults as of rustc 1.62. | ||
let target = self.get_target().ok()?; | ||
if target.contains("android") | ||
|| target.contains("apple") | ||
|| target.contains("dragonfly") | ||
|| target.contains("freebsd") | ||
|| target.contains("netbsd") | ||
|| target.contains("openbsd") | ||
|| target.contains("windows-gnu") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just in case. The original remark was specifically about mingw32, the 32-bit target. The 64-bit one was not observed to fail. And the thing is that "windows-gnu" would cover both 32- and 64-bit variants. At the same time the flag appears to be recognized by the 64-bit toolchain and causes no run-time problems. In other words, even though this line doesn't pinpoint the specific problem, it doesn't seem to incur any collateral damage. If it's acceptable is up to the actual cc-rs maintainers. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea what will happen on 64-bit targets because they typically use SEH instead of DWARF. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Note that the 32-bit problem is not really/necessarily about exception handling. Because it was specifically debug-build binaries, ones packed with debugging information, that were rendered unexecutable. This is not to say that I'm saying that the 64-bit toolchain uses DWARF for debugging symbols. Because I'm not, as I don't really know. But I can confirm that -gdwarf appears to be an acceptable option. It can just as well be ignored, but the binaries are executable, and that's what counts for the moment.
But it won't be affected by this target.contains. Right? So that if anything, you should double-check and report back. Or keep this in mind and suggest a workaround later on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Exceptions handling and Debug info are more or less orthogonal. |
||
{ | ||
Some(2) | ||
} else if target.contains("linux") { | ||
Some(4) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
fn get_force_frame_pointer(&self) -> bool { | ||
self.force_frame_pointer.unwrap_or_else(|| self.get_debug()) | ||
} | ||
|
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 would argue that it would be more than appropriate to add a commentary stating that the version choice reflects rustc defaults as of version X through Y. Idea is that whenever defaults change, there would be a hint that corresponding adjustment would be needed.