about summary refs log tree commit diff
diff options
context:
space:
mode:
authorantoyo <antoyo@users.noreply.github.com>2021-09-27 09:34:06 -0400
committerGitHub <noreply@github.com>2021-09-27 09:34:06 -0400
commitab4ff2dfe0955ede04c4ddb7373337a6141081b8 (patch)
tree542217c58ddc26a5f4d1f8c5387189fa61c2bcab
parent64c561dc2253463659a8ae93b3d265dda45c6ee9 (diff)
downloadrust-ab4ff2dfe0955ede04c4ddb7373337a6141081b8.tar.gz
rust-ab4ff2dfe0955ede04c4ddb7373337a6141081b8.zip
Cleanup fix for global initialization (#93)
* Cleanup fix for global initialization
* Remove linker script hack
* Use v0 symbol mangling
* Fix warnings
-rw-r--r--config.sh2
-rw-r--r--src/common.rs4
-rw-r--r--src/lib.rs12
-rwxr-xr-xtest.sh2
4 files changed, 5 insertions, 15 deletions
diff --git a/config.sh b/config.sh
index d022371eebe..87df2f2102b 100644
--- a/config.sh
+++ b/config.sh
@@ -38,7 +38,7 @@ if [[ "$HOST_TRIPLE" != "$TARGET_TRIPLE" ]]; then
    fi
 fi
 
-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"
+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"
 
 # FIXME(antoyo): remove once the atomic shim is gone
 if [[ `uname` == 'Darwin' ]]; then
diff --git a/src/common.rs b/src/common.rs
index c60cbd81f63..709fa2a297b 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -43,10 +43,8 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
         // TODO(antoyo): handle non-null-terminated strings.
         let string = self.context.new_string_literal(&*string);
         let sym = self.generate_local_symbol_name("str");
-        // NOTE: TLS is always off for a string litteral.
-        // NOTE: string litterals do not have a link section.
         let global = self.declare_private_global(&sym, self.val_ty(string));
-        global.global_set_initializer_value(string); // TODO: only set if not imported?
+        global.global_set_initializer_value(string);
         global
         // TODO(antoyo): set linkage.
     }
diff --git a/src/lib.rs b/src/lib.rs
index 3c3a3568228..f3c02e2634f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -63,7 +63,7 @@ use rustc_errors::{ErrorReported, Handler};
 use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
 use rustc_middle::middle::cstore::EncodedMetadata;
 use rustc_middle::ty::TyCtxt;
-use rustc_session::config::{CrateType, Lto, OptLevel, OutputFilenames};
+use rustc_session::config::{Lto, OptLevel, OutputFilenames};
 use rustc_session::Session;
 use rustc_span::Symbol;
 use rustc_span::fatal_error::FatalError;
@@ -106,16 +106,8 @@ impl CodegenBackend for GccCodegenBackend {
         Ok((codegen_results, work_products))
     }
 
-    fn link(&self, sess: &Session, mut codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorReported> {
+    fn link(&self, sess: &Session, codegen_results: CodegenResults, outputs: &OutputFilenames) -> Result<(), ErrorReported> {
         use rustc_codegen_ssa::back::link::link_binary;
-        if let Some(symbols) = codegen_results.crate_info.exported_symbols.get_mut(&CrateType::Dylib) {
-            // TODO:(antoyo): remove when global initializer work without calling a function at runtime.
-            // HACK: since this codegen add some symbols (e.g. __gccGlobalCrateInit) and the UI
-            // tests load libstd.so as a dynamic library, and rustc use a version-script to specify
-            // the symbols visibility, we add * to export all symbols.
-            // It seems other symbols from libstd/libcore are causing some issues here as well.
-            symbols.push("*".to_string());
-        }
 
         link_binary::<crate::archive::ArArchiveBuilder<'_>>(
             sess,
diff --git a/test.sh b/test.sh
index 12df1f8af2f..92cbdbb7c00 100755
--- a/test.sh
+++ b/test.sh
@@ -171,7 +171,7 @@ git checkout src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice.rs
 git checkout src/test/ui/type-alias-impl-trait/auxiliary/cross_crate_ice2.rs
 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.
 
-RUSTC_ARGS="-Zpanic-abort-tests -Zcodegen-backend="$(pwd)"/../target/"$CHANNEL"/librustc_codegen_gcc."$dylib_ext" --sysroot "$(pwd)"/../build_sysroot/sysroot -Cpanic=abort"
+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"
 
 echo "[TEST] rustc test suite"
 COMPILETEST_FORCE_STAGE0=1 ./x.py test --run always --stage 0 src/test/ui/ --rustc-args "$RUSTC_ARGS"