Skip to content

Correctly import foreign statics #115

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

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion cargo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pushd $(dirname "$0") >/dev/null
source config.sh

# read nightly compiler from rust-toolchain file
TOOLCHAIN=$(cat rust-toolchain)
TOOLCHAIN=$(cat rust-toolchain | grep channel | sed 's/channel = "\(.*\)"/\1/')

popd >/dev/null

Expand Down
1 change: 0 additions & 1 deletion prepare_build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/bash --verbose
set -e

rustup component add rust-src rustc-dev llvm-tools-preview
./build_sysroot/prepare_sysroot_src.sh
4 changes: 3 additions & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
nightly-2021-12-30
[toolchain]
channel = "nightly-2021-12-30"
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]
12 changes: 9 additions & 3 deletions src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gccjit::{LValue, RValue, ToRValue, Type};
use gccjit::{GlobalKind, LValue, RValue, ToRValue, Type};
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, DerivedTypeMethods, StaticMethods};
use rustc_hir as hir;
use rustc_hir::Node;
Expand Down Expand Up @@ -218,7 +218,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
}

let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
let global = self.declare_global(&sym, llty, is_tls, fn_attrs.link_section);
let global = self.declare_global(
&sym,
llty,
GlobalKind::Exported,
is_tls,
fn_attrs.link_section,
);

if !self.tcx.is_reachable_non_generic(def_id) {
// TODO(antoyo): set visibility.
Expand Down Expand Up @@ -389,6 +395,6 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
// don't do this then linker errors can be generated where the linker
// complains that one object files has a thread local version of the
// symbol and another one doesn't.
cx.declare_global(&sym, llty, is_tls, attrs.link_section)
cx.declare_global(&sym, llty, GlobalKind::Imported, is_tls, attrs.link_section)
}
}
6 changes: 3 additions & 3 deletions src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
global
}
else {
self.declare_global(name, ty, is_tls, link_section)
self.declare_global(name, ty, GlobalKind::Exported, is_tls, link_section)
}
}

Expand All @@ -47,8 +47,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
unsafe { std::mem::transmute(func) }
}*/

pub fn declare_global(&self, name: &str, ty: Type<'gcc>, is_tls: bool, link_section: Option<Symbol>) -> LValue<'gcc> {
let global = self.context.new_global(None, GlobalKind::Exported, ty, name);
pub fn declare_global(&self, name: &str, ty: Type<'gcc>, global_kind: GlobalKind, is_tls: bool, link_section: Option<Symbol>) -> LValue<'gcc> {
let global = self.context.new_global(None, global_kind, ty, name);
if is_tls {
global.set_tls_model(self.tls_model);
}
Expand Down
2 changes: 1 addition & 1 deletion test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ function test_rustc() {
echo
echo "[TEST] rust-lang/rust"

rust_toolchain=$(cat rust-toolchain)
rust_toolchain=$(cat rust-toolchain | grep channel | sed 's/channel = "\(.*\)"/\1/')

git clone https://github.com/rust-lang/rust.git || true
cd rust
Expand Down
4 changes: 2 additions & 2 deletions tests/run/assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod libc {
pub fn fflush(stream: *mut i32) -> i32;
pub fn printf(format: *const i8, ...) -> i32;

pub static STDOUT: *mut i32;
pub static stdout: *mut i32;
}
}

Expand All @@ -67,7 +67,7 @@ mod intrinsics {
pub fn panic(_msg: &str) -> ! {
unsafe {
libc::puts("Panicking\0" as *const str as *const u8);
libc::fflush(libc::STDOUT);
libc::fflush(libc::stdout);
intrinsics::abort();
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run/int_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod libc {
pub fn puts(s: *const u8) -> i32;
pub fn fflush(stream: *mut i32) -> i32;

pub static STDOUT: *mut i32;
pub static stdout: *mut i32;
}
}

Expand All @@ -65,7 +65,7 @@ mod intrinsics {
pub fn panic(_msg: &str) -> ! {
unsafe {
libc::puts("Panicking\0" as *const str as *const u8);
libc::fflush(libc::STDOUT);
libc::fflush(libc::stdout);
intrinsics::abort();
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run/mut_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ mod libc {
pub fn fflush(stream: *mut i32) -> i32;
pub fn printf(format: *const i8, ...) -> i32;

pub static STDOUT: *mut i32;
pub static stdout: *mut i32;
}
}

Expand All @@ -69,7 +69,7 @@ mod intrinsics {
pub fn panic(_msg: &str) -> ! {
unsafe {
libc::puts("Panicking\0" as *const str as *const u8);
libc::fflush(libc::STDOUT);
libc::fflush(libc::stdout);
intrinsics::abort();
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/run/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ mod libc {
pub fn puts(s: *const u8) -> i32;
pub fn fflush(stream: *mut i32) -> i32;

pub static STDOUT: *mut i32;
pub static stdout: *mut i32;
}
}

Expand All @@ -75,7 +75,7 @@ mod intrinsics {
pub fn panic(_msg: &str) -> ! {
unsafe {
libc::puts("Panicking\0" as *const str as *const u8);
libc::fflush(libc::STDOUT);
libc::fflush(libc::stdout);
intrinsics::abort();
}
}
Expand Down