<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">HI Mats,</div><br class=""><div><blockquote type="cite" class=""><div class="">On 22 Feb 2016, at 16:48, mats petersson <<a href="mailto:mats@planetcatfish.com" class="">mats@planetcatfish.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html; charset=utf-8" class=""><div dir="ltr" class=""><div class=""><div class="">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"? <br class=""></div></div></div></div></blockquote><div><br class=""></div><div>Exactly and I want to chose this once the compilation is over.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="">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. <br class=""></div></div></div></div></blockquote><div><br class=""></div><div>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.</div><div><br class=""></div><div>So normally, you still have to pass theses values to the post-processing in order to compute the hash.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="">How are you dealing with the fact that code gets relocated during loading?<br class=""></div></div></div></div></blockquote><div><br class=""></div><div>You talk about the loading phase during the link? If yes, this is why a do the post-processing after the link.</div><div><br class=""></div><div>If you talk about something like the -fpie parameter, I used a small trick.</div><div><br class=""></div><div>The function who will call isModified will calculate the offset dynamically.</div><div><br class=""></div><div>To do this, you get the address in IR (in C++ this is like <b class="">(uint64_t)std::addressof(main);</b>) and I remove a constant value.</div><div><br class=""></div><div>During the post-processing (again) I will update this constant value with the address into the binary.</div><div><br class=""></div><div>This will give you an offset and you used it to update the addresses.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">[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?].<br class=""></div></div></div></blockquote><div><br class=""></div><div>For now, I store it into an special place.</div><div><br class=""></div><div>My first solution for my problem was to used some temporary file but this is highly impractical.</div><div><br class=""></div><div>Maybe I can create a temporary section into the binary but I didn’t find a lot of information about it.</div><span class=""></span><span class=""><div><span class=""><br class=""></span></div>Thanks,</span></div><div><span class=""><br class=""></span></div><div><span class="">Johan<br class=""></span><span class=""><br class=""></span><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="">--<br class=""></div>Mats<br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On 22 February 2016 at 14:45, Wehrli Johan <span dir="ltr" class=""><<a href="mailto:johan.wehrli@heig-vd.ch" target="_blank" class="">johan.wehrli@heig-vd.ch</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">I will try to explain better what I do.</div><div class=""><br class=""></div><div class="">The main goal behind this is to verify that a part of code is not modified by someone else (it is an integrity check).</div><div class=""><br class=""></div><div class="">To do this, I create in IR a function who take 2 parameters, a begin and an end value.</div><div class=""><br class=""></div><div class="">This function perform an hash over the code area (from begin to end) and return it.</div><div class=""><br class=""></div><div class="">At first, I don’t know the addresses and the hash value so I put random value (it is an integer 64 bits).</div><div class=""><br class=""></div><div class="">The function look like<b class=""> uint32_t isModified(uint64_t* begin, uint64_t* end). </b></div><div class=""><br class=""></div><div class="">Once the compilation is over, I need to update the begin address, end address and the hash value.</div><div class=""><br class=""></div><div class="">When I say the compilation is over, I mean the clang driver has finished all of his action (compiling, linking, etc.).</div><div class=""><br class=""></div><div class="">Greetings,</div><div class=""><br class=""></div><div class="">Johan</div><div class=""><div class="h5"><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 22 Feb 2016, at 15:04, mats petersson <<a href="mailto:mats@planetcatfish.com" target="_blank" class="">mats@planetcatfish.com</a>> wrote:</div><br class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><div class="">What kind of constant: type, value and how is it created?<br class=""><br class=""></div>You can make public symbols that you can extract in a linker script to a special section.<br class=""><br class=""></div>Or perhaps you want some metadata that a special late state (machine instr) pass is extracting and adding. <br class=""><br class=""></div><div class="">The "best" solution really depends on what you are trying to achieve overall and what kind of data you are working with.<br class=""></div><div class=""><br class="">--<br class=""></div>Mats<br class=""></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On 22 February 2016 at 13:04, Wehrli Johan via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br class="">
<br class="">
I want to know if it is possible to pass information from IR to the final binary (like a constant value)?<br class="">
<br class="">
I have a module pass in IR who make some transformation and, once the compilation is finished, I need to apply a post-processing.<br class="">
<br class="">
The post-processing need information from the IR part.<br class="">
<br class="">
Greetings,<br class="">
<br class="">
Johan<br class="">
<br class="">
<br class="">
<br class="">_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></body></html>