Hank Fu
Hank Fu

Reputation: 43

How to put functions from one object file to one special section and memory region for GCC linker?

How to put functions from one object file to one special section and memory region for GCC linker? I am building one standalone application for Xilinx MPSoC A53 processor. GNU ld from Linaro 2.27 is used. Xilinx software is Xilinx SDK 2017.4. I plan to put most code into DDR and some critical functions from one file into on-chip memory. I checked '4.6.4.5. Input Section Example' from Using_ld_the_GNU_Linker/sections.html. So I created the following linker script. The output section '.text_ocm' is added by me.

.text_ocm : {
    src/ocm_init.o(.text)
}  > psu_ocm_ram_0_MEM_0

.text : {
   KEEP (*(.vectors))
   *(.boot)
   *(.text)
   *(.text.*)
   *(.gnu.linkonce.t.*)
   *(.plt)
   *(.gnu_warning)
   *(.gcc_execpt_table)
   *(.glue_7)
   *(.glue_7t)
   *(.ARM.extab)
   *(.gnu.linkonce.armextab.*)
} > psu_ddr_0_MEM_0

But I got error message. It seems there are two 'ocm_init'. But there is only one definition for 'ocm_init' in file 'src/ocm_init.c' my source code.

'Invoking: ARM v8 gcc linker'
aarch64-none-elf-gcc -Wl,-T -Wl,../src/lscript.ld -L../../a53a0_ddrsr_wfi_bsp/psu_cortexa53_0/lib -o "a53a0_ddrsr_wfi_step4_from_ddr.elf"  ./src/ocm_init.o ./src/gic_setup.o ./src/helloworld.o ./src/platform.o ./src/timer.o   -Wl,--start-group,-lxil,-lgcc,-lc,--end-group -Wl,--start-group,-lxil,-lmetal,-lgcc,-lc,--end-group -Wl,--start-group,-lxilpm,-lxil,-lgcc,-lc,--end-group
./src/ocm_init.o: In function `ocm_init':
C:\prj\mpsoc\v174\zcu102\a53a0_ddr\Debug/../src/ocm_init.c:1667: multiple definition of `ocm_init'
src/ocm_init.o:C:\prj\mpsoc\v174\zcu102\a53a0_ddr\Debug/../src/ocm_init.c:1667: first defined here

Upvotes: 1

Views: 2946

Answers (1)

matli
matli

Reputation: 28600

The linker cares about the leading ./ in some ways when matching file names, so either write

.text_ocm : {
    *src/ocm_init.o(.text)
}  > psu_ocm_ram_0_MEM_0

in your linker script, or reference the object file as src/ocm_init.o on your linker command line.

(It's not really intuitive why this omission causes multiple definitions, but I could reproduce your problem, and the change fixes it.)

Upvotes: 1

Related Questions