This is an archive of the discontinued LLVM Phabricator instance.

Expose llvm::linkShadowStackGC() via C bindings
Needs ReviewPublic

Authored by mjsabby on Apr 1 2015, 3:31 PM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

An LLVMSharp user filed a bug report (https://github.com/mjsabby/LLVMSharp/issues/3) that using the library they were unable to call SetGC("shadow-stack") on a function and then subsequently ask MCJIT to finalize the object containing the function.

They also created an LLVM bug report (https://llvm.org/bugs/show_bug.cgi?id=23095) that demonstrates the problem.

I have investigated the root cause for this and it is because LLVMSharp and other C binding users do not have access to llvm::linkShadowStackGC (in addition to other GCs defined in llvm/include/llvm/CodeGen/GCs.h) which GC clients of the C++ API would need to call in order to successfully complete this scenario.

I'm proposing to expose LLVMLinkShadowStackGC via the C bindings. The ShadowStackGC is very useful functionality that is referenced in the official documentation and likely to be beneficial to many users.

I'm consciously choosing not to link other GCs, but maybe I should? Let me know as part of the review feedback if I should also expose other GCs (currently StatepointExample, Erlang, and Ocaml)

Diff Detail

Repository
rL LLVM

Event Timeline

mjsabby updated this revision to Diff 23092.Apr 1 2015, 3:31 PM
mjsabby retitled this revision from to Expose llvm::linkShadowStackGC() via C bindings.
mjsabby updated this object.
mjsabby edited the test plan for this revision. (Show Details)
mjsabby added a reviewer: reames.
mjsabby set the repository for this revision to rL LLVM.
mjsabby added a subscriber: Unknown Object (MLST).
reames edited edge metadata.Apr 3 2015, 10:44 AM

When updating, please include full diff context.

include/llvm-c/Core.h
1928

Two comments:

  • I don't believe this warrants a separate call per built in GC. I would rather see a single LLVMLinkBuiltinGCs().
  • Going one step further, I'm not clear why a separate function is needed at all. I assume there must be a function which is responsible for linking code gen as a whole. Why is this not handled by calling that function? At worst, it seems like we should need to add a call to link the various GCs in that (entirely internal) routine.
lib/IR/Core.cpp
1713

This is the wrong place for this, even if we do need to expose an explicit link routine. Your introducing a dependency between IR and CodeGen which should not exist.

I think this should probably be handled in
void llvm::initializeCodeGen(PassRegistry &Registry) from CodeGen.cpp

reames resigned from this revision.May 5 2015, 3:40 PM
reames removed a reviewer: reames.

Cleaning old stale reviews. Please readd if needed.