This is the mail archive of the
mailing list for the GCC project.
Re: How to add a NOP instruction in each basic block for obj code that gcc generates
- From: Paolo Bonzini <paolo dot bonzini at lu dot unisi dot ch>
- To: jeff jeff <jeffhuang9999 at gmail dot com>, GCC Development <gcc at gcc dot gnu dot org>
- Date: Thu, 10 Aug 2006 11:55:33 +0200
- Subject: Re: How to add a NOP instruction in each basic block for obj code that gcc generates
- References: <firstname.lastname@example.org>
jeff jeff wrote:
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
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.