Skip to content

Commit 00c4421

Browse files
author
Pavel V Chupin
committed
Merge from 'main' to 'sycl-web' (32 commits)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaDeclAttr.cpp
2 parents 2cac4e7 + 7aa8c38 commit 00c4421

File tree

121 files changed

+5828
-1146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+5828
-1146
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3108,6 +3108,10 @@ void RewriteInstance::emitAndLink() {
31083108
emitBinaryContext(*Streamer, *BC, getOrgSecPrefix());
31093109

31103110
Streamer->Finish();
3111+
if (Streamer->getContext().hadError()) {
3112+
errs() << "BOLT-ERROR: Emission failed.\n";
3113+
exit(1);
3114+
}
31113115

31123116
//////////////////////////////////////////////////////////////////////////////
31133117
// Assign addresses to new sections.
@@ -3137,7 +3141,7 @@ void RewriteInstance::emitAndLink() {
31373141

31383142
RTDyld->finalizeWithMemoryManagerLocking();
31393143
if (RTDyld->hasError()) {
3140-
outs() << "BOLT-ERROR: RTDyld failed: " << RTDyld->getErrorString() << "\n";
3144+
errs() << "BOLT-ERROR: RTDyld failed: " << RTDyld->getErrorString() << "\n";
31413145
exit(1);
31423146
}
31433147

clang/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ set(PPC_LINUX_DEFAULT_IEEELONGDOUBLE OFF CACHE BOOL
245245
set(CLANG_SPAWN_CC1 OFF CACHE BOOL
246246
"Whether clang should use a new process for the CC1 invocation")
247247

248-
option(CLANG_DEFAULT_PIE_ON_LINUX "Default to -fPIE and -pie on Linux" OFF)
248+
option(CLANG_DEFAULT_PIE_ON_LINUX "Default to -fPIE and -pie on linux-gnu" ON)
249249

250250
# Manually handle default so we can change the meaning of a cached default.
251251
set(CLANG_ENABLE_OPAQUE_POINTERS "DEFAULT" CACHE STRING

clang/docs/ReleaseNotes.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ 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+
5771
Bug Fixes
5872
------------------
5973
- ``CXXNewExpr::getArraySize()`` previously returned a ``llvm::Optional``
@@ -307,6 +321,12 @@ Internal API Changes
307321
Build System Changes
308322
--------------------
309323

324+
* CMake ``-DCLANG_DEFAULT_PIE_ON_LINUX=ON`` is now the default. This is used by
325+
linux-gnu systems to decide whether ``-fPIE -pie`` is the default (instead of
326+
``-fno-pic -no-pie``). This matches GCC installations on many Linux distros.
327+
Note: linux-android and linux-musl always default to ``-fPIE -pie``, ignoring
328+
this variable. ``-DCLANG_DEFAULT_PIE_ON_LINUX`` may be removed in the future.
329+
310330
AST Matchers
311331
------------
312332

clang/docs/tools/dump_format_help.py

100644100755
File mode changed.

clang/include/clang/AST/Decl.h

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

4055+
bool isRandomized() const { return RecordDeclBits.IsRandomized; }
4056+
4057+
void setIsRandomized(bool V) { RecordDeclBits.IsRandomized = V; }
4058+
4059+
void reorderFields(const SmallVectorImpl<Decl *> &Fields);
4060+
40554061
/// Determines whether this declaration represents the
40564062
/// injected class name.
40574063
///

clang/include/clang/AST/DeclBase.h

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

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

15411542
/// Represents the way this type is passed to a function.
15421543
uint64_t ArgPassingRestrictions : 2;
1544+
1545+
/// Indicates whether this struct has had its field layout randomized.
1546+
uint64_t IsRandomized : 1;
15431547
};
15441548

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

15481552
/// Stores the bits used by OMPDeclareReductionDecl.
15491553
/// If modified NumOMPDeclareReductionDeclBits and the accessor

clang/include/clang/AST/OpenMPClause.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7416,6 +7416,110 @@ class OMPIsDevicePtrClause final
74167416
}
74177417
};
74187418

7419+
/// This represents clause 'has_device_ptr' in the '#pragma omp ...'
7420+
/// directives.
7421+
///
7422+
/// \code
7423+
/// #pragma omp target has_device_addr(a,b)
7424+
/// \endcode
7425+
/// In this example directive '#pragma omp target' has clause
7426+
/// 'has_device_ptr' with the variables 'a' and 'b'.
7427+
class OMPHasDeviceAddrClause final
7428+
: public OMPMappableExprListClause<OMPHasDeviceAddrClause>,
7429+
private llvm::TrailingObjects<
7430+
OMPHasDeviceAddrClause, Expr *, ValueDecl *, unsigned,
7431+
OMPClauseMappableExprCommon::MappableComponent> {
7432+
friend class OMPClauseReader;
7433+
friend OMPMappableExprListClause;
7434+
friend OMPVarListClause;
7435+
friend TrailingObjects;
7436+
7437+
/// Build clause with number of variables \a NumVars.
7438+
///
7439+
/// \param Locs Locations needed to build a mappable clause. It includes 1)
7440+
/// StartLoc: starting location of the clause (the clause keyword); 2)
7441+
/// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
7442+
/// \param Sizes All required sizes to build a mappable clause. It includes 1)
7443+
/// NumVars: number of expressions listed in this clause; 2)
7444+
/// NumUniqueDeclarations: number of unique base declarations in this clause;
7445+
/// 3) NumComponentLists: number of component lists in this clause; and 4)
7446+
/// NumComponents: total number of expression components in the clause.
7447+
explicit OMPHasDeviceAddrClause(const OMPVarListLocTy &Locs,
7448+
const OMPMappableExprListSizeTy &Sizes)
7449+
: OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr, Locs,
7450+
Sizes) {}
7451+
7452+
/// Build an empty clause.
7453+
///
7454+
/// \param Sizes All required sizes to build a mappable clause. It includes 1)
7455+
/// NumVars: number of expressions listed in this clause; 2)
7456+
/// NumUniqueDeclarations: number of unique base declarations in this clause;
7457+
/// 3) NumComponentLists: number of component lists in this clause; and 4)
7458+
/// NumComponents: total number of expression components in the clause.
7459+
explicit OMPHasDeviceAddrClause(const OMPMappableExprListSizeTy &Sizes)
7460+
: OMPMappableExprListClause(llvm::omp::OMPC_has_device_addr,
7461+
OMPVarListLocTy(), Sizes) {}
7462+
7463+
/// Define the sizes of each trailing object array except the last one. This
7464+
/// is required for TrailingObjects to work properly.
7465+
size_t numTrailingObjects(OverloadToken<Expr *>) const {
7466+
return varlist_size();
7467+
}
7468+
size_t numTrailingObjects(OverloadToken<ValueDecl *>) const {
7469+
return getUniqueDeclarationsNum();
7470+
}
7471+
size_t numTrailingObjects(OverloadToken<unsigned>) const {
7472+
return getUniqueDeclarationsNum() + getTotalComponentListNum();
7473+
}
7474+
7475+
public:
7476+
/// Creates clause with a list of variables \a Vars.
7477+
///
7478+
/// \param C AST context.
7479+
/// \param Locs Locations needed to build a mappable clause. It includes 1)
7480+
/// StartLoc: starting location of the clause (the clause keyword); 2)
7481+
/// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.
7482+
/// \param Vars The original expression used in the clause.
7483+
/// \param Declarations Declarations used in the clause.
7484+
/// \param ComponentLists Component lists used in the clause.
7485+
static OMPHasDeviceAddrClause *
7486+
Create(const ASTContext &C, const OMPVarListLocTy &Locs,
7487+
ArrayRef<Expr *> Vars, ArrayRef<ValueDecl *> Declarations,
7488+
MappableExprComponentListsRef ComponentLists);
7489+
7490+
/// Creates an empty clause with the place for \a NumVars variables.
7491+
///
7492+
/// \param C AST context.
7493+
/// \param Sizes All required sizes to build a mappable clause. It includes 1)
7494+
/// NumVars: number of expressions listed in this clause; 2)
7495+
/// NumUniqueDeclarations: number of unique base declarations in this clause;
7496+
/// 3) NumComponentLists: number of component lists in this clause; and 4)
7497+
/// NumComponents: total number of expression components in the clause.
7498+
static OMPHasDeviceAddrClause *
7499+
CreateEmpty(const ASTContext &C, const OMPMappableExprListSizeTy &Sizes);
7500+
7501+
child_range children() {
7502+
return child_range(reinterpret_cast<Stmt **>(varlist_begin()),
7503+
reinterpret_cast<Stmt **>(varlist_end()));
7504+
}
7505+
7506+
const_child_range children() const {
7507+
auto Children = const_cast<OMPHasDeviceAddrClause *>(this)->children();
7508+
return const_child_range(Children.begin(), Children.end());
7509+
}
7510+
7511+
child_range used_children() {
7512+
return child_range(child_iterator(), child_iterator());
7513+
}
7514+
const_child_range used_children() const {
7515+
return const_child_range(const_child_iterator(), const_child_iterator());
7516+
}
7517+
7518+
static bool classof(const OMPClause *T) {
7519+
return T->getClauseKind() == llvm::omp::OMPC_has_device_addr;
7520+
}
7521+
};
7522+
74197523
/// This represents clause 'nontemporal' in the '#pragma omp ...' directives.
74207524
///
74217525
/// \code

clang/include/clang/AST/Randstruct.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//===- Randstruct.h - Interfact for structure randomization -------*- C++ -*-=//
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 contains the interface for Clang's structure field layout
10+
// randomization.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_CLANG_AST_RANDSTRUCT_H
15+
#define LLVM_CLANG_AST_RANDSTRUCT_H
16+
17+
namespace llvm {
18+
template <typename T> class ArrayRef;
19+
template <typename T> class SmallVectorImpl;
20+
class StringRef;
21+
} // end namespace llvm
22+
23+
namespace clang {
24+
25+
class ASTContext;
26+
class Decl;
27+
class RecordDecl;
28+
29+
namespace randstruct {
30+
31+
bool randomizeStructureLayout(const ASTContext &Context, llvm::StringRef Name,
32+
llvm::ArrayRef<Decl *> Fields,
33+
llvm::SmallVectorImpl<Decl *> &FinalOrdering);
34+
35+
} // namespace randstruct
36+
} // namespace clang
37+
38+
#endif // LLVM_CLANG_AST_RANDSTRUCT_H

clang/include/clang/AST/RecursiveASTVisitor.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3717,6 +3717,13 @@ bool RecursiveASTVisitor<Derived>::VisitOMPIsDevicePtrClause(
37173717
return true;
37183718
}
37193719

3720+
template <typename Derived>
3721+
bool RecursiveASTVisitor<Derived>::VisitOMPHasDeviceAddrClause(
3722+
OMPHasDeviceAddrClause *C) {
3723+
TRY_TO(VisitOMPClauseList(C));
3724+
return true;
3725+
}
3726+
37203727
template <typename Derived>
37213728
bool RecursiveASTVisitor<Derived>::VisitOMPNontemporalClause(
37223729
OMPNontemporalClause *C) {

clang/include/clang/Basic/Attr.td

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4859,3 +4859,18 @@ def HLSLNumThreads: InheritableAttr {
48594859
let LangOpts = [HLSL];
48604860
let Documentation = [NumThreadsDocs];
48614861
}
4862+
4863+
def RandomizeLayout : InheritableAttr {
4864+
let Spellings = [GCC<"randomize_layout">];
4865+
let Subjects = SubjectList<[Record]>;
4866+
let Documentation = [ClangRandomizeLayoutDocs];
4867+
let LangOpts = [COnly];
4868+
}
4869+
4870+
def NoRandomizeLayout : InheritableAttr {
4871+
let Spellings = [GCC<"no_randomize_layout">];
4872+
let Subjects = SubjectList<[Record]>;
4873+
let Documentation = [ClangRandomizeLayoutDocs];
4874+
let LangOpts = [COnly];
4875+
}
4876+
def : MutualExclusions<[RandomizeLayout, NoRandomizeLayout]>;

0 commit comments

Comments
 (0)