Skip to content

Commit fc23678

Browse files
authored
Merge pull request #115 from bjorn3/foreign_statics
Correctly import foreign statics
2 parents e690fb1 + 6663f4e commit fc23678

File tree

10 files changed

+25
-18
lines changed

10 files changed

+25
-18
lines changed

cargo.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pushd $(dirname "$0") >/dev/null
88
source config.sh
99

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

1313
popd >/dev/null
1414

prepare_build.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/bin/bash --verbose
22
set -e
33

4-
rustup component add rust-src rustc-dev llvm-tools-preview
54
./build_sysroot/prepare_sysroot_src.sh

rust-toolchain

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
nightly-2021-12-30
1+
[toolchain]
2+
channel = "nightly-2021-12-30"
3+
components = ["rust-src", "rustc-dev", "llvm-tools-preview"]

src/consts.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use gccjit::{LValue, RValue, ToRValue, Type};
1+
use gccjit::{GlobalKind, LValue, RValue, ToRValue, Type};
22
use rustc_codegen_ssa::traits::{BaseTypeMethods, ConstMethods, DerivedTypeMethods, StaticMethods};
33
use rustc_hir as hir;
44
use rustc_hir::Node;
@@ -218,7 +218,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
218218
}
219219

220220
let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
221-
let global = self.declare_global(&sym, llty, is_tls, fn_attrs.link_section);
221+
let global = self.declare_global(
222+
&sym,
223+
llty,
224+
GlobalKind::Exported,
225+
is_tls,
226+
fn_attrs.link_section,
227+
);
222228

223229
if !self.tcx.is_reachable_non_generic(def_id) {
224230
// TODO(antoyo): set visibility.
@@ -389,6 +395,6 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
389395
// don't do this then linker errors can be generated where the linker
390396
// complains that one object files has a thread local version of the
391397
// symbol and another one doesn't.
392-
cx.declare_global(&sym, llty, is_tls, attrs.link_section)
398+
cx.declare_global(&sym, llty, GlobalKind::Imported, is_tls, attrs.link_section)
393399
}
394400
}

src/declare.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2222
global
2323
}
2424
else {
25-
self.declare_global(name, ty, is_tls, link_section)
25+
self.declare_global(name, ty, GlobalKind::Exported, is_tls, link_section)
2626
}
2727
}
2828

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

50-
pub fn declare_global(&self, name: &str, ty: Type<'gcc>, is_tls: bool, link_section: Option<Symbol>) -> LValue<'gcc> {
51-
let global = self.context.new_global(None, GlobalKind::Exported, ty, name);
50+
pub fn declare_global(&self, name: &str, ty: Type<'gcc>, global_kind: GlobalKind, is_tls: bool, link_section: Option<Symbol>) -> LValue<'gcc> {
51+
let global = self.context.new_global(None, global_kind, ty, name);
5252
if is_tls {
5353
global.set_tls_model(self.tls_model);
5454
}

test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function test_rustc() {
145145
echo
146146
echo "[TEST] rust-lang/rust"
147147

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

150150
git clone https://github.com/rust-lang/rust.git || true
151151
cd rust

tests/run/assign.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ mod libc {
5151
pub fn fflush(stream: *mut i32) -> i32;
5252
pub fn printf(format: *const i8, ...) -> i32;
5353

54-
pub static STDOUT: *mut i32;
54+
pub static stdout: *mut i32;
5555
}
5656
}
5757

@@ -67,7 +67,7 @@ mod intrinsics {
6767
pub fn panic(_msg: &str) -> ! {
6868
unsafe {
6969
libc::puts("Panicking\0" as *const str as *const u8);
70-
libc::fflush(libc::STDOUT);
70+
libc::fflush(libc::stdout);
7171
intrinsics::abort();
7272
}
7373
}

tests/run/int_overflow.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mod libc {
4949
pub fn puts(s: *const u8) -> i32;
5050
pub fn fflush(stream: *mut i32) -> i32;
5151

52-
pub static STDOUT: *mut i32;
52+
pub static stdout: *mut i32;
5353
}
5454
}
5555

@@ -65,7 +65,7 @@ mod intrinsics {
6565
pub fn panic(_msg: &str) -> ! {
6666
unsafe {
6767
libc::puts("Panicking\0" as *const str as *const u8);
68-
libc::fflush(libc::STDOUT);
68+
libc::fflush(libc::stdout);
6969
intrinsics::abort();
7070
}
7171
}

tests/run/mut_ref.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ mod libc {
5353
pub fn fflush(stream: *mut i32) -> i32;
5454
pub fn printf(format: *const i8, ...) -> i32;
5555

56-
pub static STDOUT: *mut i32;
56+
pub static stdout: *mut i32;
5757
}
5858
}
5959

@@ -69,7 +69,7 @@ mod intrinsics {
6969
pub fn panic(_msg: &str) -> ! {
7070
unsafe {
7171
libc::puts("Panicking\0" as *const str as *const u8);
72-
libc::fflush(libc::STDOUT);
72+
libc::fflush(libc::stdout);
7373
intrinsics::abort();
7474
}
7575
}

tests/run/operations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod libc {
5959
pub fn puts(s: *const u8) -> i32;
6060
pub fn fflush(stream: *mut i32) -> i32;
6161

62-
pub static STDOUT: *mut i32;
62+
pub static stdout: *mut i32;
6363
}
6464
}
6565

@@ -75,7 +75,7 @@ mod intrinsics {
7575
pub fn panic(_msg: &str) -> ! {
7676
unsafe {
7777
libc::puts("Panicking\0" as *const str as *const u8);
78-
libc::fflush(libc::STDOUT);
78+
libc::fflush(libc::stdout);
7979
intrinsics::abort();
8080
}
8181
}

0 commit comments

Comments
 (0)