diff options
| author | Antoni Boucher <bouanto@zoho.com> | 2024-09-01 11:23:24 -0400 |
|---|---|---|
| committer | Antoni Boucher <bouanto@zoho.com> | 2024-09-01 11:23:24 -0400 |
| commit | 0bdc5ffd685db3d1506dbf21c8df5daaf68aeaac (patch) | |
| tree | 7f995412a413cbc937bbf904cdb208710d50df3a /src | |
| parent | d3cfb7274d87c441b47c3d4790246be0a5a54e3f (diff) | |
| download | rust-0bdc5ffd685db3d1506dbf21c8df5daaf68aeaac.tar.gz rust-0bdc5ffd685db3d1506dbf21c8df5daaf68aeaac.zip | |
Support the weak variable attribute
Diffstat (limited to 'src')
| -rw-r--r-- | src/consts.rs | 7 | ||||
| -rw-r--r-- | src/mono_item.rs | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/src/consts.rs b/src/consts.rs index e5673cddc4a..53dbb35d711 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -7,6 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs} use rustc_middle::mir::interpret::{ self, read_target_uint, ConstAllocation, ErrorHandled, Scalar as InterpScalar, }; +use rustc_middle::mir::mono::Linkage; use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::{self, Instance}; use rustc_middle::{bug, span_bug}; @@ -256,7 +257,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { if !self.tcx.is_reachable_non_generic(def_id) { #[cfg(feature = "master")] - global.add_string_attribute(VarAttribute::Visibility(Visibility::Hidden)); + global.add_attribute(VarAttribute::Visibility(Visibility::Hidden)); } global @@ -384,6 +385,10 @@ fn check_and_apply_linkage<'gcc, 'tcx>( let global1 = cx.declare_global_with_linkage(sym, cx.type_i8(), base::global_linkage_to_gcc(linkage)); + if linkage == Linkage::ExternalWeak { + global1.add_attribute(VarAttribute::Weak); + } + // Declare an internal global `extern_with_linkage_foo` which // is initialized with the address of `foo`. If `foo` is // discarded during linking (for example, if `foo` has weak diff --git a/src/mono_item.rs b/src/mono_item.rs index e6b22d51871..ba81dea49d5 100644 --- a/src/mono_item.rs +++ b/src/mono_item.rs @@ -37,7 +37,7 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> { let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL); let global = self.define_global(symbol_name, gcc_type, is_tls, attrs.link_section); #[cfg(feature = "master")] - global.add_string_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility))); + global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility))); // TODO(antoyo): set linkage. self.instances.borrow_mut().insert(instance, global); |
