Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1 | //===-- ShadowStackGC.cpp - GC support for uncooperative targets ----------===// |
Gordon Henriksen | 8fa8929 | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements lowering for the llvm.gc* intrinsics for targets that do |
| 11 | // not natively support them (which includes the C backend). Note that the code |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 12 | // generated is not quite as efficient as algorithms which generate stack maps |
Gordon Henriksen | 8fa8929 | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 13 | // to identify roots. |
| 14 | // |
| 15 | // This pass implements the code transformation described in this paper: |
| 16 | // "Accurate Garbage Collection in an Uncooperative Environment" |
| 17 | // Fergus Henderson, ISMM, 2002 |
| 18 | // |
| 19 | // In runtime/GC/SemiSpace.cpp is a prototype runtime which is compatible with |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 20 | // ShadowStackGC. |
Gordon Henriksen | 8fa8929 | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 21 | // |
| 22 | // In order to support this particular transformation, all stack roots are |
| 23 | // coallocated in the stack. This allows a fully target-independent stack map |
| 24 | // while introducing only minor runtime overhead. |
| 25 | // |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Chandler Carruth | d04a8d4 | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/GCs.h" |
| 29 | #include "llvm/ADT/StringExtras.h" |
| 30 | #include "llvm/CodeGen/GCStrategy.h" |
Stephen Hines | 36b5688 | 2014-04-23 16:57:46 -0700 | [diff] [blame] | 31 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | 0b8c9a8 | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 32 | #include "llvm/IR/IRBuilder.h" |
| 33 | #include "llvm/IR/IntrinsicInst.h" |
| 34 | #include "llvm/IR/Module.h" |
Gordon Henriksen | 8fa8929 | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 35 | |
| 36 | using namespace llvm; |
| 37 | |
Stephen Hines | dce4a40 | 2014-05-29 02:49:00 -0700 | [diff] [blame] | 38 | #define DEBUG_TYPE "shadowstackgc" |
| 39 | |
Gordon Henriksen | 8fa8929 | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 40 | namespace { |
Stephen Hines | ebe69fe | 2015-03-23 12:10:34 -0700 | [diff] [blame^] | 41 | class ShadowStackGC : public GCStrategy { |
| 42 | public: |
| 43 | ShadowStackGC(); |
| 44 | }; |
Dan Gohman | 844731a | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 45 | } |
Mikhail Glushenkov | 5c1799b | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 46 | |
Gordon Henriksen | 5eca075 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 47 | static GCRegistry::Add<ShadowStackGC> |
Stephen Hines | ebe69fe | 2015-03-23 12:10:34 -0700 | [diff] [blame^] | 48 | X("shadow-stack", "Very portable GC for uncooperative code generators"); |
Mikhail Glushenkov | 5c1799b | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 49 | |
Stephen Hines | ebe69fe | 2015-03-23 12:10:34 -0700 | [diff] [blame^] | 50 | void llvm::linkShadowStackGC() {} |
Mikhail Glushenkov | 5c1799b | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 51 | |
Stephen Hines | ebe69fe | 2015-03-23 12:10:34 -0700 | [diff] [blame^] | 52 | ShadowStackGC::ShadowStackGC() { |
Gordon Henriksen | 8fa8929 | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 53 | InitRoots = true; |
| 54 | CustomRoots = true; |
| 55 | } |