Forum Discussion
Altera_Forum
Honored Contributor
20 years agolinker directive for memory size
I want to place a filesystem in upper memory. The default linker script lets certain data sections span all remaining memory (and puts top of stack there too). Is there a simple directive I can use to limit the memory used, or do I need a custom linker script?
Is there a way to get objdump to give me a clearer picture of what is being used and what is free? The default dump does have a part called "Sections:", but it is kinda cryptic (what's an LMA?), and you need a calculator too. Is there a page describing what all those extra sections are (.comment, .debug_blah_blah) and if they ever use memory on the target? thanks2 Replies
- Altera_Forum
Honored Contributor
Hi tns1,
> Is there a simple directive I can use to limit the memory used, crt0 sets the stack pointer to the symbol __alt_stack_pointer which is wrapped in a linker PROVIDE ... so you should be able to define it with a command line argument: --defsym __alt_stack_pointer=0xWHATEVER You might need the "-Wl,xxx" in the IDE. > Is there a way to get objdump to give me a clearer picture of what is being used and > what is free? objdump (with -h) is about as clear (well ... detailed) as you can get -- it's all there. > but it is kinda cryptic (what's an LMA?), and you need a calculator too. Fair enough ... it's not exactly the friendliest output to become familiar with ... but it's _well_ worth the effort to learn ... just dig in and suffer for a few hours ... you won't be sorry ... objdump is a very powerful tool. LMA is an acronym for "Load Memory Address", as opposed to VMA which is "Virtual Memory Address". For Nios-II, the VMA is just the physical address where the code and data should be located before main() is called. The LMA is where the code is loaded. For example, you can set the LMA of each section to an address in flash, then let the linker provide the "load addresses" to the startup code so it knows where each section is located in flash (and then does the copy from LMA to VMA). > Is there a page describing what all those extra sections are (.comment, > .debug_blah_blah) and if they ever use memory on the target? Look at the compiler/linker docs, manpages and info pages. But a simple rule is: if the ALLOC attribute is not set, it's not occupying any target memory. If the LOAD attribute is not set -- it doesn't get loaded (e.g. .bss/.sbss). You can strip most of the junk if you like (but you'll loose your symbols). Sometimes it's handy to just make a copy of your elf, then strip the copy: $ nios2-elf-strip myapp-copy.elf Regards, --Scott - Altera_Forum
Honored Contributor
OK, so maybe the objdump format isn't so bad, but the mapfile is clearer for some things.
>You might need the "-Wl,xxx" in the IDE. Because the syntax is so bizarre I list it here: -Wl,-Map -Wl,'./my_mapfile' ;for just a mapfile -Wl,-defsym -Wl,'__alt_stack_pointer=0x900000' ;to override stack pointer -Wl,-defsym -Wl,'__alt_stack_pointer=0x900000',-Map -Wl,'./my_mapfile' ;both The above are entered as linker flags in the IDE. Overriding the stack pointer isn't the whole story if you look at the mapfile. The symbol __alt_data_end also extends to the end of memory, and I don't think I want that. Part of the reason is I have less physical memory loaded on my board than is defined in the Nios project (for expandability), but my system worked because the non-functional high order address bit aliased the stack down to a working memory range (whew!). I want the memory limits to be more clearly defined. I also wonder if the stack limits check will work properly. You cannot use the -defsym trick on __alt_data_end, but if I edit the default linker script to override __alt_data_end instead, the stack pointer gets taken care of automatically. There is a comment which warns against this, but it may be the only way to really get what I want. thanks