Skip to content

Commit

Permalink
Rollup merge of rust-lang#74631 - petrochenkov:ehdr2, r=jonas-schievink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Manishearth authored Jul 22, 2020
2 parents 14e5415 + 49b9a64 commit dbe2726
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,9 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
}

// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
cmd.add_eh_frame_header();
if sess.target.target.options.eh_frame_header {
cmd.add_eh_frame_header();
}

// NO-OPT-OUT, OBJECT-FILES-NO
if crt_objects_fallback {
Expand Down
8 changes: 1 addition & 7 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,13 +619,7 @@ impl<'a> Linker for GccLinker<'a> {
// Some versions of `gcc` add it implicitly, some (e.g. `musl-gcc`) don't,
// so we just always add it.
fn add_eh_frame_header(&mut self) {
if !self.sess.target.target.options.is_like_osx
&& !self.sess.target.target.options.is_like_windows
&& !self.sess.target.target.options.is_like_solaris
&& self.sess.target.target.target_os != "uefi"
{
self.linker_arg("--eh-frame-hdr");
}
self.linker_arg("--eh-frame-hdr");
}
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/apple_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub fn opts() -> TargetOptions {
has_elf_tls: version >= (10, 7),
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
eh_frame_header: false,

// This environment variable is pretty magical but is intended for
// producing deterministic builds. This was first discovered to be used
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/freestanding_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn opts() -> TargetOptions {
has_rpath: false,
pre_link_args: args,
position_independent_executables: false,
eh_frame_header: false,
..Default::default()
}
}
1 change: 1 addition & 0 deletions src/librustc_target/spec/illumos_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub fn opts() -> TargetOptions {
is_like_solaris: true,
limit_rdylib_exports: false, // Linker doesn't support this
eliminate_frame_pointer: false,
eh_frame_header: false,
late_link_args,

// While we support ELF TLS, rust requires a way to register
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,11 @@ pub struct TargetOptions {
/// Whether to use legacy .ctors initialization hooks rather than .init_array. Defaults
/// to false (uses .init_array).
pub use_ctors_section: bool,

/// Whether the linker is instructed to add a `GNU_EH_FRAME` ELF header
/// used to locate unwinding information is passed
/// (only has effect if the linker is `ld`-like).
pub eh_frame_header: bool,
}

impl Default for TargetOptions {
Expand Down Expand Up @@ -1079,6 +1084,7 @@ impl Default for TargetOptions {
relax_elf_relocations: false,
llvm_args: vec![],
use_ctors_section: false,
eh_frame_header: true,
}
}
}
Expand Down Expand Up @@ -1471,6 +1477,7 @@ impl Target {
key!(relax_elf_relocations, bool);
key!(llvm_args, list);
key!(use_ctors_section, bool);
key!(eh_frame_header, bool);

// NB: The old name is deprecated, but support for it is retained for
// compatibility.
Expand Down Expand Up @@ -1708,6 +1715,7 @@ impl ToJson for Target {
target_option_val!(relax_elf_relocations);
target_option_val!(llvm_args);
target_option_val!(use_ctors_section);
target_option_val!(eh_frame_header);

if default.unsupported_abis != self.options.unsupported_abis {
d.insert(
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_target/spec/msp430_none_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ pub fn target() -> TargetResult {
// See the thumb_base.rs file for an explanation of this value
emit_debug_gdb_scripts: false,

eh_frame_header: false,

..Default::default()
},
})
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/riscv32i_unknown_none_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn target() -> TargetResult {
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
eh_frame_header: false,
..Default::default()
},
})
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/riscv32imac_unknown_none_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn target() -> TargetResult {
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
eh_frame_header: false,
..Default::default()
},
})
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/riscv32imc_unknown_none_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub fn target() -> TargetResult {
relocation_model: RelocModel::Static,
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
eh_frame_header: false,
..Default::default()
},
})
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/riscv64gc_unknown_none_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn target() -> TargetResult {
code_model: Some(CodeModel::Medium),
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
eh_frame_header: false,
..Default::default()
},
})
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/riscv64imac_unknown_none_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn target() -> TargetResult {
code_model: Some(CodeModel::Medium),
emit_debug_gdb_scripts: false,
unsupported_abis: super::riscv_base::unsupported_abis(),
eh_frame_header: false,
..Default::default()
},
})
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/solaris_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub fn opts() -> TargetOptions {
target_family: Some("unix".to_string()),
is_like_solaris: true,
limit_rdylib_exports: false, // Linker doesn't support this
eh_frame_header: false,

..Default::default()
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_target/spec/windows_gnu_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn opts() -> TargetOptions {
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
requires_uwtable: true,
eh_frame_header: false,

..Default::default()
}
Expand Down

0 comments on commit dbe2726

Please sign in to comment.