public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Linker won't bail out on non-existing functions?
@ 2020-09-04 10:18 Josef Wolf
  2020-09-04 11:45 ` Alexander Monakov
  0 siblings, 1 reply; 3+ messages in thread
From: Josef Wolf @ 2020-09-04 10:18 UTC (permalink / raw)
  To: gcc-help

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Linker won't bail out on non-existing functions?
  2020-09-04 10:18 Linker won't bail out on non-existing functions? Josef Wolf
@ 2020-09-04 11:45 ` Alexander Monakov
  2020-09-04 12:56   ` Josef Wolf
  0 siblings, 1 reply; 3+ messages in thread
From: Alexander Monakov @ 2020-09-04 11:45 UTC (permalink / raw)
  To: Josef Wolf; +Cc: gcc-help

On Fri, 4 Sep 2020, Josef Wolf wrote:

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

You're linking with --gc-sections, and if all references to undefined functions
are in discarded sections, the linker won't complain. In other words, checking
for remaining undefined references happens after discarding unneeded sections.

Alexander

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Linker won't bail out on non-existing functions?
  2020-09-04 11:45 ` Alexander Monakov
@ 2020-09-04 12:56   ` Josef Wolf
  0 siblings, 0 replies; 3+ messages in thread
From: Josef Wolf @ 2020-09-04 12:56 UTC (permalink / raw)
  To: gcc-help

On Fri, Sep 04, 2020 at 02:45:04PM +0300, Alexander Monakov wrote:
> On Fri, 4 Sep 2020, Josef Wolf wrote:
> 
> > So why won't the linker bail out when it can't resolve a reference?
> > Any hints?
> 
> You're linking with --gc-sections, and if all references to undefined functions
> are in discarded sections, the linker won't complain. In other words, checking
> for remaining undefined references happens after discarding unneeded sections.

Thanks for the hint, Alexander!

the problem was that this function was used in a different task which was not
instantiated yet. =8-O

-- 
Josef Wolf
jw@raven.inka.de

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-09-04 13:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-04 10:18 Linker won't bail out on non-existing functions? Josef Wolf
2020-09-04 11:45 ` Alexander Monakov
2020-09-04 12:56   ` Josef Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).