Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #95911

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a867b8d
Add a test for issue 47384
nbdd0121 Feb 9, 2022
aa8413c
Add `SymbolExportInfo`
nbdd0121 Apr 2, 2022
08b7029
Make `#[used]` considered reachable
nbdd0121 Apr 2, 2022
c34473b
Reimplement lowering of sym operands for asm! so that it also works w…
Amanieu Mar 1, 2022
c1fa773
Add codegen for global_asm! sym operands
Amanieu Mar 1, 2022
e0ed0f4
Update tests for sym support in global_asm!
Amanieu Mar 1, 2022
fefc69a
Synthesis object file for `#[used]` and exported symbols
nbdd0121 Apr 2, 2022
3730fe3
Ignore paths in temporary dir in reproducible build test
nbdd0121 Apr 2, 2022
77f610e
Note that CI tests Windows 10
ChrisDenton Apr 9, 2022
bf3ef0d
Switch to the 'normal' basic block for writing asm outputs if needed.
luqmana Apr 9, 2022
0b2f360
Update asm-may_unwind test to handle use of asm with outputs.
luqmana Apr 9, 2022
460054c
Add a note to reachable.rs about `#[used]`
nbdd0121 Apr 9, 2022
98cd818
Refactor exported_symbols and linked_symbols for code reuse
nbdd0121 Apr 10, 2022
80152ed
use `to_string` instead of `format!`
TaKO8Ki Apr 10, 2022
386ca6a
Allow usage of sudo while not accessing root
Apr 10, 2022
dfe13db
only suggest removing semicolon when expr implements trait
compiler-errors Apr 7, 2022
0ca05f1
Rollup merge of #94468 - Amanieu:global_asm_sym, r=nagisa
Dylan-DPC Apr 10, 2022
406e171
Rollup merge of #95604 - nbdd0121:used2, r=petrochenkov
Dylan-DPC Apr 10, 2022
b51979a
Rollup merge of #95671 - gimbles:master, r=Mark-Simulacrum
Dylan-DPC Apr 10, 2022
d1d8fa4
Rollup merge of #95758 - compiler-errors:issue-54771, r=estebank
Dylan-DPC Apr 10, 2022
83fe17a
Rollup merge of #95861 - ChrisDenton:windows7-support, r=Dylan-DPC
Dylan-DPC Apr 10, 2022
6d93832
Rollup merge of #95864 - luqmana:inline-asm-unwind-store-miscompile, …
Dylan-DPC Apr 10, 2022
82f9f57
Rollup merge of #95881 - TaKO8Ki:use-to-string-instead-of-format, r=c…
Dylan-DPC Apr 10, 2022
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
Prev Previous commit
Next Next commit
Refactor exported_symbols and linked_symbols for code reuse
  • Loading branch information
nbdd0121 committed Apr 10, 2022
commit 98cd818d785f38b59ec874e13e7b83f6521553c7
70 changes: 26 additions & 44 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::{env, mem, str};

use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo, SymbolExportKind};
use rustc_middle::ty::TyCtxt;
use rustc_serialize::{json, Encoder};
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
Expand Down Expand Up @@ -1519,22 +1519,13 @@ impl<'a> L4Bender<'a> {
}
}

pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
if let Some(ref exports) = tcx.sess.target.override_export_symbols {
return exports.clone();
}

let mut symbols = Vec::new();

let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
fn for_each_exported_symbols_include_dep<'tcx>(
tcx: TyCtxt<'tcx>,
crate_type: CrateType,
mut callback: impl FnMut(ExportedSymbol<'tcx>, SymbolExportInfo, CrateNum),
) {
for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() {
if info.level.is_below_threshold(export_threshold) {
symbols.push(symbol_export::symbol_name_for_instance_in_crate(
tcx,
symbol,
LOCAL_CRATE,
));
}
callback(symbol, info, LOCAL_CRATE);
}

let formats = tcx.dependency_formats(());
Expand All @@ -1544,16 +1535,26 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
let cnum = CrateNum::new(index + 1);
// For each dependency that we are linking to statically ...
if *dep_format == Linkage::Static {
// ... we add its symbol list to our export list.
for &(symbol, info) in tcx.exported_symbols(cnum).iter() {
if !info.level.is_below_threshold(export_threshold) {
continue;
}

symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum));
callback(symbol, info, cnum);
}
}
}
}

pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
if let Some(ref exports) = tcx.sess.target.override_export_symbols {
return exports.clone();
}

let mut symbols = Vec::new();

let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
if info.level.is_below_threshold(export_threshold) {
symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum));
}
});

symbols
}
Expand All @@ -1572,33 +1573,14 @@ pub(crate) fn linked_symbols(
let mut symbols = Vec::new();

let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() {
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
if info.level.is_below_threshold(export_threshold) || info.used {
symbols.push((
symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, LOCAL_CRATE),
symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum),
info.kind,
));
}
}

let formats = tcx.dependency_formats(());
let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();

for (index, dep_format) in deps.iter().enumerate() {
let cnum = CrateNum::new(index + 1);
// For each dependency that we are linking to statically ...
if *dep_format == Linkage::Static {
// ... we add its symbol list to our export list.
for &(symbol, info) in tcx.exported_symbols(cnum).iter() {
if info.level.is_below_threshold(export_threshold) || info.used {
symbols.push((
symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum),
info.kind,
));
}
}
}
}
});

symbols
}
Expand Down