Forum Discussion
Altera_Forum
Honored Contributor
20 years agoget start and end of .text from C
I am trying to get the start and end of the .text section in C code. I have currently tried: extern int stext;
extern int etext;
struct ta
{
void * start;
void * end;
};
struct ta tex...
Altera_Forum
Honored Contributor
20 years agoHi Cliff,
By default, the compiler wants to access data less than 8 bytes with the global pointer. An int is less than 8 bytes, so the global pointer is used to calculate the address. In your case, .text section can't be reached with the gp. The -G0 option can be used to turn off addressing via the gp, but it's not very portable. So far, I've found it best to use a void data type so you don't have to worry about the gp at all: <div class='quotetop'>QUOTE </div> --- Quote Start --- - extern int stext; + extern void stext; - extern int etext; + extern void etext;[/b] --- Quote End --- Basically, void doesn't have a size, so the compiler _should_ never use the gp. You can also define the symbols as functions & cast on assignment, but void is probably more readible ;-) Regards, --Scott