Syntax error in ld-file at linking

When running platformio run I get the error:

platformio run
Processing disco_f072rb (board: disco_f072rb_libopencm; platform: https://github.com/platformio/platform-ststm32.git; framework: libopencm3)
------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/ststm32/disco_f072rb_libopencm.html
PLATFORM: ST STM32 6.1.0 #35b13fb > ST Discovery F072RB
HARDWARE: STM32F072RBT6 48MHz, 16KB RAM, 128KB Flash
DEBUG: Current (stlink) On-board (stlink) External (blackmagic, jlink)
PACKAGES:
 - framework-libopencm3 9bf6ce8
 - toolchain-gccarmnoneeabi 1.70201.0 (7.2.1)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 0 compatible libraries
Scanning dependencies...
No dependencies
Building in release mode
Linking .pio/build/disco_f072rb/firmware.elf
/Users/bodokaiser/.platformio/packages/toolchain-gccarmnoneeabi/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/ld:/Users/bodokaiser/.platformio/packages/framework-libopencm3@src-9c8ebe1ef30e0eefffb6631e281f274d/lib/stm32/f0/stm32f07xzb.ld:429: syntax error
collect2: error: ld returned 1 exit status
*** [.pio/build/disco_f072rb/firmware.elf] Error 1

The custom board setup disco_f072rb_libopencm3 can be found here.
The platformio source code can be found here.

When I open /Users/bodokaiser/.platformio/packages/framework-libopencm3@src-9c8ebe1ef30e0eefffb6631e281f274d/lib/stm32/f0/stm32f07xzb.ld and check line 429 I find a lonely */. Maybe we are missing the corresponding opening /*.

Any ideas what to do?

This indicates that the modification of libopencm3.py isn’t working properly.

The current PlatformIO builder for libopencm3 modifies the .ld files by resolving INCLUDE directives. Unfortunately, the latest libopencm3 .ld files also contain an INCLUDE directive in the comments, which is not supposed to be resolved. PlatformIO does it anyway. On the first run it works, on the second run it creates an invalid file. Then you get the error you describe.

To fix it:

Reset the ld file:

cd ~/.platformio/packages/framework-libopencm3/lib/stm32/f0
git checkout stm32f07xzb.ld

Then check the libopencm3.py modification again. You might have lost it with some update.

Instead of modifying libopencm3.py, you can also modify stm32f07xzb.ld: Just remove the INCLUDE directive that serves as an example and is placed in a comment block.

I cannot reset stm32f07xzb.ld because

fatal: not a git repository (or any of the parent directories): .git

The content of stm32f07xzb.ld is:

/*
 * This file is part of the libopencm3 project.
 *
 * Copyright (C) 2015 Karl Palsson <karlp@tweak.net.au>
 *
 * This library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
 */

/* Linker script for STM32F07xzB, 128k flash, 16k RAM. */

/* Define memory regions. */
MEMORY
{
	rom (rx) : ORIGIN = 0x08000000, LENGTH = 128K
	ram (rwx) : ORIGIN = 0x20000000, LENGTH = 16K
}

/* Include the common ld script. */
INCLUDE libopencm3_stm32f0.ld

I removed the last line without effect.

I also manually replaced stm32f07xzb.ld with the file in the libopencm3 repository also without effect.

Delete all folders starting with framework-libopencm in ~/.platformio/packages. PlatformIO will restore them as needed.