Skip to content

Commit 3a02689

Browse files
authored
Merge branch 'main' into users/el-ev/fold-masked-merge
2 parents 2f08e99 + 96eeb6c commit 3a02689

File tree

438 files changed

+8912
-2887
lines changed

Some content is hidden

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

438 files changed

+8912
-2887
lines changed

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2697,20 +2697,19 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
26972697
BD->nameStartsWith("_ZTCN"))) { // construction vtable
26982698
BinaryFunction *BF = BC->getBinaryFunctionContainingAddress(
26992699
SymbolAddress, /*CheckPastEnd*/ false, /*UseMaxSize*/ true);
2700-
if (!BF || BF->getAddress() != SymbolAddress) {
2701-
BC->errs()
2702-
<< "BOLT-ERROR: the virtual function table entry at offset 0x"
2703-
<< Twine::utohexstr(Rel.getOffset());
2704-
if (BF)
2705-
BC->errs() << " points to the middle of a function @ 0x"
2706-
<< Twine::utohexstr(BF->getAddress()) << "\n";
2707-
else
2708-
BC->errs() << " does not point to any function\n";
2709-
exit(1);
2700+
if (BF) {
2701+
if (BF->getAddress() != SymbolAddress) {
2702+
BC->errs()
2703+
<< "BOLT-ERROR: the virtual function table entry at offset 0x"
2704+
<< Twine::utohexstr(Rel.getOffset())
2705+
<< " points to the middle of a function @ 0x"
2706+
<< Twine::utohexstr(BF->getAddress()) << "\n";
2707+
exit(1);
2708+
}
2709+
BC->addRelocation(Rel.getOffset(), BF->getSymbol(), RType, Addend,
2710+
ExtractedValue);
2711+
return;
27102712
}
2711-
BC->addRelocation(Rel.getOffset(), BF->getSymbol(), RType, Addend,
2712-
ExtractedValue);
2713-
return;
27142713
}
27152714
}
27162715

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Test the fix that BOLT should skip special handling of any non-virtual
2+
// function pointer relocations in relative vtable.
3+
4+
// RUN: llvm-mc -filetype=obj -triple aarch64-unknown-gnu %s -o %t.o
5+
// RUN: %clang %cxxflags -fuse-ld=lld %t.o -o %t.so -Wl,-q
6+
// RUN: llvm-bolt %t.so -o %t.bolted.so
7+
8+
.text
9+
.p2align 2
10+
.type foo,@function
11+
foo:
12+
.cfi_startproc
13+
adrp x8, _ZTV3gooE
14+
add x8, x8, :lo12:_ZTV3gooE
15+
ldr x0, [x8]
16+
ret
17+
.Lfunc_end0:
18+
.size foo, .Lfunc_end0-foo
19+
.cfi_endproc
20+
21+
.type _fake_rtti_data,@object
22+
.section .rodata.cst16._fake_rtti_data,"aMG",@progbits,16,_fake_rtti_data,comdat
23+
.p2align 3, 0x0
24+
_fake_rtti_data:
25+
.ascii "_FAKE_RTTI_DATA_"
26+
.size _fake_rtti_data, 16
27+
28+
.type _ZTV3gooE,@object
29+
.section .rodata,"a",@progbits
30+
.p2align 2, 0x0
31+
_ZTV3gooE:
32+
.word 0
33+
.word _fake_rtti_data-_ZTV3gooE-8
34+
.word foo@PLT-_ZTV3gooE-8
35+
.size _ZTV3gooE, 12

bolt/test/non-empty-debug-line.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
REQUIRES: system-linux
55

66
RUN: %clang %cflags %S/Inputs/hello.c -g -o %t
7-
RUN: llvm-bolt %t -o %t1 --update-debug-sections --funcs=_start
7+
RUN: llvm-bolt %t -o %t1 --update-debug-sections --funcs=_start --keep-nops
88
RUN: llvm-readobj -S %t > %t2
99
RUN: llvm-readobj -S %t1 >> %t2
1010
RUN: FileCheck %s --input-file %t2

clang-tools-extra/clang-doc/BitcodeReader.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ static llvm::Error decodeRecord(const Record &R, std::optional<Location> &Field,
7979
if (R[0] > INT_MAX)
8080
return llvm::createStringError(llvm::inconvertibleErrorCode(),
8181
"integer too large to parse");
82-
Field.emplace(static_cast<int>(R[0]), Blob, static_cast<bool>(R[1]));
82+
Field.emplace(static_cast<int>(R[0]), static_cast<int>(R[1]), Blob,
83+
static_cast<bool>(R[2]));
8384
return llvm::Error::success();
8485
}
8586

@@ -130,7 +131,8 @@ static llvm::Error decodeRecord(const Record &R,
130131
if (R[0] > INT_MAX)
131132
return llvm::createStringError(llvm::inconvertibleErrorCode(),
132133
"integer too large to parse");
133-
Field.emplace_back(static_cast<int>(R[0]), Blob, static_cast<bool>(R[1]));
134+
Field.emplace_back(static_cast<int>(R[0]), static_cast<int>(R[1]), Blob,
135+
static_cast<bool>(R[2]));
134136
return llvm::Error::success();
135137
}
136138

clang-tools-extra/clang-doc/BitcodeWriter.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,16 @@ static void genLocationAbbrev(std::shared_ptr<llvm::BitCodeAbbrev> &Abbrev) {
7878
{// 0. Fixed-size integer (line number)
7979
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
8080
BitCodeConstants::LineNumberSize),
81-
// 1. Boolean (IsFileInRootDir)
81+
// 1. Fixed-size integer (start line number)
82+
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
83+
BitCodeConstants::LineNumberSize),
84+
// 2. Boolean (IsFileInRootDir)
8285
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
8386
BitCodeConstants::BoolSize),
84-
// 2. Fixed-size integer (length of the following string (filename))
87+
// 3. Fixed-size integer (length of the following string (filename))
8588
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Fixed,
8689
BitCodeConstants::StringLengthSize),
87-
// 3. The string blob
90+
// 4. The string blob
8891
llvm::BitCodeAbbrevOp(llvm::BitCodeAbbrevOp::Blob)});
8992
}
9093

@@ -357,7 +360,8 @@ void ClangDocBitcodeWriter::emitRecord(const Location &Loc, RecordId ID) {
357360
if (!prepRecordData(ID, true))
358361
return;
359362
// FIXME: Assert that the line number is of the appropriate size.
360-
Record.push_back(Loc.LineNumber);
363+
Record.push_back(Loc.StartLineNumber);
364+
Record.push_back(Loc.EndLineNumber);
361365
assert(Loc.Filename.size() < (1U << BitCodeConstants::StringLengthSize));
362366
Record.push_back(Loc.IsFileInRootDir);
363367
Record.push_back(Loc.Filename.size());

clang-tools-extra/clang-doc/HTMLGenerator.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static std::unique_ptr<TagNode> writeSourceFileRef(const ClangDocContext &CDCtx,
455455

456456
if (!L.IsFileInRootDir && !CDCtx.RepositoryUrl)
457457
return std::make_unique<TagNode>(
458-
HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
458+
HTMLTag::TAG_P, "Defined at line " + std::to_string(L.StartLineNumber) +
459459
" of file " + L.Filename);
460460

461461
SmallString<128> FileURL(CDCtx.RepositoryUrl.value_or(""));
@@ -472,13 +472,14 @@ static std::unique_ptr<TagNode> writeSourceFileRef(const ClangDocContext &CDCtx,
472472
llvm::sys::path::Style::windows));
473473
auto Node = std::make_unique<TagNode>(HTMLTag::TAG_P);
474474
Node->Children.emplace_back(std::make_unique<TextNode>("Defined at line "));
475-
auto LocNumberNode =
476-
std::make_unique<TagNode>(HTMLTag::TAG_A, std::to_string(L.LineNumber));
475+
auto LocNumberNode = std::make_unique<TagNode>(
476+
HTMLTag::TAG_A, std::to_string(L.StartLineNumber));
477477
// The links to a specific line in the source code use the github /
478478
// googlesource notation so it won't work for all hosting pages.
479479
LocNumberNode->Attributes.emplace_back(
480-
"href", formatv("{0}#{1}{2}", FileURL,
481-
CDCtx.RepositoryLinePrefix.value_or(""), L.LineNumber));
480+
"href",
481+
formatv("{0}#{1}{2}", FileURL, CDCtx.RepositoryLinePrefix.value_or(""),
482+
L.StartLineNumber));
482483
Node->Children.emplace_back(std::move(LocNumberNode));
483484
Node->Children.emplace_back(std::make_unique<TextNode>(" of file "));
484485
auto LocFileNode = std::make_unique<TagNode>(

clang-tools-extra/clang-doc/MDGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ static void writeSourceFileRef(const ClangDocContext &CDCtx, const Location &L,
5656
raw_ostream &OS) {
5757

5858
if (!CDCtx.RepositoryUrl) {
59-
OS << "*Defined at " << L.Filename << "#" << std::to_string(L.LineNumber)
60-
<< "*";
59+
OS << "*Defined at " << L.Filename << "#"
60+
<< std::to_string(L.StartLineNumber) << "*";
6161
} else {
6262

6363
OS << formatv("*Defined at [#{0}{1}{2}](#{0}{1}{3})*",
64-
CDCtx.RepositoryLinePrefix.value_or(""), L.LineNumber,
64+
CDCtx.RepositoryLinePrefix.value_or(""), L.StartLineNumber,
6565
L.Filename, *CDCtx.RepositoryUrl);
6666
}
6767
OS << "\n\n";

clang-tools-extra/clang-doc/Mapper.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ template <typename T> static bool isTypedefAnonRecord(const T *D) {
2828
return false;
2929
}
3030

31+
Location MapASTVisitor::getDeclLocation(const NamedDecl *D) const {
32+
bool IsFileInRootDir;
33+
llvm::SmallString<128> File =
34+
getFile(D, D->getASTContext(), CDCtx.SourceRoot, IsFileInRootDir);
35+
SourceManager &SM = D->getASTContext().getSourceManager();
36+
int Start = SM.getPresumedLoc(D->getBeginLoc()).getLine();
37+
int End = SM.getPresumedLoc(D->getEndLoc()).getLine();
38+
39+
return Location(Start, End, File, IsFileInRootDir);
40+
}
41+
3142
void MapASTVisitor::HandleTranslationUnit(ASTContext &Context) {
3243
TraverseDecl(Context.getTranslationUnitDecl());
3344
}
@@ -59,9 +70,9 @@ bool MapASTVisitor::mapDecl(const T *D, bool IsDefinition) {
5970
bool IsFileInRootDir;
6071
llvm::SmallString<128> File =
6172
getFile(D, D->getASTContext(), CDCtx.SourceRoot, IsFileInRootDir);
62-
auto [Child, Parent] = serialize::emitInfo(
63-
D, getComment(D, D->getASTContext()), getLine(D, D->getASTContext()),
64-
File, IsFileInRootDir, CDCtx.PublicOnly);
73+
auto [Child, Parent] =
74+
serialize::emitInfo(D, getComment(D, D->getASTContext()),
75+
getDeclLocation(D), CDCtx.PublicOnly);
6576

6677
// A null in place of a valid Info indicates that the serializer is skipping
6778
// this decl for some reason (e.g. we're only reporting public decls).

clang-tools-extra/clang-doc/Mapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class MapASTVisitor : public clang::RecursiveASTVisitor<MapASTVisitor>,
4646
template <typename T> bool mapDecl(const T *D, bool IsDefinition);
4747

4848
int getLine(const NamedDecl *D, const ASTContext &Context) const;
49+
50+
Location getDeclLocation(const NamedDecl *D) const;
51+
4952
llvm::SmallString<128> getFile(const NamedDecl *D, const ASTContext &Context,
5053
StringRef RootDir,
5154
bool &IsFileInRootDir) const;

clang-tools-extra/clang-doc/Representation.h

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -241,31 +241,29 @@ struct MemberTypeInfo : public FieldTypeInfo {
241241
};
242242

243243
struct Location {
244-
Location(int LineNumber = 0, StringRef Filename = StringRef(),
245-
bool IsFileInRootDir = false)
246-
: LineNumber(LineNumber), Filename(Filename),
247-
IsFileInRootDir(IsFileInRootDir) {}
244+
Location(int StartLineNumber = 0, int EndLineNumber = 0,
245+
StringRef Filename = StringRef(), bool IsFileInRootDir = false)
246+
: StartLineNumber(StartLineNumber), EndLineNumber(EndLineNumber),
247+
Filename(Filename), IsFileInRootDir(IsFileInRootDir) {}
248248

249249
bool operator==(const Location &Other) const {
250-
return std::tie(LineNumber, Filename) ==
251-
std::tie(Other.LineNumber, Other.Filename);
250+
return std::tie(StartLineNumber, EndLineNumber, Filename) ==
251+
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
252252
}
253253

254-
bool operator!=(const Location &Other) const {
255-
return std::tie(LineNumber, Filename) !=
256-
std::tie(Other.LineNumber, Other.Filename);
257-
}
254+
bool operator!=(const Location &Other) const { return !(*this == Other); }
258255

259256
// This operator is used to sort a vector of Locations.
260257
// No specific order (attributes more important than others) is required. Any
261258
// sort is enough, the order is only needed to call std::unique after sorting
262259
// the vector.
263260
bool operator<(const Location &Other) const {
264-
return std::tie(LineNumber, Filename) <
265-
std::tie(Other.LineNumber, Other.Filename);
261+
return std::tie(StartLineNumber, EndLineNumber, Filename) <
262+
std::tie(Other.StartLineNumber, Other.EndLineNumber, Other.Filename);
266263
}
267264

268-
int LineNumber = 0; // Line number of this Location.
265+
int StartLineNumber = 0; // Line number of this Location.
266+
int EndLineNumber = 0;
269267
SmallString<32> Filename; // File for this Location.
270268
bool IsFileInRootDir = false; // Indicates if file is inside root directory
271269
};

0 commit comments

Comments
 (0)