Skip to content

Commit ab4ff2d

Browse files
authored
Cleanup fix for global initialization (rust-lang#93)
* Cleanup fix for global initialization * Remove linker script hack * Use v0 symbol mangling * Fix warnings
1 parent 64c561d commit ab4ff2d

File tree

4 files changed

+5
-15
lines changed

4 files changed

+5
-15
lines changed

config.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
3838
fi
3939
fi
4040

41-
export RUSTFLAGS="$linker -Cpanic=abort -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
41+
export RUSTFLAGS="$linker -Cpanic=abort -Zsymbol-mangling-version=v0 -Cdebuginfo=2 -Clto=off -Zpanic-abort-tests -Zcodegen-backend=$(pwd)/target/${CHANNEL:-debug}/librustc_codegen_gcc.$dylib_ext --sysroot $(pwd)/build_sysroot/sysroot"
4242

4343
# FIXME(antoyo): remove once the atomic shim is gone
4444
if [[ `uname` == 'Darwin' ]]; then

src/common.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
4343
// TODO(antoyo): handle non-null-terminated strings.
4444
let string = self.context.new_string_literal(&*string);
4545
let sym = self.generate_local_symbol_name("str");
46-
// NOTE: TLS is always off for a string litteral.
47-
// NOTE: string litterals do not have a link section.
4846
let global = self.declare_private_global(&sym, self.val_ty(string));
49-
global.global_set_initializer_value(string); // TODO: only set if not imported?
47+
global.global_set_initializer_value(string);
5048
global
5149
// TODO(antoyo): set linkage.
5250
}

src/lib.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use rustc_errors::{ErrorReported, Handler};
6363
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
6464
use rustc_middle::middle::cstore::EncodedMetadata;
6565
use rustc_middle::ty::TyCtxt;
66-
use rustc_session::config::{CrateType, Lto, OptLevel, OutputFilenames};
66+
use rustc_session::config::{Lto, OptLevel, OutputFilenames};
6767
use rustc_session::Session;
6868
use rustc_span::Symbol;
6969
use rustc_span::fatal_error::FatalError;
@@ -106,16 +106,8 @@ impl CodegenBackend for GccCodegenBackend {
106106
Ok((codegen_results, work_products))
107107
}
108108

109-
fn link(&self, sess: &Session, mut codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorReported> {
109+
fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorReported> {
110110
use rustc_codegen_ssa::back::link::link_binary;
111-
if let Some(symbols) = codegen_results.crate_info.exported_symbols.get_mut(&CrateType::Dylib) {
112-
// TODO:(antoyo): remove when global initializer work without calling a function at runtime.
113-
// HACK: since this codegen add some symbols (e.g. __gccGlobalCrateInit) and the UI
114-
// tests load libstd.so as a dynamic library, and rustc use a version-script to specify
115-
// the symbols visibility, we add * to export all symbols.
116-
// It seems other symbols from libstd/libcore are causing some issues here as well.
117-
symbols.push("*".to_string());
118-
}
119111

120112
link_binary::<crate::archive::ArArchiveBuilder<'_>>(
121113
sess,

test.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ git checkout src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs
171171
git checkout src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice2.rs
172172
rm src/test/ui/llvm-asm/llvm-asm-in-out-operand.rs || true # TODO(antoyo): Enable back this test if I ever implement the llvm_asm! macro.
173173

174-
RUSTC_ARGS="-Zpanic-abort-tests -Zcodegen-backend="$(pwd)"/../target/"$CHANNEL"/librustc_codegen_gcc."$dylib_ext" --sysroot "$(pwd)"/../build_sysroot/sysroot -Cpanic=abort"
174+
RUSTC_ARGS="-Zpanic-abort-tests -Zsymbol-mangling-version=v0 -Zcodegen-backend="$(pwd)"/../target/"$CHANNEL"/librustc_codegen_gcc."$dylib_ext" --sysroot "$(pwd)"/../build_sysroot/sysroot -Cpanic=abort"
175175

176176
echo "[TEST] rustc test suite"
177177
COMPILETEST_FORCE_STAGE0=1 ./x.py test --run always --stage 0 src/test/ui/ --rustc-args "$RUSTC_ARGS"

0 commit comments

Comments
 (0)