Skip to content

Commit 40ee677

Browse files
committed
Cleanup
1 parent 9843f6e commit 40ee677

File tree

12 files changed

+10
-111
lines changed

12 files changed

+10
-111
lines changed

Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ set substitute-path /usr/src/debug/gcc /path/to/gcc-repo/gcc
182182
183183
TODO(antoyo): but that's not what I remember I was doing.
184184
185+
### How to debug GCC LTO
186+
187+
Run do the command with `-v -save-temps` and then extract the `lto1` line from the output and run that under the debugger
188+
185189
### How to use a custom-build rustc
186190
187191
* Build the stage2 compiler (`rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2`).

build_sysroot/build_sysroot.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ rm -r sysroot/ 2>/dev/null || true
1919
export RUSTFLAGS="$RUSTFLAGS -Z force-unstable-if-unmarked"
2020
if [[ "$1" == "--release" ]]; then
2121
sysroot_channel='release'
22-
# RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build -v --target $TARGET_TRIPLE --release
2322
RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3 -C embed-bitcode=yes -C lto=no " cargo build --target $TARGET_TRIPLE --release
2423
else
2524
sysroot_channel='debug'

cargo.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ fi
2020
cmd=$1
2121
shift
2222

23+
# FIXME: LIBRARY_PATH here is needed for crtbeginS.o, …
2324
LIBRARY_PATH=/home/bouanto/Ordinateur/Programmation/Projets/gcc-repo/gcc-build/build/gcc GCC_EXEC_PREFIX=/opt/gcc/lib/gcc/x86_64-pc-linux-gnu PATH=$PATH:/opt/gcc/bin RUSTDOCFLAGS="$RUSTFLAGS" cargo +${TOOLCHAIN} $cmd $@

src/allocator.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam
5151
.collect();
5252
// FIXME: __rust_alloc is only in ASM form, not in gimple form, in the object file.
5353
let func = context.new_function(None, FunctionType::Exported, output.unwrap_or(void), &args, name, false);
54-
// TODO: it seems that adding ExternallyVisible doesn't help.
55-
// func.add_attribute(FnAttribute::ExternallyVisible);
5654

5755
if tcx.sess.target.options.default_hidden_visibility {
5856
#[cfg(feature="master")]

src/attributes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ pub fn from_fn_attrs<'gcc, 'tcx>(
112112
codegen_fn_attrs.inline
113113
};
114114
if let Some(attr) = inline_attr(cx, inline) {
115-
// TODO TODO TODO: inlining is part of the issue.
116115
func.add_attribute(attr);
117116
}
118117
}

src/back/lto.rs

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,10 @@
22
// => Maybe it's the symbol file?
33
// => There's a least the rust_alloc file.
44
//
5-
// TODO: vérifier si les symbols sont dans les fichiers .ltrans0.ltrans.o.
6-
// Ils ne sont pas là.
7-
//
8-
// FIXME: compile the object files (including the ones from sysroot) directly to the executable to see if this works.
9-
// TODO TODO TODO: WE'RE MAKING PROGRESS HERE!
10-
// Compiling with gcc and removing the -r flag compiles correctly!
11-
// For now, adding these environment variables is needed:
12-
// COLLECT_GCC=gcc GCC_EXEC_PREFIX=/opt/gcc/lib/gcc/x86_64-pc-linux-gnu
5+
// FIXME:
136
// I had to copy lto1, crtbegin.o from the system to /opt/…
7+
// * sudo cp /usr/lib/gcc/x86_64-pc-linux-gnu/13.1.1/lto1 /opt/gcc/libexec/gcc/x86_64-pc-linux-gnu/13.1.0/lto1
148
// I had to copy liblto_plugin.so to /opt/gcc/lib/gcc
15-
// I compile a .o as an executable.
16-
//
17-
// TODO: you do the command with -v -save-temps and then extract the lto1 line from the output and run that under the debugger
189

1910
use std::ffi::CString;
2011
use std::fs::{self, File};
@@ -284,7 +275,6 @@ fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler, mod
284275
// above. Like above, though, we don't know much about the memory management
285276
// here so we err on the side of being save and persist everything with
286277
// the original module.
287-
//let mut linker = Linker::new(context);
288278
for (bc_decoded, name) in serialized_modules {
289279
let _timer = cgcx
290280
.prof
@@ -299,10 +289,6 @@ fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler, mod
299289
SerializedModule::FromRlib(_) => unimplemented!("from rlib"),
300290
SerializedModule::FromUncompressedFile(_) => unimplemented!("from uncompressed file"),
301291
}
302-
// let data = bc_decoded.data();
303-
/*linker
304-
.add(data)
305-
.map_err(|()| write::llvm_err(diag_handler, LoadBitcode { name }))?;*/
306292
serialized_bitcode.push(bc_decoded);
307293
}
308294
save_temp_bitcode(cgcx, &module, "lto.input");
@@ -325,36 +311,6 @@ fn fat_lto(cgcx: &CodegenContext<GccCodegenBackend>, diag_handler: &Handler, mod
325311
Ok(LtoModuleCodegen::Fat { module, _serialized_bitcode: serialized_bitcode })
326312
}
327313

328-
/*pub(crate) struct Linker<'a>(&'a mut llvm::Linker<'a>);
329-
330-
impl<'a> Linker<'a> {
331-
pub(crate) fn new(llmod: &'a llvm::Module) -> Self {
332-
unsafe { Linker(llvm::LLVMRustLinkerNew(llmod)) }
333-
}
334-
335-
pub(crate) fn add(&mut self, bytecode: &[u8]) -> Result<(), ()> {
336-
unsafe {
337-
if llvm::LLVMRustLinkerAdd(
338-
self.0,
339-
bytecode.as_ptr() as *const libc::c_char,
340-
bytecode.len(),
341-
) {
342-
Ok(())
343-
} else {
344-
Err(())
345-
}
346-
}
347-
}
348-
}
349-
350-
impl Drop for Linker<'_> {
351-
fn drop(&mut self) {
352-
unsafe {
353-
llvm::LLVMRustLinkerFree(&mut *(self.0 as *mut _));
354-
}
355-
}
356-
}*/
357-
358314
pub struct ModuleBuffer(PathBuf);
359315

360316
unsafe impl Send for ModuleBuffer {}

src/back/write.rs

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
2020

2121
let module_name = module.name.clone();
2222

23-
// println!("Module name: {}", module_name);
24-
// let should_combine_object_files = module_name == "test_rust.3ab6d383-cgu.0"; // With debug info.
23+
// FIXME: by adding a variable in CodegenContext.
2524
let should_combine_object_files = module_name == "test_rust.8bd2b20a-cgu.0";
2625

2726
let module_name = Some(&module_name[..]);
@@ -43,28 +42,18 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
4342
);
4443
}*/
4544

46-
// println!("{:?}: Emit bc: {}, Emit obj: {:?}", module_name, config.emit_bc, config.emit_obj == EmitObj::Bitcode);
47-
4845
if config.emit_bc || config.emit_obj == EmitObj::Bitcode {
4946
let _timer = cgcx
5047
.prof
5148
.generic_activity_with_arg("GCC_module_codegen_emit_bitcode", &*module.name);
52-
// println!("Compiling {:?} with bitcode: {:?}", module_name, bc_out);
53-
// FIXME FIXME FIXME: the undefined symbols might also be caused by not embedding the bitcode since the function is in asm.
54-
// FIXME: some symbols like _RNvXsV_NtCsgpzv4I1UvGY_4core3fmtRNtNtNtB7_5alloc6layout6LayoutNtB5_5Debug3fmtCscFQYr8hhBzE_9hashbrown are defined in the object file, but not the *ltrans*.o object files.
55-
// TODO TODO TODO: check if core::panicking::panic_bounds_check (_RNvNtCsgpzv4I1UvGY_4core9panicking18panic_bounds_check) is compiled with bitcode.
56-
// TODO: so maybe we need ffat-objects here?
57-
// TODO: use the flag -save-temps on a manual invoke of gcc to link to keep the *.ltrans*.o files and to inspect them.
5849
context.add_command_line_option("-flto");
5950
context.add_driver_option("-flto");
60-
// TODO: use flto-partition=one?
6151
context.add_command_line_option("-flto-partition=one");
6252
context.add_driver_option("-flto-partition=one");
6353
if should_combine_object_files {
6454
unimplemented!(); // TODO: remove this line.
6555
context.add_driver_option("-Wl,-r");
6656
context.add_driver_option("-nostdlib");
67-
println!("Output file: {:?}", obj_out);
6857
// NOTE: this doesn't actually generate an executable. With the above flags, it combines the .o files together in another .o.
6958
context.compile_to_file(OutputKind::Executable, obj_out.to_str().expect("path to str"));
7059
}
@@ -74,33 +63,6 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
7463
}
7564

7665
if config.emit_obj == EmitObj::ObjectCode(BitcodeSection::Full) {
77-
// FIXME: lto1 fails with the following error:
78-
/*
79-
= note: lto1: internal compiler error: decompressed stream: Destination buffer is too small
80-
0x11e5a6b lto_uncompression_zstd
81-
../../../gcc/gcc/lto-compress.cc:171
82-
0x11e5a6b lto_end_uncompression(lto_compression_stream*, lto_compression)
83-
../../../gcc/gcc/lto-compress.cc:406
84-
0x11e4052 lto_get_section_data(lto_file_decl_data*, lto_section_type, char const*, int, unsigned long*, bool)
85-
../../../gcc/gcc/lto-section-in.cc:168
86-
0xde7930 lto_file_finalize
87-
../../../gcc/gcc/lto/lto-common.cc:2280
88-
0xde7930 lto_create_files_from_ids
89-
../../../gcc/gcc/lto/lto-common.cc:2298
90-
0xde7930 lto_file_read
91-
../../../gcc/gcc/lto/lto-common.cc:2353
92-
0xde7930 read_cgraph_and_symbols(unsigned int, char const**)
93-
../../../gcc/gcc/lto/lto-common.cc:2801
94-
0xdcccdf lto_main()
95-
../../../gcc/gcc/lto/lto.cc:654
96-
Please submit a full bug report, with preprocessed source (by using -freport-bug).
97-
Please include the complete backtrace with any bug report.
98-
See <https://gcc.gnu.org/bugs/> for instructions.
99-
lto-wrapper: fatal error: cc returned 1 exit status
100-
compilation terminated.
101-
/usr/bin/ld: error: lto-wrapper failed
102-
collect2: error: ld returned 1 exit status
103-
*/
10466
let _timer = cgcx
10567
.prof
10668
.generic_activity_with_arg("GCC_module_codegen_embed_bitcode", &*module.name);
@@ -110,10 +72,8 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
11072
unimplemented!();
11173
}
11274

113-
// println!("Compiling {:?} with bitcode and asm: {:?}", module_name, bc_out);
11475
context.add_command_line_option("-flto");
11576
context.add_driver_option("-flto");
116-
// TODO: use flto-partition=one?
11777
context.add_command_line_option("-flto-partition=one");
11878
context.add_driver_option("-flto-partition=one");
11979
context.add_command_line_option("-ffat-lto-objects");
@@ -161,20 +121,15 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
161121
if should_combine_object_files {
162122
context.add_command_line_option("-flto");
163123
context.add_driver_option("-flto");
164-
// TODO: use flto-partition=one?
165124
context.add_command_line_option("-flto-partition=one");
166125
context.add_driver_option("-flto-partition=one");
167126

168-
// let inner = context.new_child_context();
169-
// context.add_driver_option("-v");
170127
context.add_driver_option("-Wl,-r");
171128
context.add_driver_option("-nostdlib");
172129
context.add_driver_option("-fuse-linker-plugin");
173130

174-
println!("Output file: {:?}", obj_out);
175131
// NOTE: this doesn't actually generate an executable. With the above flags, it combines the .o files together in another .o.
176132
context.compile_to_file(OutputKind::Executable, obj_out.to_str().expect("path to str"));
177-
// println!("After");
178133
}
179134
else {
180135
context.compile_to_file(OutputKind::ObjectFile, obj_out.to_str().expect("path to str"));
@@ -188,7 +143,7 @@ pub(crate) unsafe fn codegen(cgcx: &CodegenContext<GccCodegenBackend>, diag_hand
188143
}
189144

190145
if !config.emit_bc {
191-
//debug!("removing_bitcode {:?}", bc_out);
146+
debug!("removing_bitcode {:?}", bc_out);
192147
ensure_removed(diag_handler, &bc_out);
193148
}
194149
}

src/base.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, supports_128bit_i
8888
// Instantiate monomorphizations without filling out definitions yet...
8989
//let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str());
9090
let context = Context::default();
91-
context.add_driver_option("-save-temps");
9291

9392
context.add_command_line_option("-fexceptions");
9493
context.add_driver_option("-fexceptions");

src/consts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
249249
);
250250

251251
if !self.tcx.is_reachable_non_generic(def_id) {
252-
println!("Should set visibility of {}", sym);
253252
// TODO(antoyo): set visibility.
254253
}
255254

src/declare.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ fn declare_raw_fn<'gcc>(cx: &CodegenCx<'gcc, '_>, name: &str, _callconv: () /*ll
113113
.map(|(index, param)| cx.context.new_parameter(None, *param, &format!("param{}", index))) // TODO(antoyo): set name.
114114
.collect();
115115
let func = cx.context.new_function(None, cx.linkage.get(), return_type, &params, mangle_name(name), variadic);
116-
// TODO TODO TODO: seems like making functions externally_visible helps.
117-
// func.add_attribute(FnAttribute::ExternallyVisible);
118116
cx.functions.borrow_mut().insert(name.to_string(), func);
119117
func
120118
};

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl ExtraBackendMethods for GccCodegenBackend {
170170
context: Context::default(),
171171
};
172172

173+
// TODO: only set for x86.
173174
mods.context.add_command_line_option("-masm=intel");
174175
unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); }
175176
mods

src/mono_item.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
3636
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
3737
self.linkage.set(base::linkage_to_gcc(linkage));
3838
let decl = self.declare_fn(symbol_name, &fn_abi);
39-
/*if linkage == Linkage::AvailableExternally {
40-
decl.add_attribute(FnAttribute::ExternallyVisible);
41-
}*/
4239
//let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
4340

4441
attributes::from_fn_attrs(self, decl, instance);
@@ -59,13 +56,6 @@ impl<'gcc, 'tcx> PreDefineMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
5956
decl.add_attribute(FnAttribute::Visibility(base::visibility_to_gcc(visibility)));
6057
}
6158

62-
if linkage != Linkage::Internal && linkage != Linkage::External {
63-
println!("Linkage: {:?}", linkage);
64-
}
65-
if linkage == Linkage::LinkOnceODR || linkage == Linkage::WeakODR {
66-
println!("Function: {}", symbol_name);
67-
}
68-
6959
// TODO(antoyo): call set_link_section() to allow initializing argc/argv.
7060
// TODO(antoyo): set unique comdat.
7161
// TODO(antoyo): use inline attribute from there in linkage.set() above.

0 commit comments

Comments
 (0)