Hello Jorge, Did you use a recent version of SDCC? If so, this looks like a bug so please post this to our bug tracker. Dot not forget to mention the SDCC version you're using.
Regards, Maarten > Hi. > > I can't use static variables inside functions or I get "Error: <r> > relocation 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 initializing with a > value: > > void communications_controller (void) > { > static uint16_t ui16_battery_current_accumulated = 100; > > 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 > ebike_app.c:315: warning 156: symbol name too long, truncated to 64 chars > 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$ > > > Now without value initialization: > > void communications_controller (void) > { > static uint16_t ui16_battery_current_accumulated; > > 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. > sdcc -IStdPeriphLib/inc -I. -mstm8 -Ddouble=float --std-c99 --nolospre > --out-fmt-elf --debug main.c StdPeriphLib/src/stm8s_itc.rel > StdPeriphLib/src/stm8s_clk.rel StdPeriphLib/src/stm8s_iwdg.rel > StdPeriphLib/src/stm8s_gpio.rel StdPeriphLib/src/stm8s_exti.rel > StdPeriphLib/src/stm8s_uart2.rel StdPeriphLib/src/stm8s_tim1.rel > StdPeriphLib/src/stm8s_tim2.rel StdPeriphLib/src/stm8s_adc1.rel > StdPeriphLib/src/stm8s_flash.rel watchdog.rel gpio.rel utils.rel uart.rel > adc.rel brake.rel pas.rel wheel_speed_sensor.rel timers.rel pwm.rel > eeprom.rel motor.rel ebike_app.rel > main.c:131: warning 126: unreachable code > stm8-size main.elf -A > main.elf : > section size addr > DATA 109 1 > INITIALIZED 335 110 > SSEG 1 4294967295 > HOME 99 32768 > GSINIT 26 32867 > GSFINAL 3 32893 > CODE 18289 32896 > INITIALIZER 335 51185 > .debug_line 24248 0 > .debug_loc 22308 0 > .debug_abbrev 2738 0 > .debug_info 35791 0 > .debug_pubnames 11646 0 > .debug_frame 22693 0 > Total 138621 > > > stm8-objcopy -O binary -R DATA -R INITIALIZED -R SSEG -R .debug_line -R > .debug_loc -R .debug_abbrev -R .debug_info -R .debug_pubnames -R > .debug_frame main.elf main.bin > cas@ubuntu > :~/OpenSource-EBike-firmware/BMSBattery_S_controllers_firmware/firmware$ > > Regards > Jorge Pinto ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user