Inserting labels before and after my program's global variables

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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:

Disassembly of section .bss

... [Some library stuff perhaps] ...

0000000000605100 <my_bss_start>:
...
0000000000605108 <global_a>:
...
0000000000605110 <global_b>:
...
0000000000605118 <my_bss_end>:
...
...[Some other library stuff]...

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

head.s:

	.section	.bss
	.globl my_bss_start
my_bss_start:


tail.s:

	.section	.bss
	.globl my_bss_end
my_bss_end:


Then, I compiled and linked these two files before and after my main source file, respectively:

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

My resulting executable file had the my_bss_end label but  not the my_bss_start file.  (If I did not include tail.s on my gcc command line, then I would get my_bss_start.  Also, if I did the equivalent trick for .rodata, I did get both my "start" and my "end" labels.  Why are the results different between .rodata and .bss?)  In addition, the label was just stuck in among the other .bss symbols, with library symbols occurring before and after it.  The location of the label had no special relation that I could see to the location of global_a and global_b.

Any suggestions for how I could accomplish my goal?  Thank you!

Amittai Aviram
PhD Student in Computer Science
Yale University
646 483 2639
amittai.aviram@xxxxxxxx
http://www.amittai.com




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux