jeff jeff wrote:
Hi all,
I'm doing an experiment with gcc. I need to modify gcc so that a NOP
instruction will be inserted into each basic block in binary code that
gcc generates. I know this sounds weird but it is part of my
experiment. As I'm unfamiliar with gcc, is there someone willing to
help me out and do a quick hack for me?
You can probably do so much more easily by modifying the assembly
language. That is, instead of letting the compiler produce a .o, you
produce a .s file (using the -S option), run some perl or awk script on
the assembly, and compile it again (gcc accepts .s as well as .c).
If you care, you can write a shell script that does these three steps
automatically, and receives the same command line as gcc (or a suitable
subset).
Otherwise, you can use the "-B" option to replace "as" with your own
executable or shell script. This shell script would run the perl or awk
script on the input, and call the system "as" with the output. To
understand what's going on (i.e. debugging), in turn, the "-###" option
shows you which commands the gcc driver is executing ("cc1" is the
compiler proper, "as" is the assembler", etc.).
What's in the perl or awk script? To find basic block boundaries,
search for things like "L123". If you need the nop at the beginning,
you need to look for jump tables and not insert the nop there. If you
need the nop at the end, you can blindly insert one at the end of a jump
table, but on the other hand you will have to insert it before jump
instructions. If you need more information, please ask on a
Perl/awk/shell-scripting newsgroups or mailing lists.
Paolo