fungos / cr

cr.h: A Simple C Hot Reload Header-only Library
https://fungos.github.io/cr-simple-c-hot-reload/
MIT License
1.54k stars 101 forks source link

Bug: Elf relocation #32

Open septag opened 5 years ago

septag commented 5 years ago

On linux (elf), when we define a new .section add assign some variables to it, the .state section data gets mangled. I couldn't solve it yet, because I don't have enough knowledge on elf format and how the code accesses section data pointers. But I suspect that there must a bug within cr_elf_validate_sections where we fetch the pointer to section's data. For example, if we define a new variable:

__attribute__((section(".test"))) int test;

the .state data seems to be overwritten with zeros by 4 bytes I may do more investigations and keep you posted

fungos commented 5 years ago

This can be some alignment issue. The new section may have caused .state to misalign or something similar. It would be nice to add this case in our tests, testing that it is broken and then another time we can fix for real and make sure we cover this case.

Unfortunately I'll not have much time to help on this for some time, in the meantime, if you get it fixed it will be awesome!

septag commented 5 years ago

Ok, I'll try to fix the issue but my knowledge from ELF is lacking and the vague api documentation doesn't help either.