Topic : setting linker script from default to custom

Forum : ARM

Original Post
Post Information Post
May 26, 2015 - 4:45pm
Guest account

I want to edit my linker script (the goal is to place a single 192kB array into SRAM at 0x2000 0000 for framebuffer, and put all the rest (variables, stack etc) to CCM at 0x1000 0000). I have a MX generated + manual edited project, which compiles fine when "Use Default Script File" is Yes. In Project Options - LD Linker - Scripts I make a new Config, set Use Default... to Yes, set the "Script File" line to a custom name "oszlopdisp-mx.elf.ld". 
After pushing F9, 3 new LD files are generated (file dates are brand new):
"oszlopdisp-mx.elf.ld",
"STM32F429_2048K_192K_DEF.LD" and
"STM32F429_2048K_192K_FLASH.LD".
and compile is succesful.
Now I set "Use Default Script File" to No (Script File name is the same, 3 LD files are untouched), push F9, and got an error: "multiple startup files". Shouldn't it be successful? What is this?

I paste the build text here:

----------------Make Started: 'oszlopdisp-mx' in configuration 'NT-oszlopdisp'--------------------------
 
Building D:\MUNKA\Tekinvest\OszlopDisp\Prog\Projects\MDK-ARM\oszlopdisp-mx.rapp
due to out of date oszlopdisp-mx Configuration\oszlopdisp-mx.elf
Running: LD Linker
"C:\Program Files\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -u _start -u _Minimum_Stack_Size  --verbose -mcpu=cortex-m4 -mthumb -specs=nano.specs -specs=nosys.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Wl,-T -Xlinker "oszlopdisp-mx Configuration\oszlopdisp-mx.elf.ld" -Wl,-static -Wl,--gc-sections  -Wl,-Map -Xlinker "D:\MUNKA\Tekinvest\OszlopDisp\Prog\Projects\MDK-ARM\oszlopdisp-mx Configuration\oszlopdisp-mx.map" -N -nostartfiles -Wl,--warn-once 
Using built-in specs. 
Reading specs from c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/nano.specs 
rename spec link to nano_link 
rename spec link_gcc_c_sequence to nano_link_gcc_c_sequence 
Reading specs from c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/nosys.specs 
rename spec link_gcc_c_sequence to nosys_link_gcc_c_sequence 
COLLECT_GCC=C:\Program Files\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe 
COLLECT_LTO_WRAPPER=c:/program\ files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/lto-wrapper.exe 
Target: arm-none-eabi 
Configured with: /home/build/work/GCC-4-8-build/src/gcc/configure --build=i686-linux-gnu --host=i686-w64-mingw32 --target=arm-none-eabi --prefix=/home/build/work/GCC-4-8-build/install-mingw --libexecdir=/home/build/work/GCC-4-8-build/install-mingw/lib --infodir=/home/build/work/GCC-4-8-build/install-mingw/share/doc/gcc-arm-none-eabi/info --mandir=/home/build/work/GCC-4-8-build/install-mingw/share/doc/gcc-arm-none-eabi/man --htmldir=/home/build/work/GCC-4-8-build/install-mingw/share/doc/gcc-arm-none-eabi/html --pdfdir=/home/build/work/GCC-4-8-build/install-mingw/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-headers=yes --with-newlib --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/home/build/work/GCC-4-8-build/install-mingw/arm-none-eabi --with-libiconv-prefix=/home/build/work/GCC-4-8-build/build-mingw/host-libs/usr --with-gmp=/home/build/work/GCC-4-8-build/build-mingw/host-libs/usr --with-mpfr=/home/build/work/GCC-4-8-build/build-mingw/host-libs/usr --with-mpc=/home/build/work/GCC-4-8-build/build-mingw/host-libs/usr --with-isl=/home/build/work/GCC-4-8-build/build-mingw/host-libs/usr --with-cloog=/home/build/work/GCC-4-8-build/build-mingw/host-libs/usr --with-libelf=/home/build/work/GCC-4-8-build/build-mingw/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for ARM Embedded Processors' --with-multilib-list=armv6-m,armv7-m,armv7e-m,armv7-r 
Thread model: single 
gcc version 4.8.4 20140526 (release) [ARM/embedded-4_8-branch revision 211358] (GNU Tools for ARM Embedded Processors)   
COMPILER_PATH=c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/;c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/;c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ 
LIBRARY_PATH=c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/armv7e-m/fpu/;c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu/;c:/program files/raisonance/ride/arm-gcc/bin/../arm-none-eabi/lib/armv7e-m/fpu/;c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/;c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/;c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/;c:/program files/raisonance/ride/arm-gcc/bin/../arm-none-eabi/lib/ 
COLLECT_GCC_OPTIONS='-u' '_start' '-u' '_Minimum_Stack_Size' '-v' '-mcpu=cortex-m4' '-mthumb' '-specs=nano.specs' '-specs=nosys.specs' '-mfpu=fpv4-sp-d16' '-mfloat-abi=hard' '-N' '-nostartfiles' 
c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/collect2.exe --sysroot=c:\program files\raisonance\ride\arm-gcc\bin\../arm-none-eabi -X -N -u _start -u _Minimum_Stack_Size -Lc:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/armv7e-m/fpu -Lc:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib/armv7e-m/fpu -Lc:/program files/raisonance/ride/arm-gcc/bin/../arm-none-eabi/lib/armv7e-m/fpu -Lc:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4 -Lc:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc -Lc:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/lib -Lc:/program files/raisonance/ride/arm-gcc/bin/../arm-none-eabi/lib -T oszlopdisp-mx Configuration\oszlopdisp-mx.elf.ld -static --gc-sections -Map D:\MUNKA\Tekinvest\OszlopDisp\Prog\Projects\MDK-ARM\oszlopdisp-mx Configuration\oszlopdisp-mx.map --warn-once --start-group -lgcc -lc_s --end-group --start-group -lgcc -lc_s -lnosys --end-group --start-group -lgcc -lc_s -lnosys --end-group 
c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: multiple STARTUP files 
collect2.exe: error: ld returned 1 exit status 
  Error Code: 0x1
 
Build failed

Replies
Post Information Post
+1
0
-1
May 26, 2015 - 4:45pm
Etienne Cassin

Hi,

I guess you did not specify the correct script to use in the "Script File" option...

You should use "STM32F429_2048K_192K_FLASH.LD". (the one that was generated by the previous link with default script ON)

Note that "oszlopdisp-mx.elf.ld" will always be generated at every link, even when using a custom linker script.

This is explained a little more in the GettingStarted doc.

I hope it helps.

Best Regards,

Vincent

+1
0
-1
May 26, 2015 - 4:46pm
Guest account

Thanks, you are right. "oszlopdisp-mx.elf.ld" is regenerated even when Auto linker script is OFF. And this generated script has a recursive call: it has a line
INCLUDE "D:\MUNKA\Tekinvest\OszlopDisp\Prog\Projects\MDK-ARM\oszlopdisp-mx Configuration\oszlopdisp-mx.elf.ld"
to include itself.
I think the problem is that the single line
STARTUP("startup_stm32f4xx.o")
in that script gets doubled because of recursive include.  Is it a bug at script generation?
What to do?
- Is there any "#ifdef" kind of solution in linker scripting language to avoid double include?
- Can I disable re-generating this file (to keep manually edited script)?
- If I run ld.exe manually with parameters script will not be re-generated (is it done by Ride IDE)?

I attach the script "D:\MUNKA\Tekinvest\OszlopDisp\Prog\Projects\MDK-ARM\oszlopdisp-mx Configuration\oszlopdisp-mx.elf.ld":


/*
!!! Primary linker script file generated automatically !!!
This file contains the input and output files names
It also includes the secondary/main linker script that is specified in the Ride options (default or custom)
*/

SEARCH_DIR(".")
SEARCH_DIR("oszlopdisp-mx Configuration")
SEARCH_DIR("C:\Program Files\Raisonance\Ride\Lib\ARM")
STARTUP("startup_stm32f4xx.o")
INPUT("oszlopdisp-mx Configuration\bsp_driver_sd.o")
INPUT("oszlopdisp-mx Configuration\main.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_msp.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_it.o")
INPUT("oszlopdisp-mx Configuration\usb_device.o")
INPUT("oszlopdisp-mx Configuration\usbd_conf.o")
INPUT("oszlopdisp-mx Configuration\usbd_desc.o")
INPUT("oszlopdisp-mx Configuration\tft.o")
INPUT("oszlopdisp-mx Configuration\system_stm32f4xx.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_cortex.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_crc.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_dma.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_dma2d.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_dma_ex.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_flash.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_flash_ex.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_flash_ramfunc.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_gpio.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_iwdg.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_ltdc.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_nand.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_pcd.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_pcd_ex.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_pwr.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_pwr_ex.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_rcc.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_rcc_ex.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_sd.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_sdram.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_tim.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_tim_ex.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_hal_uart.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_ll_fmc.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_ll_sdmmc.o")
INPUT("oszlopdisp-mx Configuration\stm32f4xx_ll_usb.o")
INPUT("oszlopdisp-mx Configuration\diskio.o")
INPUT("oszlopdisp-mx Configuration\sd_diskio.o")
INPUT("oszlopdisp-mx Configuration\ff.o")
INPUT("oszlopdisp-mx Configuration\ff_gen_drv.o")
INPUT("oszlopdisp-mx Configuration\ccsbcs.o")
INPUT("oszlopdisp-mx Configuration\syscall.o")
INPUT("oszlopdisp-mx Configuration\usbd_hid.o")
INPUT("oszlopdisp-mx Configuration\usbd_core.o")
INPUT("oszlopdisp-mx Configuration\usbd_ctlreq.o")
INPUT("oszlopdisp-mx Configuration\usbd_ioreq.o")
GROUP(
"smallprintf_thumb_fpu.a"
"Cortex_SWV_io_putchar_thumb_fpu.a"
"libc_s.a"
"libm.a"

)
INCLUDE "D:\MUNKA\Tekinvest\OszlopDisp\Prog\Projects\MDK-ARM\oszlopdisp-mx Configuration\oszlopdisp-mx.elf.ld"
PROVIDE ( _Minimum_Stack_Size = 0x20 );
PROVIDE ( malloc_getpagesize_P = 0x1000 );
OUTPUT("oszlopdisp-mx Configuration\oszlopdisp-mx.elf")

+1
0
-1
May 26, 2015 - 4:47pm
Guest account

and one more "anomaly" when firing up linker:

the last couple lines of Build log window after unsuccessful Make

Running: LD Linker
"C:\Program Files\Raisonance\Ride\arm-gcc\bin\arm-none-eabi-gcc.exe" -u _start -u _Minimum_Stack_Size  -mcpu=cortex-m4 -mthumb -specs=nano.specs -specs=nosys.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Wl,-T -Xlinker "oszlopdisp-mx Configuration\oszlopdisp-mx.elf.ld" -Wl,-static -Wl,--gc-sections  -Wl,-Map -Xlinker "D:\MUNKA\Tekinvest\OszlopDisp\Prog\Projects\MDK-ARM\oszlopdisp-mx Configuration\oszlopdisp-mx.map" -N -nostartfiles -Wl,--warn-once 
c:/program files/raisonance/ride/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.8.4/../../../../arm-none-eabi/bin/ld.exe: multiple STARTUP files 
collect2.exe: error: ld returned 1 exit status 
  Error Code: 0x1
 
Build failed


The "-Xlinker" option is doubled...I don't know if it causes a problem...but anomaly.

+1
0
-1
May 26, 2015 - 4:47pm
Guest account

I only spread the breaking news of my "investigation":))

If I Auto generate linker script, my "oszlopdisp-mx.elf.ld" file has one include:
INCLUDE "oszlopdisp-mx Configuration\STM32F429_2048K_192K_FLASH.ld"
and compile+link is fine.

Now  I turn off auto linker script generation while Ride7 still running, and push F9 again,
"oszlopdisp-mx.elf.ld" is NOT re-generated, and "make" is still successful.

Sometimes, when "oszlopdisp-mx.elf.ld" is re-generated, the recursive line
INCLUDE "D:\MUNKA\Tekinvest\OszlopDisp\Prog\Projects\MDK-ARM\oszlopdisp-mx Configuration\oszlopdisp-mx.elf.ld"
is added, and Make ends up with "multiple STARTUP files " error.

Re-generation of "oszlopdisp-mx.elf.ld" sometimes happens after Clean Project, or manual deletion of "oszlopdisp-mx.elf.ld"...but I can't clearly see the condition whether re-generating or not.

I think this is an minor issue of Ride7 (v7.50.14.0185)

+1
0
-1
May 26, 2015 - 4:48pm
Etienne Cassin

Hi,

The auto-generated .elf.ld primary script file includes the secondary file that you specified in Ride's "Script File" option. Your custom script is this secondary script file, not the primary.

If you see the primary file auto-including itself, it means that you have written the name of the .elf.ld file in Ride's "Script File" option. (and then of course the script auto-includes itself and the link has little hope to succeed wink )

You must change this "Script File" option (in Ride, not in a ld file) to use "STM32F429_2048K_192K_FLASH.ld" as your custom script. (and NOT the .elf.ld) Then the auto-generated script .elf.ld file will include STM32F429_2048K_192K_FLASH.ld, which itself includes three other sub-scripts. Then you'll have a custom script that provides the same result as the default script, and only then can you start modifying one or several of these four scripts. (the secondary and the sub-scripts, but not the primary .elf.ld, which will always be auto-generated.)

Concerning the fact that you see that the script is sometimes not generated, this is normal: the file is generated at every Link, not at every Make. Sometimes the Make process does not launch the link, which is what you'd expect from Make. (otherwise it would be a Build) I think that your observation of this behavior is disturbed by the fact that you have the wrong file referenced in the linker "Script File" option. Please first correct this option and the rest should be all right.

I hope it helps.

Best Regards,

Vincent

+1
0
-1
May 26, 2015 - 4:48pm
Guest account

Big thanks, Vincent, it's clear(er) now:))
I've checked "Raisonance Tools for ARM core-based microcontrollers - Getting Started" dated 03 July 2014.
I've found a half page (4.3.2.4 Scripts), but it's not enough for dumb guys like me:))
You should write a bit more on this subject in next version, like this:

There is a base linker script, which is always generated independently of "Use Default Script File" setting. This base script always named as <project name>.elf.ld.  This script includes a secondary script. If "Use Default Script File" setting is Yes, then this secondary script fits MCU type (eg. "STM32F429_2048K_192K_FLASH.ld" for STM32F429 without Starter Kit limitation).  If "Use Default Script File" setting is No, then user must supply the secondary script file, which is given in next "Script file" line (within Project properties - LD linker - Scripts).
Automatically generated primary script will include the given secondary name. Secondary script includes more (tertiary) scripts by default; check scripts as they are simple textfiles.
When "Use Default Script File" setting is Yes, primary, secondary and tertiary scripts are generated (or overwritten if already exists). When "Use Default Script File" setting is No, only primary script is generated, and contains INCLUDE command to the given secondary script.

Merci, thank you
Tamas

Secondary and tertiary files may be edited/replaced if "Use Default Script File" setting is No.