Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 1 | //===-- ShadowStackGC.cpp - GC support for uncooperative targets ----------===// |
Gordon Henriksen | 6047b6e | 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 | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 12 | // generated is not quite as efficient as algorithms which generate stack maps |
Gordon Henriksen | 6047b6e | 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 | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 20 | // ShadowStackGC. |
Gordon Henriksen | 6047b6e | 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 | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/GCs.h" |
Philip Reames | 56a0393 | 2015-01-26 18:26:35 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/GCStrategy.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 30 | #include "llvm/ADT/StringExtras.h" |
Chandler Carruth | 219b89b | 2014-03-04 11:01:28 +0000 | [diff] [blame] | 31 | #include "llvm/IR/CallSite.h" |
Chandler Carruth | 9fb823b | 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 | 6047b6e | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 35 | |
| 36 | using namespace llvm; |
| 37 | |
Chandler Carruth | 1b9dde0 | 2014-04-22 02:02:50 +0000 | [diff] [blame] | 38 | #define DEBUG_TYPE "shadowstackgc" |
| 39 | |
Gordon Henriksen | 6047b6e | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 40 | namespace { |
Philip Reames | 3631953 | 2015-01-16 23:16:12 +0000 | [diff] [blame] | 41 | class ShadowStackGC : public GCStrategy { |
Philip Reames | 3631953 | 2015-01-16 23:16:12 +0000 | [diff] [blame] | 42 | public: |
| 43 | ShadowStackGC(); |
Philip Reames | 3631953 | 2015-01-16 23:16:12 +0000 | [diff] [blame] | 44 | }; |
Dan Gohman | d78c400 | 2008-05-13 00:00:25 +0000 | [diff] [blame] | 45 | } |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 46 | |
Gordon Henriksen | d930f91 | 2008-08-17 18:44:35 +0000 | [diff] [blame] | 47 | static GCRegistry::Add<ShadowStackGC> |
Philip Reames | 3631953 | 2015-01-16 23:16:12 +0000 | [diff] [blame] | 48 | X("shadow-stack", "Very portable GC for uncooperative code generators"); |
Mikhail Glushenkov | b2f9a73 | 2009-01-16 06:53:46 +0000 | [diff] [blame] | 49 | |
Philip Reames | 3631953 | 2015-01-16 23:16:12 +0000 | [diff] [blame] | 50 | void llvm::linkShadowStackGC() {} |
Gordon Henriksen | 6047b6e | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 51 | |
Philip Reames | 23cf2e2 | 2015-01-28 19:28:03 +0000 | [diff] [blame] | 52 | ShadowStackGC::ShadowStackGC() { |
Gordon Henriksen | 6047b6e | 2008-01-07 01:30:53 +0000 | [diff] [blame] | 53 | InitRoots = true; |
| 54 | CustomRoots = true; |
| 55 | } |