about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--build_system/src/build.rs23
-rw-r--r--build_system/src/test.rs26
-rw-r--r--src/back/write.rs60
-rw-r--r--src/base.rs10
-rw-r--r--src/consts.rs83
-rw-r--r--src/context.rs1
-rw-r--r--src/declare.rs4
-rw-r--r--src/lib.rs3
-rw-r--r--src/mono_item.rs3
9 files changed, 8 insertions, 205 deletions
diff --git a/build_system/src/build.rs b/build_system/src/build.rs
index d0e6beb376e..d0ced211a61 100644
--- a/build_system/src/build.rs
+++ b/build_system/src/build.rs
@@ -130,7 +130,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
     if config.no_default_features {
         rustflags.push_str(" -Csymbol-mangling-version=v0");
     }
-    //rustflags.push_str(" --print link-args");
 
     let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
     for feature in &config.features {
@@ -157,28 +156,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
     }
 
     let mut env = env.clone();
-    /*rustflags.push_str(" -C link-arg=-Wl,--verbose");
-    rustflags.push_str(" -C link-arg=-Wl,--warn-shared-textrel"); // Mold and Gold.
-    //rustflags.push_str(" -C link-arg=-Wl,--warn-textrel"); // Mold
-    rustflags.push_str(" -C link-arg=-Wl,--warn-unresolved-symbols");
-    rustflags.push_str(" -C link-arg=-Wl,--fatal-warnings");
-    rustflags.push_str(" -C link-arg=-Wl,--print-gc-sections");*/
-    //rustflags.push_str(" -C link-arg=-Wl,--no-apply-dynamic-relocs"); // Mold
-    /*rustflags.push_str(" -C link-arg=-Wl,--warn-ifunc-textrel");
-    rustflags.push_str(" -C link-arg=-Wl,--warn-backrefs");
-    rustflags.push_str(" -C link-arg=-Wl,-znotext");
-    //rustflags.push_str(" -C link-arg=-Wl,--emit-relocs");
-    //rustflags.push_str(" -C link-arg=-Wl,--trace-symbol=memchr::arch::x86_64::memchr::memchr_raw::FN");
-    //rustflags.push_str(" -C link-arg=-Wl,--trace-symbol=_ZN6memchr4arch6x86_646memchr10memchr_raw2FN17haaf621f7b8ca567eE");
-    //rustflags.push_str(" -C link-arg=-Wl,--print-map");
-    //rustflags.push_str(" -C link-arg=-Wl,");*/
-    //rustflags.push_str(" -Clinker=/usr/bin/ld.gold");
-    // TODO: try with verbose, warnings and logs.
-    //rustflags.push_str(" -Clinker=/usr/bin/clang");
-    //rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/mold");
-    //rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.bfd");
-    //rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.gold");
-    //env.insert("RUSTC_LOG".to_string(), "rustc_codegen_ssa::back::link=info".to_string());
     env.insert("RUSTFLAGS".to_string(), rustflags);
     run_command_with_output_and_env(&args, Some(&start_dir), Some(&env))?;
 
diff --git a/build_system/src/test.rs b/build_system/src/test.rs
index 060bfb8880e..371fcb4bc30 100644
--- a/build_system/src/test.rs
+++ b/build_system/src/test.rs
@@ -692,32 +692,6 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
     println!("[TEST] libcore");
     let path = get_sysroot_dir().join("sysroot_src/library/core/tests");
     let _ = remove_dir_all(path.join("target"));
-    /*let mut env = env.clone();
-    env.insert("RUSTC_LOG".to_string(), "rustc_codegen_ssa::back::link=info".to_string());*/
-    /*let rustflags =
-    env.entry("RUSTFLAGS".to_string())
-    .or_default();*/
-    //rustflags.push_str(" -C link-arg=-Wl,--verbose");
-    //rustflags.push_str(" -C link-arg=-Wl,--fatal-warnings");
-    //rustflags.push_str(" -C link-arg=-Wl,--warn-unresolved-symbols");
-    //rustflags.push_str(" -C link-arg=-Wl,--warn-shared-textrel"); // Mold and Gold.
-    //rustflags.push_str(" -C link-arg=-Wl,--warn-textrel"); // Mold
-    //rustflags.push_str(" -C link-arg=-Wl,--print-gc-sections");
-    //rustflags.push_str(" -C link-arg=-Wl,--no-apply-dynamic-relocs"); // Mold
-    /*rustflags.push_str(" -C link-arg=-Wl,--warn-ifunc-textrel");
-    rustflags.push_str(" -C link-arg=-Wl,--warn-backrefs");
-    rustflags.push_str(" -C link-arg=-Wl,-znotext");
-    rustflags.push_str(" -C link-arg=-Wl,--emit-relocs");
-    rustflags.push_str(" -C link-arg=-Wl,--trace-symbol=memchr::arch::x86_64::memchr::memchr_raw::FN");*/
-    //rustflags.push_str(" -Clinker=/usr/bin/ld.gol");
-    //rustflags.push_str(" -Clinker=/usr/bin/clang");
-    //rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/mold");
-    //rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.bfd");
-    //rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.gold");
-    // FIXME FIXME: seems like RUSTFLAGS is not set here.
-    //rustflags.push_str(" -C link-arg=-Wl,--trace-symbol=_ZN6memchr4arch6x86_646memchr10memchr_raw2FN17haaf621f7b8ca567eE");
-    //rustflags.push_str(" -C link-arg=-Wl,--print-map");
-    //rustflags.push_str(" -Clink-arg=-not-an-arg");
     run_cargo_command(&[&"test"], Some(&path), env, args)?;
     Ok(())
 }
diff --git a/src/back/write.rs b/src/back/write.rs
index 37a59e51c4b..007f30369ab 100644
--- a/src/back/write.rs
+++ b/src/back/write.rs
@@ -31,14 +31,9 @@ pub(crate) unsafe fn codegen(
 
         // NOTE: Only generate object files with GIMPLE when this environment variable is set for
         // now because this requires a particular setup (same gcc/lto1/lto-wrapper commit as libgccjit).
-        // TODO: remove this environment variable.
+        // TODO(antoyo): remove this environment variable.
         let fat_lto = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1");
 
-        /*if cgcx.msvc_imps_needed {
-            println!("************************************************** Imps needed");
-            create_msvc_imps(cgcx, context);
-        }*/
-
         let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
         let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name);
 
@@ -64,7 +59,7 @@ pub(crate) unsafe fn codegen(
                     );
                     context.add_command_line_option("-flto=auto");
                     context.add_command_line_option("-flto-partition=one");
-                    // TODO: remove since we don't want fat objects when it is for Bitcode only.
+                    // TODO(antoyo): remove since we don't want fat objects when it is for Bitcode only.
                     context.add_command_line_option("-ffat-lto-objects");
                     context.compile_to_file(
                         OutputKind::ObjectFile,
@@ -102,7 +97,7 @@ pub(crate) unsafe fn codegen(
                 }
 
                 if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
-                    // TODO: we might want to emit to emit an error here, saying to set the
+                    // TODO(antoyo): we might want to emit to emit an error here, saying to set the
                     // environment variable EMBED_LTO_BITCODE.
                     let _timer = cgcx.prof.generic_activity_with_arg(
                         "GCC_module_codegen_embed_bitcode",
@@ -111,12 +106,6 @@ pub(crate) unsafe fn codegen(
                     // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
                     //embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
 
-                    // TODO: check if this condition makes sense.
-                    if fat_lto {
-                        context.add_command_line_option("-flto=auto");
-                        context.add_command_line_option("-flto-partition=one");
-                        context.add_command_line_option("-ffat-lto-objects");
-                    }
                     // TODO(antoyo): Send -plugin/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/liblto_plugin.so to linker (this should be done when specifying the appropriate rustc cli argument).
                     context.compile_to_file(
                         OutputKind::ObjectFile,
@@ -172,8 +161,6 @@ pub(crate) unsafe fn codegen(
                         // lto1: internal compiler error: decompressed stream: Destination buffer is too small
                         // TODO: since we do not do LTO when the linker is invoked anymore, perhaps
                         // the following flag is not necessary anymore.
-                        // TODO: also, perhaps compiling the gcc driver in the CI is not necessary
-                        // anymore.
                         context.add_driver_option("-fuse-linker-plugin");
                     }
 
@@ -182,15 +169,6 @@ pub(crate) unsafe fn codegen(
                     // /usr/bin/ld: cannot find -lgcc_s: No such file or directory
                     context.add_driver_option("-nostdlib");
 
-                    // NOTE: this doesn't actually generate an executable. With the above flags, it combines the .o files together in another .o.
-                    // FIXME FIXME: this produces an object file with GIMPLE IR, but it should
-                    // produce an object file with machine code.
-                    //println!("LTO-ed object file: {:?}", obj_out);
-                    /*context.compile_to_file(
-                        OutputKind::Executable,
-                        obj_out.to_str().expect("path to str"),
-                    );*/
-
                     let path = obj_out.to_str().expect("path to str");
 
                     if fat_lto {
@@ -208,11 +186,7 @@ pub(crate) unsafe fn codegen(
                         context.compile_to_file(OutputKind::Executable, &lto_path);
 
                         let context = Context::default(); // TODO: might need to set some other flags from new_context.
-                        //context.add_driver_option("-v");
-                        //println!("*** Arch: {}", cgcx.target_arch);
                         if cgcx.target_arch == "x86" || cgcx.target_arch == "x86_64" {
-                            //println!("**** Added -masm=intel");
-                            //context.add_command_line_option("-masm=intel");
                             // NOTE: it seems we need to use add_driver_option instead of
                             // add_command_line_option here because we use the LTO frontend via gcc.
                             context.add_driver_option("-masm=intel");
@@ -295,31 +269,3 @@ pub(crate) fn save_temp_bitcode(
         llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
     }*/
 }
-
-/*fn create_msvc_imps<'gcc>(cgcx: &CodegenContext<GccCodegenBackend>, _context: &Context<'gcc>) {
-    if !cgcx.msvc_imps_needed {
-        return;
-    }
-
-    /*unsafe {
-        let ptr_ty = Type::ptr_llcx(llcx);
-        let globals = base::iter_globals(llmod)
-            .filter(|&val| {
-                llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage
-                    && llvm::LLVMIsDeclaration(val) == 0
-            })
-            .map(move |(val, name)| {
-                let mut imp_name = prefix.as_bytes().to_vec();
-                imp_name.extend(name);
-                let imp_name = CString::new(imp_name).unwrap();
-                (imp_name, val)
-            })
-            .collect::<Vec<_>>();
-
-        for (imp_name, val) in globals {
-            let imp = llvm::LLVMAddGlobal(llmod, ptr_ty, imp_name.as_ptr());
-            llvm::LLVMSetInitializer(imp, val);
-            llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage);
-        }
-    }*/
-}*/
diff --git a/src/base.rs b/src/base.rs
index eaa692a2046..4ac25fd7019 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -43,8 +43,8 @@ pub fn symbol_visibility_to_gcc(visibility: SymbolVisibility) -> gccjit::Visibil
 
 pub fn global_linkage_to_gcc(linkage: Linkage) -> GlobalKind {
     match linkage {
-        Linkage::External => GlobalKind::Exported,
-        Linkage::AvailableExternally => GlobalKind::Exported,
+        Linkage::External => GlobalKind::Imported,
+        Linkage::AvailableExternally => GlobalKind::Imported,
         Linkage::LinkOnceAny => unimplemented!(),
         Linkage::LinkOnceODR => unimplemented!(),
         Linkage::WeakAny => unimplemented!(),
@@ -153,19 +153,13 @@ pub fn compile_codegen_unit(
 
         match tcx.sess.relocation_model() {
             rustc_target::spec::RelocModel::Static => {
-                //println!("*** Static");
                 context.add_command_line_option("-fno-pie");
-                context.add_driver_option("-fno-pie");
             }
             rustc_target::spec::RelocModel::Pic => {
-                //println!("*** Pic");
                 context.add_command_line_option("-fPIC");
-                context.add_driver_option("-fPIC");
             }
             rustc_target::spec::RelocModel::Pie => {
-                //println!("*** Pie");
                 context.add_command_line_option("-fPIE");
-                context.add_driver_option("-fPIE");
             }
             model => eprintln!("Unsupported relocation model: {:?}", model),
         }
diff --git a/src/consts.rs b/src/consts.rs
index 4c3f0378064..1631ecfeecf 100644
--- a/src/consts.rs
+++ b/src/consts.rs
@@ -92,85 +92,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
         }
         set_global_alignment(self, global, alloc.align);
 
-        // TODO: if I still use this code, find the name of the variable in a better way (using
-        // def_id).
-        let var_name = format!("{:?}", global);
-        if var_name.contains("FN") && var_name.contains("memchr") {
-            //println!("Var name: {:?}", var_name);
-            //println!("INITIALIZE: {:?} = {:?}", var_name, value);
-
-            /*
-            let ptr_type = value.get_type().make_pointer();
-
-            // TODO: remove \x01
-            //let prefix = if self.cgcx.target_arch == "x86" { "\x01__imp__" } else { "\x01__imp_" };
-            let prefix = "__imp__";
-            let mut imp_name = prefix.to_string();
-            imp_name.push_str(&var_name);
-
-            // FIXME: if I understand correctly the code in cg_llvm, the kind should be Imported.
-            let imp_global = self.context.new_global(None, GlobalKind::Exported, ptr_type, &imp_name);
-            imp_global.global_set_initializer_rvalue(global.get_address(None));
-            */
-
-            /*
-            /*let context = gccjit::Context::default();
-            let global = context.new_global(None, GlobalKind::Exported, val_llty, &var_name);
-            global.global_set_initializer_rvalue(value);
-            context.compile_to_file(gccjit::OutputKind::ObjectFile, format!("{}.o", var_name));*/
-
-            let void_type = self.context.new_type::<()>();
-            let fn_ptr_type = self.context.new_function_pointer_type(None, void_type, &[], false);
-            let my_name = format!("MY_NAME${}", var_name);
-            //let global = self.context.new_global(None, GlobalKind::Exported, fn_ptr_type, my_name);
-            //global.add_attribute(VarAttribute::Used);
-
-            let my_func_name = format!("MY_FUNC${}", var_name);
-            let func = self.context.new_function(None, FunctionType::Exported, void_type, &[], &my_func_name, false);
-            func.add_attribute(FnAttribute::Used);
-            let block = func.new_block("start");
-            block.end_with_void_return(None);
-
-            //let func = self.context.new_function(None, FunctionType::Extern, void_type, &[], "puts", false);
-            let value = func.get_address(None);
-            //let global = self.context.new_global(None, GlobalKind::Exported, value.get_type(), my_name);
-            //let value = self.context.new_bitcast(None, func.get_address(None), fn_ptr_type);
-            /*
-             * TODO: Check if the hard-coded function has the correct name.
-             * ===> It seems so.
-             * TODO: try with a function we know exists.
-             * ===> It doesn't seem to help.
-             * TODO: check if the .o contains the value (before linking into the .so).
-             * ===> It seems the object file doesn't contain the value either.
-             * ======> This is because there are relocations.
-             * TODO: check if fold in GCC erases the value.
-             * ===> It doesn't seem so.
-             *
-             * TODO TODO: try again this code with using the used attribute.
-             */
-
-            /*let var_type = global.to_rvalue().get_type();
-            let struct_type = var_type.is_struct().unwrap();
-            /*let field1_type = struct_type.get_field(0).get_type();
-            let field2_type = struct_type.get_field(1).get_type();*/
-
-            let field1 = value;
-            let field2 = self.context.new_rvalue_zero(self.int_type);
-
-            let struct_val = self.context.new_struct_constructor(None, var_type, None, &[field1, field2]);
-            let value = struct_val;*/
-
-            //let value = self.context.new_bitcast(None, func.get_address(None), val_llty);
-
-            //let value = self.context.new_rvalue_from_int(self.usize_type, 10293);
-            //let value = self.context.new_cast(None, value, fn_ptr_type); // WORKS
-            //let value = self.context.new_bitcast(None, value, fn_ptr_type); // Also WORKS
-            let value = self.context.new_bitcast(None, value, val_llty);*/
-            global.global_set_initializer_rvalue(value);
-            //println!("=== AFTER INITIALIZE");
-        } else {
-            global.global_set_initializer_rvalue(value);
-        }
+        global.global_set_initializer_rvalue(value);
 
         // As an optimization, all shared statics which do not have interior
         // mutability are placed into read-only memory.
@@ -327,9 +249,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
             }
 
             let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
-            /*if sym.contains("memchr") && sym.contains("FN") {
-                println!("** DECLARE");
-            }*/
             let global = self.declare_global(
                 sym,
                 gcc_type,
diff --git a/src/context.rs b/src/context.rs
index f67dcf0cb11..c81c53359fd 100644
--- a/src/context.rs
+++ b/src/context.rs
@@ -386,6 +386,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
 impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
     type Value = RValue<'gcc>;
     type Metadata = RValue<'gcc>;
+    // TODO(antoyo): change to Function<'gcc>.
     type Function = RValue<'gcc>;
 
     type BasicBlock = Block<'gcc>;
diff --git a/src/declare.rs b/src/declare.rs
index fa4f2e622e9..442488b7fd6 100644
--- a/src/declare.rs
+++ b/src/declare.rs
@@ -29,7 +29,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
             }
             global
         } else {
-            // HERE: ExternalLinkage.
             self.declare_global(name, ty, GlobalKind::Exported, is_tls, link_section)
         }
     }
@@ -70,9 +69,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
         is_tls: bool,
         link_section: Option<Symbol>,
     ) -> LValue<'gcc> {
-        /*if name.contains("memchr") && name.contains("FN") {
-            println!("{}: {:?}: {:?}", self.codegen_unit.name(), name, global_kind);
-        }*/
         let global = self.context.new_global(None, global_kind, ty, name);
         if is_tls {
             global.set_tls_model(self.tls_model);
diff --git a/src/lib.rs b/src/lib.rs
index a71ec9ba6a4..0c209ebc26f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -27,7 +27,7 @@
 // Some "regular" crates we want to share with rustc
 extern crate object;
 extern crate smallvec;
-// FIXME: clippy bug: remove the #[allow] when it's fixed.
+// FIXME(antoyo): clippy bug: remove the #[allow] when it's fixed.
 #[allow(unused_extern_crates)]
 extern crate tempfile;
 #[macro_use]
@@ -269,7 +269,6 @@ impl CodegenBackend for GccCodegenBackend {
 
 fn new_context<'gcc, 'tcx>(tcx: TyCtxt<'tcx>) -> Context<'gcc> {
     let context = Context::default();
-    //context.add_driver_option("-pie");
     if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
         context.add_command_line_option("-masm=intel");
     }
diff --git a/src/mono_item.rs b/src/mono_item.rs
index 4fc2aad6437..239902df7f0 100644
--- a/src/mono_item.rs
+++ b/src/mono_item.rs
@@ -32,9 +32,6 @@ impl<'gcc, 'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
         let gcc_type = self.layout_of(ty).gcc_type(self);
 
         let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
-        /*if symbol_name.contains("memchr") && symbol_name.contains("FN") {
-            println!("** DECLARE static");
-        }*/
         let global = self.define_global(symbol_name, gcc_type, is_tls, attrs.link_section);
         #[cfg(feature = "master")]
         global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));