23. January 2020

Invalid data statement gcc linker

GCC Linker is not really descriptive with the error messages. While most of them do hint on the real problem, this below one gives you no indication what-so-ever of where to search or what to search for as error. There are a lot of gcc based linkers around from Microchip's X16, to arm-none-eabi-gcc, to arm-linux-eabi-gcc to something even more exotic like mlx16-gcc. All of them will produce same type of errors, as all of them share gcc frontend, while have a chip/manufacturer specific backend.

/bin/ld: invalid data statement

Above error is usually triggered by forgotten semi-colon or some other ending in the dedicated data section (see example below). Because there is no line number of the error, the only way to track it down is to comment parts of your linker file out and check if it then fails with either different error or without. Then look at the possible blocks in detail. In my case below block produced the error


.fw_reserved :
     {
         SHORT(0x07FF);
         . = LENGTH(fw_reserved);
     } > fw_reserved = 0xFF07

while this is the solution:


.fw_reserved :
     {
         SHORT(0x07FF)
         . = LENGTH(fw_reserved);
     } > fw_reserved = 0xFF07

If you have idea why, please write in comment section below, as usually semi-colon after functions do not cause problems.

Newest from this category: