[llvm-dev] [HELP] Segfault on printing out structure elements

Sunghyun Park via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 1 08:22:22 PDT 2017


Hi, all.
I'm a graduate student working on creating llvm pass that generates
resilient version of code automatically.
Basically, what it does is to duplicate instructions and compare them at
the synchronization points, such as function call, branch. Plus, there is
one more copy for recovery. So if two copies agree, program will proceed
with original copy, or otherwise it will use the third copy as corrected
one. It looks like below.
e.g.
$inst1 = add $1, $2
$inst2 = add $3, $4
$inst3 = add $5, $6
$cmp = icmp $inst1, $inst2
$corrected = sel $cmp, $inst1, $inst3
printf $corrected //very simplified form

Everything was going fine, but now I'm stuck at a weird bug that I cannot
quite understand.
If the instructions to be copied are accessing structure elements and they
are printed out by printf or fprintf(like example above except it does not
access structure), it occurs segfault at runtime even though they are legit
memory access.

* Here's more clarification for my situation.
- It compiles successfully.
- If I commented out 'printf' or 'fprintf' from the source code, the
program works fine. So it seems like there's a problem on this part.
- For other printf with corrected value, they works fine if they are not
accessing structure element.


Error msg and comparison between original code and transformed code by my
pass are attached below. I tried to make it shown here but the size wasn't
fit.

Is there anyone who had same problem or have any idea/guess/hint for me?
Thank you in advance!


-- 
Best, Sung
​
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170801/e5baa589/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: cfgs.png
Type: image/png
Size: 208458 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170801/e5baa589/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: error_msg
Type: application/octet-stream
Size: 211586 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170801/e5baa589/attachment-0001.obj>


More information about the llvm-dev mailing list