简体   繁体   中英

how to solve this linker script error?

I created a linker script file as memory.ld –

MEMORY
{
        MYMEMORY(rw)   : ORIGIN = 0x0041c620 ,  LENGTH = 30
}

.myvars (NOLOAD) :
{
  *(.myvarloc)

} > MYMEMORY


In my c program :
__attribute__((section(".myvarloc")))
   uint8 measurements[30];

I am using eclipse IDE on linux rtos. I added –T memory.ld in project – properties -- linker – libraries – miscellaneous in eclipse I am creating this because : I want a fixed memory address for the variable measurements of size 30 starting from 0x0041c620 .

My question : Is it right way of doing this ?? If I do like above : I am getting error as – Linker input file unused and linking not done.

NOTE : I am reposting the question.

This is most likely because Eclipse doesn't invoke the linker directly. Instead it uses gcc (or g++ ) as a wrapper which in turn calls the linker with the default linker script.

If you're cross-compiling for a specific target where memory is fixed, your best bet is probably to make your own makefile that invokes the linker directly.

If you're not cross-compiling, but building for eg Windows or Linux, then don't do what you're doing! You don't really know that the virtual address you have in the linker-script will actually be available to you. And you can't use it for sharing memory between processes, as a virtual address in one process may not actually the same as the same virtual address in another process (even if both processes are created from the same executable). Instead read about shared memory or other inter-process communication methods.

Unless your program is really simple, chances are that linker script should contain way more than you've put in yours. Typically there would be .text (code, normally read-only), .data (r/w, initialized), .bss (r/w, zero-filled) plus some others, depending on what your toolchain produces and what your RTOS' runtime expects.

Bottom line is that starting from scratch only works if you already know what you're doing or if your project is really simple.

In your case I'd probably start with the linker script that linker uses by default and would then only adjust the portions you need.

You can get default linker script by running gcc-for-your-platform some-file.c -Wl,-verbose or ld-for-your-platform -verbose .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM