Skip to content

Commit

Permalink
Support the weak variable attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Sep 1, 2024
1 parent d3cfb72 commit 0bdc5ff
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
6 changes: 2 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ master = ["gccjit/master"]
default = ["master"]

[dependencies]
gccjit = "2.1"
#gccjit = "2.1"
gccjit = { git = "https://github.com/rust-lang/gccjit.rs" }

# Local copy.
#gccjit = { path = "../gccjit.rs" }
Expand Down
7 changes: 6 additions & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/mono_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0bdc5ff

Please sign in to comment.