Skip to content

Commit 3cb1c11

Browse files
committed
Auto merge of #86774 - GuillaumeGomez:rollup-rkcgvph, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #86558 (Add suggestions for "undefined reference" link errors) - #86616 (rustc_span: Explicitly handle crates that differ from package names) - #86652 (Add support for leaf function frame pointer elimination) - #86666 (Fix misleading "impl Trait" error) - #86762 (mailmap: Add my work email address) - #86773 (Enable the tests developed with #86594) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents f8ac8fd + d10af08 commit 3cb1c11

35 files changed

+216
-77
lines changed

.mailmap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ Xuefeng Wu <benewu@gmail.com> XuefengWu <benewu@gmail.com>
290290
York Xiang <bombless@126.com>
291291
Youngsoo Son <ysson83@gmail.com> <ysoo.son@samsung.com>
292292
Yuki Okushi <jtitor@2k36.org> <huyuumi.dev@gmail.com>
293+
Yuki Okushi <jtitor@2k36.org> <yuki.okushi@huawei.com>
293294
Zach Pomerantz <zmp@umich.edu>
294295
Zack Corr <zack@z0w0.me> <zackcorr95@gmail.com>
295296
Zack Slayton <zack.slayton@gmail.com>

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_middle::ty::{self, TyCtxt};
1212
use rustc_session::config::OptLevel;
1313
use rustc_session::Session;
1414
use rustc_target::spec::abi::Abi;
15-
use rustc_target::spec::{SanitizerSet, StackProbeType};
15+
use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType};
1616

1717
use crate::attributes;
1818
use crate::llvm::AttributePlace::Function;
@@ -69,15 +69,25 @@ fn naked(val: &'ll Value, is_naked: bool) {
6969
Attribute::Naked.toggle_llfn(Function, val, is_naked);
7070
}
7171

72-
pub fn set_frame_pointer_elimination(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
73-
if cx.sess().must_not_eliminate_frame_pointers() {
74-
llvm::AddFunctionAttrStringValue(
75-
llfn,
76-
llvm::AttributePlace::Function,
77-
cstr!("frame-pointer"),
78-
cstr!("all"),
79-
);
72+
pub fn set_frame_pointer_type(cx: &CodegenCx<'ll, '_>, llfn: &'ll Value) {
73+
let mut fp = cx.sess().target.frame_pointer;
74+
// "mcount" function relies on stack pointer.
75+
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
76+
if cx.sess().instrument_mcount() || matches!(cx.sess().opts.cg.force_frame_pointers, Some(true))
77+
{
78+
fp = FramePointer::Always;
8079
}
80+
let attr_value = match fp {
81+
FramePointer::Always => cstr!("all"),
82+
FramePointer::NonLeaf => cstr!("non-leaf"),
83+
FramePointer::MayOmit => return,
84+
};
85+
llvm::AddFunctionAttrStringValue(
86+
llfn,
87+
llvm::AttributePlace::Function,
88+
cstr!("frame-pointer"),
89+
attr_value,
90+
);
8191
}
8292

8393
/// Tell LLVM what instrument function to insert.
@@ -254,7 +264,7 @@ pub fn from_fn_attrs(cx: &CodegenCx<'ll, 'tcx>, llfn: &'ll Value, instance: ty::
254264
}
255265

256266
// FIXME: none of these three functions interact with source level attributes.
257-
set_frame_pointer_elimination(cx, llfn);
267+
set_frame_pointer_type(cx, llfn);
258268
set_instrument_function(cx, llfn);
259269
set_probestack(cx, llfn);
260270

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,8 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
410410
&self.used_statics
411411
}
412412

413-
fn set_frame_pointer_elimination(&self, llfn: &'ll Value) {
414-
attributes::set_frame_pointer_elimination(self, llfn)
413+
fn set_frame_pointer_type(&self, llfn: &'ll Value) {
414+
attributes::set_frame_pointer_type(self, llfn)
415415
}
416416

417417
fn apply_target_cpu_attr(&self, llfn: &'ll Value) {

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ fn gen_fn<'ll, 'tcx>(
674674
) -> &'ll Value {
675675
let fn_abi = FnAbi::of_fn_ptr(cx, rust_fn_sig, &[]);
676676
let llfn = cx.declare_fn(name, &fn_abi);
677-
cx.set_frame_pointer_elimination(llfn);
677+
cx.set_frame_pointer_type(llfn);
678678
cx.apply_target_cpu_attr(llfn);
679679
// FIXME(eddyb) find a nicer way to do this.
680680
unsafe { llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::InternalLinkage) };

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -912,14 +912,23 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
912912
if !prog.status.success() {
913913
let mut output = prog.stderr.clone();
914914
output.extend_from_slice(&prog.stdout);
915-
sess.struct_err(&format!(
915+
let escaped_output = escape_stdout_stderr_string(&output);
916+
let mut err = sess.struct_err(&format!(
916917
"linking with `{}` failed: {}",
917918
linker_path.display(),
918919
prog.status
919-
))
920-
.note(&format!("{:?}", &cmd))
921-
.note(&escape_stdout_stderr_string(&output))
922-
.emit();
920+
));
921+
err.note(&format!("{:?}", &cmd)).note(&escaped_output);
922+
if escaped_output.contains("undefined reference to") {
923+
err.help(
924+
"some `extern` functions couldn't be found; some native libraries may \
925+
need to be installed or have their path specified",
926+
);
927+
err.note("use the `-l` flag to specify native libraries to link");
928+
err.note("use the `cargo:rustc-link-lib` directive to specify the native \
929+
libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)");
930+
}
931+
err.emit();
923932

924933
// If MSVC's `link.exe` was expected but the return code
925934
// is not a Microsoft LNK error then suggest a way to fix or

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
406406
};
407407

408408
// `main` should respect same config for frame pointer elimination as rest of code
409-
cx.set_frame_pointer_elimination(llfn);
409+
cx.set_frame_pointer_type(llfn);
410410
cx.apply_target_cpu_attr(llfn);
411411

412412
let llbb = Bx::append_block(&cx, llfn, "top");

compiler/rustc_codegen_ssa/src/traits/misc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub trait MiscMethods<'tcx>: BackendTypes {
1616
fn sess(&self) -> &Session;
1717
fn codegen_unit(&self) -> &'tcx CodegenUnit<'tcx>;
1818
fn used_statics(&self) -> &RefCell<Vec<Self::Value>>;
19-
fn set_frame_pointer_elimination(&self, llfn: Self::Function);
19+
fn set_frame_pointer_type(&self, llfn: Self::Function);
2020
fn apply_target_cpu_attr(&self, llfn: Self::Function);
2121
fn create_used_variable(&self);
2222
/// Declares the extern "C" main function for the entry point. Returns None if the symbol already exists.

compiler/rustc_session/src/session.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -792,18 +792,6 @@ impl Session {
792792
!self.target.is_like_windows && !self.target.is_like_osx
793793
}
794794

795-
pub fn must_not_eliminate_frame_pointers(&self) -> bool {
796-
// "mcount" function relies on stack pointer.
797-
// See <https://sourceware.org/binutils/docs/gprof/Implementation.html>.
798-
if self.instrument_mcount() {
799-
true
800-
} else if let Some(x) = self.opts.cg.force_frame_pointers {
801-
x
802-
} else {
803-
!self.target.eliminate_frame_pointer
804-
}
805-
}
806-
807795
pub fn must_emit_unwind_tables(&self) -> bool {
808796
// This is used to control the emission of the `uwtable` attribute on
809797
// LLVM functions.

compiler/rustc_span/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ scoped-tls = "1.0"
1717
unicode-width = "0.1.4"
1818
cfg-if = "0.1.2"
1919
tracing = "0.1"
20-
sha-1 = "0.9"
20+
sha1 = { package = "sha-1", version = "0.9" }
2121
sha2 = "0.9"
22-
md-5 = "0.9"
22+
md5 = { package = "md-5", version = "0.9" }

compiler/rustc_target/src/spec/aarch64_apple_darwin.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{LinkerFlavor, SanitizerSet, Target, TargetOptions};
1+
use crate::spec::{FramePointer, LinkerFlavor, SanitizerSet, Target, TargetOptions};
22

33
pub fn target() -> Target {
44
let mut base = super::apple_base::opts("macos");
@@ -20,6 +20,10 @@ pub fn target() -> Target {
2020
pointer_width: 64,
2121
data_layout: "e-m:o-i64:64-i128:128-n32:64-S128".to_string(),
2222
arch: arch.to_string(),
23-
options: TargetOptions { mcount: "\u{1}mcount".to_string(), ..base },
23+
options: TargetOptions {
24+
mcount: "\u{1}mcount".to_string(),
25+
frame_pointer: FramePointer::NonLeaf,
26+
..base
27+
},
2428
}
2529
}

0 commit comments

Comments
 (0)