[PATCH] D37597: [ubsan] Function Sanitizer: Don't require writable text segments

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 12 12:15:59 PDT 2017


vsk added inline comments.


================
Comment at: lib/CodeGen/CodeGenFunction.cpp:463
+  auto *PCRelAsInt =
+      Builder.CreatePtrToInt(EncodedAddr, IntPtrTy, "encoded_addr.int");
+  auto *FuncAsInt = Builder.CreatePtrToInt(F, IntPtrTy, "func_addr.int");
----------------
vsk wrote:
> pcc wrote:
> > pcc wrote:
> > > Maybe use `Int32Ty` (here and below). That should be sufficient under the small code model.
> > Sorry, I meant that the difference could be truncated to `Int32Ty`, and stored as an integer, not a pointer.
> I tried this out but it resulted in a mysterious dyld crash after the indirect callee returns, which I've yet to understand. I'll have to try using a Debug build of dyld to see what's happening.
@pcc It turned out that the jump we encode in getUBSanFunctionSignature not correct if we truncate a 64-bit address to a 32-bit address. If we jump to +8 instead of +12, we can make the truncation work :). There is no dyld bug.

That said, I think we should store the pc-rel address as an IntPtrTy to keep things a bit simpler. We could avoid logic to truncate/sign-extend conditionally, and not emit those instructions at all. Wdyt?


https://reviews.llvm.org/D37597





More information about the cfe-commits mailing list