Skip to content

Commit 423701a

Browse files
committed
Add comment
1 parent 3e4df68 commit 423701a

File tree

9 files changed

+8
-205
lines changed

9 files changed

+8
-205
lines changed

build_system/src/build.rs

Lines changed: 0 additions & 23 deletions
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

Lines changed: 0 additions & 26 deletions
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

Lines changed: 3 additions & 57 deletions
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,15 +169,6 @@ 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
if fat_lto {
@@ -208,11 +186,7 @@ pub(crate) unsafe fn codegen(
208186
context.compile_to_file(OutputKind::Executable, &lto_path);
209187

210188
let context = Context::default(); // TODO: might need to set some other flags from new_context.
211-
//context.add_driver_option("-v");
212-
//println!("*** Arch: {}", cgcx.target_arch);
213189
if cgcx.target_arch == "x86" || cgcx.target_arch == "x86_64" {
214-
//println!("**** Added -masm=intel");
215-
//context.add_command_line_option("-masm=intel");
216190
// NOTE: it seems we need to use add_driver_option instead of
217191
// add_command_line_option here because we use the LTO frontend via gcc.
218192
context.add_driver_option("-masm=intel");
@@ -295,31 +269,3 @@ pub(crate) fn save_temp_bitcode(
295269
llvm::LLVMWriteBitcodeToFile(llmod, cstr.as_ptr());
296270
}*/
297271
}
298-
299-
/*fn create_msvc_imps<'gcc>(cgcx: &CodegenContext<GccCodegenBackend>, _context: &Context<'gcc>) {
300-
if !cgcx.msvc_imps_needed {
301-
return;
302-
}
303-
304-
/*unsafe {
305-
let ptr_ty = Type::ptr_llcx(llcx);
306-
let globals = base::iter_globals(llmod)
307-
.filter(|&val| {
308-
llvm::get_linkage(val) == llvm::Linkage::ExternalLinkage
309-
&& llvm::LLVMIsDeclaration(val) == 0
310-
})
311-
.map(move |(val, name)| {
312-
let mut imp_name = prefix.as_bytes().to_vec();
313-
imp_name.extend(name);
314-
let imp_name = CString::new(imp_name).unwrap();
315-
(imp_name, val)
316-
})
317-
.collect::<Vec<_>>();
318-
319-
for (imp_name, val) in globals {
320-
let imp = llvm::LLVMAddGlobal(llmod, ptr_ty, imp_name.as_ptr());
321-
llvm::LLVMSetInitializer(imp, val);
322-
llvm::set_linkage(imp, llvm::Linkage::ExternalLinkage);
323-
}
324-
}*/
325-
}*/

src/base.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ pub fn symbol_visibility_to_gcc(visibility: SymbolVisibility) -> gccjit::Visibil
4343

4444
pub fn global_linkage_to_gcc(linkage: Linkage) -> GlobalKind {
4545
match linkage {
46-
Linkage::External => GlobalKind::Exported,
47-
Linkage::AvailableExternally => GlobalKind::Exported,
46+
Linkage::External => GlobalKind::Imported,
47+
Linkage::AvailableExternally => GlobalKind::Imported,
4848
Linkage::LinkOnceAny => unimplemented!(),
4949
Linkage::LinkOnceODR => unimplemented!(),
5050
Linkage::WeakAny => unimplemented!(),
@@ -153,19 +153,13 @@ 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");
158-
context.add_driver_option("-fno-pie");
159157
}
160158
rustc_target::spec::RelocModel::Pic => {
161-
//println!("*** Pic");
162159
context.add_command_line_option("-fPIC");
163-
context.add_driver_option("-fPIC");
164160
}
165161
rustc_target::spec::RelocModel::Pie => {
166-
//println!("*** Pie");
167162
context.add_command_line_option("-fPIE");
168-
context.add_driver_option("-fPIE");
169163
}
170164
model => eprintln!("Unsupported relocation model: {:?}", model),
171165
}

src/consts.rs

Lines changed: 1 addition & 82 deletions
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/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
386386
impl<'gcc, 'tcx> BackendTypes for CodegenCx<'gcc, 'tcx> {
387387
type Value = RValue<'gcc>;
388388
type Metadata = RValue<'gcc>;
389+
// TODO(antoyo): change to Function<'gcc>.
389390
type Function = RValue<'gcc>;
390391

391392
type BasicBlock = Block<'gcc>;

src/declare.rs

Lines changed: 0 additions & 4 deletions
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

Lines changed: 1 addition & 2 deletions
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
}

src/mono_item.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ impl<'gcc, 'tcx> PreDefineCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
3232
let gcc_type = self.layout_of(ty).gcc_type(self);
3333

3434
let is_tls = attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL);
35-
/*if symbol_name.contains("memchr") && symbol_name.contains("FN") {
36-
println!("** DECLARE static");
37-
}*/
3835
let global = self.define_global(symbol_name, gcc_type, is_tls, attrs.link_section);
3936
#[cfg(feature = "master")]
4037
global.add_attribute(VarAttribute::Visibility(base::visibility_to_gcc(visibility)));

0 commit comments

Comments
 (0)