compiler/rustc_codegen_gcc/doc/tips.md MARKDOWN 89 lines View on github.com → Search inside
1# Tips23The following shows how to do different random small things we encountered and thought could4be useful.56### How to send arguments to the GCC linker78```9CG_RUSTFLAGS="-Clink-args=-save-temps -v" ../y.sh cargo build10```1112### How to send arguments to GCC1314The `-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:1516```17CG_RUSTFLAGS="-Cllvm-args=-fflag-name" ../y.sh cargo build18```1920### How to see the personality functions in the asm dump2122```23CG_RUSTFLAGS="-Clink-arg=-save-temps -v -Clink-arg=-dA" ../y.sh cargo build24```2526### How to see the LLVM IR for a sysroot crate2728```29cargo build -v --target x86_64-unknown-linux-gnu -Zbuild-std30# Take the command from the output and add --emit=llvm-ir31```3233### To prevent the linker from unmangling symbols3435Run with:3637```38COLLECT_NO_DEMANGLE=139```4041### How to use a custom-build rustc4243 * Build the stage2 compiler (`rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2`).44 * Clean and rebuild the codegen with `debug-current` in the file `rust-toolchain`.4546### How to use a custom sysroot source path4748If you wish to build a custom sysroot, pass the path of your sysroot source to `--sysroot-source` during the `prepare` step, like so:4950```51./y.sh prepare --sysroot-source /path/to/custom/source52```5354### How to use [mem-trace](https://github.com/antoyo/mem-trace)5556`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`.5758### How to generate GIMPLE5960If you need to check what gccjit is generating (GIMPLE), then take a look at how to61generate it in [gimple.md](./doc/gimple.md).6263### How to build a cross-compiling libgccjit6465#### Building libgccjit6667 * Follow the instructions on [this repo](https://github.com/cross-cg-gcc-tools/cross-gcc).6869#### Configuring rustc_codegen_gcc7071 * Run `./y.sh prepare --cross` so that the sysroot is patched for the cross-compiling case.72 * Set the path to the cross-compiling libgccjit in `gcc-path` (in `config.toml`).73 * 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 via `CG_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`.74 * 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`.7576If the target is not yet supported by the Rust compiler, create a [target specification file](https://docs.rust-embedded.org/embedonomicon/custom-target.html) (note that the `arch` specified in this file must be supported by the rust compiler).77Then, you can use it the following way:7879 * Add the target specification file using `--target` as an **absolute** path to build the sysroot: `./y.sh build --sysroot --target-triple m68k-unknown-linux-gnu --target $(pwd)/m68k-unknown-linux-gnu.json`80 * Build your project by specifying the target specification file: `../y.sh cargo build --target path/to/m68k-unknown-linux-gnu.json`.8182If you get the following error:8384```85/usr/bin/ld: unrecognised emulation mode: m68kelf86```8788Make sure you set `gcc-path` (in `config.toml`) to the install directory.

Findings

✓ No findings reported for this file.

Get this view in your editor

Same data, no extra tab — call code_get_file + code_get_findings over MCP from Claude/Cursor/Copilot.