Skip to content

Commit 6234742

Browse files
authored
merge main into amd-staging (llvm#1644)
2 parents f1bbfc4 + e780aef commit 6234742

File tree

45 files changed

+232
-126
lines changed

Some content is hidden

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

45 files changed

+232
-126
lines changed

.github/workflows/containers/github-action-ci/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ RUN cmake -B ./build -G Ninja ./llvm \
3232
-DLLVM_ENABLE_RUNTIMES="compiler-rt" \
3333
-DCMAKE_INSTALL_PREFIX="$LLVM_SYSROOT" \
3434
-DLLVM_ENABLE_PROJECTS="bolt;clang;lld;clang-tools-extra" \
35-
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format;scan-build" \
35+
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format;scan-build;llvm-symbolizer" \
3636
-DCLANG_DEFAULT_LINKER="lld"
3737

3838
RUN ninja -C ./build stage2-clang-bolt stage2-install-distribution && ninja -C ./build install-distribution

bolt/lib/Profile/DataAggregator.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -871,18 +871,27 @@ DataAggregator::getFallthroughsInTrace(BinaryFunction &BF,
871871

872872
BinaryContext &BC = BF.getBinaryContext();
873873

874-
if (!BF.isSimple())
875-
return std::nullopt;
876-
877-
assert(BF.hasCFG() && "can only record traces in CFG state");
878-
879874
// Offsets of the trace within this function.
880875
const uint64_t From = FirstLBR.To - BF.getAddress();
881876
const uint64_t To = SecondLBR.From - BF.getAddress();
882877

883878
if (From > To)
884879
return std::nullopt;
885880

881+
// Accept fall-throughs inside pseudo functions (PLT/thunks).
882+
// This check has to be above BF.empty as pseudo functions would pass it:
883+
// pseudo => ignored => CFG not built => empty.
884+
// If we return nullopt, trace would be reported as mismatching disassembled
885+
// function contents which it is not. To avoid this, return an empty
886+
// fall-through list instead.
887+
if (BF.isPseudo())
888+
return Branches;
889+
890+
if (!BF.isSimple())
891+
return std::nullopt;
892+
893+
assert(BF.hasCFG() && "can only record traces in CFG state");
894+
886895
const BinaryBasicBlock *FromBB = BF.getBasicBlockContainingOffset(From);
887896
const BinaryBasicBlock *ToBB = BF.getBasicBlockContainingOffset(To);
888897

bolt/test/X86/callcont-fallthru.s

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# RUN: link_fdata %s %t %t.pa3 PREAGG3
1010
# RUN: link_fdata %s %t %t.pat PREAGGT1
1111
# RUN: link_fdata %s %t %t.pat2 PREAGGT2
12+
# RUN: link_fdata %s %t %t.patplt PREAGGPLT
1213

1314
## Check normal case: fallthrough is not LP or secondary entry.
1415
# RUN: llvm-strip --strip-unneeded %t -o %t.strip
@@ -42,6 +43,12 @@
4243
# RUN: llvm-bolt %t.strip --pa -p %t.pat2 -o %t.out \
4344
# RUN: --print-cfg --print-only=main | FileCheck %s --check-prefix=CHECK3
4445

46+
## Check pre-aggregated traces don't report zero-sized PLT fall-through as
47+
## invalid trace
48+
# RUN: llvm-bolt %t.strip --pa -p %t.patplt -o %t.out | FileCheck %s \
49+
# RUN: --check-prefix=CHECK-PLT
50+
# CHECK-PLT: traces mismatching disassembled function contents: 0
51+
4552
.globl foo
4653
.type foo, %function
4754
foo:
@@ -65,7 +72,10 @@ main:
6572
movl $0x0, -0x4(%rbp)
6673
movl %edi, -0x8(%rbp)
6774
movq %rsi, -0x10(%rbp)
75+
Ltmp0_br:
6876
callq puts@PLT
77+
## Check PLT traces are accepted
78+
# PREAGGPLT: T #Ltmp0_br# #puts@plt# #puts@plt# 3
6979
## Target is an external-origin call continuation
7080
# PREAGG1: B X:0 #Ltmp1# 2 0
7181
# PREAGGT1: T X:0 #Ltmp1# #Ltmp4_br# 2

bolt/test/link_fdata.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99

1010
import argparse
11+
import os
1112
import subprocess
1213
import sys
1314
import re
@@ -84,8 +85,16 @@
8485
exit("ERROR: unexpected input:\n%s" % line)
8586

8687
# Read nm output: <symbol value> <symbol type> <symbol name>
88+
is_llvm_nm = os.path.basename(args.nmtool) == "llvm-nm"
8789
nm_output = subprocess.run(
88-
[args.nmtool, "--defined-only", args.objfile], text=True, capture_output=True
90+
[
91+
args.nmtool,
92+
"--defined-only",
93+
"--special-syms" if is_llvm_nm else "--synthetic",
94+
args.objfile,
95+
],
96+
text=True,
97+
capture_output=True,
8998
).stdout
9099
# Populate symbol map
91100
symbols = {}

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,14 @@ class CompilerInstance : public ModuleLoader {
871871
bool IsInclusionDirective);
872872

873873
public:
874+
/// Creates a new \c CompilerInstance for compiling a module.
875+
///
876+
/// This takes care of creating appropriate \c FrontendInputFile for
877+
/// public/private frameworks, inferred modules and such.
878+
std::unique_ptr<CompilerInstance>
879+
cloneForModuleCompile(SourceLocation ImportLoc, Module *Module,
880+
StringRef ModuleFileName);
881+
874882
ModuleLoadResult loadModule(SourceLocation ImportLoc, ModuleIdPath Path,
875883
Module::NameVisibilityKind Visibility,
876884
bool IsInclusionDirective) override;

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1970,7 +1970,7 @@ bool CodeGenFunction::EmitScalarRangeCheck(llvm::Value *Value, QualType Ty,
19701970
SanitizerKind::SanitizerOrdinal Kind =
19711971
NeedsEnumCheck ? SanitizerKind::SO_Enum : SanitizerKind::SO_Bool;
19721972
EmitCheck(std::make_pair(Check, Kind), SanitizerHandler::LoadInvalidValue,
1973-
StaticArgs, EmitCheckValue(Value));
1973+
StaticArgs, Value);
19741974
return true;
19751975
}
19761976

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,9 +3197,7 @@ void CodeGenFunction::emitAlignmentAssumptionCheck(
31973197
llvm::Constant *StaticData[] = {EmitCheckSourceLocation(Loc),
31983198
EmitCheckSourceLocation(SecondaryLoc),
31993199
EmitCheckTypeDescriptor(Ty)};
3200-
llvm::Value *DynamicData[] = {EmitCheckValue(Ptr),
3201-
EmitCheckValue(Alignment),
3202-
EmitCheckValue(OffsetValue)};
3200+
llvm::Value *DynamicData[] = {Ptr, Alignment, OffsetValue};
32033201
EmitCheck({std::make_pair(TheCheck, SanitizerKind::SO_Alignment)},
32043202
SanitizerHandler::AlignmentAssumption, StaticData, DynamicData);
32053203
}

clang/lib/Frontend/CompilerInstance.cpp

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1335,23 +1335,15 @@ static OptionalFileEntryRef getPublicModuleMap(FileEntryRef File,
13351335
return FileMgr.getOptionalFileRef(PublicFilename);
13361336
}
13371337

1338-
/// Creates a \c CompilerInstance for compiling a module.
1339-
///
1340-
/// This takes care of creating appropriate \c FrontendInputFile for
1341-
/// public/private frameworks, inferred modules and such.
1342-
static std::unique_ptr<CompilerInstance>
1343-
createCompilerInstanceForModuleCompile(CompilerInstance &ImportingInstance,
1344-
SourceLocation ImportLoc, Module *Module,
1345-
StringRef ModuleFileName) {
1338+
std::unique_ptr<CompilerInstance> CompilerInstance::cloneForModuleCompile(
1339+
SourceLocation ImportLoc, Module *Module, StringRef ModuleFileName) {
13461340
StringRef ModuleName = Module->getTopLevelModuleName();
13471341

1348-
InputKind IK(getLanguageFromOptions(ImportingInstance.getLangOpts()),
1349-
InputKind::ModuleMap);
1342+
InputKind IK(getLanguageFromOptions(getLangOpts()), InputKind::ModuleMap);
13501343

13511344
// Get or create the module map that we'll use to build this module.
1352-
ModuleMap &ModMap =
1353-
ImportingInstance.getPreprocessor().getHeaderSearchInfo().getModuleMap();
1354-
SourceManager &SourceMgr = ImportingInstance.getSourceManager();
1345+
ModuleMap &ModMap = getPreprocessor().getHeaderSearchInfo().getModuleMap();
1346+
SourceManager &SourceMgr = getSourceManager();
13551347

13561348
if (FileID ModuleMapFID = ModMap.getContainingModuleMapFileID(Module);
13571349
ModuleMapFID.isValid()) {
@@ -1372,8 +1364,8 @@ createCompilerInstanceForModuleCompile(CompilerInstance &ImportingInstance,
13721364
// Canonicalize compilation to start with the public module map. This is
13731365
// vital for submodules declarations in the private module maps to be
13741366
// correctly parsed when depending on a top level module in the public one.
1375-
if (OptionalFileEntryRef PublicMMFile = getPublicModuleMap(
1376-
*ModuleMapFile, ImportingInstance.getFileManager()))
1367+
if (OptionalFileEntryRef PublicMMFile =
1368+
getPublicModuleMap(*ModuleMapFile, getFileManager()))
13771369
ModuleMapFile = PublicMMFile;
13781370

13791371
StringRef ModuleMapFilePath = ModuleMapFile->getNameAsRequested();
@@ -1387,7 +1379,7 @@ createCompilerInstanceForModuleCompile(CompilerInstance &ImportingInstance,
13871379

13881380
// Use the module map where this module resides.
13891381
return createCompilerInstanceForModuleCompileImpl(
1390-
ImportingInstance, ImportLoc, ModuleName,
1382+
*this, ImportLoc, ModuleName,
13911383
FrontendInputFile(ModuleMapFilePath, IK, IsSystem),
13921384
ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName);
13931385
}
@@ -1404,7 +1396,7 @@ createCompilerInstanceForModuleCompile(CompilerInstance &ImportingInstance,
14041396
Module->print(OS);
14051397

14061398
auto Instance = createCompilerInstanceForModuleCompileImpl(
1407-
ImportingInstance, ImportLoc, ModuleName,
1399+
*this, ImportLoc, ModuleName,
14081400
FrontendInputFile(FakeModuleMapFile, IK, +Module->IsSystem),
14091401
ModMap.getModuleMapFileForUniquing(Module)->getName(), ModuleFileName);
14101402

@@ -1465,8 +1457,8 @@ static bool compileModuleAndReadASTImpl(CompilerInstance &ImportingInstance,
14651457
SourceLocation ModuleNameLoc,
14661458
Module *Module,
14671459
StringRef ModuleFileName) {
1468-
auto Instance = createCompilerInstanceForModuleCompile(
1469-
ImportingInstance, ModuleNameLoc, Module, ModuleFileName);
1460+
auto Instance = ImportingInstance.cloneForModuleCompile(ModuleNameLoc, Module,
1461+
ModuleFileName);
14701462

14711463
if (!compileModule(ImportingInstance, ModuleNameLoc,
14721464
Module->getTopLevelModuleName(), ModuleFileName,

clang/test/CodeGen/catch-alignment-assumption-array.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ void *caller(void) {
1616
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint ptr %[[ARRAYDECAY]] to i64
1717
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 0
1818
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
19-
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint ptr %[[ARRAYDECAY]] to i64, !nosanitize
2019
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
2120
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
21+
// CHECK-SANITIZE-ANYRECOVER-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint ptr %[[ARRAYDECAY]] to i64, !nosanitize
2222
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(ptr @[[ALIGNMENT_ASSUMPTION]], i64 %[[PTRINT_DUP]], i64 1, i64 0){{.*}}, !nosanitize
2323
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(ptr @[[ALIGNMENT_ASSUMPTION]], i64 %[[PTRINT_DUP]], i64 1, i64 0){{.*}}, !nosanitize
2424
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize

clang/test/CodeGen/catch-alignment-assumption-attribute-align_value-on-lvalue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ char **load_from_ac_struct(struct ac_struct *x) {
2424
// CHECK-SANITIZE-NEXT: %[[PTRINT:.*]] = ptrtoint ptr %[[A]] to i64
2525
// CHECK-SANITIZE-NEXT: %[[MASKEDPTR:.*]] = and i64 %[[PTRINT]], 4294967295
2626
// CHECK-SANITIZE-NEXT: %[[MASKCOND:.*]] = icmp eq i64 %[[MASKEDPTR]], 0
27-
// CHECK-SANITIZE-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint ptr %[[A]] to i64, !nosanitize
2827
// CHECK-SANITIZE-NEXT: br i1 %[[MASKCOND]], label %[[CONT:.*]], label %[[HANDLER_ALIGNMENT_ASSUMPTION:[^,]+]],{{.*}} !nosanitize
2928
// CHECK-SANITIZE: [[HANDLER_ALIGNMENT_ASSUMPTION]]:
29+
// CHECK-SANITIZE-ANYRECOVER-NEXT: %[[PTRINT_DUP:.*]] = ptrtoint ptr %[[A]] to i64, !nosanitize
3030
// CHECK-SANITIZE-NORECOVER-NEXT: call void @__ubsan_handle_alignment_assumption_abort(ptr @[[LINE_100_ALIGNMENT_ASSUMPTION]], i64 %[[PTRINT_DUP]], i64 4294967296, i64 0){{.*}}, !nosanitize
3131
// CHECK-SANITIZE-RECOVER-NEXT: call void @__ubsan_handle_alignment_assumption(ptr @[[LINE_100_ALIGNMENT_ASSUMPTION]], i64 %[[PTRINT_DUP]], i64 4294967296, i64 0){{.*}}, !nosanitize
3232
// CHECK-SANITIZE-TRAP-NEXT: call void @llvm.ubsantrap(i8 23){{.*}}, !nosanitize

0 commit comments

Comments
 (0)