Skip to main content
Katzenberger.Michael
Associate III
Dec 26, 2020 11:38 AM UTC
Solved

elf parser seems not working properly

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.
stephane.legargeant
ST Employee
Jan 4, 2021 9:50 AM UTC

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

3 replies

stephane.legargeant
ST Employee
Jan 4, 2021 9:50 AM UTC

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
Jan 4, 2021 10:08 AM UTC

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 Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Katzenberger.Michael
Associate III
Jan 4, 2021 10:32 AM UTC

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