Skip to content

Commit 2c12278

Browse files
dwrobelfpistm
authored andcommitted
Add support for using -g3 compiler option
Currently when one need to debug code with full debugging symbols (including access to macros -g3) then the linker fails because adding -g3 causes that preprocessed {preprocld.filepath} file contains a series of #define like: #define __STDC__ 1 #define __STDC_VERSION__ 201112L #define __STDC_UTF_16__ 1 #define __STDC_UTF_32__ 1 #define __STDC_HOSTED__ 1 #define __GNUC__ 7 #define __GNUC_MINOR__ 4 #define __GNUC_PATCHLEVEL__ 0 #define __VERSION__ "7.4.0" #define __ATOMIC_RELAXED 0 #define __ATOMIC_SEQ_CST 5 #define __ATOMIC_ACQUIRE 2 #define __ATOMIC_RELEASE 3 ... which later on causes the linker to not accept such a file: /usr/lib/gcc/arm-none-eabi/7.4.0/../../../../arm-none-eabi/bin/ld:/home/sw/Arduino/DS18B20Test/.build/preproc.ld:1: ignoring invalid character `#' in expression /usr/lib/gcc/arm-none-eabi/7.4.0/../../../../arm-none-eabi/bin/ld:/home/sw/Arduino/DS18B20Test/.build/preproc.ld:1: syntax error The fix removes entirely preprocessing of linker file operation step and passes an appropriate value of the symbol directly to the linker using: -Wl,--defsym= option. Log excerpt: Linking everything together... "/usr/bin/arm-none-eabi-gcc" -mcpu=cortex-m3 -mthumb -Os --specs=nano.specs -Wl,--defsym=LD_MAX_SIZE=131072 -Wl,--defsym=LD_MAX_DATA_SIZE=20480 Signed-off-by: Damian Wrobel <[email protected]>
1 parent 24b38e5 commit 2c12278

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

platform.txt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ compiler.cpp.flags={compiler.extra_flags} -c {build.flags.optimize} {compiler.wa
3737

3838
compiler.ar.flags=rcs
3939

40-
compiler.c.elf.flags=-mcpu={build.mcu} -mthumb {build.flags.optimize} {build.flags.ldspecs} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common
40+
compiler.c.elf.flags=-mcpu={build.mcu} -mthumb {build.flags.optimize} {build.flags.ldspecs} -Wl,--defsym=LD_MAX_SIZE={upload.maximum_size} -Wl,--defsym=LD_MAX_DATA_SIZE={upload.maximum_data_size} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common
4141

4242
compiler.objcopy.eep.flags=-O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0
4343

@@ -94,12 +94,6 @@ recipe.hooks.prebuild.1.pattern.windows=cmd /c if not exist "{build.opt.sourcepa
9494
recipe.hooks.prebuild.1.pattern.linux=bash -c "[ -f {build.opt.sourcepath} ] || (mkdir -p {build.path}/sketch && touch {build.opt.path})"
9595
recipe.hooks.prebuild.1.pattern.macosx=bash -c "[ -f {build.opt.sourcepath} ] || (mkdir -p {build.path}/sketch && touch {build.opt.path})"
9696

97-
# preprocess linker file
98-
preprocld.name=preproc.ld
99-
preprocld.filepath={build.path}/{preprocld.name}
100-
preprocld.flags=-DLD_MAX_SIZE={upload.maximum_size} -DLD_MAX_DATA_SIZE={upload.maximum_data_size}
101-
recipe.hooks.linking.prelink.1.pattern="{compiler.path}{compiler.c.cmd}" -x c -E -P {preprocld.flags} {compiler.c.flags} {build.info.flags} {compiler.c.extra_flags} {build.extra_flags} {compiler.arm.cmsis.c.flags} "{build.variant.path}/{build.ldscript}" -o "{preprocld.filepath}"
102-
10397
# compile patterns
10498
# ---------------------
10599

@@ -116,7 +110,7 @@ recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} {build.i
116110
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
117111

118112
## Combine gc-sections, archives, and objects
119-
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} "-T{preprocld.filepath}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} {compiler.ldflags} {compiler.arm.cmsis.ldflags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--start-group {object_files} -Wl,--whole-archive "{archive_file_path}" -Wl,--no-whole-archive -lc -Wl,--end-group -lm -lgcc -lstdc++
113+
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} "-T{build.variant.path}/{build.ldscript}" "-Wl,-Map,{build.path}/{build.project_name}.map" {compiler.c.elf.extra_flags} {compiler.ldflags} {compiler.arm.cmsis.ldflags} -o "{build.path}/{build.project_name}.elf" "-L{build.path}" -Wl,--start-group {object_files} -Wl,--whole-archive "{archive_file_path}" -Wl,--no-whole-archive -lc -Wl,--end-group -lm -lgcc -lstdc++
120114

121115
## Create output (.bin file)
122116
recipe.objcopy.bin.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.elf2bin.flags} {compiler.elf2bin.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"

0 commit comments

Comments
 (0)