Skip to main content
Katzenberger.Michael
Associate III
December 26, 2020
Solved

elf parser seems not working properly

  • December 26, 2020
  • 2 replies
  • 1493 views

After loading the elf file variables are detected incorrect (wrong address an/or size)

Two examples with output of readelf

1) used in *.c file:

uint8_t counter_error_handler __attribute__((section(".internal_ram")));

> readelf Bluepill_USB_CDC.elf -s |grep error
 1374: 20002e28 1 OBJECT GLOBAL DEFAULT 9 counter_error_handler

2) used in *.cpp file:

static uint16_t blink_period;

> readelf Bluepill_USB_CDC.elf -a |grep blink
 389: 2000052c 2 OBJECT LOCAL DEFAULT 8 _ZL12blink_period

in STM32CubeMonitor these variables are listed with incorrect address and size (blink_period) and incorrect address (counter_error_handler)

0693W000006GuTKQA0.png 

Is this an issue of using a c/cpp project ?

This topic has been closed for replies.
Best answer by stephane.legargeant

Hello Michael

This is quite strange. I am surprised by the result shown.

  • For the _ZL12blink_period, in the readelf, it is shown LOCAL, so it may be not visible, but we see another similar one. Can you tell me how is declared this symbol? The "blink_period" listed 0x20000124 seems to be different. Can you check if there is global declaration for this symbol ?
  • For the counter_error_handler, there is an offset of 2 bytes, which is very strange. Are you sure that file used for readelf and in STM32CubeMonitor are exactly the same ? (This offset happen most of the time when a variable is added and elf file is not updated)

Best regards

Stephane

2 replies

stephane.legargeant
ST Employee
January 4, 2021

Hello Michael

This is quite strange. I am surprised by the result shown.

  • For the _ZL12blink_period, in the readelf, it is shown LOCAL, so it may be not visible, but we see another similar one. Can you tell me how is declared this symbol? The "blink_period" listed 0x20000124 seems to be different. Can you check if there is global declaration for this symbol ?
  • For the counter_error_handler, there is an offset of 2 bytes, which is very strange. Are you sure that file used for readelf and in STM32CubeMonitor are exactly the same ? (This offset happen most of the time when a variable is added and elf file is not updated)

Best regards

Stephane

Tesla DeLorean
Guru
January 4, 2021

A contemporary .MAP file might be definitive.

G​enerally I'd have more confidence in the Linker than the average ELF parser.

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Katzenberger.Michael
Associate III
January 4, 2021

Hi Stephane,

thanks for your feedback.

According to your notes I've tried to reproduce the issue with a clean build. But I can't ;)

The addresses and sizes are now correct. Don't know whats going wrong the first time - therefore sorry for any confusion ...

0693W000006HOL1QAO.png

> readelf Bluepill_USB_CDC.elf -s | grep blink
 343: 200002bc 2 OBJECT LOCAL DEFAULT 7 _ZL12blink_period
> readelf Bluepill_USB_CDC.elf -s | grep error
 1208: 20002b60 1 OBJECT GLOBAL DEFAULT 8 counter_error_handler

Best regards,

Michel