How to inform GCC to not use a particular register
compiler-construction, cpu-registers, gcc, linux
Solution
You tell GCC not to allocate a register via the `-ffixed-reg` option (gcc docs).
`-ffixed-reg`
Treat the register named `reg` as a fixed register; generated code should never refer to it (except perhaps as a stack pointer, frame pointer or in some other fixed role). `reg` must be the name of a register. The register names accepted are machine-specific and are defined in the REGISTER_NAMES macro in the machine description macro file.
For example, `gcc -ffixed-r13` will make gcc leave it alone entirely. Using registers that are part of the calling convention, or required for certain instructions, may be problematic.
Problem
Assume I have a very big source code and intend to make the `rdx` register totally unused during the execution, i.e., while generating the assembly code, all I want is to inform my compiler (GCC) that it should not use `rdx` at all. NOTE: register `rdx` is just an example. I am OK with any available Intel x86 register. I am even happy to update the source code of the compiler and use my custom GCC. But which changes to the source code are needed?