Skip to content

Commit b9d7efe

Browse files
authored
Rollup merge of rust-lang#74631 - petrochenkov:ehdr2, r=jonas-schievink
rustc_target: Add a target spec option for disabling `--eh-frame-hdr` Disable `--eh-frame-hdr` for targets that use an `ld`-like linker, but don't support that option. Do it through a target spec option rather than through hard-coding in `linker.rs`. The option is still enabled by default though. cc rust-lang#73564 Fixes rust-lang#73564 (comment) Fixes rust-lang#74625 Fixes rust-embedded/msp430-rt#12
2 parents 679e1a6 + 49b9a64 commit b9d7efe

14 files changed

+24
-8
lines changed

src/librustc_codegen_ssa/back/link.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,9 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
15981598
}
15991599

16001600
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
1601-
cmd.add_eh_frame_header();
1601+
if sess.target.target.options.eh_frame_header {
1602+
cmd.add_eh_frame_header();
1603+
}
16021604

16031605
// NO-OPT-OUT, OBJECT-FILES-NO
16041606
if crt_objects_fallback {

src/librustc_codegen_ssa/back/linker.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -619,13 +619,7 @@ impl<'a> Linker for GccLinker<'a> {
619619
// Some versions of `gcc` add it implicitly, some (e.g. `musl-gcc`) don't,
620620
// so we just always add it.
621621
fn add_eh_frame_header(&mut self) {
622-
if !self.sess.target.target.options.is_like_osx
623-
&& !self.sess.target.target.options.is_like_windows
624-
&& !self.sess.target.target.options.is_like_solaris
625-
&& self.sess.target.target.target_os != "uefi"
626-
{
627-
self.linker_arg("--eh-frame-hdr");
628-
}
622+
self.linker_arg("--eh-frame-hdr");
629623
}
630624
}
631625

src/librustc_target/spec/apple_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn opts() -> TargetOptions {
3131
has_elf_tls: version >= (10, 7),
3232
abi_return_struct_as_int: true,
3333
emit_debug_gdb_scripts: false,
34+
eh_frame_header: false,
3435

3536
// This environment variable is pretty magical but is intended for
3637
// producing deterministic builds. This was first discovered to be used

src/librustc_target/spec/freestanding_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn opts() -> TargetOptions {
2525
has_rpath: false,
2626
pre_link_args: args,
2727
position_independent_executables: false,
28+
eh_frame_header: false,
2829
..Default::default()
2930
}
3031
}

src/librustc_target/spec/illumos_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn opts() -> TargetOptions {
2323
is_like_solaris: true,
2424
limit_rdylib_exports: false, // Linker doesn't support this
2525
eliminate_frame_pointer: false,
26+
eh_frame_header: false,
2627
late_link_args,
2728

2829
// While we support ELF TLS, rust requires a way to register

src/librustc_target/spec/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,11 @@ pub struct TargetOptions {
988988
/// Whether to use legacy .ctors initialization hooks rather than .init_array. Defaults
989989
/// to false (uses .init_array).
990990
pub use_ctors_section: bool,
991+
992+
/// Whether the linker is instructed to add a `GNU_EH_FRAME` ELF header
993+
/// used to locate unwinding information is passed
994+
/// (only has effect if the linker is `ld`-like).
995+
pub eh_frame_header: bool,
991996
}
992997

993998
impl Default for TargetOptions {
@@ -1079,6 +1084,7 @@ impl Default for TargetOptions {
10791084
relax_elf_relocations: false,
10801085
llvm_args: vec![],
10811086
use_ctors_section: false,
1087+
eh_frame_header: true,
10821088
}
10831089
}
10841090
}
@@ -1471,6 +1477,7 @@ impl Target {
14711477
key!(relax_elf_relocations, bool);
14721478
key!(llvm_args, list);
14731479
key!(use_ctors_section, bool);
1480+
key!(eh_frame_header, bool);
14741481

14751482
// NB: The old name is deprecated, but support for it is retained for
14761483
// compatibility.
@@ -1708,6 +1715,7 @@ impl ToJson for Target {
17081715
target_option_val!(relax_elf_relocations);
17091716
target_option_val!(llvm_args);
17101717
target_option_val!(use_ctors_section);
1718+
target_option_val!(eh_frame_header);
17111719

17121720
if default.unsupported_abis != self.options.unsupported_abis {
17131721
d.insert(

src/librustc_target/spec/msp430_none_elf.rs

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ pub fn target() -> TargetResult {
5656
// See the thumb_base.rs file for an explanation of this value
5757
emit_debug_gdb_scripts: false,
5858

59+
eh_frame_header: false,
60+
5961
..Default::default()
6062
},
6163
})

src/librustc_target/spec/riscv32i_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn target() -> TargetResult {
2525
relocation_model: RelocModel::Static,
2626
emit_debug_gdb_scripts: false,
2727
unsupported_abis: super::riscv_base::unsupported_abis(),
28+
eh_frame_header: false,
2829
..Default::default()
2930
},
3031
})

src/librustc_target/spec/riscv32imac_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn target() -> TargetResult {
2525
relocation_model: RelocModel::Static,
2626
emit_debug_gdb_scripts: false,
2727
unsupported_abis: super::riscv_base::unsupported_abis(),
28+
eh_frame_header: false,
2829
..Default::default()
2930
},
3031
})

src/librustc_target/spec/riscv32imc_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub fn target() -> TargetResult {
2525
relocation_model: RelocModel::Static,
2626
emit_debug_gdb_scripts: false,
2727
unsupported_abis: super::riscv_base::unsupported_abis(),
28+
eh_frame_header: false,
2829
..Default::default()
2930
},
3031
})

src/librustc_target/spec/riscv64gc_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn target() -> TargetResult {
2626
code_model: Some(CodeModel::Medium),
2727
emit_debug_gdb_scripts: false,
2828
unsupported_abis: super::riscv_base::unsupported_abis(),
29+
eh_frame_header: false,
2930
..Default::default()
3031
},
3132
})

src/librustc_target/spec/riscv64imac_unknown_none_elf.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn target() -> TargetResult {
2626
code_model: Some(CodeModel::Medium),
2727
emit_debug_gdb_scripts: false,
2828
unsupported_abis: super::riscv_base::unsupported_abis(),
29+
eh_frame_header: false,
2930
..Default::default()
3031
},
3132
})

src/librustc_target/spec/solaris_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub fn opts() -> TargetOptions {
88
target_family: Some("unix".to_string()),
99
is_like_solaris: true,
1010
limit_rdylib_exports: false, // Linker doesn't support this
11+
eh_frame_header: false,
1112

1213
..Default::default()
1314
}

src/librustc_target/spec/windows_gnu_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ pub fn opts() -> TargetOptions {
9191
abi_return_struct_as_int: true,
9292
emit_debug_gdb_scripts: false,
9393
requires_uwtable: true,
94+
eh_frame_header: false,
9495

9596
..Default::default()
9697
}

0 commit comments

Comments
 (0)