<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/54172>54172</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
DataFlowSanitizer custom trampoline functions incompatible with opaque pointers
</td>
</tr>
<tr>
<th>Labels</th>
<td>
opaque-pointers
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nikic
</td>
</tr>
</table>
<pre>
DataFlowSanitizer supports an (apparently undocumented?) feature where function-pointer-typed arguments to functions with custom ABI will be converted into two arguments, one being a trampoline function, and the other the original argument cast to a void pointer. I believe the intention is that the user will then call the trampoline function, while passing the original function, the call arguments, plus any necessary labels, and the trampoline will take care of the necessary __dfsan_arg_tls / __dfsan_retval_tls writes.
Unfortunately, this is incompatible with opaque pointers, because the form of the trampoline is determined based on the function pointer type. I think this is also a bit problematic at a higher level, because pointer types are also arbitrary in C, not just in IR (i.e. you could pass in a callback as `void*` and later cast it, or more problematically, pass it in with one signature and then cast it before the call).
I'm not entirely sure what the right way to resolve this is. My first inclination would be that we should remove this automatic rewrite in instrumentation, and instead provide a helper for invoking callbacks in custom functions in dfsan.h. So you'd do something like `dfsan_call(cb, ...args, ...labels, ret_label)` in the custom function. This might come in the form of a builtin (I'm not sure if it's possible to implement dfsan_call as just C++?)
However, I'm not familiar with dfsan, so I'm not sure whether the above is possible, both on a technical level, and in terms of stability -- is that dfsan interface considered stable?
The alternative I see here would be to do something very sad, like require the frontend to annotate everything with elementtype attributes or some metadata when dfsan is enabled.
cc @aeubanks
cc @pcc who added this functionality in https://reviews.llvm.org/D1503
cc @DerSaidin who has recent DFSan activity
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVstu4zgQ_Br70ojgSHYeBx8yEwSbw152Zs9BS6QsTihSQ1I2vF-_1ZRt2YNZYAHDkWiyu7qrqpnaq-P2lRO_WX_4xs4k848OFMdh8CFFYkeL8omHgYN2yR5pdMo3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