2
0

ShadowStackGC.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //===-- ShadowStackGC.cpp - GC support for uncooperative targets ----------===//
  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
  12. // generated is not quite as efficient as algorithms which generate stack maps
  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
  20. // ShadowStackGC.
  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. #include "llvm/CodeGen/GCs.h"
  28. #include "llvm/ADT/StringExtras.h"
  29. #include "llvm/CodeGen/GCStrategy.h"
  30. #include "llvm/IR/CallSite.h"
  31. #include "llvm/IR/IRBuilder.h"
  32. #include "llvm/IR/IntrinsicInst.h"
  33. #include "llvm/IR/Module.h"
  34. using namespace llvm;
  35. #define DEBUG_TYPE "shadowstackgc"
  36. namespace {
  37. class ShadowStackGC : public GCStrategy {
  38. public:
  39. ShadowStackGC();
  40. };
  41. }
  42. static GCRegistry::Add<ShadowStackGC>
  43. X("shadow-stack", "Very portable GC for uncooperative code generators");
  44. void llvm::linkShadowStackGC() {}
  45. ShadowStackGC::ShadowStackGC() {
  46. InitRoots = true;
  47. CustomRoots = true;
  48. }