I'm newly interested in linker command files, as I have a specific request. But first:
Working with a Nuvoton NuMicro M2351 and OpenOCD with an ARM GNU GCC compiler (gcc-arm-none-eabi-9-2019-q4-major) in a Xubuntu 20.04 VirtualMachine.
With the Nuvoton board came a "board support package" with some sample code on it. This also includes a linker script. There the MEMORY is defined as:
MEMORY
{
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x80000 /* 512k */
RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x18000 /* 160k */
}
Now, I have the following code setup: a main.c with some system setup (and the definition of a XOM (execute-only) region, but I think that actually does not matter for the question) and an add_xom.c with a simple addition function (named Lib_XOM_ADD). My request is to locate the add_xom.o output file at the base address 0x10000, which is inside the FLASH region. How do I do that? Do I have to split up the FLASH region? But I want it inside the FLASH region, just at a specific memory location.
After the specification of MEMORY, the beginning of the linker file looks like this:
SECTIONS
{
.text :
{
KEEP(*(.vectors))
__Vectors_End = .;
__Vectors_Size = __Vectors_End - __Vectors;
__end__ = .;
*(.text*)
KEEP(*(.init))
KEEP(*(.fini))
/* .ctors */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(.rodata*)
KEEP(*(.eh_frame*))
} > FLASH
So, I thought just inserting the xom_add.o like this would work (just showing the top of the linker file):
SECTIONS
{
XOMR0 0x10000:
{
xom_add.o
}
.text :
{
KEEP(*(.vectors))
__Vectors_End = .;
__Vectors_Size = __Vectors_End - __Vectors;
__end__ = .;
But while compiling/linking this gives me the error, that the function inside the xom_add.o file is defined multiple times. I could imagine this is due to fact, that the xom_add.o is also included in the *(.text*) and therefore kind of linked twice.
I am really new to linker files and don't know, what is possible. And I could not find a similar question/answer, because all of them have as answer to define a specific MEMORY region, but I want the function to be inside the FLASH, not be an own region (or is this the same?).
Hope the question is not too stupid and as I said above, I am really not familiar with linker scripts and just read some articles/descriptions about it and know only the basics. So if you also have a nice link to a good description how linker scripts are build, then please drop it to me.
P.S. The whole purpose of this is the example code to install a XOM region (called XOMR0, see Nuvoton XOM Configuration Manual, where one step is to "Program the user code into XOM region" with no further description)
The compiler error message is:
/arm-none-eabi/bin/ld: build/xom_add.o: in function `Lib_XOM_ADD':
/nuvotonM2351/FMC_XOM/xom_add.c:13: multiple definition of `Lib_XOM_ADD'; build/./xom_add.o:/nuvotonM2351/FMC_XOM/xom_add.c:13: first defined here
collect2: error: ld returned 1 exit status
make: *** [Makefile:59: build/main.elf] Error 1
User contributions licensed under CC BY-SA 3.0