From 3f23706c6ca89f25dc337b65e1769ca749960a94 Mon Sep 17 00:00:00 2001 From: Antoni Boucher Date: Wed, 8 Jan 2025 21:31:32 -0500 Subject: [PATCH] Cleanup --- build_system/src/build.rs | 4 +-- build_system/src/test.rs | 12 +++---- src/back/write.rs | 76 ++++++++++++++++++++------------------- src/base.rs | 6 ++-- src/consts.rs | 14 ++++---- src/declare.rs | 4 +-- src/mono_item.rs | 4 +-- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/build_system/src/build.rs b/build_system/src/build.rs index b62bd44c6ac..d0e6beb376e 100644 --- a/build_system/src/build.rs +++ b/build_system/src/build.rs @@ -130,7 +130,7 @@ pub fn build_sysroot(env: &HashMap, config: &ConfigInfo) -> Resu if config.no_default_features { rustflags.push_str(" -Csymbol-mangling-version=v0"); } - rustflags.push_str(" --print link-args"); + //rustflags.push_str(" --print link-args"); let mut args: Vec<&dyn AsRef> = vec![&"cargo", &"build", &"--target", &config.target]; for feature in &config.features { @@ -178,7 +178,7 @@ pub fn build_sysroot(env: &HashMap, config: &ConfigInfo) -> Resu //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("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 6a70fe8d2b8..060bfb8880e 100644 --- a/build_system/src/test.rs +++ b/build_system/src/test.rs @@ -692,11 +692,11 @@ 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(); + /*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"); @@ -718,7 +718,7 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> { //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)?; + run_cargo_command(&[&"test"], Some(&path), env, args)?; Ok(()) } diff --git a/src/back/write.rs b/src/back/write.rs index 9d903a3f75e..33e76c4565c 100644 --- a/src/back/write.rs +++ b/src/back/write.rs @@ -1,12 +1,12 @@ use std::{env, fs}; -use gccjit::{Context, OutputKind}; +use gccjit::OutputKind; use rustc_codegen_ssa::back::link::ensure_removed; use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig}; use rustc_codegen_ssa::{CompiledModule, ModuleCodegen}; use rustc_errors::DiagCtxtHandle; use rustc_fs_util::link_or_copy; -use rustc_session::config::{Lto, OutputType}; +use rustc_session::config::OutputType; use rustc_span::fatal_error::FatalError; use rustc_target::spec::SplitDebuginfo; @@ -34,10 +34,10 @@ pub(crate) unsafe fn codegen( // TODO: remove this environment variable. let fat_lto = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1"); - if cgcx.msvc_imps_needed { + /*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); @@ -58,21 +58,25 @@ pub(crate) unsafe fn codegen( }*/ if config.emit_bc || config.emit_obj == EmitObj::Bitcode { - let _timer = cgcx - .prof - .generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name); + let _timer = cgcx.prof.generic_activity_with_arg( + "GCC_module_codegen_emit_bitcode", + &*module.name, + ); 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. context.add_command_line_option("-ffat-lto-objects"); - context - .compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str")); + context.compile_to_file( + OutputKind::ObjectFile, + bc_out.to_str().expect("path to str"), + ); } if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) { - let _timer = cgcx - .prof - .generic_activity_with_arg("GCC_module_codegen_embed_bitcode", &*module.name); + let _timer = cgcx.prof.generic_activity_with_arg( + "GCC_module_codegen_embed_bitcode", + &*module.name, + ); // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes? //embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data); @@ -80,26 +84,30 @@ pub(crate) unsafe fn codegen( 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, bc_out.to_str().expect("path to str")); + context.compile_to_file( + OutputKind::ObjectFile, + bc_out.to_str().expect("path to str"), + ); } - } - else { + } else { if config.emit_bc || config.emit_obj == EmitObj::Bitcode { - let _timer = cgcx - .prof - .generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name); - context - .compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str")); + let _timer = cgcx.prof.generic_activity_with_arg( + "GCC_module_codegen_emit_bitcode", + &*module.name, + ); + context.compile_to_file( + OutputKind::ObjectFile, + bc_out.to_str().expect("path to str"), + ); } if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) { // TODO: we might want to emit to emit an error here, saying to set the // environment variable EMBED_LTO_BITCODE. - unreachable!(); - let _timer = cgcx - .prof - .generic_activity_with_arg("GCC_module_codegen_embed_bitcode", &*module.name); + let _timer = cgcx.prof.generic_activity_with_arg( + "GCC_module_codegen_embed_bitcode", + &*module.name, + ); // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes? //embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data); @@ -107,8 +115,10 @@ pub(crate) unsafe fn codegen( 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, bc_out.to_str().expect("path to str")); + context.compile_to_file( + OutputKind::ObjectFile, + bc_out.to_str().expect("path to str"), + ); } } } @@ -231,18 +241,10 @@ pub(crate) fn save_temp_bitcode( }*/ } -fn create_msvc_imps<'gcc>( - cgcx: &CodegenContext, - context: &Context<'gcc>, -) { +/*fn create_msvc_imps<'gcc>(cgcx: &CodegenContext, _context: &Context<'gcc>) { if !cgcx.msvc_imps_needed { return; } - // The x86 ABI seems to require that leading underscores are added to symbol - // names, so we need an extra underscore on x86. There's also a leading - // '\x01' here which disables LLVM's symbol mangling (e.g., no extra - // underscores added in front). - let prefix = if cgcx.target_arch == "x86" { "\x01__imp__" } else { "\x01__imp_" }; /*unsafe { let ptr_ty = Type::ptr_llcx(llcx); @@ -265,4 +267,4 @@ fn create_msvc_imps<'gcc>( llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage); } }*/ -} +}*/ diff --git a/src/base.rs b/src/base.rs index d457928ce08..eaa692a2046 100644 --- a/src/base.rs +++ b/src/base.rs @@ -156,17 +156,17 @@ pub fn compile_codegen_unit( //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 7cba39bcea1..4c3f0378064 100644 --- a/src/consts.rs +++ b/src/consts.rs @@ -1,6 +1,6 @@ #[cfg(feature = "master")] use gccjit::{FnAttribute, VarAttribute, Visibility}; -use gccjit::{Function, FunctionType, GlobalKind, LValue, RValue, ToRValue, Type}; +use gccjit::{Function, GlobalKind, LValue, RValue, ToRValue, Type}; use rustc_codegen_ssa::traits::{ BaseTypeCodegenMethods, ConstCodegenMethods, StaticCodegenMethods, }; @@ -92,13 +92,12 @@ 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); + //println!("INITIALIZE: {:?} = {:?}", var_name, value); /* let ptr_type = value.get_type().make_pointer(); @@ -168,9 +167,8 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> { //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 { + //println!("=== AFTER INITIALIZE"); + } else { global.global_set_initializer_rvalue(value); } @@ -329,9 +327,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { } let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL); - if sym.contains("memchr") && sym.contains("FN") { + /*if sym.contains("memchr") && sym.contains("FN") { println!("** DECLARE"); - } + }*/ let global = self.declare_global( sym, gcc_type, diff --git a/src/declare.rs b/src/declare.rs index ac82ed4b3b8..fa4f2e622e9 100644 --- a/src/declare.rs +++ b/src/declare.rs @@ -70,9 +70,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { is_tls: bool, link_section: Option, ) -> LValue<'gcc> { - if name.contains("memchr") && name.contains("FN") { + /*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/mono_item.rs b/src/mono_item.rs index 90d4386a760..4fc2aad6437 100644 --- a/src/mono_item.rs +++ b/src/mono_item.rs @@ -32,9 +32,9 @@ 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") { + /*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)));