Linker Bug?!?

bkgoodman
Posts: 45
Joined: Fri Feb 17, 2017 12:41 pm

Linker Bug?!?

Postby bkgoodman » Sat Jul 08, 2023 7:04 pm

LOTS of debugging of random crashes - boils down to this:

My Code:

Code: Select all

#define RC_CHANNELS 6
unsigned long rc_val[RC_CHANNELS];
When I do:

Code: Select all

ESP_LOGE(TAG,"rc_val ptr is at %p size is %d",rc_val,sizeof(rc_val));
As you might expect - it tells me:

Code: Select all

E (1972) CouchLED: rc_val ptr is at 0x3ffb2a84 size is 24
(Because 6x 32-bit "longs" of 4 bytes each should be 24 bytes total)
Problem was - when I was writing into indexes above "3" on this map, a buffer pointer started experiences corruption. So I look at the memory map and it tells me:

Code: Select all

.bss.rc_val    0x000000003ffb2a84        0x2 esp-idf/neopixel/libneopixel.a(neopixel.c.obj)
                0x000000003ffb2a84                rc_val
 *fill*         0x000000003ffb2a86        0x2
 .bss.used_channels
                0x000000003ffb2a88        0x8 esp-idf/neopixel/libneopixel.a(neopixel.c.obj)
 .bss.savebuf   0x000000003ffb2a90        0x4 esp-idf/neopixel/libneopixel.a(neopixel.c.obj)
 .bss.neopixel_buffer
                0x000000003ffb2a94        0x4 esp-idf/neopixel/libneopixel.a(neopixel.c.obj)
(i.e. rc_val is right before savebuf but they are only 12 bytes apart. i.e. When I write to rc_val[3] - it corrupts savebuf).
Is it my - or is this this a legit linker issue?!?!?!?!

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Linker Bug?!?

Postby ESP_igrr » Sat Jul 08, 2023 9:06 pm

Hi bkgoodman,

I would recommend checking the size of this variable in the object file (neopixel.c.obj).
If the size there is same as you see in the map file (2 bytes) then you have to troubleshoot what happens at the compilation stage.

If the size there is 24 bytes, then possibly the issue is at linking stage. For example, this could occur if a "common" (non-extern, non-static) symbol is defined with the same name but different sizes in different translation units. In recent versions of IDF we do have a warning about common symbols enabled by default, though.

bkgoodman
Posts: 45
Joined: Fri Feb 17, 2017 12:41 pm

Re: Linker Bug?!?

Postby bkgoodman » Sun Jul 09, 2023 10:05 am

That was totally it! Thanks!

Who is online

Users browsing this forum: No registered users and 305 guests