HI Mats,
And you want this for only SOME bits of code, and that’s why you need to have the IR report what sections are “sensitive”?
Exactly and I want to chose this once the compilation is over.
It would be fairly easy if the code you want to check is a normal functions, just store the start address of the function, and the length should be doable too at machine code level, but not IR level. If you want to check only the middle of the function, it’s a bit harder.
Sadly I need to be able to check random part of the code. One of the problem I have is even if a get the address in the IR level, you still need the CRC value.
So normally, you still have to pass theses values to the post-processing in order to compute the hash.
How are you dealing with the fact that code gets relocated during loading?
You talk about the loading phase during the link? If yes, this is why a do the post-processing after the link.
If you talk about something like the -fpie parameter, I used a small trick.
The function who will call isModified will calculate the offset dynamically.
To do this, you get the address in IR (in C++ this is like (uint64_t)std::addressof(main);) and I remove a constant value.
During the post-processing (again) I will update this constant value with the address into the binary.
This will give you an offset and you used it to update the addresses.
[I’m always curious as to how these type of designs cope with someone modifying the checksumming code itself, but that’s another problem - or is this one of these things where the checksum is stored in special hardwareprotected memory?].
For now, I store it into an special place.
My first solution for my problem was to used some temporary file but this is highly impractical.
Maybe I can create a temporary section into the binary but I didn’t find a lot of information about it.
Thanks,
Johan