Skip to content

Commit 346dc2f

Browse files
petrochenkovMark-Simulacrum
authored andcommitted
rustc_target: Add a target spec option for disabling --eh-frame-hdr
1 parent e69dd7a commit 346dc2f

14 files changed

+24
-8
lines changed

src/librustc_codegen_ssa/back/link.rs

Lines changed: 3 additions & 1 deletion
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

Lines changed: 1 addition & 7 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

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

994999
impl Default for TargetOptions {
@@ -1081,6 +1086,7 @@ impl Default for TargetOptions {
10811086
relax_elf_relocations: false,
10821087
llvm_args: vec![],
10831088
use_ctors_section: false,
1089+
eh_frame_header: true,
10841090
}
10851091
}
10861092
}
@@ -1474,6 +1480,7 @@ impl Target {
14741480
key!(relax_elf_relocations, bool);
14751481
key!(llvm_args, list);
14761482
key!(use_ctors_section, bool);
1483+
key!(eh_frame_header, bool);
14771484

14781485
// NB: The old name is deprecated, but support for it is retained for
14791486
// compatibility.
@@ -1712,6 +1719,7 @@ impl ToJson for Target {
17121719
target_option_val!(relax_elf_relocations);
17131720
target_option_val!(llvm_args);
17141721
target_option_val!(use_ctors_section);
1722+
target_option_val!(eh_frame_header);
17151723

17161724
if default.unsupported_abis != self.options.unsupported_abis {
17171725
d.insert(

src/librustc_target/spec/msp430_none_elf.rs

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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
})

0 commit comments

Comments
 (0)