- Readme.md: add missing "you" ("If don't" → "If you don't")
- Readme.md: fix wrong preposition ("without this backend" → "with this backend")
- Readme.md: fix double space
- doc/errors.md: fix transposed letters ("libgccijt" → "libgccjit")
- doc/debugging.md: remove extra word ("Run do the command" → "Run the command")
- doc/debugging.md: fix past participle ("cannot be ran" → "cannot be run")
- doc/tips.md: add missing verb ("won't a chance" → "won't have a chance")
- doc/gimple.md: fix preposition ("interested into" → "interested in")
3.5 KiB
Tips
The following shows how to do different random small things we encountered and thought could be useful.
How to send arguments to the GCC linker
CG_RUSTFLAGS="-Clink-args=-save-temps -v" ../y.sh cargo build
How to send arguments to GCC
The -Cllvm-args rustc flag is repurposed by rustc_codegen_gcc to pass arguments directly to the GCC backend. You can use it via the CG_RUSTFLAGS environment variable. For example, to pass a -f flag to GCC:
CG_RUSTFLAGS="-Cllvm-args=-fflag-name" ../y.sh cargo build
How to see the personality functions in the asm dump
CG_RUSTFLAGS="-Clink-arg=-save-temps -v -Clink-arg=-dA" ../y.sh cargo build
How to see the LLVM IR for a sysroot crate
cargo build -v --target x86_64-unknown-linux-gnu -Zbuild-std
# Take the command from the output and add --emit=llvm-ir
To prevent the linker from unmangling symbols
Run with:
COLLECT_NO_DEMANGLE=1
How to use a custom-build rustc
- Build the stage2 compiler (
rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2). - Clean and rebuild the codegen with
debug-currentin the filerust-toolchain.
How to use a custom sysroot source path
If you wish to build a custom sysroot, pass the path of your sysroot source to --sysroot-source during the prepare step, like so:
./y.sh prepare --sysroot-source /path/to/custom/source
How to use mem-trace
rustc needs to be built without jemalloc so that mem-trace can overload malloc since jemalloc is linked statically, so a LD_PRELOAD-ed library won't have a chance to intercept the calls to malloc.
How to generate GIMPLE
If you need to check what gccjit is generating (GIMPLE), then take a look at how to generate it in gimple.md.
How to build a cross-compiling libgccjit
Building libgccjit
- Follow the instructions on this repo.
Configuring rustc_codegen_gcc
- Run
./y.sh prepare --crossso that the sysroot is patched for the cross-compiling case. - Set the path to the cross-compiling libgccjit in
gcc-path(inconfig.toml). - Make sure you have the linker for your target (for instance
m68k-unknown-linux-gnu-gcc) in your$PATH. You can specify which linker to use viaCG_RUSTFLAGS="-Clinker=<linker>", for instance:CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc". Specify the target when building the sysroot:./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu. - Build your project by specifying the target and the linker to use:
CG_RUSTFLAGS="-Clinker=m68k-unknown-linux-gnu-gcc" ../y.sh cargo build --target m68k-unknown-linux-gnu.
If the target is not yet supported by the Rust compiler, create a target specification file (note that the arch specified in this file must be supported by the rust compiler).
Then, you can use it the following way:
- Add the target specification file using
--targetas an absolute path to build the sysroot:./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu --target $(pwd)/m68k-unknown-linux-gnu.json - Build your project by specifying the target specification file:
../y.sh cargo build --target path/to/m68k-unknown-linux-gnu.json.
If you get the following error:
/usr/bin/ld: unrecognised emulation mode: m68kelf
Make sure you set gcc-path (in config.toml) to the install directory.