Specifying alternate linker does not work

In platformio.ini, using the option ‘board_build.ldscript=custom.ld’ does not use the ‘custom.ld’ linker as expected. Doing a verbose build shows the standard platform-specified linker is always called.

Example:
I have two linker files, LPC1768.ld, which is the stock platform-specified file, and it has the line

FLASH (rx) : ORIGIN = 0x00004000, LENGTH = (512K - 48K)

.
My second file, LPC1768_0K.ld, has the line as follows to specify a different ROM load address

FLASH (rx) : ORIGIN = 0x00000000, LENGTH = (512K - 32K)

.

In this particular case, the micro controller needs to load at address 0x00000000 to work correctly, so I need to specify LPC1768_0K.ld file.
(in a different case the micro may need to load at 0x00004000 and I would instead
let the original LPC1768.ld file be used).

By default, the platform calls ‘LPC1768.ld’ when building.

If I add this option

board_build.ldscript=C:/Users/tony/.platformio/packages/framework-arduino-lpc176x/system/CMSIS/system/LPC1768_0K.ld

, it should call LPC1768_0K.ld when building but it doesn’t. A verbose build shows this:

arm-none-eabi-g++ -o .pio/build/LPC1769_RELEASE/firmware.elf -mthumb --specs=nano.specs --specs=nosys.specs -u_printf_float -flto -mcpu=cortex-m3 -Wl,-TC:/Users/tony/.platformio/packages/framework-arduino-lpc176x/system/CMSIS/system/LPC1768.ld

So it didn’t work, it’s still pointing to the platform-specified LPC1768.ld file.

Next I tried adding the -T option to ‘build_flags’ like this:

-TC:/Users/tony/.platformio/packages/framework-arduino-lpc176x/system/CMSIS/system/LPC1768_0K.ld

, and it seemed to work because the verbose output now showed:

arm-none-eabi-gcc -o .pio\build\LPC1769_RELEASE\lib8bf\U8glib-HAL\clib\u8g_virtual_screen.c.o -c -Os -ffunction-sections -fdata-sections -fsingle-precision-constant -Wall -mthumb --specs=nano.specs --specs=nosys.specs -mcpu=cortex-m3 -g -fmerge-constants -fmax-errors=5 -Wno-int-in-bool-context -Wno-unused-variable -Wno-unknown-pragmas -g -ggdb -O1 -TC:/Users/tony/.platformio/packages/framework-arduino-lpc176x/system/CMSIS/system/LPC1768_0K.ld

But it really doesn’t work. When I upload the generated code, the microcontroller doesn’t run!
But if I modify the original platform-specified LPC1768.ld by changing the load address to ORIGIN = 0x00000000 and upload the generated code, the microcontroller runs fine!

It acts like neither of these work:

option ‘board_build.ldscript=LPC1768_0K.ld’ or
option to ‘build_flags’ TLPC1768_0K.ld

The build process always uses the platform-specifed .ld file no matter what.

Can this be fixed?

What is your platformio.ini? The project you’re working in might have a script which ignores board_build.ldscript or overwrites it unconditionally.