- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to access a linker symbol from my C file. The idea is to find out where the end of my code and R/O memory is in flash so I can use the remainder for storage. I have the following in my .c file:
.C file: extern int __ram_rodata_end; void *p = &__ram_rodata_end; The .map file shows the symbol __ram_rodata_end like this: 0x01014f20 PROVIDE (__ram_rodata_end, <code 336> (.)) But the linker gives me the error below. If I use a symbol that's in reach (e.g. __sbss_end) everything works and p points to the end of data. The format in the map file is exactly the same so I know that's not the problem. Linker error: ../test.c:33: Unable to reach __ram_rodata_end (at 0x01014f20) from the global pointer (at 0x0101ed34) because the offset (-40468) is out of the allowed range, -32678 to 32767. Here's the assembly code causing the problem: 145 0100 040080D0 addi r2,gp,%gprel(__ram_rodata_end) 146 0104 150680E0 stw r2,24(fp) Is there an easy way of getting the value of a linker symbol into a C variable? I'm not above using inline assembly with a global or static variable to get the value. Thanks, AndrewLink Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Ok, I'll answer my own question. To access a linker symbol that's out of reach use the following code:
extern int __ram_rodata_end[]; printf("%x\n", __ram_rodata_end); That'll print out the same value you'll see in the .map file. The trick is to use an array declaration which forces GCC to use full-range addressing. Thanks to David Brooks on comp.arch.embedded for the answer. Andrew- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem you had is related to the fact that you declared the extern variable as "int", that means the compiler will generate GP-relative addressing, that is not the right one in your case.
Take a look at the post "Disabling GP-addressing in generated source code" on this forum... bye PJ
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page