Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion compiler/rustc_codegen_gcc/src/gcc_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use rustc_codegen_ssa::target_features;
use rustc_data_structures::smallvec::{SmallVec, smallvec};
use rustc_session::config::NATIVE_CPU;
use rustc_session::{EarlySession, Session};
use rustc_target::spec::{Arch, RelocModel, StackProbeType, StackProtector, Target};
use rustc_target::spec::{
Arch, MergeFunctions, RelocModel, StackProbeType, StackProtector, Target,
};

fn gcc_features_by_flags(sess: &EarlySession, features: &mut Vec<String>) {
target_features::retpoline_features_by_flags(sess, features);
Expand Down Expand Up @@ -220,6 +222,16 @@ pub fn new_context<'gcc>(sess: &Session) -> Context<'gcc> {
StackProtector::None => (),
}

match sess.merge_functions() {
MergeFunctions::Disabled => {
context.add_command_line_option("-fno-ipa-icf-functions");
Comment thread
bjorn3 marked this conversation as resolved.
}
// GCC always merges functions with trampolines rather than aliases, so we don't
// need to differentiate MergeFunctions::Trampolines and MergeFunctions::Aliases
// as trampolines are allowed either way.
MergeFunctions::Trampolines | MergeFunctions::Aliases => {}
}

match sess.target.stack_probes {
StackProbeType::None => (),
StackProbeType::Inline | StackProbeType::InlineOrCall { .. } => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ unsafe fn configure_llvm(sess: &EarlySession) {
add("-generate-arange-section", false);
}

match sess.opts.unstable_opts.merge_functions.unwrap_or(sess.target.merge_functions) {
match sess.merge_functions() {
MergeFunctions::Disabled | MergeFunctions::Trampolines => {}
MergeFunctions::Aliases => {
add("-mergefunc-use-aliases", false);
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,7 @@ impl ModuleConfig {
// backends (again, NVPTX). Therefore, allow targets to opt out of
// the MergeFunctions pass, but otherwise keep the pass enabled (at
// O2 and O3) since it can be useful for reducing code size.
merge_functions: match sess
.opts
.unstable_opts
.merge_functions
.unwrap_or(sess.target.merge_functions)
{
merge_functions: match sess.merge_functions() {
MergeFunctions::Disabled => false,
MergeFunctions::Trampolines | MergeFunctions::Aliases => {
use config::OptLevel::*;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2643,6 +2643,7 @@ options! {
maximal_hir_to_mir_coverage: bool = (false, parse_bool, [TRACKED],
"save as much information as possible about the correspondence between MIR and HIR \
as source scopes (default: no)"),
#[rustc_lint_opt_deny_field_access("use `Session::merge_functions` instead of this field")]
merge_functions: Option<MergeFunctions> = (None, parse_merge_functions, [TRACKED],
"control the operation of the MergeFunctions LLVM pass, taking \
the same values as the target option of the same name"),
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ use rustc_span::{RealFileName, Span, Symbol};
use rustc_structures::{CrateType, Limit};
use rustc_target::asm::InlineAsmArch;
use rustc_target::spec::{
Arch, CfgAbi, CodeModel, DebuginfoKind, Os, PanicStrategy, RelocModel, RelroLevel,
SanitizerSet, SmallDataThresholdSupport, SplitDebuginfo, StackProtector, SymbolVisibility,
Target, TargetTuple, TlsModel, apple,
Arch, CfgAbi, CodeModel, DebuginfoKind, MergeFunctions, Os, PanicStrategy, RelocModel,
RelroLevel, SanitizerSet, SmallDataThresholdSupport, SplitDebuginfo, StackProtector,
SymbolVisibility, Target, TargetTuple, TlsModel, apple,
};

use crate::code_stats::CodeStats;
Expand Down Expand Up @@ -423,6 +423,10 @@ impl EarlySession {
.sanitizer
.combine_with_defaults(self.target.options.default_sanitizers)
}

pub fn merge_functions(&self) -> MergeFunctions {
self.opts.unstable_opts.merge_functions.unwrap_or(self.target.merge_functions)
}
}

/// Some info about the backend, returned by `CodegenBackend::init` and put into the `Session`.
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,15 @@ impl ToJson for SmallDataThresholdSupport {

crate::target_spec_enum! {
pub enum MergeFunctions {
/// Disable function merging entirely.
Disabled = "disabled",
/// Allow function merging via trampolines (i.e., functions can be implemented
/// in terms of a jump to an unrelated function with identical behavior), but
/// not via object-format-level global aliases.
Trampolines = "trampolines",
/// (Default) allow function merging via either trampolines or (object format
/// level) global aliases. LLVM will normally use global aliases for merging, but
/// trampolines are also permissible.
Aliases = "aliases",
}

Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2040,6 +2040,12 @@ test!(BuildStd {
default: false
});

test!(AssemblyGcc {
path: "tests/assembly-gcc",
mode: CompiletestMode::Assembly,
suite: "assembly-gcc",
default: true
});
test!(AssemblyLlvm {
path: "tests/assembly-llvm",
mode: CompiletestMode::Assembly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ expression: test
[Test] test::CodegenUnits
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/codegen-units)
[Test] test::AssemblyGcc
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-gcc)
[Test] test::AssemblyLlvm
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-llvm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ expression: test --skip=coverage
[Test] test::CodegenUnits
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/codegen-units)
[Test] test::AssemblyGcc
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-gcc)
[Test] test::AssemblyLlvm
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-llvm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ expression: test --skip=coverage-map
[Test] test::CodegenUnits
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/codegen-units)
[Test] test::AssemblyGcc
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-gcc)
[Test] test::AssemblyLlvm
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-llvm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ expression: test --skip=coverage-run
[Test] test::CodegenUnits
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/codegen-units)
[Test] test::AssemblyGcc
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-gcc)
[Test] test::AssemblyLlvm
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-llvm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ expression: test --skip=tests/coverage
[Test] test::CodegenUnits
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/codegen-units)
[Test] test::AssemblyGcc
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-gcc)
[Test] test::AssemblyLlvm
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-llvm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ expression: test tests
[Test] test::CodegenUnits
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/codegen-units)
[Test] test::AssemblyGcc
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-gcc)
[Test] test::AssemblyLlvm
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-llvm)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ expression: test tests --skip=coverage
[Test] test::CodegenUnits
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/codegen-units)
[Test] test::AssemblyGcc
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-gcc)
[Test] test::AssemblyLlvm
targets: [aarch64-unknown-linux-gnu]
- Suite(tests/assembly-llvm)
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,7 @@ impl<'a> Builder<'a> {
test::MirOpt,
test::CodegenLlvm,
test::CodegenUnits,
test::AssemblyGcc,
test::AssemblyLlvm,
test::Incremental,
test::Debuginfo,
Expand Down
2 changes: 2 additions & 0 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,7 @@ mod snapshot {
[test] compiletest-mir-opt 1 <host>
[test] compiletest-codegen-llvm 1 <host>
[test] compiletest-codegen-units 1 <host>
[test] compiletest-assembly-gcc 1 <host>
[test] compiletest-assembly-llvm 1 <host>
[test] compiletest-incremental 1 <host>
[test] compiletest-debuginfo 1 <host>
Expand Down Expand Up @@ -2124,6 +2125,7 @@ mod snapshot {
[test] compiletest-mir-opt 2 <host>
[test] compiletest-codegen-llvm 2 <host>
[test] compiletest-codegen-units 2 <host>
[test] compiletest-assembly-gcc 2 <host>
[test] compiletest-assembly-llvm 2 <host>
[test] compiletest-incremental 2 <host>
[test] compiletest-debuginfo 2 <host>
Expand Down
1 change: 1 addition & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl TestMode {
string_enum! {
#[derive(Clone, Copy, PartialEq, Debug)]
pub(crate) enum TestSuite {
AssemblyGcc => "assembly-gcc",
AssemblyLlvm => "assembly-llvm",
CodegenLlvm => "codegen-llvm",
CodegenUnits => "codegen-units",
Expand Down
3 changes: 2 additions & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,8 @@ impl<'test> TestCx<'test> {
// Exhaustively match all other suites.
// Note that some suites never actually use this method, so the
// return value for those suites is not necessarily meaningful.
TestSuite::AssemblyLlvm
TestSuite::AssemblyGcc
| TestSuite::AssemblyLlvm
| TestSuite::BuildStd
| TestSuite::CodegenLlvm
| TestSuite::CodegenUnits
Expand Down
Loading
Loading