134 changes: 103 additions & 31 deletions compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Expand Up @@ -9,7 +9,7 @@ use rustc_hir::Node;
use rustc_index::vec::IndexVec;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::middle::exported_symbols::{
metadata_symbol_name, ExportedSymbol, SymbolExportLevel,
metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel,
};
use rustc_middle::ty::query::{ExternProviders, Providers};
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn crates_export_threshold(crate_types: &[CrateType]) -> SymbolExportLevel {
}
}

fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<SymbolExportLevel> {
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<SymbolExportInfo> {
assert_eq!(cnum, LOCAL_CRATE);

if !tcx.sess.opts.output_types.should_codegen() {
Expand Down Expand Up @@ -105,36 +105,51 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
}
})
.map(|def_id| {
let export_level = if special_runtime_crate {
let (export_level, used) = if special_runtime_crate {
let name = tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())).name;
// We can probably do better here by just ensuring that
// it has hidden visibility rather than public
// visibility, as this is primarily here to ensure it's
// not stripped during LTO.
//
// In general though we won't link right if these
// symbols are stripped, and LTO currently strips them.
match name {
// We won't link right if these symbols are stripped during LTO.
let used = match name {
"rust_eh_personality"
| "rust_eh_register_frames"
| "rust_eh_unregister_frames" =>
SymbolExportLevel::C,
_ => SymbolExportLevel::Rust,
}
| "rust_eh_unregister_frames" => true,
_ => false,
};
(SymbolExportLevel::Rust, used)
} else {
symbol_export_level(tcx, def_id.to_def_id())
(symbol_export_level(tcx, def_id.to_def_id()), false)
};
let codegen_attrs = tcx.codegen_fn_attrs(def_id.to_def_id());
debug!(
"EXPORTED SYMBOL (local): {} ({:?})",
tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())),
export_level
);
(def_id.to_def_id(), export_level)
(def_id.to_def_id(), SymbolExportInfo {
level: export_level,
kind: if tcx.is_static(def_id.to_def_id()) {
if codegen_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL) {
SymbolExportKind::Tls
} else {
SymbolExportKind::Data
}
} else {
SymbolExportKind::Text
},
used: codegen_attrs.flags.contains(CodegenFnAttrFlags::USED)
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) || used,
})
})
.collect();

if let Some(id) = tcx.proc_macro_decls_static(()) {
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
reachable_non_generics.insert(
id.to_def_id(),
SymbolExportInfo {
level: SymbolExportLevel::C,
kind: SymbolExportKind::Data,
used: false,
},
);
}

reachable_non_generics
Expand All @@ -143,8 +158,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
let export_threshold = threshold(tcx);

if let Some(&level) = tcx.reachable_non_generics(def_id.krate).get(&def_id) {
level.is_below_threshold(export_threshold)
if let Some(&info) = tcx.reachable_non_generics(def_id.krate).get(&def_id) {
info.level.is_below_threshold(export_threshold)
} else {
false
}
Expand All @@ -157,7 +172,7 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
fn exported_symbols_provider_local<'tcx>(
tcx: TyCtxt<'tcx>,
cnum: CrateNum,
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
assert_eq!(cnum, LOCAL_CRATE);

if !tcx.sess.opts.output_types.should_codegen() {
Expand All @@ -167,21 +182,35 @@ fn exported_symbols_provider_local<'tcx>(
let mut symbols: Vec<_> = tcx
.reachable_non_generics(LOCAL_CRATE)
.iter()
.map(|(&def_id, &level)| (ExportedSymbol::NonGeneric(def_id), level))
.map(|(&def_id, &info)| (ExportedSymbol::NonGeneric(def_id), info))
.collect();

if tcx.entry_fn(()).is_some() {
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main"));

symbols.push((exported_symbol, SymbolExportLevel::C));
symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::C,
kind: SymbolExportKind::Text,
used: false,
},
));
}

if tcx.allocator_kind(()).is_some() {
for method in ALLOCATOR_METHODS {
let symbol_name = format!("__rust_{}", method.name);
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));

symbols.push((exported_symbol, SymbolExportLevel::Rust));
symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
},
));
}
}

Expand All @@ -194,25 +223,54 @@ fn exported_symbols_provider_local<'tcx>(

symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| {
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
(exported_symbol, SymbolExportLevel::C)
(
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::C,
kind: SymbolExportKind::Data,
used: false,
},
)
}));
}

if tcx.sess.opts.debugging_opts.sanitizer.contains(SanitizerSet::MEMORY) {
let mut msan_weak_symbols = Vec::new();

// Similar to profiling, preserve weak msan symbol during LTO.
const MSAN_WEAK_SYMBOLS: [&str; 2] = ["__msan_track_origins", "__msan_keep_going"];
if tcx.sess.opts.debugging_opts.sanitizer_recover.contains(SanitizerSet::MEMORY) {
msan_weak_symbols.push("__msan_keep_going");
}

if tcx.sess.opts.debugging_opts.sanitizer_memory_track_origins != 0 {
msan_weak_symbols.push("__msan_track_origins");
}

symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| {
symbols.extend(msan_weak_symbols.into_iter().map(|sym| {
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
(exported_symbol, SymbolExportLevel::C)
(
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::C,
kind: SymbolExportKind::Data,
used: false,
},
)
}));
}

if tcx.sess.crate_types().contains(&CrateType::Dylib) {
let symbol_name = metadata_symbol_name(tcx);
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));

symbols.push((exported_symbol, SymbolExportLevel::Rust));
symbols.push((
exported_symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Data,
used: false,
},
));
}

if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() {
Expand Down Expand Up @@ -245,7 +303,14 @@ fn exported_symbols_provider_local<'tcx>(
MonoItem::Fn(Instance { def: InstanceDef::Item(def), substs }) => {
if substs.non_erasable_generics().next().is_some() {
let symbol = ExportedSymbol::Generic(def.did, substs);
symbols.push((symbol, SymbolExportLevel::Rust));
symbols.push((
symbol,
SymbolExportInfo {
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
},
));
}
}
MonoItem::Fn(Instance { def: InstanceDef::DropGlue(_, Some(ty)), substs }) => {
Expand All @@ -254,7 +319,14 @@ fn exported_symbols_provider_local<'tcx>(
substs.non_erasable_generics().next(),
Some(GenericArgKind::Type(ty))
);
symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportLevel::Rust));
symbols.push((
ExportedSymbol::DropGlue(ty),
SymbolExportInfo {
level: SymbolExportLevel::Rust,
kind: SymbolExportKind::Text,
used: false,
},
));
}
_ => {
// Any other symbols don't qualify for sharing
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/write.rs
Expand Up @@ -23,7 +23,7 @@ use rustc_incremental::{
};
use rustc_metadata::EncodedMetadata;
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
use rustc_middle::middle::exported_symbols::SymbolExportLevel;
use rustc_middle::middle::exported_symbols::SymbolExportInfo;
use rustc_middle::ty::TyCtxt;
use rustc_session::cgu_reuse_tracker::CguReuseTracker;
use rustc_session::config::{self, CrateType, Lto, OutputFilenames, OutputType};
Expand Down Expand Up @@ -304,7 +304,7 @@ pub type TargetMachineFactoryFn<B> = Arc<
+ Sync,
>;

pub type ExportedSymbols = FxHashMap<CrateNum, Arc<Vec<(String, SymbolExportLevel)>>>;
pub type ExportedSymbols = FxHashMap<CrateNum, Arc<Vec<(String, SymbolExportInfo)>>>;

/// Additional resources used by optimize_and_codegen (not module specific)
#[derive(Clone)]
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_codegen_ssa/src/base.rs
Expand Up @@ -801,6 +801,12 @@ impl CrateInfo {
.iter()
.map(|&c| (c, crate::back::linker::exported_symbols(tcx, c)))
.collect();
let linked_symbols = tcx
.sess
.crate_types()
.iter()
.map(|&c| (c, crate::back::linker::linked_symbols(tcx, c)))
.collect();
let local_crate_name = tcx.crate_name(LOCAL_CRATE);
let crate_attrs = tcx.hir().attrs(rustc_hir::CRATE_HIR_ID);
let subsystem = tcx.sess.first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem);
Expand Down Expand Up @@ -834,6 +840,7 @@ impl CrateInfo {
let mut info = CrateInfo {
target_cpu,
exported_symbols,
linked_symbols,
local_crate_name,
compiler_builtins: None,
profiler_runtime: None,
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_ssa/src/lib.rs
Expand Up @@ -28,6 +28,7 @@ use rustc_hir::def_id::CrateNum;
use rustc_hir::LangItem;
use rustc_middle::dep_graph::WorkProduct;
use rustc_middle::middle::dependency_format::Dependencies;
use rustc_middle::middle::exported_symbols::SymbolExportKind;
use rustc_middle::ty::query::{ExternProviders, Providers};
use rustc_session::config::{CrateType, OutputFilenames, OutputType, RUST_CGU_EXT};
use rustc_session::cstore::{self, CrateSource};
Expand Down Expand Up @@ -140,6 +141,7 @@ impl From<&cstore::NativeLib> for NativeLib {
pub struct CrateInfo {
pub target_cpu: String,
pub exported_symbols: FxHashMap<CrateType, Vec<String>>,
pub linked_symbols: FxHashMap<CrateType, Vec<(String, SymbolExportKind)>>,
pub local_crate_name: Symbol,
pub compiler_builtins: Option<CrateNum>,
pub profiler_runtime: Option<CrateNum>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Expand Up @@ -22,7 +22,7 @@ use rustc_hir::lang_items;
use rustc_index::vec::{Idx, IndexVec};
use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::metadata::ModChild;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
use rustc_middle::middle::stability::DeprecationEntry;
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
use rustc_middle::thir;
Expand Down Expand Up @@ -1405,7 +1405,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
fn exported_symbols(
self,
tcx: TyCtxt<'tcx>,
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
tcx.arena.alloc_from_iter(self.root.exported_symbols.decode((self, tcx)))
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Expand Up @@ -188,9 +188,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
let reachable_non_generics = tcx
.exported_symbols(cdata.cnum)
.iter()
.filter_map(|&(exported_symbol, export_level)| {
.filter_map(|&(exported_symbol, export_info)| {
if let ExportedSymbol::NonGeneric(def_id) = exported_symbol {
Some((def_id, export_level))
Some((def_id, export_info))
} else {
None
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Expand Up @@ -21,7 +21,7 @@ use rustc_index::vec::Idx;
use rustc_middle::hir::nested_filter;
use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::middle::exported_symbols::{
metadata_symbol_name, ExportedSymbol, SymbolExportLevel,
metadata_symbol_name, ExportedSymbol, SymbolExportInfo,
};
use rustc_middle::mir::interpret;
use rustc_middle::thir;
Expand Down Expand Up @@ -1844,8 +1844,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
// definition (as that's not defined in this crate).
fn encode_exported_symbols(
&mut self,
exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportLevel)],
) -> Lazy<[(ExportedSymbol<'tcx>, SymbolExportLevel)]> {
exported_symbols: &[(ExportedSymbol<'tcx>, SymbolExportInfo)],
) -> Lazy<[(ExportedSymbol<'tcx>, SymbolExportInfo)]> {
empty_proc_macro!(self);
// The metadata symbol name is special. It should not show up in
// downstream crates.
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Expand Up @@ -13,7 +13,7 @@ use rustc_hir::definitions::DefKey;
use rustc_hir::lang_items;
use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec};
use rustc_middle::metadata::ModChild;
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
use rustc_middle::mir;
use rustc_middle::thir;
use rustc_middle::ty::fast_reject::SimplifiedType;
Expand Down Expand Up @@ -218,7 +218,7 @@ crate struct CrateRoot<'tcx> {

tables: LazyTables<'tcx>,

exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportLevel)]),
exported_symbols: Lazy!([(ExportedSymbol<'tcx>, SymbolExportInfo)]),

syntax_contexts: SyntaxContextTable,
expn_data: ExpnDataTable,
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_middle/src/middle/exported_symbols.rs
Expand Up @@ -21,6 +21,23 @@ impl SymbolExportLevel {
}
}

/// Kind of exported symbols.
#[derive(Eq, PartialEq, Debug, Copy, Clone, Encodable, Decodable, HashStable)]
pub enum SymbolExportKind {
Text,
Data,
Tls,
}

/// The `SymbolExportInfo` of a symbols specifies symbol-related information
/// that is relevant to code generation and linking.
#[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
pub struct SymbolExportInfo {
pub level: SymbolExportLevel,
pub kind: SymbolExportKind,
pub used: bool,
}

#[derive(Eq, PartialEq, Debug, Copy, Clone, TyEncodable, TyDecodable, HashStable)]
pub enum ExportedSymbol<'tcx> {
NonGeneric(DefId),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Expand Up @@ -1355,7 +1355,7 @@ rustc_queries! {
// Does not include external symbols that don't have a corresponding DefId,
// like the compiler-generated `main` function and so on.
query reachable_non_generics(_: CrateNum)
-> DefIdMap<SymbolExportLevel> {
-> DefIdMap<SymbolExportInfo> {
storage(ArenaCacheSelector<'tcx>)
desc { "looking up the exported symbols of a crate" }
separate_provide_extern
Expand Down Expand Up @@ -1672,7 +1672,7 @@ rustc_queries! {
/// correspond to a publicly visible symbol in `cnum` machine code.
/// - The `exported_symbols` sets of different crates do not intersect.
query exported_symbols(_: CrateNum)
-> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
-> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
desc { "exported_symbols" }
separate_provide_extern
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/query.rs
Expand Up @@ -3,7 +3,7 @@ use crate::infer::canonical::{self, Canonical};
use crate::lint::LintLevelMap;
use crate::metadata::ModChild;
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
use crate::middle::lib_features::LibFeatures;
use crate::middle::privacy::AccessLevels;
use crate::middle::region;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_monomorphize/src/partitioning/default.rs
Expand Up @@ -5,7 +5,7 @@ use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::definitions::DefPathDataName;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::middle::exported_symbols::SymbolExportLevel;
use rustc_middle::middle::exported_symbols::{SymbolExportInfo, SymbolExportLevel};
use rustc_middle::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, Linkage, Visibility};
use rustc_middle::mir::mono::{InstantiationMode, MonoItem};
use rustc_middle::ty::print::characteristic_def_id_of_type;
Expand Down Expand Up @@ -554,7 +554,7 @@ fn default_visibility(tcx: TyCtxt<'_>, id: DefId, is_generic: bool) -> Visibilit
// C-export level items remain at `Default`, all other internal
// items become `Hidden`.
match tcx.reachable_non_generics(id.krate).get(&id) {
Some(SymbolExportLevel::C) => Visibility::Default,
Some(SymbolExportInfo { level: SymbolExportLevel::C, .. }) => Visibility::Default,
_ => Visibility::Hidden,
}
}
5 changes: 5 additions & 0 deletions compiler/rustc_passes/src/reachable.rs
Expand Up @@ -333,6 +333,11 @@ impl CollectPrivateImplItemsVisitor<'_, '_> {
let codegen_attrs = self.tcx.codegen_fn_attrs(def_id);
if codegen_attrs.contains_extern_indicator()
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL)
// FIXME(nbdd0121): `#[used]` are marked as reachable here so it's picked up by
// `linked_symbols` in cg_ssa. They won't be exported in binary or cdylib due to their
// `SymbolExportLevel::Rust` export level but may end up being exported in dylibs.
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED)
|| codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER)
{
self.worklist.push(def_id);
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/run-make-fulldeps/reproducible-build/linker.rs
Expand Up @@ -25,6 +25,12 @@ fn main() {
let mut contents = Vec::new();
File::open(path).unwrap().read_to_end(&mut contents).unwrap();

// This file is produced during linking in a temporary directory.
let arg = if arg.ends_with("/symbols.o") || arg.ends_with("\\symbols.o") {
"symbols.o"
} else {
&*arg
};
out.push_str(&format!("{}: {}\n", arg, hash(&contents)));
}

Expand Down
5 changes: 5 additions & 0 deletions src/test/run-make-fulldeps/symbol-visibility/Makefile
Expand Up @@ -54,9 +54,12 @@ all:
# Check that a Rust dylib does not export generics if -Zshare-generics=no
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rlib)" -eq "0" ]

# FIXME(nbdd0121): This is broken in MinGW, see https://github.com/rust-lang/rust/pull/95604#issuecomment-1101564032
ifndef IS_WINDOWS
# Check that an executable does not export any dynamic symbols
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "0" ]
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_rust_function_from_exe)" -eq "0" ]
endif


# Check the combined case, where we generate a cdylib and an rlib in the same
Expand Down Expand Up @@ -91,6 +94,8 @@ all:
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_rust_function_from_rlib)" -eq "1" ]
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -v __imp_ | grep -c public_generic_function_from_rlib)" -eq "1" ]

ifndef IS_WINDOWS
# Check that an executable does not export any dynamic symbols
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_c_function_from_rlib)" -eq "0" ]
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -v __imp_ | grep -c public_rust_function_from_exe)" -eq "0" ]
endif
12 changes: 12 additions & 0 deletions src/test/run-make/issue-47384/Makefile
@@ -0,0 +1,12 @@
-include ../../run-make-fulldeps/tools.mk

# only-linux
# ignore-cross-compile

all: main.rs
$(RUSTC) --crate-type lib lib.rs
$(RUSTC) --crate-type cdylib -Clink-args="-Tlinker.ld" main.rs
# Ensure `#[used]` and `KEEP`-ed section is there
objdump -s -j".static" $(TMPDIR)/libmain.so
# Ensure `#[no_mangle]` symbol is there
nm $(TMPDIR)/libmain.so | $(CGREP) bar
12 changes: 12 additions & 0 deletions src/test/run-make/issue-47384/lib.rs
@@ -0,0 +1,12 @@
mod foo {
#[link_section = ".rodata.STATIC"]
#[used]
static STATIC: [u32; 10] = [1; 10];
}

mod bar {
#[no_mangle]
extern "C" fn bar() -> i32 {
0
}
}
7 changes: 7 additions & 0 deletions src/test/run-make/issue-47384/linker.ld
@@ -0,0 +1,7 @@
SECTIONS
{
.static : ALIGN(4)
{
KEEP(*(.rodata.STATIC));
}
}
1 change: 1 addition & 0 deletions src/test/run-make/issue-47384/main.rs
@@ -0,0 +1 @@
extern crate lib;