Skip to content

Commit 428acf6

Browse files
committed
Cleanup
1 parent bc02f85 commit 428acf6

File tree

8 files changed

+8
-208
lines changed

8 files changed

+8
-208
lines changed

build_system/src/build.rs

-23
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
130130
if config.no_default_features {
131131
rustflags.push_str(" -Csymbol-mangling-version=v0");
132132
}
133-
//rustflags.push_str(" --print link-args");
134133

135134
let mut args: Vec<&dyn AsRef<OsStr>> = vec![&"cargo", &"build", &"--target", &config.target];
136135
for feature in &config.features {
@@ -157,28 +156,6 @@ pub fn build_sysroot(env: &HashMap<String, String>, config: &ConfigInfo) -> Resu
157156
}
158157

159158
let mut env = env.clone();
160-
/*rustflags.push_str(" -C link-arg=-Wl,--verbose");
161-
rustflags.push_str(" -C link-arg=-Wl,--warn-shared-textrel"); // Mold and Gold.
162-
//rustflags.push_str(" -C link-arg=-Wl,--warn-textrel"); // Mold
163-
rustflags.push_str(" -C link-arg=-Wl,--warn-unresolved-symbols");
164-
rustflags.push_str(" -C link-arg=-Wl,--fatal-warnings");
165-
rustflags.push_str(" -C link-arg=-Wl,--print-gc-sections");*/
166-
//rustflags.push_str(" -C link-arg=-Wl,--no-apply-dynamic-relocs"); // Mold
167-
/*rustflags.push_str(" -C link-arg=-Wl,--warn-ifunc-textrel");
168-
rustflags.push_str(" -C link-arg=-Wl,--warn-backrefs");
169-
rustflags.push_str(" -C link-arg=-Wl,-znotext");
170-
//rustflags.push_str(" -C link-arg=-Wl,--emit-relocs");
171-
//rustflags.push_str(" -C link-arg=-Wl,--trace-symbol=memchr::arch::x86_64::memchr::memchr_raw::FN");
172-
//rustflags.push_str(" -C link-arg=-Wl,--trace-symbol=_ZN6memchr4arch6x86_646memchr10memchr_raw2FN17haaf621f7b8ca567eE");
173-
//rustflags.push_str(" -C link-arg=-Wl,--print-map");
174-
//rustflags.push_str(" -C link-arg=-Wl,");*/
175-
//rustflags.push_str(" -Clinker=/usr/bin/ld.gold");
176-
// TODO: try with verbose, warnings and logs.
177-
//rustflags.push_str(" -Clinker=/usr/bin/clang");
178-
//rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/mold");
179-
//rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.bfd");
180-
//rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.gold");
181-
//env.insert("RUSTC_LOG".to_string(), "rustc_codegen_ssa::back::link=info".to_string());
182159
env.insert("RUSTFLAGS".to_string(), rustflags);
183160
run_command_with_output_and_env(&args, Some(&start_dir), Some(&env))?;
184161

build_system/src/test.rs

-26
Original file line numberDiff line numberDiff line change
@@ -692,32 +692,6 @@ fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
692692
println!("[TEST] libcore");
693693
let path = get_sysroot_dir().join("sysroot_src/library/core/tests");
694694
let _ = remove_dir_all(path.join("target"));
695-
/*let mut env = env.clone();
696-
env.insert("RUSTC_LOG".to_string(), "rustc_codegen_ssa::back::link=info".to_string());*/
697-
/*let rustflags =
698-
env.entry("RUSTFLAGS".to_string())
699-
.or_default();*/
700-
//rustflags.push_str(" -C link-arg=-Wl,--verbose");
701-
//rustflags.push_str(" -C link-arg=-Wl,--fatal-warnings");
702-
//rustflags.push_str(" -C link-arg=-Wl,--warn-unresolved-symbols");
703-
//rustflags.push_str(" -C link-arg=-Wl,--warn-shared-textrel"); // Mold and Gold.
704-
//rustflags.push_str(" -C link-arg=-Wl,--warn-textrel"); // Mold
705-
//rustflags.push_str(" -C link-arg=-Wl,--print-gc-sections");
706-
//rustflags.push_str(" -C link-arg=-Wl,--no-apply-dynamic-relocs"); // Mold
707-
/*rustflags.push_str(" -C link-arg=-Wl,--warn-ifunc-textrel");
708-
rustflags.push_str(" -C link-arg=-Wl,--warn-backrefs");
709-
rustflags.push_str(" -C link-arg=-Wl,-znotext");
710-
rustflags.push_str(" -C link-arg=-Wl,--emit-relocs");
711-
rustflags.push_str(" -C link-arg=-Wl,--trace-symbol=memchr::arch::x86_64::memchr::memchr_raw::FN");*/
712-
//rustflags.push_str(" -Clinker=/usr/bin/ld.gol");
713-
//rustflags.push_str(" -Clinker=/usr/bin/clang");
714-
//rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/mold");
715-
//rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.bfd");
716-
//rustflags.push_str(" -Clink-arg=--ld-path=/usr/bin/ld.gold");
717-
// FIXME FIXME: seems like RUSTFLAGS is not set here.
718-
//rustflags.push_str(" -C link-arg=-Wl,--trace-symbol=_ZN6memchr4arch6x86_646memchr10memchr_raw2FN17haaf621f7b8ca567eE");
719-
//rustflags.push_str(" -C link-arg=-Wl,--print-map");
720-
//rustflags.push_str(" -Clink-arg=-not-an-arg");
721695
run_cargo_command(&[&"test"], Some(&path), env, args)?;
722696
Ok(())
723697
}

src/back/write.rs

+6-65
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,9 @@ pub(crate) unsafe fn codegen(
3131

3232
// NOTE: Only generate object files with GIMPLE when this environment variable is set for
3333
// now because this requires a particular setup (same gcc/lto1/lto-wrapper commit as libgccjit).
34-
// TODO: remove this environment variable.
34+
// TODO(antoyo): remove this environment variable.
3535
let fat_lto = env::var("EMBED_LTO_BITCODE").as_deref() == Ok("1");
3636

37-
/*if cgcx.msvc_imps_needed {
38-
println!("************************************************** Imps needed");
39-
create_msvc_imps(cgcx, context);
40-
}*/
41-
4237
let bc_out = cgcx.output_filenames.temp_path(OutputType::Bitcode, module_name);
4338
let obj_out = cgcx.output_filenames.temp_path(OutputType::Object, module_name);
4439

@@ -64,7 +59,7 @@ pub(crate) unsafe fn codegen(
6459
);
6560
context.add_command_line_option("-flto=auto");
6661
context.add_command_line_option("-flto-partition=one");
67-
// TODO: remove since we don't want fat objects when it is for Bitcode only.
62+
// TODO(antoyo): remove since we don't want fat objects when it is for Bitcode only.
6863
context.add_command_line_option("-ffat-lto-objects");
6964
context.compile_to_file(
7065
OutputKind::ObjectFile,
@@ -102,7 +97,7 @@ pub(crate) unsafe fn codegen(
10297
}
10398

10499
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
105-
// TODO: we might want to emit to emit an error here, saying to set the
100+
// TODO(antoyo): we might want to emit to emit an error here, saying to set the
106101
// environment variable EMBED_LTO_BITCODE.
107102
let _timer = cgcx.prof.generic_activity_with_arg(
108103
"GCC_module_codegen_embed_bitcode",
@@ -111,12 +106,6 @@ pub(crate) unsafe fn codegen(
111106
// TODO(antoyo): maybe we should call embed_bitcode to have the proper iOS fixes?
112107
//embed_bitcode(cgcx, llcx, llmod, &config.bc_cmdline, data);
113108

114-
// TODO: check if this condition makes sense.
115-
if fat_lto {
116-
context.add_command_line_option("-flto=auto");
117-
context.add_command_line_option("-flto-partition=one");
118-
context.add_command_line_option("-ffat-lto-objects");
119-
}
120109
// 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).
121110
context.compile_to_file(
122111
OutputKind::ObjectFile,
@@ -172,8 +161,6 @@ pub(crate) unsafe fn codegen(
172161
// lto1: internal compiler error: decompressed stream: Destination buffer is too small
173162
// TODO: since we do not do LTO when the linker is invoked anymore, perhaps
174163
// the following flag is not necessary anymore.
175-
// TODO: also, perhaps compiling the gcc driver in the CI is not necessary
176-
// anymore.
177164
context.add_driver_option("-fuse-linker-plugin");
178165
}
179166

@@ -182,36 +169,23 @@ pub(crate) unsafe fn codegen(
182169
// /usr/bin/ld: cannot find -lgcc_s: No such file or directory
183170
context.add_driver_option("-nostdlib");
184171

185-
// NOTE: this doesn't actually generate an executable. With the above flags, it combines the .o files together in another .o.
186-
// FIXME FIXME: this produces an object file with GIMPLE IR, but it should
187-
// produce an object file with machine code.
188-
//println!("LTO-ed object file: {:?}", obj_out);
189-
/*context.compile_to_file(
190-
OutputKind::Executable,
191-
obj_out.to_str().expect("path to str"),
192-
);*/
193-
194172
let path = obj_out.to_str().expect("path to str");
195173

196174
let lto_path = format!("{}.lto", path);
197-
//eprintln!("Before Executable");
198-
// FIXME: The LTO frontend generates the following warning:
175+
// FIXME(antoyo): The LTO frontend generates the following warning:
199176
// ../build_sysroot/sysroot_src/library/core/src/num/dec2flt/lemire.rs:150:15: warning: type of ‘_ZN4core3num7dec2flt5table17POWER_OF_FIVE_12817ha449a68fb31379e4E’ does not match original declaration [-Wlto-type-mismatch]
200177
// 150 | let (lo5, hi5) = POWER_OF_FIVE_128[index];
201178
// | ^
202179
// lto1: note: ‘_ZN4core3num7dec2flt5table17POWER_OF_FIVE_12817ha449a68fb31379e4E’ was previously declared here
203180
//
204181
// This option is to mute it to make the UI tests pass with LTO enabled.
205182
context.add_driver_option("-Wno-lto-type-mismatch");
183+
// NOTE: this doesn't actually generate an executable. With the above flags, it combines the .o files together in another .o.
184+
// TODO: can this be switched back to OutputKind::Object?
206185
context.compile_to_file(OutputKind::Executable, &lto_path);
207-
//eprintln!("****************************************************************************************************");
208186

209187
let context = Context::default(); // TODO: might need to set some other flags from new_context.
210-
//context.add_driver_option("-v");
211-
//println!("*** Arch: {}", cgcx.target_arch);
212188
if cgcx.target_arch == "x86" || cgcx.target_arch == "x86_64" {
213-
//println!("**** Added -masm=intel");
214-
//context.add_command_line_option("-masm=intel");
215189
// NOTE: it seems we need to use add_driver_option instead of
216190
// add_command_line_option here because we use the LTO frontend via gcc.
217191
context.add_driver_option("-masm=intel");
@@ -220,18 +194,13 @@ pub(crate) unsafe fn codegen(
220194
// NOTE: these two options are needed to invoke LTO to produce an object file.
221195
// We need to initiate a second compilation because the arguments "-x lto"
222196
// needs to be at the very beginning.
223-
// TODO TODO: check that LTO still does the optimizations across different
224-
// object files with this change.
225-
// TODO: this should probably be in a condition `if fat_lto`.
226197
if fat_lto {
227198
context.add_driver_option("-x");
228199
context.add_driver_option("lto");
229200
}
230201
context.add_driver_option("-fPIC"); // TODO TODO: only add this flag when necessary.
231202
context.add_driver_option(lto_path);
232203

233-
// FIXME FIXME: it seems this object file doesn't contain the main function and
234-
// some other code.
235204
context.compile_to_file(OutputKind::ObjectFile, path);
236205
} else {
237206
context.compile_to_file(
@@ -293,31 +262,3 @@ pub(crate) fn save_temp_bitcode(
293262
llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
294263
}*/
295264
}
296-
297-
/*fn create_msvc_imps<'gcc>(cgcx: &CodegenContext<GccCodegenBackend>, _context: &Context<'gcc>) {
298-
if !cgcx.msvc_imps_needed {
299-
return;
300-
}
301-
302-
/*unsafe {
303-
let ptr_ty = Type::ptr_llcx(llcx);
304-
let globals = base::iter_globals(llmod)
305-
.filter(|&val| {
306-
llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage
307-
&& llvm::LLVMIsDeclaration(val) == 0
308-
})
309-
.map(move |(val, name)| {
310-
let mut imp_name = prefix.as_bytes().to_vec();
311-
imp_name.extend(name);
312-
let imp_name = CString::new(imp_name).unwrap();
313-
(imp_name, val)
314-
})
315-
.collect::<Vec<_>>();
316-
317-
for (imp_name, val) in globals {
318-
let imp = llvm::LLVMAddGlobal(llmod, ptr_ty, imp_name.as_ptr());
319-
llvm::LLVMSetInitializer(imp, val);
320-
llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage);
321-
}
322-
}*/
323-
}*/

src/base.rs

-3
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,14 @@ pub fn compile_codegen_unit(
153153

154154
match tcx.sess.relocation_model() {
155155
rustc_target::spec::RelocModel::Static => {
156-
//println!("*** Static");
157156
context.add_command_line_option("-fno-pie");
158157
context.add_driver_option("-fno-pie");
159158
}
160159
rustc_target::spec::RelocModel::Pic => {
161-
//println!("*** Pic");
162160
context.add_command_line_option("-fPIC");
163161
context.add_driver_option("-fPIC");
164162
}
165163
rustc_target::spec::RelocModel::Pie => {
166-
//println!("*** Pie");
167164
context.add_command_line_option("-fPIE");
168165
context.add_driver_option("-fPIE");
169166
}

src/consts.rs

+1-82
Original file line numberDiff line numberDiff line change
@@ -92,85 +92,7 @@ impl<'gcc, 'tcx> StaticCodegenMethods for CodegenCx<'gcc, 'tcx> {
9292
}
9393
set_global_alignment(self, global, alloc.align);
9494

95-
// TODO: if I still use this code, find the name of the variable in a better way (using
96-
// def_id).
97-
let var_name = format!("{:?}", global);
98-
if var_name.contains("FN") && var_name.contains("memchr") {
99-
//println!("Var name: {:?}", var_name);
100-
//println!("INITIALIZE: {:?} = {:?}", var_name, value);
101-
102-
/*
103-
let ptr_type = value.get_type().make_pointer();
104-
105-
// TODO: remove \x01
106-
//let prefix = if self.cgcx.target_arch == "x86" { "\x01__imp__" } else { "\x01__imp_" };
107-
let prefix = "__imp__";
108-
let mut imp_name = prefix.to_string();
109-
imp_name.push_str(&var_name);
110-
111-
// FIXME: if I understand correctly the code in cg_llvm, the kind should be Imported.
112-
let imp_global = self.context.new_global(None, GlobalKind::Exported, ptr_type, &imp_name);
113-
imp_global.global_set_initializer_rvalue(global.get_address(None));
114-
*/
115-
116-
/*
117-
/*let context = gccjit::Context::default();
118-
let global = context.new_global(None, GlobalKind::Exported, val_llty, &var_name);
119-
global.global_set_initializer_rvalue(value);
120-
context.compile_to_file(gccjit::OutputKind::ObjectFile, format!("{}.o", var_name));*/
121-
122-
let void_type = self.context.new_type::<()>();
123-
let fn_ptr_type = self.context.new_function_pointer_type(None, void_type, &[], false);
124-
let my_name = format!("MY_NAME${}", var_name);
125-
//let global = self.context.new_global(None, GlobalKind::Exported, fn_ptr_type, my_name);
126-
//global.add_attribute(VarAttribute::Used);
127-
128-
let my_func_name = format!("MY_FUNC${}", var_name);
129-
let func = self.context.new_function(None, FunctionType::Exported, void_type, &[], &my_func_name, false);
130-
func.add_attribute(FnAttribute::Used);
131-
let block = func.new_block("start");
132-
block.end_with_void_return(None);
133-
134-
//let func = self.context.new_function(None, FunctionType::Extern, void_type, &[], "puts", false);
135-
let value = func.get_address(None);
136-
//let global = self.context.new_global(None, GlobalKind::Exported, value.get_type(), my_name);
137-
//let value = self.context.new_bitcast(None, func.get_address(None), fn_ptr_type);
138-
/*
139-
* TODO: Check if the hard-coded function has the correct name.
140-
* ===> It seems so.
141-
* TODO: try with a function we know exists.
142-
* ===> It doesn't seem to help.
143-
* TODO: check if the .o contains the value (before linking into the .so).
144-
* ===> It seems the object file doesn't contain the value either.
145-
* ======> This is because there are relocations.
146-
* TODO: check if fold in GCC erases the value.
147-
* ===> It doesn't seem so.
148-
*
149-
* TODO TODO: try again this code with using the used attribute.
150-
*/
151-
152-
/*let var_type = global.to_rvalue().get_type();
153-
let struct_type = var_type.is_struct().unwrap();
154-
/*let field1_type = struct_type.get_field(0).get_type();
155-
let field2_type = struct_type.get_field(1).get_type();*/
156-
157-
let field1 = value;
158-
let field2 = self.context.new_rvalue_zero(self.int_type);
159-
160-
let struct_val = self.context.new_struct_constructor(None, var_type, None, &[field1, field2]);
161-
let value = struct_val;*/
162-
163-
//let value = self.context.new_bitcast(None, func.get_address(None), val_llty);
164-
165-
//let value = self.context.new_rvalue_from_int(self.usize_type, 10293);
166-
//let value = self.context.new_cast(None, value, fn_ptr_type); // WORKS
167-
//let value = self.context.new_bitcast(None, value, fn_ptr_type); // Also WORKS
168-
let value = self.context.new_bitcast(None, value, val_llty);*/
169-
global.global_set_initializer_rvalue(value);
170-
//println!("=== AFTER INITIALIZE");
171-
} else {
172-
global.global_set_initializer_rvalue(value);
173-
}
95+
global.global_set_initializer_rvalue(value);
17496

17597
// As an optimization, all shared statics which do not have interior
17698
// mutability are placed into read-only memory.
@@ -327,9 +249,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
327249
}
328250

329251
let is_tls = fn_attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
330-
/*if sym.contains("memchr") && sym.contains("FN") {
331-
println!("** DECLARE");
332-
}*/
333252
let global = self.declare_global(
334253
sym,
335254
gcc_type,

src/declare.rs

-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
2929
}
3030
global
3131
} else {
32-
// HERE: ExternalLinkage.
3332
self.declare_global(name, ty, GlobalKind::Exported, is_tls, link_section)
3433
}
3534
}
@@ -70,9 +69,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
7069
is_tls: bool,
7170
link_section: Option<Symbol>,
7271
) -> LValue<'gcc> {
73-
/*if name.contains("memchr") && name.contains("FN") {
74-
println!("{}: {:?}: {:?}", self.codegen_unit.name(), name, global_kind);
75-
}*/
7672
let global = self.context.new_global(None, global_kind, ty, name);
7773
if is_tls {
7874
global.set_tls_model(self.tls_model);

src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// Some "regular" crates we want to share with rustc
2828
extern crate object;
2929
extern crate smallvec;
30-
// FIXME: clippy bug: remove the #[allow] when it's fixed.
30+
// FIXME(antoyo): clippy bug: remove the #[allow] when it's fixed.
3131
#[allow(unused_extern_crates)]
3232
extern crate tempfile;
3333
#[macro_use]
@@ -269,7 +269,6 @@ impl CodegenBackend for GccCodegenBackend {
269269

270270
fn new_context<'gcc, 'tcx>(tcx: TyCtxt<'tcx>) -> Context<'gcc> {
271271
let context = Context::default();
272-
//context.add_driver_option("-pie");
273272
if tcx.sess.target.arch == "x86" || tcx.sess.target.arch == "x86_64" {
274273
context.add_command_line_option("-masm=intel");
275274
}

0 commit comments

Comments
 (0)