Skip to content

Commit 4511f8b

Browse files
committed
Add a target option for selecting a DWARF version
Certain platforms need to limit the DWARF version emitted (oxs, *bsd). This change adds a dwarf_version entry to the options that allows a platform to specify the dwarf version to use. By default this option is none and the default DWARF version is selected. Also adds an option for printing Option<u32> json keys
1 parent 08764ad commit 4511f8b

File tree

8 files changed

+23
-4
lines changed

8 files changed

+23
-4
lines changed

Diff for: compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,8 @@ pub fn finalize(cx: &CodegenCx<'_, '_>) {
120120
// for macOS to understand. For more info see #11352
121121
// This can be overridden using --llvm-opts -dwarf-version,N.
122122
// Android has the same issue (#22398)
123-
if cx.sess().target.target.options.is_like_osx
124-
|| cx.sess().target.target.options.is_like_android
125-
{
126-
llvm::LLVMRustAddModuleFlag(cx.llmod, "Dwarf Version\0".as_ptr().cast(), 2)
123+
if let Some(version) = cx.sess().target.target.options.dwarf_version {
124+
llvm::LLVMRustAddModuleFlag(cx.llmod, "Dwarf Version\0".as_ptr().cast(), version)
127125
}
128126

129127
// Indicate that we want CodeView debug information on MSVC

Diff for: compiler/rustc_target/src/spec/android_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub fn opts() -> TargetOptions {
99
.unwrap()
1010
.push("-Wl,--allow-multiple-definition".to_string());
1111
base.is_like_android = true;
12+
base.dwarf_version = Some(2);
1213
base.position_independent_executables = true;
1314
base.has_elf_tls = false;
1415
base.requires_uwtable = true;

Diff for: compiler/rustc_target/src/spec/apple_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn opts() -> TargetOptions {
2323
executables: true,
2424
target_family: Some("unix".to_string()),
2525
is_like_osx: true,
26+
dwarf_version: Some(2),
2627
has_rpath: true,
2728
dll_prefix: "lib".to_string(),
2829
dll_suffix: ".dylib".to_string(),

Diff for: compiler/rustc_target/src/spec/dragonfly_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn opts() -> TargetOptions {
2424
pre_link_args: args,
2525
position_independent_executables: true,
2626
relro_level: RelroLevel::Full,
27+
dwarf_version: Some(2),
2728
..Default::default()
2829
}
2930
}

Diff for: compiler/rustc_target/src/spec/freebsd_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn opts() -> TargetOptions {
2626
eliminate_frame_pointer: false, // FIXME 43575
2727
relro_level: RelroLevel::Full,
2828
abi_return_struct_as_int: true,
29+
dwarf_version: Some(2),
2930
..Default::default()
3031
}
3132
}

Diff for: compiler/rustc_target/src/spec/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,9 @@ pub struct TargetOptions {
816816
pub is_like_emscripten: bool,
817817
/// Whether the target toolchain is like Fuchsia's.
818818
pub is_like_fuchsia: bool,
819+
/// Version of DWARF to use if not using the default.
820+
/// Useful because some platforms (osx, bsd) only want up to DWARF2.
821+
pub dwarf_version: Option<u32>,
819822
/// Whether the linker support GNU-like arguments such as -O. Defaults to false.
820823
pub linker_is_gnu: bool,
821824
/// The MinGW toolchain has a known issue that prevents it from correctly
@@ -1012,6 +1015,7 @@ impl Default for TargetOptions {
10121015
is_like_emscripten: false,
10131016
is_like_msvc: false,
10141017
is_like_fuchsia: false,
1018+
dwarf_version: None,
10151019
linker_is_gnu: false,
10161020
allows_weak_linkage: true,
10171021
has_rpath: false,
@@ -1165,6 +1169,15 @@ impl Target {
11651169
base.options.$key_name = s;
11661170
}
11671171
} );
1172+
($key_name:ident, Option<u32>) => ( {
1173+
let name = (stringify!($key_name)).replace("_", "-");
1174+
if let Some(s) = obj.find(&name).and_then(Json::as_u64) {
1175+
if s < 1 || s > 5 {
1176+
return Err("Not a valid DWARF version number".to_string());
1177+
}
1178+
base.options.$key_name = Some(s as u32);
1179+
}
1180+
} );
11681181
($key_name:ident, Option<u64>) => ( {
11691182
let name = (stringify!($key_name)).replace("_", "-");
11701183
if let Some(s) = obj.find(&name).and_then(Json::as_u64) {
@@ -1417,6 +1430,7 @@ impl Target {
14171430
key!(is_like_emscripten, bool);
14181431
key!(is_like_android, bool);
14191432
key!(is_like_fuchsia, bool);
1433+
key!(dwarf_version, Option<u32>);
14201434
key!(linker_is_gnu, bool);
14211435
key!(allows_weak_linkage, bool);
14221436
key!(has_rpath, bool);
@@ -1654,6 +1668,7 @@ impl ToJson for Target {
16541668
target_option_val!(is_like_emscripten);
16551669
target_option_val!(is_like_android);
16561670
target_option_val!(is_like_fuchsia);
1671+
target_option_val!(dwarf_version);
16571672
target_option_val!(linker_is_gnu);
16581673
target_option_val!(allows_weak_linkage);
16591674
target_option_val!(has_rpath);

Diff for: compiler/rustc_target/src/spec/netbsd_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn opts() -> TargetOptions {
2424
position_independent_executables: true,
2525
relro_level: RelroLevel::Full,
2626
use_ctors_section: true,
27+
dwarf_version: Some(2),
2728
..Default::default()
2829
}
2930
}

Diff for: compiler/rustc_target/src/spec/openbsd_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn opts() -> TargetOptions {
2626
position_independent_executables: true,
2727
eliminate_frame_pointer: false, // FIXME 43575
2828
relro_level: RelroLevel::Full,
29+
dwarf_version: Some(2),
2930
..Default::default()
3031
}
3132
}

0 commit comments

Comments
 (0)