Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

GCC

Altera_Forum
Honored Contributor II
1,035 Views

Dear gurus, 

 

I have the following problem. I have built a library which is compiled and 

linked separately from the rest of software. This library is stored in flash 

memory as a standalone piece of software. Then I have built an application which  

uses this library by calling its functions at some defined flash addresses. The  

application has been compiled and linked separately from the library and it 

resides at different addresses in flash.  

 

Both the library and the application use global variables. These variables are 

allocated at different ram addresses. Since GCC uses global pointer to reference 

to global variables, when the application calls a library function, that function 

is not able to reference its globals because the global pointer is assigned to the 

application's ram area and not to library's ram area. 

 

Can you suggest a way to workaround this problem ? (without suggesting to 

rewrite the compiler ...) 

 

Best Regards 

 

/Alessandro
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
339 Views

Hi Alessandro, 

 

> Can you suggest a way to workaround this problem ? 

 

Disable use of the global pointer with the -G0 compiler option (for both library and app). 

 

If you _must_ use the gp, you can write some fixup code in your library to 

save/restore the gp. But, depending on your requirements ... it might not be 

worth the effort. 

 

Regards, 

--Scott
0 Kudos
Altera_Forum
Honored Contributor II
339 Views

 

--- Quote Start ---  

originally posted by alessandro@Feb 28 2006, 07:58 PM 

can you suggest a way to workaround this problem ? (without suggesting to 

rewrite the compiler ...) 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=12991) 

--- quote end ---  

 

--- Quote End ---  

 

 

Another possible workaround could be that the fixed locations of the functions you have to call in reality contains an assembler stub which only swaps the gp pointer value... 

 

bye 

 

PJ
0 Kudos
Reply