Hi.
I can't use static variables initialized with a value inside functions or I get "Error: <r> relocation error" (with initialized value there is no error). My solution has been avoid them and use as global but the firmware is growing and it makes a mess to read and understand... Please see bellow the examples of how it fails and the build error.
This is my first message to SDCC mailing list I would you like to give a BIG <3 THANK YOU for everyone involved!! I started a project to develop (the very first) OpenSource firmware for Bicycle/EBikes, popular, cheap and Chinese motor controllers and for the success of the project we need to use free tools so more developers can join, which happened and was a great success. Again, thank you for helping us working towards a better green environment <3
Project page: https://opensourceebikefirmware.bitbucket.io
When I build with for instance a static variable initialized with a value:
void communications_controller (void)
{
static uint16_t ui16_battery_current_accumulated = 100;
- Code (master branch): https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware
- Built with this Makefile "make -f Makefile_linux": https://github.com/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/blob/master/firmware/Makefile_linux
- SDCC 3.7.0 built and running on Linux
- Error: <r> relocation error
cas@ubuntu:~/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/firmware$ make -f Makefile_linux
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_itc.c StdPeriphLib/src/stm8s_itc.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_clk.c StdPeriphLib/src/stm8s_clk.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_iwdg.c StdPeriphLib/src/stm8s_iwdg.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_gpio.c StdPeriphLib/src/stm8s_gpio.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_exti.c StdPeriphLib/src/stm8s_exti.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_uart2.c StdPeriphLib/src/stm8s_uart2.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp4. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_tim1.c StdPeriphLib/src/stm8s_tim1.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_tim2.c StdPeriphLib/src/stm8s_tim2.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_adc1.c StdPeriphLib/src/stm8s_adc1.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp1. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oStdPeriphLib/src/stm8s_flash.c StdPeriphLib/src/stm8s_flash.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -owatchdog.c watchdog.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -ogpio.c gpio.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -outils.c utils.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -ouart.c uart.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oadc.c adc.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -obrake.c brake.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -opas.c pas.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -owheel_speed_sensor.c wheel_speed_sensor.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -otimers.c timers.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -opwm.c pwm.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oeeprom.c eeprom.c
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -omotor.c motor.c
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp152. Please contact sdcc authors with source code to reproduce.
sdcc -c -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre --out-fmt-elf --debug -oebike_app.c ebike_app.c
ebike_app.c:165: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp44. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp44. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp44. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp44. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp32. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp32. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp32. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp32. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp0. Please contact sdcc authors with source code to reproduce.
Warning: Non-connected liverange found and extended to connected component of the CFG:iTemp13. Please contact sdcc authors with source code to reproduce.
ebike_app.asm:4826: Error: <r> relocation error
Segmentation fault (core dumped)
Makefile_linux:79: recipe for target 'ebike_app.rel' failed
make: *** [ebike_app.rel] Error 1
cas@ubuntu:~/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/firmware$
From the output you posted, we get an error message from the assembler, followed by a Segfault (most likely also from the assembler).
I can't reproduce the issue using the SDCC 3.7.0 I built on my Debian GNU/Linux system.
Could you please:
1) Attach the ebike_app.asm file to this bug report, so I can see the asm code that the assembler can't deal with.
2) Attach the output of ./configure, so I can see with which options and libraries SDCC was built.
Philipp
Thanks for looking at this. Attached files.
And I just started on a new EBike motor controller that also runs STM8S105: https://opensourceebikefirmware.bitbucket.io/development_tsdz2/Various--2018.04.18_-_original_firmware_and_debug_session_using_OpenOCD.html
Last edit: casainho 2018-04-18
Thanks. I can reproduce the assembler crash using the .asm file you provided.
Philipp
It seems the crash happens while processing debug info. What happens when you compile without --debug?
Philipp
You are correct, no issue happens when not using the --debug. But that is not a workaround for me as I need to debug the code...
The project source is here, if you want to try: https://github.com/OpenSource-EBike-firmware/Kunteng_LCD3_firmware
I found that the popular LCDs for ebikes as also motor controllers, cheap and chinese, use STM8 and so we need a good compiler. Thank you for your work!!!
An idea for a workaround that I didn't try yet: What happens when you split the file into multiple smaller source files, so that each file fewer functions? Then each .asm file would have less debug information in it.
Philipp
Thanks for further understanding the issue.
Using smaller source files is not an option for me, I prefer to keep doing the code as it is done for now. I really hope developers can improve this issue. Thank you.
This project is now mostly finished (is in practice 2 projects: firmware for an ebike LCD + firmware for ebike motor controller, both using STM8) and users are very happy, this aretheir words:
- the TSDZ2 now feels more like the Bosch motor
- the motor is more efficient, stronger, it's feel like I have a new motor
- the bike feels very responsive and is very fast and agile whenever you need it to
- the info which is shown on LCD makes the total package way better
- this is GOLD. I still have a smile on my face
And a video review:
![](https://img.youtube.com/vi/IrWn6e8bIuQ/sddefault.jpg)
https://www.youtube.com/watch?v=IrWn6e8bIuQ
Last edit: casainho 2018-09-20
Well, there is always a lack of developer time lately in SDCC. I still hope (and think there is a good chance) that this can be fixed before the 3.9.0 release next year (but the bug is not important enough¹ to delay the 3.8.0 release planned for next week).
Philipp
I'm seeing the same things still happening in SDCC 4.0.7 #11994 (Linux) (x86_64) for STM8 targets, the linker segfaults when it encounters a static variable within a function, with debug on.
turning debug off isn't an option for me, so I've been using global variables as a workaround.
I can provide code examples if needed