1
Fork 0
This commit is contained in:
Antoni Boucher 2025-01-08 21:31:32 -05:00
parent 59afbe0913
commit 3f23706c6c
7 changed files with 60 additions and 60 deletions

View file

@ -130,7 +130,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
if config.no_default_features { if config.no_default_features {
rustflags.push_str(" -Csymbol-mangling-version=v0"); 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<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target]; let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
for feature in &config.features { for feature in &config.features {
@ -178,7 +178,7 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
//rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/mold"); //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.bfd");
//rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.gold"); //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); env.insert("RUSTFLAGS".to_string(), rustflags);
run_command_with_output_and_env(&args, Some(&start_dir), Some(&env))?; run_command_with_output_and_env(&args, Some(&start_dir), Some(&env))?;

View file

@ -692,11 +692,11 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
println!("[TEST] libcore"); println!("[TEST] libcore");
let path = get_sysroot_dir().join("sysroot_src/library/core/tests"); let path = get_sysroot_dir().join("sysroot_src/library/core/tests");
let _ = remove_dir_all(path.join("target")); let _ = remove_dir_all(path.join("target"));
let mut env = env.clone(); /*let mut env = env.clone();
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());*/
let rustflags = /*let rustflags =
env.entry("RUSTFLAGS".to_string()) env.entry("RUSTFLAGS".to_string())
.or_default(); .or_default();*/
//rustflags.push_str(" -C link-arg=-Wl,--verbose"); //rustflags.push_str(" -C link-arg=-Wl,--verbose");
//rustflags.push_str(" -C link-arg=-Wl,--fatal-warnings"); //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-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,--trace-symbol=_ZN6memchr4arch6x86_646memchr10memchr_raw2FN17haaf621f7b8ca567eE");
//rustflags.push_str(" -C link-arg=-Wl,--print-map"); //rustflags.push_str(" -C link-arg=-Wl,--print-map");
//rustflags.push_str(" -Clink-arg=-not-an-arg"); //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(()) Ok(())
} }

View file

@ -1,12 +1,12 @@
use std::{env, fs}; use std::{env, fs};
use gccjit::{Context, OutputKind}; use gccjit::OutputKind;
use rustc_codegen_ssa::back::link::ensure_removed; use rustc_codegen_ssa::back::link::ensure_removed;
use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig}; use rustc_codegen_ssa::back::write::{BitcodeSection, CodegenContext, EmitObj, ModuleConfig};
use rustc_codegen_ssa::{CompiledModule, ModuleCodegen}; use rustc_codegen_ssa::{CompiledModule, ModuleCodegen};
use rustc_errors::DiagCtxtHandle; use rustc_errors::DiagCtxtHandle;
use rustc_fs_util::link_or_copy; 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_span::fatal_error::FatalError;
use rustc_target::spec::SplitDebuginfo; use rustc_target::spec::SplitDebuginfo;
@ -34,10 +34,10 @@ pub(crate) unsafe fn codegen(
// TODO: remove this environment variable. // TODO: remove this environment variable.
let fat_lto = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1"); 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"); println!("************************************************** Imps needed");
create_msvc_imps(cgcx, context); create_msvc_imps(cgcx, context);
} }*/
let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name); let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, 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 { if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
let _timer = cgcx let _timer = cgcx.prof.generic_activity_with_arg(
.prof "GCC_module_codegen_emit_bitcode",
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name); &*module.name,
);
context.add_command_line_option("-flto=auto"); context.add_command_line_option("-flto=auto");
context.add_command_line_option("-flto-partition=one"); context.add_command_line_option("-flto-partition=one");
// TODO: remove since we don't want fat objects when it is for Bitcode only. // TODO: remove since we don't want fat objects when it is for Bitcode only.
context.add_command_line_option("-ffat-lto-objects"); context.add_command_line_option("-ffat-lto-objects");
context context.compile_to_file(
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str")); OutputKind::ObjectFile,
bc_out.to_str().expect("path to str"),
);
} }
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) { if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
let _timer = cgcx let _timer = cgcx.prof.generic_activity_with_arg(
.prof "GCC_module_codegen_embed_bitcode",
.generic_activity_with_arg("GCC_module_codegen_embed_bitcode", &*module.name); &*module.name,
);
// TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes? // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data); //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("-flto-partition=one");
context.add_command_line_option("-ffat-lto-objects"); 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). // 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 context.compile_to_file(
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str")); OutputKind::ObjectFile,
bc_out.to_str().expect("path to str"),
);
} }
} } else {
else {
if config.emit_bc || config.emit_obj == EmitObj::Bitcode { if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
let _timer = cgcx let _timer = cgcx.prof.generic_activity_with_arg(
.prof "GCC_module_codegen_emit_bitcode",
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name); &*module.name,
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) { if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
// TODO: we might want to emit to emit an error here, saying to set the // TODO: we might want to emit to emit an error here, saying to set the
// environment variable EMBED_LTO_BITCODE. // environment variable EMBED_LTO_BITCODE.
unreachable!(); let _timer = cgcx.prof.generic_activity_with_arg(
let _timer = cgcx "GCC_module_codegen_embed_bitcode",
.prof &*module.name,
.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? // TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data); //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("-flto-partition=one");
context.add_command_line_option("-ffat-lto-objects"); 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). // 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 context.compile_to_file(
.compile_to_file(OutputKind::ObjectFile, bc_out.to_str().expect("path to str")); 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>( /*fn create_msvc_imps<'gcc>(cgcx: &CodegenContext<GccCodegenBackend>, _context: &Context<'gcc>) {
cgcx: &CodegenContext<GccCodegenBackend>,
context: &Context<'gcc>,
) {
if !cgcx.msvc_imps_needed { if !cgcx.msvc_imps_needed {
return; 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 { /*unsafe {
let ptr_ty = Type::ptr_llcx(llcx); let ptr_ty = Type::ptr_llcx(llcx);
@ -265,4 +267,4 @@ fn create_msvc_imps<'gcc>(
llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage); llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage);
} }
}*/ }*/
} }*/

View file

@ -156,17 +156,17 @@ pub fn compile_codegen_unit(
//println!("*** Static"); //println!("*** Static");
context.add_command_line_option("-fno-pie"); context.add_command_line_option("-fno-pie");
context.add_driver_option("-fno-pie"); context.add_driver_option("-fno-pie");
}, }
rustc_target::spec::RelocModel::Pic => { rustc_target::spec::RelocModel::Pic => {
//println!("*** Pic"); //println!("*** Pic");
context.add_command_line_option("-fPIC"); context.add_command_line_option("-fPIC");
context.add_driver_option("-fPIC"); context.add_driver_option("-fPIC");
}, }
rustc_target::spec::RelocModel::Pie => { rustc_target::spec::RelocModel::Pie => {
//println!("*** Pie"); //println!("*** Pie");
context.add_command_line_option("-fPIE"); context.add_command_line_option("-fPIE");
context.add_driver_option("-fPIE"); context.add_driver_option("-fPIE");
}, }
model => eprintln!("Unsupported relocation model: {:?}", model), model => eprintln!("Unsupported relocation model: {:?}", model),
} }

View file

@ -1,6 +1,6 @@
#[cfg(feature = "master")] #[cfg(feature = "master")]
use gccjit::{FnAttribute, VarAttribute, Visibility}; 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::{ use rustc_codegen_ssa::traits::{
BaseTypeCodegenMethods, ConstCodegenMethods, StaticCodegenMethods, BaseTypeCodegenMethods, ConstCodegenMethods, StaticCodegenMethods,
}; };
@ -92,13 +92,12 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
} }
set_global_alignment(self, global, alloc.align); 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 // TODO: if I still use this code, find the name of the variable in a better way (using
// def_id). // def_id).
let var_name = format!("{:?}", global); let var_name = format!("{:?}", global);
if var_name.contains("FN") && var_name.contains("memchr") { if var_name.contains("FN") && var_name.contains("memchr") {
//println!("Var name: {:?}", var_name); //println!("Var name: {:?}", var_name);
println!("INITIALIZE: {:?} = {:?}", var_name, value); //println!("INITIALIZE: {:?} = {:?}", var_name, value);
/* /*
let ptr_type = value.get_type().make_pointer(); 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, fn_ptr_type); // Also WORKS
let value = self.context.new_bitcast(None, value, val_llty);*/ let value = self.context.new_bitcast(None, value, val_llty);*/
global.global_set_initializer_rvalue(value); global.global_set_initializer_rvalue(value);
println!("=== AFTER INITIALIZE"); //println!("=== AFTER INITIALIZE");
} } else {
else {
global.global_set_initializer_rvalue(value); 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); 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"); println!("** DECLARE");
} }*/
let global = self.declare_global( let global = self.declare_global(
sym, sym,
gcc_type, gcc_type,

View file

@ -70,9 +70,9 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
is_tls: bool, is_tls: bool,
link_section: Option<Symbol>, link_section: Option<Symbol>,
) -> LValue<'gcc> { ) -> LValue<'gcc> {
if name.contains("memchr") && name.contains("FN") { /*if name.contains("memchr") && name.contains("FN") {
println!("{}: {:?}: {:?}", self.codegen_unit.name(), name, global_kind); println!("{}: {:?}: {:?}", self.codegen_unit.name(), name, global_kind);
} }*/
let global = self.context.new_global(None, global_kind, ty, name); let global = self.context.new_global(None, global_kind, ty, name);
if is_tls { if is_tls {
global.set_tls_model(self.tls_model); global.set_tls_model(self.tls_model);

View file

@ -32,9 +32,9 @@ impl<'gcc, 'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
let gcc_type = self.layout_of(ty).gcc_type(self); let gcc_type = self.layout_of(ty).gcc_type(self);
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL); 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"); println!("** DECLARE static");
} }*/
let global = self.define_global(symbol_name, gcc_type, is_tls, attrs.link_section); let global = self.define_global(symbol_name, gcc_type, is_tls, attrs.link_section);
#[cfg(feature = "master")] #[cfg(feature = "master")]
global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility))); global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));