Auto merge of #88032 - hyd-dev:no-mangle-method, r=petrochenkov
Fix `reachable_set` for non-function items in non-library crates I unintentionally changed `reachable_set` to ignore non-function items when `!self.any_library` in https://github.com/rust-lang/rust/pull/86492, which can lead to "undefined reference" errors in non-library (`cdylib`/`staticlib`/`bin`) crates, for example: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=6bb2c5065a9be7e40943d0541e161b5a This PR restores the behavior of `reachable_set` for non-function items. Fixes https://github.com/rust-lang/rust/issues/88016. <details> <summary>The modified test will fail with this output without the `reachable_set` change</summary> ``` ---- [codegen] codegen/external-no-mangle-statics.rs#staticlib stdout ---- error in revision `staticlib`: verification with 'FileCheck' failed status: exit status: 1 command: "/checkout/build/x86_64-unknown-linux-gnu/ci-llvm/bin/FileCheck" "--input-file" "/checkout/build/x86_64-unknown-linux-gnu/test/codegen/external-no-mangle-statics.staticlib/external-no-mangle-statics.ll" "/checkout/src/test/codegen/external-no-mangle-statics.rs" "--check-prefixes" "CHECK,NONMSVC,staticlib" stdout: ------------------------------------------ ------------------------------------------ stderr: ------------------------------------------ /checkout/src/test/codegen/external-no-mangle-statics.rs:10:11: error: CHECK: expected string not found in input // CHECK: `@A` = local_unnamed_addr constant ^ /checkout/build/x86_64-unknown-linux-gnu/test/codegen/external-no-mangle-statics.staticlib/external-no-mangle-statics.ll:1:1: note: scanning from here ; ModuleID = 'external_no_mangle_statics.b50529d3-cgu.0' ^ /checkout/build/x86_64-unknown-linux-gnu/test/codegen/external-no-mangle-statics.staticlib/external-no-mangle-statics.ll:1:6: note: possible intended match here ; ModuleID = 'external_no_mangle_statics.b50529d3-cgu.0' ^ Input file: /checkout/build/x86_64-unknown-linux-gnu/test/codegen/external-no-mangle-statics.staticlib/external-no-mangle-statics.ll Check file: /checkout/src/test/codegen/external-no-mangle-statics.rs -dump-input=help explains the following input dump. Input was: <<<<<< 1: ; ModuleID = 'external_no_mangle_statics.b50529d3-cgu.0' check:10'0 X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found check:10'1 ? possible intended match 2: source_filename = "external_no_mangle_statics.b50529d3-cgu.0" check:10'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3: target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" check:10'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 4: target triple = "x86_64-unknown-linux-gnu" check:10'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 5: check:10'0 ~ 6: !llvm.module.flags = !{!0, !1} check:10'0 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ . . . >>>>>> ------------------------------------------ failures: [codegen] codegen/external-no-mangle-statics.rs#staticlib ``` </details>
This commit is contained in:
commit
73d96b090b
2 changed files with 19 additions and 17 deletions
|
@ -211,21 +211,22 @@ impl<'tcx> ReachableContext<'tcx> {
|
|||
if !self.any_library {
|
||||
// If we are building an executable, only explicitly extern
|
||||
// types need to be exported.
|
||||
if let Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), def_id, .. })
|
||||
| Node::ImplItem(hir::ImplItem {
|
||||
kind: hir::ImplItemKind::Fn(sig, ..),
|
||||
def_id,
|
||||
..
|
||||
}) = *node
|
||||
{
|
||||
let reachable = sig.header.abi != Abi::Rust;
|
||||
let codegen_attrs = self.tcx.codegen_fn_attrs(*def_id);
|
||||
let is_extern = codegen_attrs.contains_extern_indicator();
|
||||
let std_internal =
|
||||
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
|
||||
if reachable || is_extern || std_internal {
|
||||
self.reachable_symbols.insert(search_item);
|
||||
}
|
||||
let reachable =
|
||||
if let Node::Item(hir::Item { kind: hir::ItemKind::Fn(sig, ..), .. })
|
||||
| Node::ImplItem(hir::ImplItem {
|
||||
kind: hir::ImplItemKind::Fn(sig, ..), ..
|
||||
}) = *node
|
||||
{
|
||||
sig.header.abi != Abi::Rust
|
||||
} else {
|
||||
false
|
||||
};
|
||||
let codegen_attrs = self.tcx.codegen_fn_attrs(search_item);
|
||||
let is_extern = codegen_attrs.contains_extern_indicator();
|
||||
let std_internal =
|
||||
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
|
||||
if reachable || is_extern || std_internal {
|
||||
self.reachable_symbols.insert(search_item);
|
||||
}
|
||||
} else {
|
||||
// If we are building a library, then reachable symbols will
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue