[PATCH] D37597: [ubsan] Function Sanitizer: Don't require writable text segments
Peter Collingbourne via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 7 15:56:31 PDT 2017
pcc added a comment.
Thanks. Once we apply this fix to other platforms this would seem to fix PR17633.
We may also want to change the ubsan function signature in order to avoid bad pointer reads in case of version mismatches.
================
Comment at: lib/CodeGen/CodeGenFunction.cpp:434
+ llvm::Constant *Addr) {
+ if (!CGM.getTriple().isOSDarwin())
+ return Addr;
----------------
I think you can just do this unconditionally. As far as I know, all three object formats should support 32-bit relative relocations on x86 and x86_64, which are the only two architectures which currently support `-fsanitize=function`.
================
Comment at: lib/CodeGen/CodeGenFunction.cpp:445
+ auto *GV = new llvm::GlobalVariable(CGM.getModule(), Addr->getType(),
+ /*isConstant=*/false,
+ llvm::GlobalValue::PrivateLinkage, Addr);
----------------
This can be constant I think.
================
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");
----------------
Maybe use `Int32Ty` (here and below). That should be sufficient under the small code model.
https://reviews.llvm.org/D37597
More information about the cfe-commits
mailing list