Skip to content

Commit 169f045

Browse files
committed
Correctly import foreign statics
Previously foreign statics would actually cause a local static to be defined and exported. This issue was found because std::env::vars() was found to return no env vars despite many being defined. This was caused by libstd importing environ as foreign static. The accidental definition of environ caused libstd to read a null pointer which was interpreted as there being no environment variables at all.
1 parent e690fb1 commit 169f045

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ 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(&sym, llty, false, is_tls, fn_attrs.link_section);
222222

223223
if !self.tcx.is_reachable_non_generic(def_id) {
224224
// TODO(antoyo): set visibility.
@@ -389,6 +389,6 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
389389
// don't do this then linker errors can be generated where the linker
390390
// complains that one object files has a thread local version of the
391391
// symbol and another one doesn't.
392-
cx.declare_global(&sym, llty, is_tls, attrs.link_section)
392+
cx.declare_global(&sym, llty, true, is_tls, attrs.link_section)
393393
}
394394
}

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, false, 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>, is_import: bool, is_tls: bool, link_section: Option<Symbol>) -> LValue<'gcc> {
51+
let global = self.context.new_global(None, if is_import { GlobalKind::Imported } else { GlobalKind::Exported }, ty, name);
5252
if is_tls {
5353
global.set_tls_model(self.tls_model);
5454
}

0 commit comments

Comments
 (0)