Skip to content

Commit 0bdc5ff

Browse files
committed
Support the weak variable attribute
1 parent d3cfb72 commit 0bdc5ff

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

Cargo.lock

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ master = ["gccjit/master"]
2222
default = ["master"]
2323

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

2728
# Local copy.
2829
#gccjit = { path = "../gccjit.rs" }

src/consts.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs}
77
use rustc_middle::mir::interpret::{
88
self, read_target_uint, ConstAllocation, ErrorHandled, Scalar as InterpScalar,
99
};
10+
use rustc_middle::mir::mono::Linkage;
1011
use rustc_middle::ty::layout::LayoutOf;
1112
use rustc_middle::ty::{self, Instance};
1213
use rustc_middle::{bug, span_bug};
@@ -256,7 +257,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
256257

257258
if !self.tcx.is_reachable_non_generic(def_id) {
258259
#[cfg(feature = "master")]
259-
global.add_string_attribute(VarAttribute::Visibility(Visibility::Hidden));
260+
global.add_attribute(VarAttribute::Visibility(Visibility::Hidden));
260261
}
261262

262263
global
@@ -384,6 +385,10 @@ fn check_and_apply_linkage<'gcc, 'tcx>(
384385
let global1 =
385386
cx.declare_global_with_linkage(sym, cx.type_i8(), base::global_linkage_to_gcc(linkage));
386387

388+
if linkage == Linkage::ExternalWeak {
389+
global1.add_attribute(VarAttribute::Weak);
390+
}
391+
387392
// Declare an internal global `extern_with_linkage_foo` which
388393
// is initialized with the address of `foo`. If `foo` is
389394
// discarded during linking (for example, if `foo` has weak

src/mono_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
3737
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
3838
let global = self.define_global(symbol_name, gcc_type, is_tls, attrs.link_section);
3939
#[cfg(feature = "master")]
40-
global.add_string_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));
40+
global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));
4141

4242
// TODO(antoyo): set linkage.
4343
self.instances.borrow_mut().insert(instance, global);

0 commit comments

Comments
 (0)