Linker won't bail out on non-existing functions?

Josef Wolf jw@raven.inka.de
Fri Sep 4 10:18:35 GMT 2020


Hello,

I have an effect here which is somewhat surprising to me. The linker won't
complain on non-defined functions. There's only a warning at compile-time
about missing prototype. When I try to set a breakpoint in gdb, gdb
complains that the function is not defined:

  (gdb) break delay_ms
  Function "delay_ms" not defined.
  Make breakpoint pending on future shared library load? (y or [n]) n
  (gdb)

But this is on an embedded system, statically built. There's even an
explicit "-Wl,-Bstatic" and ldd confirms that this is not a shared
library (please see below)

BTW: There's nothing special about this function name. I tried really wired
function names with the same effect. So it's not that this function might
be defined internally somehow.

So why won't the linker bail out when it can't resolve a reference?
Any hints?


/usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-gcc -c -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -DUSE_HAL_DRIVER -DSTM32F429xx -Icubemx/Core/Inc -Icubemx/Drivers/STM32F4xx_HAL_Driver/Inc -Icubemx/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -Icubemx/Drivers/CMSIS/Device/ST/STM32F4xx/Include -Icubemx/Drivers/CMSIS/Include -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/include -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2 -Icubemx/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F -O3 -std=c99 -pedantic -Wall -fdata-sections -ffunction-sections -g -gdwarf-2 -MMD -MP -MF"app/blinkenlight.d" -Wa,-a,-ad,-alms=build/blinkenlight.lst app/blinkenlight.c -o app/blinkenlight.o
app/blinkenlight.c: In function 'blinkenlight':
app/blinkenlight.c:41:9: warning: implicit declaration of function 'delay_ms' [-Wimplicit-function-declaration]
   41 |         delay_ms (uval&1 ? ld->ms_on : ld->ms_off);
      |         ^~~~~~~~
/usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-gcc cubemx/Core/Src/main.o cubemx/Core/Src/stm32f4xx_it.o cubemx/Core/Src/stm32f4xx_hal_msp.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.o cubemx/Core/Src/system_stm32f4xx.o cubemx/Core/Src/gpio.o cubemx/Core/Src/usart.o cubemx/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.o cubemx/Core/Src/freertos.o cubemx/Core/Src/stm32f4xx_hal_timebase_tim.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/croutine.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/event_groups.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/list.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/queue.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/stream_buffer.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/tasks.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/timers.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS_V2/cmsis_os2.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/portable/MemMang/heap_4.o cubemx/Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/port.o app/blinkenlight.o cubemx/startup_stm32f429xx.s -mcpu=cortex-m4 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=hard -Tcubemx/STM32F429BITx_FLASH.ld  -lc -lm -lnosys  -Wl,-Map=build/cubemx.map,--cref -Wl,--gc-sections,-Bstatic -o build/cubemx.elf
/usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-size build/cubemx.elf
   text    data     bss     dec     hex filename
  15084      24   20480   35588    8b04 build/cubemx.elf
/usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-objcopy -O ihex build/cubemx.elf build/cubemx.hex
/usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-objcopy -O binary -S build/cubemx.elf build/cubemx.bin
jw@bu201:/m/s/rep/git/test/src$ LANG= ldd build/cubemx.elf
   not a dynamic executable
jw@bu201:/m/s/rep/git/test/src$

-- 
Josef Wolf
jw@raven.inka.de


More information about the Gcc-help mailing list