Skip to content

Commit d225996

Browse files
committed
[𝘀𝗽𝗿] initial version
Created using spr 1.3.8-beta.1
1 parent a1bfa2f commit d225996

File tree

27 files changed

+969
-3
lines changed

27 files changed

+969
-3
lines changed

llvm/docs/LangRef.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,6 +2427,9 @@ For example:
24272427
if the attributed function is called during invocation of a function
24282428
attributed with ``sanitize_realtime``.
24292429
This attribute is incompatible with the ``sanitize_realtime`` attribute.
2430+
``sanitize_alloc_token``
2431+
This attributes indicates that implicit allocation token instrumentation
2432+
is enabled for this function.
24302433
``speculative_load_hardening``
24312434
This attribute indicates that
24322435
`Speculative Load Hardening <https://llvm.org/docs/SpeculativeLoadHardening.html>`_

llvm/docs/ReleaseNotes.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,10 @@ Changes to Sanitizers
166166
Other Changes
167167
-------------
168168

169+
* Introduces the `AllocToken` pass, an instrumentation pass designed to provide
170+
tokens to memory allocators enabling various heap organization strategies,
171+
such as heap partitioning.
172+
169173
External Open Source Projects Using LLVM {{env.config.release}}
170174
===============================================================
171175

llvm/include/llvm/Bitcode/LLVMBitCodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,7 @@ enum AttributeKindCodes {
800800
ATTR_KIND_SANITIZE_TYPE = 101,
801801
ATTR_KIND_CAPTURES = 102,
802802
ATTR_KIND_DEAD_ON_RETURN = 103,
803+
ATTR_KIND_SANITIZE_ALLOC_TOKEN = 104,
803804
};
804805

805806
enum ComdatSelectionKindCodes {

llvm/include/llvm/IR/Attributes.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ def SanitizeRealtime : EnumAttr<"sanitize_realtime", IntersectPreserve, [FnAttr]
342342
/// during a real-time sanitized function (see `sanitize_realtime`).
343343
def SanitizeRealtimeBlocking : EnumAttr<"sanitize_realtime_blocking", IntersectPreserve, [FnAttr]>;
344344

345+
/// Allocation token instrumentation is on.
346+
def SanitizeAllocToken : EnumAttr<"sanitize_alloc_token", IntersectPreserve, [FnAttr]>;
347+
345348
/// Speculative Load Hardening is enabled.
346349
///
347350
/// Note that this uses the default compatibility (always compatible during
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//===- AllocToken.h - Allocation token instrumentation --------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This file declares the AllocTokenPass, an instrumentation pass that
10+
// replaces allocation calls with ones including an allocation token.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_TRANSFORMS_INSTRUMENTATION_ALLOCTOKEN_H
15+
#define LLVM_TRANSFORMS_INSTRUMENTATION_ALLOCTOKEN_H
16+
17+
#include "llvm/IR/Analysis.h"
18+
#include "llvm/IR/PassManager.h"
19+
#include <optional>
20+
21+
namespace llvm {
22+
23+
class Module;
24+
25+
struct AllocTokenOptions {
26+
std::optional<uint64_t> MaxTokens;
27+
bool FastABI = false;
28+
bool Extended = false;
29+
AllocTokenOptions() = default;
30+
};
31+
32+
/// A module pass that rewrites heap allocations to use token-enabled
33+
/// allocation functions based on various source-level properties.
34+
class AllocTokenPass : public PassInfoMixin<AllocTokenPass> {
35+
public:
36+
LLVM_ABI explicit AllocTokenPass(AllocTokenOptions Opts = {});
37+
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM);
38+
static bool isRequired() { return true; }
39+
40+
private:
41+
const AllocTokenOptions Options;
42+
};
43+
44+
} // namespace llvm
45+
46+
#endif // LLVM_TRANSFORMS_INSTRUMENTATION_ALLOCTOKEN_H

llvm/lib/Bitcode/Reader/BitcodeReader.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,6 +2203,8 @@ static Attribute::AttrKind getAttrFromCode(uint64_t Code) {
22032203
return Attribute::SanitizeRealtime;
22042204
case bitc::ATTR_KIND_SANITIZE_REALTIME_BLOCKING:
22052205
return Attribute::SanitizeRealtimeBlocking;
2206+
case bitc::ATTR_KIND_SANITIZE_ALLOC_TOKEN:
2207+
return Attribute::SanitizeAllocToken;
22062208
case bitc::ATTR_KIND_SPECULATIVE_LOAD_HARDENING:
22072209
return Attribute::SpeculativeLoadHardening;
22082210
case bitc::ATTR_KIND_SWIFT_ERROR:

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,8 @@ static uint64_t getAttrKindEncoding(Attribute::AttrKind Kind) {
883883
return bitc::ATTR_KIND_STRUCT_RET;
884884
case Attribute::SanitizeAddress:
885885
return bitc::ATTR_KIND_SANITIZE_ADDRESS;
886+
case Attribute::SanitizeAllocToken:
887+
return bitc::ATTR_KIND_SANITIZE_ALLOC_TOKEN;
886888
case Attribute::SanitizeHWAddress:
887889
return bitc::ATTR_KIND_SANITIZE_HWADDRESS;
888890
case Attribute::SanitizeThread:

llvm/lib/Passes/PassBuilder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
#include "llvm/Transforms/IPO/WholeProgramDevirt.h"
238238
#include "llvm/Transforms/InstCombine/InstCombine.h"
239239
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
240+
#include "llvm/Transforms/Instrumentation/AllocToken.h"
240241
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
241242
#include "llvm/Transforms/Instrumentation/CGProfile.h"
242243
#include "llvm/Transforms/Instrumentation/ControlHeightReduction.h"

llvm/lib/Passes/PassRegistry.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ MODULE_PASS("openmp-opt", OpenMPOptPass())
124124
MODULE_PASS("openmp-opt-postlink",
125125
OpenMPOptPass(ThinOrFullLTOPhase::FullLTOPostLink))
126126
MODULE_PASS("partial-inliner", PartialInlinerPass())
127+
MODULE_PASS("alloc-token", AllocTokenPass())
127128
MODULE_PASS("pgo-icall-prom", PGOIndirectCallPromotion())
128129
MODULE_PASS("pgo-instr-gen", PGOInstrumentationGen())
129130
MODULE_PASS("pgo-instr-use", PGOInstrumentationUse())

0 commit comments

Comments
 (0)