Skip to content

Commit 7ba5526

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.8-beta.1 [skip ci]
1 parent d5a42a1 commit 7ba5526

File tree

26 files changed

+509
-131
lines changed

26 files changed

+509
-131
lines changed

clang/docs/AllocToken.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ example:
6565
// Instrumented:
6666
ptr = __alloc_token_malloc(size, <token id>);
6767
68-
In addition, it is typically recommended to configure the following:
68+
The following command-line options affect generated token IDs:
6969

7070
* ``-falloc-token-max=<N>``
7171
Configures the maximum number of tokens. No max by default (tokens bounded

clang/docs/ReleaseNotes.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,10 @@ Non-comprehensive list of changes in this release
203203
Currently, the use of ``__builtin_dedup_pack`` is limited to template arguments and base
204204
specifiers, it also must be used within a template context.
205205

206-
- Introduce support for allocation tokens to enable allocator-level heap
207-
organization strategies. A feature to instrument all allocation functions
208-
with a token ID can be enabled via the ``-fsanitize=alloc-token`` flag.
206+
- Introduce support for :doc:`allocation tokens <AllocToken>` to enable
207+
allocator-level heap organization strategies. A feature to instrument all
208+
allocation functions with a token ID can be enabled via the
209+
``-fsanitize=alloc-token`` flag.
209210

210211
New Compiler Flags
211212
------------------

clang/docs/UsersManual.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,13 +2155,11 @@ are listed below.
21552155

21562156
.. option:: -f[no-]sanitize=check1,check2,...
21572157

2158-
Turn on runtime checks for various forms of undefined or suspicious
2159-
behavior.
2158+
Turn on runtime checks or mitigations for various forms of undefined or
2159+
suspicious behavior. These are disabled by default.
21602160

2161-
This option controls whether Clang adds runtime checks for various
2162-
forms of undefined or suspicious behavior, and is disabled by
2163-
default. If a check fails, a diagnostic message is produced at
2164-
runtime explaining the problem. The main checks are:
2161+
The following options enable runtime checks for various forms of undefined
2162+
or suspicious behavior:
21652163

21662164
- .. _opt_fsanitize_address:
21672165

@@ -2194,8 +2192,14 @@ are listed below.
21942192
protection against stack-based memory corruption errors.
21952193
- ``-fsanitize=realtime``: :doc:`RealtimeSanitizer`,
21962194
a real-time safety checker.
2197-
- ``-fsanitize=alloc-token``: :doc:`AllocToken`,
2198-
allocation token instrumentation (requires compatible allocator).
2195+
2196+
The following options enable runtime mitigations for various forms of
2197+
undefined or suspicious behavior:
2198+
2199+
- ``-fsanitize=alloc-token``: Enables :doc:`allocation tokens <AllocToken>`
2200+
for allocator-level heap organization strategies, such as for security
2201+
hardening. It passes type-derived token IDs to a compatible memory
2202+
allocator. Requires linking against a token-aware allocator.
21992203

22002204
There are more fine-grained checks available: see
22012205
the :ref:`list <ubsan-checks>` of specific kinds of

clang/include/clang/Basic/CodeGenOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ class CodeGenOptions : public CodeGenOptionsBase {
447447

448448
std::optional<double> AllowRuntimeCheckSkipHotCutoff;
449449

450-
/// Maximum number of allocation tokens (0 = no max).
450+
/// Maximum number of allocation tokens (0 = no max), nullopt if none set (use
451+
/// pass default).
451452
std::optional<uint64_t> AllocTokenMax;
452453

453454
/// List of backend command-line options for -fembed-bitcode.

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2745,7 +2745,7 @@ defm sanitize_alloc_token_extended : BoolOption<"f", "sanitize-alloc-token-exten
27452745
} // end -f[no-]sanitize* flags
27462746

27472747
def falloc_token_max_EQ : Joined<["-"], "falloc-token-max=">,
2748-
Group<f_Group>, Visibility<[ClangOption, CC1Option, CLOption]>,
2748+
Group<f_Group>, Visibility<[ClangOption, CC1Option]>,
27492749
MetaVarName<"<N>">,
27502750
HelpText<"Limit to maximum N allocation tokens (0 = no max)">;
27512751

clang/include/clang/Driver/SanitizerArgs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "llvm/Option/Arg.h"
1414
#include "llvm/Option/ArgList.h"
1515
#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
16-
#include <optional>
1716
#include <string>
1817
#include <vector>
1918

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,8 +1279,10 @@ void CodeGenFunction::EmitAllocToken(llvm::CallBase *CB, QualType AllocType) {
12791279
PrintingPolicy Policy(CGM.getContext().getLangOpts());
12801280
Policy.SuppressTagKeyword = true;
12811281
Policy.FullyQualifiedName = true;
1282-
std::string TypeName = AllocType.getCanonicalType().getAsString(Policy);
1283-
auto *TypeMDS = llvm::MDString::get(CGM.getLLVMContext(), TypeName);
1282+
SmallString<64> TypeName;
1283+
llvm::raw_svector_ostream TypeNameOS(TypeName);
1284+
AllocType.getCanonicalType().print(TypeNameOS, Policy);
1285+
auto *TypeMDS = llvm::MDString::get(CGM.getLLVMContext(), TypeNameOS.str());
12841286

12851287
// Format: !{<type-name>}
12861288
auto *MDN = llvm::MDNode::get(CGM.getLLVMContext(), {TypeMDS});

clang/lib/Driver/ToolChain.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,8 @@ SanitizerMask ToolChain::getSupportedSanitizers() const {
16211621
SanitizerKind::CFICastStrict | SanitizerKind::FloatDivideByZero |
16221622
SanitizerKind::KCFI | SanitizerKind::UnsignedIntegerOverflow |
16231623
SanitizerKind::UnsignedShiftBase | SanitizerKind::ImplicitConversion |
1624-
SanitizerKind::Nullability | SanitizerKind::LocalBounds;
1624+
SanitizerKind::Nullability | SanitizerKind::LocalBounds |
1625+
SanitizerKind::AllocToken;
16251626
if (getTriple().getArch() == llvm::Triple::x86 ||
16261627
getTriple().getArch() == llvm::Triple::x86_64 ||
16271628
getTriple().getArch() == llvm::Triple::arm ||

clang/lib/Driver/ToolChains/BareMetal.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,6 @@ SanitizerMask BareMetal::getSupportedSanitizers() const {
726726
Res |= SanitizerKind::SafeStack;
727727
Res |= SanitizerKind::Thread;
728728
Res |= SanitizerKind::Scudo;
729-
Res |= SanitizerKind::AllocToken;
730729
if (IsX86_64 || IsAArch64 || IsRISCV64) {
731730
Res |= SanitizerKind::HWAddress;
732731
Res |= SanitizerKind::KernelHWAddress;

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,6 @@ SanitizerMask Linux::getSupportedSanitizers() const {
819819
Res |= SanitizerKind::KernelAddress;
820820
Res |= SanitizerKind::Vptr;
821821
Res |= SanitizerKind::SafeStack;
822-
Res |= SanitizerKind::AllocToken;
823822
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsLoongArch64)
824823
Res |= SanitizerKind::DataFlow;
825824
if (IsX86_64 || IsMIPS64 || IsAArch64 || IsX86 || IsArmArch || IsPowerPC64 ||

0 commit comments

Comments
 (0)