Inserting labels before and after my program's global variables

Ian Lance Taylor iant@google.com
Fri Dec 17 15:24:00 GMT 2010


Amittai Aviram <amittai.aviram@yale.edu> writes:

> I would like to insert labels into my executable as it is being linked
> so that there is a "start" label just before my user-defined global
> variables in the .bss section and an "end" right after them, when I
> use static linkage.  Thus the output of .bss from objdump -D would
> include some lines something like this, supposing I had global
> variables global_a and global_b:

This is the kind of thing which is much more easily done using a linker
script.


> Here is what I tried (but it didn't work).  I wrote a file head.s and
> one called tail.s:

> gcc -static -o hello head.s hello.c tail.s

This does not actually put the files first and last.  To see why not,
add the -v option and look at the linker command.  To put the files
first and last, you will have to use -nostdlib to disable gcc's default
start files and libraries, and then replicate them on the command line
yourself, with head and tail where you want them.

Ian



More information about the Gcc-help mailing list