Skip to content

Commit a58d0af

Browse files
committed
Revert D121556 "[randstruct] Add randomize structure layout support"
This reverts commit 3f0587d. Not all tests pass after a few rounds of fixes. I spot one failure that std::shuffle (potentially different results with different STL implementations) was misused and replaced it with llvm::shuffle, but there appears to be another failure in a Windows build. The latest failure is reported on https://reviews.llvm.org/D121556#3440383
1 parent 62c8b18 commit a58d0af

File tree

23 files changed

+2
-879
lines changed

23 files changed

+2
-879
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,6 @@ Major New Features
5454
There is an analogous ``zero_call_used_regs`` attribute to allow for finer
5555
control of this feature.
5656

57-
- Clang now supports randomizing structure layout in C. This feature is a
58-
compile-time hardening technique, making it more difficult for an attacker to
59-
retrieve data from structures. Specify randomization with the
60-
``randomize_layout`` attribute. The corresponding ``no_randomize_layout``
61-
attribute can be used to turn the feature off.
62-
63-
A seed value is required to enable randomization, and is deterministic based
64-
on a seed value. Use the ``-frandomize-layout-seed=`` or
65-
``-frandomize-layout-seed-file=`` flags.
66-
67-
.. note::
68-
69-
Randomizing structure layout is a C-only feature.
70-
7157
Bug Fixes
7258
------------------
7359
- ``CXXNewExpr::getArraySize()`` previously returned a ``llvm::Optional``

clang/include/clang/AST/Decl.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4051,12 +4051,6 @@ class RecordDecl : public TagDecl {
40514051
RecordDeclBits.ParamDestroyedInCallee = V;
40524052
}
40534053

4054-
bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4055-
4056-
void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4057-
4058-
void reorderFields(const SmallVectorImpl<Decl *> &Fields);
4059-
40604054
/// Determines whether this declaration represents the
40614055
/// injected class name.
40624056
///

clang/include/clang/AST/DeclBase.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ class alignas(8) Decl {
313313
friend class ASTReader;
314314
friend class CXXClassMemberWrapper;
315315
friend class LinkageComputer;
316-
friend class RecordDecl;
317316
template<typename decl_type> friend class Redeclarable;
318317

319318
/// Access - Used by C++ decls for the access specifier.
@@ -1541,13 +1540,10 @@ class DeclContext {
15411540

15421541
/// Represents the way this type is passed to a function.
15431542
uint64_t ArgPassingRestrictions : 2;
1544-
1545-
/// Indicates whether this struct has had its field layout randomized.
1546-
uint64_t IsRandomized : 1;
15471543
};
15481544

15491545
/// Number of non-inherited bits in RecordDeclBitfields.
1550-
enum { NumRecordDeclBits = 15 };
1546+
enum { NumRecordDeclBits = 14 };
15511547

15521548
/// Stores the bits used by OMPDeclareReductionDecl.
15531549
/// If modified NumOMPDeclareReductionDeclBits and the accessor

clang/include/clang/AST/Randstruct.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3957,18 +3957,3 @@ def HLSLNumThreads: InheritableAttr {
39573957
let LangOpts = [HLSL];
39583958
let Documentation = [NumThreadsDocs];
39593959
}
3960-
3961-
def RandomizeLayout : InheritableAttr {
3962-
let Spellings = [GCC<"randomize_layout">];
3963-
let Subjects = SubjectList<[Record]>;
3964-
let Documentation = [ClangRandomizeLayoutDocs];
3965-
let LangOpts = [COnly];
3966-
}
3967-
3968-
def NoRandomizeLayout : InheritableAttr {
3969-
let Spellings = [GCC<"no_randomize_layout">];
3970-
let Subjects = SubjectList<[Record]>;
3971-
let Documentation = [ClangRandomizeLayoutDocs];
3972-
let LangOpts = [COnly];
3973-
}
3974-
def : MutualExclusions<[RandomizeLayout, NoRandomizeLayout]>;

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6379,35 +6379,3 @@ dictate the thread id. Total number of threads executed is ``X * Y * Z``.
63796379
The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sm5-attributes-numthreads
63806380
}];
63816381
}
6382-
6383-
def ClangRandomizeLayoutDocs : Documentation {
6384-
let Category = DocCatDecl;
6385-
let Heading = "randomize_layout, no_randomize_layout";
6386-
let Content = [{
6387-
The attribute ``randomize_layout``, when attached to a C structure, selects it
6388-
for structure layout field randomization; a compile-time hardening technique. A
6389-
"seed" value, is specified via the ``-frandomize-layout-seed=`` command line flag.
6390-
For example:
6391-
6392-
.. code-block:: bash
6393-
6394-
SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
6395-
make ... CFLAGS="-frandomize-layout-seed=$SEED" ...
6396-
6397-
You can also supply the seed in a file with ``-frandomize-layout-seed-file=``.
6398-
For example:
6399-
6400-
.. code-block:: bash
6401-
6402-
od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n' > /tmp/seed_file.txt
6403-
make ... CFLAGS="-frandomize-layout-seed-file=/tmp/seed_file.txt" ...
6404-
6405-
The randomization is deterministic based for a given seed, so the entire
6406-
program should be compiled with the same seed, but keep the seed safe
6407-
otherwise.
6408-
6409-
The attribute ``no_randomize_layout``, when attached to a C structure,
6410-
instructs the compiler that this structure should not have its field layout
6411-
randomized.
6412-
}];
6413-
}

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,6 @@ def err_drv_amdgpu_ieee_without_no_honor_nans : Error<
165165
"invalid argument '-mno-amdgpu-ieee' only allowed with relaxed NaN handling">;
166166
def err_drv_argument_not_allowed_with : Error<
167167
"invalid argument '%0' not allowed with '%1'">;
168-
def err_drv_cannot_open_randomize_layout_seed_file : Error<
169-
"cannot read randomize layout seed file '%0'">;
170168
def err_drv_invalid_version_number : Error<
171169
"invalid version number in '%0'">;
172170
def err_drv_no_linker_llvm_support : Error<

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11588,7 +11588,5 @@ def err_hlsl_numthreads_argument_oor : Error<"argument '%select{X|Y|Z}0' to numt
1158811588
def err_hlsl_numthreads_invalid : Error<"total number of threads cannot exceed %0">;
1158911589
def err_hlsl_attribute_param_mismatch : Error<"%0 attribute parameters do not match the previous declaration">;
1159011590

11591-
// Layout randomization warning.
11592-
def err_cast_from_randomized_struct : Error<
11593-
"casting from randomized structure pointer type %0 to %1">;
1159411591
} // end of sema component.
11592+

clang/include/clang/Basic/LangOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,9 +445,6 @@ class LangOptions : public LangOptionsBase {
445445
/// The default stream kind used for HIP kernel launching.
446446
GPUDefaultStreamKind GPUDefaultStream;
447447

448-
/// The seed used by the randomize structure layout feature.
449-
std::string RandstructSeed;
450-
451448
LangOptions();
452449

453450
// Define accessors/mutators for language options of enumeration type.

clang/include/clang/Driver/Options.td

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2122,12 +2122,6 @@ defm merge_all_constants : BoolFOption<"merge-all-constants",
21222122
def fmessage_length_EQ : Joined<["-"], "fmessage-length=">, Group<f_Group>, Flags<[CC1Option]>,
21232123
HelpText<"Format message diagnostics so that they fit within N columns">,
21242124
MarshallingInfoInt<DiagnosticOpts<"MessageLength">>;
2125-
def frandomize_layout_seed_EQ : Joined<["-"], "frandomize-layout-seed=">,
2126-
MetaVarName<"<seed>">, Group<f_clang_Group>, Flags<[CC1Option]>,
2127-
HelpText<"The seed used by the randomize structure layout feature">;
2128-
def frandomize_layout_seed_file_EQ : Joined<["-"], "frandomize-layout-seed-file=">,
2129-
MetaVarName<"<file>">, Group<f_clang_Group>, Flags<[CC1Option]>,
2130-
HelpText<"File holding the seed used by the randomize structure layout feature">;
21312125
def fms_compatibility : Flag<["-"], "fms-compatibility">, Group<f_Group>, Flags<[CC1Option, CoreOption]>,
21322126
HelpText<"Enable full Microsoft Visual C++ compatibility">,
21332127
MarshallingInfoFlag<LangOpts<"MSVCCompat">>;

0 commit comments

Comments
 (0)