Record GCC command line switches in Object Files
- GCC accepts a large number of different command line switches, many of which have an effect on the assembly code that is finally generated. Knowing how an object file was compiled is often important when attempting to debug a problem with it, but this information can be hard to discover. IDEs and build environments are becoming increasingly more complex, and in addition GCC can now read switches from files and maybe one day from environment variables. GCC can already record the command line switches that were used and the options that were enabled when in generates an assembly file, but it only does so as comments. This project will add a new target hook to GCC that allows backends to choose how to record this information into the assembler file. In addition it will an example implementation of the target hook suitable for COFF and ELF based targets which records the switches into a mergeable .note section. This will be enabled via a new command line switch: -frecord-gcc-switches. The hook will also allow the backend to distinguish between command line switches and enabled options, so that it can choose what to record.
Personnel
- N. Clifton
Delivery Date
This patch has been submitted and is awaiting review: http://gcc.gnu.org/ml/gcc-patches/2006-01/msg01119.html.
Resubmitted now that the mainline sources are out of stage3: http://gcc.gnu.org/ml/gcc-patches/2006-12/msg00211.html.
A revised form of the patch was checked into the mainline sources on 2006-12-07. Individual targets need to enable the new feature in order for it to make it work, eg by adding these lines of code to their gcc/config/<target>/<target>.c file:
#undef TARGET_ASM_RECORD_GCC_SWITCHES
#define TARGET_ASM_RECORD_GCC_SWITCHES elf_record_gcc_switches
Benefits
- The switches used to build a object file can now be obtained by examining the file directly. There will be no need to interrogate the build environment. As a future enhancement it may be possible for the linker to examine this information and detect attemps to link together object files which are incompatible due to the way that they were compiled.
Dependencies
- None.
Modifications Required
- A new target hook must be added. Code to call the hook at the appropriate points must be added. An optional implementation of the target hook for COFF and ELF based targets must also be added.