Skip to content

Commit c8a4c91

Browse files
committed
rebase
Created using spr 1.3.4
2 parents 193d015 + 9319db3 commit c8a4c91

File tree

571 files changed

+13800
-5255
lines changed

Some content is hidden

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

571 files changed

+13800
-5255
lines changed

bolt/lib/Rewrite/LinuxKernelRewriter.cpp

Lines changed: 93 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ static cl::opt<bool> DumpParavirtualPatchSites(
5555
"dump-para-sites", cl::desc("dump Linux kernel paravitual patch sites"),
5656
cl::init(false), cl::Hidden, cl::cat(BoltCategory));
5757

58+
static cl::opt<bool>
59+
DumpPCIFixups("dump-pci-fixups",
60+
cl::desc("dump Linux kernel PCI fixup table"),
61+
cl::init(false), cl::Hidden, cl::cat(BoltCategory));
62+
5863
static cl::opt<bool> DumpStaticCalls("dump-static-calls",
5964
cl::desc("dump Linux kernel static calls"),
6065
cl::init(false), cl::Hidden,
@@ -181,6 +186,10 @@ class LinuxKernelRewriter final : public MetadataRewriter {
181186
/// Size of bug_entry struct.
182187
static constexpr size_t BUG_TABLE_ENTRY_SIZE = 12;
183188

189+
/// .pci_fixup section.
190+
ErrorOr<BinarySection &> PCIFixupSection = std::errc::bad_address;
191+
static constexpr size_t PCI_FIXUP_ENTRY_SIZE = 16;
192+
184193
/// Insert an LKMarker for a given code pointer \p PC from a non-code section
185194
/// \p SectionName.
186195
void insertLKMarker(uint64_t PC, uint64_t SectionOffset,
@@ -190,9 +199,6 @@ class LinuxKernelRewriter final : public MetadataRewriter {
190199
/// Process linux kernel special sections and their relocations.
191200
void processLKSections();
192201

193-
/// Process special linux kernel section, .pci_fixup.
194-
void processLKPCIFixup();
195-
196202
/// Process __ksymtab and __ksymtab_gpl.
197203
void processLKKSymtab(bool IsGPL = false);
198204

@@ -226,6 +232,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
226232
/// Read alternative instruction info from .altinstructions.
227233
Error readAltInstructions();
228234

235+
/// Read .pci_fixup
236+
Error readPCIFixupTable();
237+
229238
/// Mark instructions referenced by kernel metadata.
230239
Error markInstructions();
231240

@@ -256,6 +265,9 @@ class LinuxKernelRewriter final : public MetadataRewriter {
256265
if (Error E = readAltInstructions())
257266
return E;
258267

268+
if (Error E = readPCIFixupTable())
269+
return E;
270+
259271
return Error::success();
260272
}
261273

@@ -318,41 +330,11 @@ void LinuxKernelRewriter::insertLKMarker(uint64_t PC, uint64_t SectionOffset,
318330
}
319331

320332
void LinuxKernelRewriter::processLKSections() {
321-
processLKPCIFixup();
322333
processLKKSymtab();
323334
processLKKSymtab(true);
324335
processLKSMPLocks();
325336
}
326337

327-
/// Process .pci_fixup section of Linux Kernel.
328-
/// This section contains a list of entries for different PCI devices and their
329-
/// corresponding hook handler (code pointer where the fixup
330-
/// code resides, usually on x86_64 it is an entry PC relative 32 bit offset).
331-
/// Documentation is in include/linux/pci.h.
332-
void LinuxKernelRewriter::processLKPCIFixup() {
333-
ErrorOr<BinarySection &> SectionOrError =
334-
BC.getUniqueSectionByName(".pci_fixup");
335-
if (!SectionOrError)
336-
return;
337-
338-
const uint64_t SectionSize = SectionOrError->getSize();
339-
const uint64_t SectionAddress = SectionOrError->getAddress();
340-
assert((SectionSize % 16) == 0 && ".pci_fixup size is not a multiple of 16");
341-
342-
for (uint64_t I = 12; I + 4 <= SectionSize; I += 16) {
343-
const uint64_t PC = SectionAddress + I;
344-
ErrorOr<uint64_t> Offset = BC.getSignedValueAtAddress(PC, 4);
345-
assert(Offset && "cannot read value from .pci_fixup");
346-
const int32_t SignedOffset = *Offset;
347-
const uint64_t HookupAddress = PC + SignedOffset;
348-
BinaryFunction *HookupFunction =
349-
BC.getBinaryFunctionAtAddress(HookupAddress);
350-
assert(HookupFunction && "expected function for entry in .pci_fixup");
351-
BC.addRelocation(PC, HookupFunction->getSymbol(), Relocation::getPC32(), 0,
352-
*Offset);
353-
}
354-
}
355-
356338
/// Process __ksymtab[_gpl] sections of Linux Kernel.
357339
/// This section lists all the vmlinux symbols that kernel modules can access.
358340
///
@@ -1283,6 +1265,84 @@ Error LinuxKernelRewriter::readAltInstructions() {
12831265
return Error::success();
12841266
}
12851267

1268+
/// When the Linux kernel needs to handle an error associated with a given PCI
1269+
/// device, it uses a table stored in .pci_fixup section to locate a fixup code
1270+
/// specific to the vendor and the problematic device. The section contains a
1271+
/// list of the following structures defined in include/linux/pci.h:
1272+
///
1273+
/// struct pci_fixup {
1274+
/// u16 vendor; /* Or PCI_ANY_ID */
1275+
/// u16 device; /* Or PCI_ANY_ID */
1276+
/// u32 class; /* Or PCI_ANY_ID */
1277+
/// unsigned int class_shift; /* should be 0, 8, 16 */
1278+
/// int hook_offset;
1279+
/// };
1280+
///
1281+
/// Normally, the hook will point to a function start and we don't have to
1282+
/// update the pointer if we are not relocating functions. Hence, while reading
1283+
/// the table we validate this assumption. If a function has a fixup code in the
1284+
/// middle of its body, we issue a warning and ignore it.
1285+
Error LinuxKernelRewriter::readPCIFixupTable() {
1286+
PCIFixupSection = BC.getUniqueSectionByName(".pci_fixup");
1287+
if (!PCIFixupSection)
1288+
return Error::success();
1289+
1290+
if (PCIFixupSection->getSize() % PCI_FIXUP_ENTRY_SIZE)
1291+
return createStringError(errc::executable_format_error,
1292+
"PCI fixup table size error");
1293+
1294+
const uint64_t Address = PCIFixupSection->getAddress();
1295+
DataExtractor DE = DataExtractor(PCIFixupSection->getContents(),
1296+
BC.AsmInfo->isLittleEndian(),
1297+
BC.AsmInfo->getCodePointerSize());
1298+
uint64_t EntryID = 0;
1299+
DataExtractor::Cursor Cursor(0);
1300+
while (Cursor && !DE.eof(Cursor)) {
1301+
const uint16_t Vendor = DE.getU16(Cursor);
1302+
const uint16_t Device = DE.getU16(Cursor);
1303+
const uint32_t Class = DE.getU32(Cursor);
1304+
const uint32_t ClassShift = DE.getU32(Cursor);
1305+
const uint64_t HookAddress =
1306+
Address + Cursor.tell() + (int32_t)DE.getU32(Cursor);
1307+
1308+
if (!Cursor)
1309+
return createStringError(errc::executable_format_error,
1310+
"out of bounds while reading .pci_fixup: %s",
1311+
toString(Cursor.takeError()).c_str());
1312+
1313+
++EntryID;
1314+
1315+
if (opts::DumpPCIFixups) {
1316+
BC.outs() << "PCI fixup entry: " << EntryID << "\n\tVendor 0x"
1317+
<< Twine::utohexstr(Vendor) << "\n\tDevice: 0x"
1318+
<< Twine::utohexstr(Device) << "\n\tClass: 0x"
1319+
<< Twine::utohexstr(Class) << "\n\tClassShift: 0x"
1320+
<< Twine::utohexstr(ClassShift) << "\n\tHookAddress: 0x"
1321+
<< Twine::utohexstr(HookAddress) << '\n';
1322+
}
1323+
1324+
BinaryFunction *BF = BC.getBinaryFunctionContainingAddress(HookAddress);
1325+
if (!BF && opts::Verbosity) {
1326+
BC.outs() << "BOLT-INFO: no function matches address 0x"
1327+
<< Twine::utohexstr(HookAddress)
1328+
<< " of hook from .pci_fixup\n";
1329+
}
1330+
1331+
if (!BF || !BC.shouldEmit(*BF))
1332+
continue;
1333+
1334+
if (const uint64_t Offset = HookAddress - BF->getAddress()) {
1335+
BC.errs() << "BOLT-WARNING: PCI fixup detected in the middle of function "
1336+
<< *BF << " at offset 0x" << Twine::utohexstr(Offset) << '\n';
1337+
BF->setSimple(false);
1338+
}
1339+
}
1340+
1341+
BC.outs() << "BOLT-INFO: parsed " << EntryID << " PCI fixup entries\n";
1342+
1343+
return Error::success();
1344+
}
1345+
12861346
} // namespace
12871347

12881348
std::unique_ptr<MetadataRewriter>

bolt/test/X86/linux-pci-fixup.s

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# REQUIRES: system-linux
2+
3+
# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
4+
# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \
5+
# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie
6+
# RUN: llvm-bolt %t.exe --print-normalized -o %t.out |& FileCheck %s
7+
8+
## Check that BOLT correctly parses the Linux kernel .pci_fixup section and
9+
## verify that PCI fixup hook in the middle of a function is detected.
10+
11+
# CHECK: BOLT-INFO: Linux kernel binary detected
12+
# CHECK: BOLT-WARNING: PCI fixup detected in the middle of function _start
13+
# CHECK: BOLT-INFO: parsed 2 PCI fixup entries
14+
15+
.text
16+
.globl _start
17+
.type _start, %function
18+
_start:
19+
nop
20+
.L0:
21+
ret
22+
.size _start, .-_start
23+
24+
## PCI fixup table.
25+
.section .pci_fixup,"a",@progbits
26+
27+
.short 0x8086 # vendor
28+
.short 0xbeef # device
29+
.long 0xffffffff # class
30+
.long 0x0 # class shift
31+
.long _start - . # fixup
32+
33+
.short 0x8086 # vendor
34+
.short 0xbad # device
35+
.long 0xffffffff # class
36+
.long 0x0 # class shift
37+
.long .L0 - . # fixup
38+
39+
## Fake Linux Kernel sections.
40+
.section __ksymtab,"a",@progbits
41+
.section __ksymtab_gpl,"a",@progbits

clang/cmake/caches/Fuchsia.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
6565
LLDB_EMBED_PYTHON_HOME
6666
LLDB_PYTHON_HOME
6767
LLDB_PYTHON_RELATIVE_PATH
68+
LLDB_TEST_USE_VENDOR_PACKAGES
6869
Python3_EXECUTABLE
6970
Python3_LIBRARIES
7071
Python3_INCLUDE_DIRS

clang/docs/ReleaseNotes.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ Removed Compiler Flags
194194

195195
Attribute Changes in Clang
196196
--------------------------
197+
- Introduced a new function attribute ``__attribute__((amdgpu_max_num_work_groups(x, y, z)))`` or
198+
``[[clang::amdgpu_max_num_work_groups(x, y, z)]]`` for the AMDGPU target. This attribute can be
199+
attached to HIP or OpenCL kernel function definitions to provide an optimization hint. The parameters
200+
``x``, ``y``, and ``z`` specify the maximum number of workgroups for the respective dimensions,
201+
and each must be a positive integer when provided. The parameter ``x`` is required, while ``y`` and
202+
``z`` are optional with default value of 1.
197203

198204
Improvements to Clang's diagnostics
199205
-----------------------------------
@@ -265,6 +271,9 @@ Bug Fixes in This Version
265271
operator.
266272
Fixes (#GH83267).
267273

274+
- Clang now correctly generates overloads for bit-precise integer types for
275+
builtin operators in C++. Fixes #GH82998.
276+
268277
Bug Fixes to Compiler Builtins
269278
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
270279

@@ -351,6 +360,8 @@ Bug Fixes to C++ Support
351360
when one of the function had more specialized templates.
352361
Fixes (`#82509 <https://github.com/llvm/llvm-project/issues/82509>`_)
353362
and (`#74494 <https://github.com/llvm/llvm-project/issues/74494>`_)
363+
- Allow access to a public template alias declaration that refers to friend's
364+
private nested type. (#GH25708).
354365

355366
Bug Fixes to AST Handling
356367
^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -447,6 +458,8 @@ AST Matchers
447458

448459
- ``isInStdNamespace`` now supports Decl declared with ``extern "C++"``.
449460
- Add ``isExplicitObjectMemberFunction``.
461+
- Fixed ``forEachArgumentWithParam`` and ``forEachArgumentWithParamType`` to
462+
not skip the explicit object parameter for operator calls.
450463

451464
clang-format
452465
------------
@@ -497,6 +510,11 @@ Python Binding Changes
497510

498511
- Exposed `CXRewriter` API as `class Rewriter`.
499512

513+
OpenMP Support
514+
--------------
515+
516+
- Added support for the `[[omp::assume]]` attribute.
517+
500518
Additional Information
501519
======================
502520

clang/include/clang/ASTMatchers/ASTMatchers.h

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,6 +5032,25 @@ AST_POLYMORPHIC_MATCHER_P2(hasParameter,
50325032
&& InnerMatcher.matches(*Node.parameters()[N], Finder, Builder));
50335033
}
50345034

5035+
/// Matches if the given method declaration declares a member function with an
5036+
/// explicit object parameter.
5037+
///
5038+
/// Given
5039+
/// \code
5040+
/// struct A {
5041+
/// int operator-(this A, int);
5042+
/// void fun(this A &&self);
5043+
/// static int operator()(int);
5044+
/// int operator+(int);
5045+
/// };
5046+
/// \endcode
5047+
///
5048+
/// cxxMethodDecl(isExplicitObjectMemberFunction()) matches the first two
5049+
/// methods but not the last two.
5050+
AST_MATCHER(CXXMethodDecl, isExplicitObjectMemberFunction) {
5051+
return Node.isExplicitObjectMemberFunction();
5052+
}
5053+
50355054
/// Matches all arguments and their respective ParmVarDecl.
50365055
///
50375056
/// Given
@@ -5060,10 +5079,12 @@ AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParam,
50605079
// argument of the method which should not be matched against a parameter, so
50615080
// we skip over it here.
50625081
BoundNodesTreeBuilder Matches;
5063-
unsigned ArgIndex = cxxOperatorCallExpr(callee(cxxMethodDecl()))
5064-
.matches(Node, Finder, &Matches)
5065-
? 1
5066-
: 0;
5082+
unsigned ArgIndex =
5083+
cxxOperatorCallExpr(
5084+
callee(cxxMethodDecl(unless(isExplicitObjectMemberFunction()))))
5085+
.matches(Node, Finder, &Matches)
5086+
? 1
5087+
: 0;
50675088
int ParamIndex = 0;
50685089
bool Matched = false;
50695090
for (; ArgIndex < Node.getNumArgs(); ++ArgIndex) {
@@ -5121,11 +5142,12 @@ AST_POLYMORPHIC_MATCHER_P2(forEachArgumentWithParamType,
51215142
// argument of the method which should not be matched against a parameter, so
51225143
// we skip over it here.
51235144
BoundNodesTreeBuilder Matches;
5124-
unsigned ArgIndex = cxxOperatorCallExpr(callee(cxxMethodDecl()))
5125-
.matches(Node, Finder, &Matches)
5126-
? 1
5127-
: 0;
5128-
5145+
unsigned ArgIndex =
5146+
cxxOperatorCallExpr(
5147+
callee(cxxMethodDecl(unless(isExplicitObjectMemberFunction()))))
5148+
.matches(Node, Finder, &Matches)
5149+
? 1
5150+
: 0;
51295151
const FunctionProtoType *FProto = nullptr;
51305152

51315153
if (const auto *Call = dyn_cast<CallExpr>(&Node)) {
@@ -6366,25 +6388,6 @@ AST_MATCHER(CXXMethodDecl, isConst) {
63666388
return Node.isConst();
63676389
}
63686390

6369-
/// Matches if the given method declaration declares a member function with an
6370-
/// explicit object parameter.
6371-
///
6372-
/// Given
6373-
/// \code
6374-
/// struct A {
6375-
/// int operator-(this A, int);
6376-
/// void fun(this A &&self);
6377-
/// static int operator()(int);
6378-
/// int operator+(int);
6379-
/// };
6380-
/// \endcode
6381-
///
6382-
/// cxxMethodDecl(isExplicitObjectMemberFunction()) matches the first two
6383-
/// methods but not the last two.
6384-
AST_MATCHER(CXXMethodDecl, isExplicitObjectMemberFunction) {
6385-
return Node.isExplicitObjectMemberFunction();
6386-
}
6387-
63886391
/// Matches if the given method declaration declares a copy assignment
63896392
/// operator.
63906393
///

clang/include/clang/Basic/Attr.td

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2054,6 +2054,13 @@ def AMDGPUNumVGPR : InheritableAttr {
20542054
let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
20552055
}
20562056

2057+
def AMDGPUMaxNumWorkGroups : InheritableAttr {
2058+
let Spellings = [Clang<"amdgpu_max_num_work_groups", 0>];
2059+
let Args = [ExprArgument<"MaxNumWorkGroupsX">, ExprArgument<"MaxNumWorkGroupsY", 1>, ExprArgument<"MaxNumWorkGroupsZ", 1>];
2060+
let Documentation = [AMDGPUMaxNumWorkGroupsDocs];
2061+
let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
2062+
}
2063+
20572064
def AMDGPUKernelCall : DeclOrTypeAttr {
20582065
let Spellings = [Clang<"amdgpu_kernel">];
20592066
let Documentation = [Undocumented];
@@ -4159,7 +4166,7 @@ def OMPDeclareVariant : InheritableAttr {
41594166
}
41604167

41614168
def OMPAssume : InheritableAttr {
4162-
let Spellings = [Clang<"assume">];
4169+
let Spellings = [Clang<"assume">, CXX11<"omp", "assume">];
41634170
let Subjects = SubjectList<[Function, ObjCMethod]>;
41644171
let InheritEvenIfAlreadyPresent = 1;
41654172
let Documentation = [OMPAssumeDocs];

0 commit comments

Comments
 (0)