Skip to content

Commit 628f4c3

Browse files
authored
Merge pull request #5 from Xilinx/dominik.llvm_oct_31.FXML-1067
Bump LLVM to green commit 74fb770 from Oct. 31
2 parents d46f510 + a7694d2 commit 628f4c3

File tree

4,527 files changed

+235911
-70221
lines changed

Some content is hidden

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

4,527 files changed

+235911
-70221
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,10 +1236,10 @@ class BinaryContext {
12361236
return Size;
12371237
}
12381238

1239-
/// Verify that assembling instruction \p Inst results in the same sequence of
1240-
/// bytes as \p Encoding.
1241-
bool validateEncoding(const MCInst &Instruction,
1242-
ArrayRef<uint8_t> Encoding) const;
1239+
/// Validate that disassembling the \p Sequence of bytes into an instruction
1240+
/// and assembling the instruction again, results in a byte sequence identical
1241+
/// to the original one.
1242+
bool validateInstructionEncoding(ArrayRef<uint8_t> Sequence) const;
12431243

12441244
/// Return a function execution count threshold for determining whether
12451245
/// the function is 'hot'. Consider it hot if count is above the average exec

bolt/lib/Core/BinaryContext.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2287,19 +2287,25 @@ BinaryContext::calculateEmittedSize(BinaryFunction &BF, bool FixBranches) {
22872287
return std::make_pair(HotSize, ColdSize);
22882288
}
22892289

2290-
bool BinaryContext::validateEncoding(const MCInst &Inst,
2291-
ArrayRef<uint8_t> InputEncoding) const {
2290+
bool BinaryContext::validateInstructionEncoding(
2291+
ArrayRef<uint8_t> InputSequence) const {
2292+
MCInst Inst;
2293+
uint64_t InstSize;
2294+
DisAsm->getInstruction(Inst, InstSize, InputSequence, 0, nulls());
2295+
assert(InstSize == InputSequence.size() &&
2296+
"Disassembled instruction size does not match the sequence.");
2297+
22922298
SmallString<256> Code;
22932299
SmallVector<MCFixup, 4> Fixups;
22942300
raw_svector_ostream VecOS(Code);
22952301

22962302
MCE->encodeInstruction(Inst, VecOS, Fixups, *STI);
2297-
auto EncodedData = ArrayRef<uint8_t>((uint8_t *)Code.data(), Code.size());
2298-
if (InputEncoding != EncodedData) {
2303+
auto OutputSequence = ArrayRef<uint8_t>((uint8_t *)Code.data(), Code.size());
2304+
if (InputSequence != OutputSequence) {
22992305
if (opts::Verbosity > 1) {
23002306
errs() << "BOLT-WARNING: mismatched encoding detected\n"
2301-
<< " input: " << InputEncoding << '\n'
2302-
<< " output: " << EncodedData << '\n';
2307+
<< " input: " << InputSequence << '\n'
2308+
<< " output: " << OutputSequence << '\n';
23032309
}
23042310
return false;
23052311
}

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,7 +1217,7 @@ bool BinaryFunction::disassemble() {
12171217
// Check integrity of LLVM assembler/disassembler.
12181218
if (opts::CheckEncoding && !BC.MIB->isBranch(Instruction) &&
12191219
!BC.MIB->isCall(Instruction) && !BC.MIB->isNoop(Instruction)) {
1220-
if (!BC.validateEncoding(Instruction, FunctionData.slice(Offset, Size))) {
1220+
if (!BC.validateInstructionEncoding(FunctionData.slice(Offset, Size))) {
12211221
errs() << "BOLT-WARNING: mismatching LLVM encoding detected in "
12221222
<< "function " << *this << " for instruction :\n";
12231223
BC.printInstruction(errs(), Instruction, AbsoluteInstrAddr);
@@ -1233,15 +1233,10 @@ bool BinaryFunction::disassemble() {
12331233
break;
12341234
}
12351235

1236-
// Disassemble again without the symbolizer and check that the disassembly
1237-
// matches the assembler output.
1238-
MCInst TempInst;
1239-
BC.DisAsm->getInstruction(TempInst, Size, FunctionData.slice(Offset),
1240-
AbsoluteInstrAddr, nulls());
1241-
if (!BC.validateEncoding(TempInst, FunctionData.slice(Offset, Size))) {
1236+
if (!BC.validateInstructionEncoding(FunctionData.slice(Offset, Size))) {
12421237
errs() << "BOLT-WARNING: internal assembler/disassembler error "
12431238
"detected for AVX512 instruction:\n";
1244-
BC.printInstruction(errs(), TempInst, AbsoluteInstrAddr);
1239+
BC.printInstruction(errs(), Instruction, AbsoluteInstrAddr);
12451240
errs() << " in function " << *this << '\n';
12461241
setIgnored();
12471242
break;

bolt/lib/Rewrite/DWARFRewriter.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -498,20 +498,20 @@ void DWARFRewriter::updateUnitDebugInfo(
498498
Optional<uint64_t> Address = AttrVal.V.getAsAddress();
499499
const BinaryFunction *Function =
500500
BC.getBinaryFunctionContainingAddress(*Address);
501-
uint32_t Index = 0;
502-
// Preserving original address instead of using whatever ends up at this
503-
// index.
504-
if (!Function) {
505-
Index = AddrWriter->getIndexFromAddress(*Address, Unit);
506-
} else {
507-
const uint64_t UpdatedAddress =
508-
Function->translateInputToOutputAddress(*Address);
509-
Index = AddrWriter->getIndexFromAddress(UpdatedAddress, Unit);
510-
}
511-
if (AttrVal.V.getForm() == dwarf::DW_FORM_addrx)
501+
uint64_t UpdatedAddress = *Address;
502+
if (Function)
503+
UpdatedAddress =
504+
Function->translateInputToOutputAddress(UpdatedAddress);
505+
506+
if (AttrVal.V.getForm() == dwarf::DW_FORM_addrx) {
507+
const uint32_t Index =
508+
AddrWriter->getIndexFromAddress(UpdatedAddress, Unit);
512509
DebugInfoPatcher.addUDataPatch(AttrVal.Offset, Index, AttrVal.Size);
513-
else
510+
} else if (AttrVal.V.getForm() == dwarf::DW_FORM_addr) {
511+
DebugInfoPatcher.addLE32Patch(AttrVal.Offset, UpdatedAddress);
512+
} else {
514513
errs() << "BOLT-ERROR: unsupported form for " << Entry << "\n";
514+
}
515515
};
516516

517517
if (Optional<AttrInfo> AttrVal =

bolt/lib/Rewrite/RewriteInstance.cpp

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,6 @@ Error RewriteInstance::discoverStorage() {
407407
NamedRegionTimer T("discoverStorage", "discover storage", TimerGroupName,
408408
TimerGroupDesc, opts::TimeRewrite);
409409

410-
// Stubs are harmful because RuntimeDyld may try to increase the size of
411-
// sections accounting for stubs when we need those sections to match the
412-
// same size seen in the input binary, in case this section is a copy
413-
// of the original one seen in the binary.
414-
BC->EFMM.reset(new ExecutableFileMemoryManager(*BC, /*AllowStubs*/ false));
415-
BC->EFMM->setNewSecPrefix(getNewSecPrefix());
416-
BC->EFMM->setOrgSecPrefix(getOrgSecPrefix());
417-
418410
auto ELF64LEFile = dyn_cast<ELF64LEObjectFile>(InputFile);
419411
const ELFFile<ELF64LE> &Obj = ELF64LEFile->getELFFile();
420412

@@ -607,10 +599,19 @@ void RewriteInstance::parsePseudoProbe() {
607599
errs() << "BOLT-WARNING: fail in building GUID2FuncDescMap\n";
608600
return;
609601
}
602+
603+
MCPseudoProbeDecoder::Uint64Set GuidFilter;
604+
MCPseudoProbeDecoder::Uint64Map FuncStartAddrs;
605+
for (const BinaryFunction *F : BC->getAllBinaryFunctions()) {
606+
for (const MCSymbol *Sym : F->getSymbols()) {
607+
FuncStartAddrs[Function::getGUID(NameResolver::restore(Sym->getName()))] =
608+
F->getAddress();
609+
}
610+
}
610611
Contents = PseudoProbeSection->getContents();
611612
if (!BC->ProbeDecoder.buildAddress2ProbeMap(
612-
reinterpret_cast<const uint8_t *>(Contents.data()),
613-
Contents.size())) {
613+
reinterpret_cast<const uint8_t *>(Contents.data()), Contents.size(),
614+
GuidFilter, FuncStartAddrs)) {
614615
BC->ProbeDecoder.getAddress2ProbesMap().clear();
615616
errs() << "BOLT-WARNING: fail in building Address2ProbeMap\n";
616617
return;
@@ -974,7 +975,19 @@ void RewriteInstance::discoverFileObjects() {
974975
if (Name.empty()) {
975976
UniqueName = "ANONYMOUS." + std::to_string(AnonymousId++);
976977
} else if (cantFail(Symbol.getFlags()) & SymbolRef::SF_Global) {
977-
assert(!BC->getBinaryDataByName(Name) && "global name not unique");
978+
if (const BinaryData *BD = BC->getBinaryDataByName(Name)) {
979+
if (BD->getSize() == ELFSymbolRef(Symbol).getSize() &&
980+
BD->getAddress() == Address) {
981+
if (opts::Verbosity > 1)
982+
errs() << "BOLT-WARNING: ignoring duplicate global symbol " << Name
983+
<< "\n";
984+
// Ignore duplicate entry - possibly a bug in the linker
985+
continue;
986+
}
987+
errs() << "BOLT-ERROR: bad input binary, global symbol \"" << Name
988+
<< "\" is not unique\n";
989+
exit(1);
990+
}
978991
UniqueName = Name;
979992
} else {
980993
// If we have a local file name, we should create 2 variants for the
@@ -1068,6 +1081,7 @@ void RewriteInstance::discoverFileObjects() {
10681081
if (opts::Verbosity >= 1)
10691082
outs() << "BOLT-INFO: skipping possibly another entry for function "
10701083
<< *PreviousFunction << " : " << UniqueName << '\n';
1084+
registerName(SymbolSize);
10711085
} else {
10721086
outs() << "BOLT-INFO: using " << UniqueName << " as another entry to "
10731087
<< "function " << *PreviousFunction << '\n';
@@ -1084,7 +1098,6 @@ void RewriteInstance::discoverFileObjects() {
10841098
assert(SI->second == Symbol && "wrong symbol found");
10851099
FileSymRefs.erase(SI);
10861100
}
1087-
registerName(SymbolSize);
10881101
continue;
10891102
}
10901103

@@ -1273,9 +1286,12 @@ void RewriteInstance::createPLTBinaryFunction(uint64_t TargetAddress,
12731286

12741287
ErrorOr<BinarySection &> Section = BC->getSectionForAddress(EntryAddress);
12751288
assert(Section && "cannot get section for address");
1276-
BF = BC->createBinaryFunction(Rel->Symbol->getName().str() + "@PLT", *Section,
1277-
EntryAddress, 0, EntrySize,
1278-
Section->getAlignment());
1289+
if (!BF)
1290+
BF = BC->createBinaryFunction(Rel->Symbol->getName().str() + "@PLT",
1291+
*Section, EntryAddress, 0, EntrySize,
1292+
Section->getAlignment());
1293+
else
1294+
BF->addAlternativeName(Rel->Symbol->getName().str() + "@PLT");
12791295
setPLTSymbol(BF, Rel->Symbol->getName());
12801296
}
12811297

@@ -1407,15 +1423,19 @@ void RewriteInstance::disassemblePLT() {
14071423
continue;
14081424

14091425
analyzeOnePLTSection(Section, PLTSI->EntrySize);
1410-
// If we did not register any function at the start of the section,
1411-
// then it must be a general PLT entry. Add a function at the location.
1412-
if (BC->getBinaryFunctions().find(Section.getAddress()) ==
1413-
BC->getBinaryFunctions().end()) {
1414-
BinaryFunction *BF = BC->createBinaryFunction(
1426+
1427+
BinaryFunction *PltBF;
1428+
auto BFIter = BC->getBinaryFunctions().find(Section.getAddress());
1429+
if (BFIter != BC->getBinaryFunctions().end()) {
1430+
PltBF = &BFIter->second;
1431+
} else {
1432+
// If we did not register any function at the start of the section,
1433+
// then it must be a general PLT entry. Add a function at the location.
1434+
PltBF = BC->createBinaryFunction(
14151435
"__BOLT_PSEUDO_" + Section.getName().str(), Section,
14161436
Section.getAddress(), 0, PLTSI->EntrySize, Section.getAlignment());
1417-
BF->setPseudo(true);
14181437
}
1438+
PltBF->setPseudo(true);
14191439
}
14201440
}
14211441

@@ -3180,6 +3200,14 @@ void RewriteInstance::emitAndLink() {
31803200
MCAsmLayout FinalLayout(
31813201
static_cast<MCObjectStreamer *>(Streamer.get())->getAssembler());
31823202

3203+
// Disable stubs because RuntimeDyld may try to increase the size of
3204+
// sections accounting for stubs. We need those sections to match the
3205+
// same size seen in the input binary, in case this section is a copy
3206+
// of the original one seen in the binary.
3207+
BC->EFMM.reset(new ExecutableFileMemoryManager(*BC, /*AllowStubs=*/false));
3208+
BC->EFMM->setNewSecPrefix(getNewSecPrefix());
3209+
BC->EFMM->setOrgSecPrefix(getOrgSecPrefix());
3210+
31833211
RTDyld.reset(new decltype(RTDyld)::element_type(*BC->EFMM, Resolver));
31843212
RTDyld->setProcessAllSections(false);
31853213
RTDyld->loadObject(*Obj);
@@ -3407,6 +3435,8 @@ void RewriteInstance::encodePseudoProbes() {
34073435
// Address of the first probe is absolute.
34083436
// Other probes' address are represented by delta
34093437
auto EmitDecodedPseudoProbe = [&](MCDecodedPseudoProbe *&CurProbe) {
3438+
assert(!isSentinelProbe(CurProbe->getAttributes()) &&
3439+
"Sentinel probes should not be emitted");
34103440
EmitULEB128IntValue(CurProbe->getIndex());
34113441
uint8_t PackedType = CurProbe->getType() | (CurProbe->getAttributes() << 4);
34123442
uint8_t Flag =
@@ -3511,9 +3541,17 @@ void RewriteInstance::encodePseudoProbes() {
35113541
reinterpret_cast<const uint8_t *>(DescContents.data()),
35123542
DescContents.size());
35133543
StringRef ProbeContents = PseudoProbeSection->getOutputContents();
3544+
MCPseudoProbeDecoder::Uint64Set GuidFilter;
3545+
MCPseudoProbeDecoder::Uint64Map FuncStartAddrs;
3546+
for (const BinaryFunction *F : BC->getAllBinaryFunctions()) {
3547+
const uint64_t Addr =
3548+
F->isEmitted() ? F->getOutputAddress() : F->getAddress();
3549+
FuncStartAddrs[Function::getGUID(
3550+
NameResolver::restore(F->getOneName()))] = Addr;
3551+
}
35143552
DummyDecoder.buildAddress2ProbeMap(
35153553
reinterpret_cast<const uint8_t *>(ProbeContents.data()),
3516-
ProbeContents.size());
3554+
ProbeContents.size(), GuidFilter, FuncStartAddrs);
35173555
DummyDecoder.printProbesForAllAddresses(outs());
35183556
}
35193557
}

bolt/test/AArch64/double_jump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: %clang %cflags -O0 %s -o %t.exe
44
// RUN: llvm-bolt %t.exe -o %t.bolt --peepholes=double-jumps | \
55
// RUN: FileCheck %s -check-prefix=CHECKBOLT
6-
// RUN: llvm-objdump -d %t.bolt | FileCheck %s
6+
// RUN: llvm-objdump --no-print-imm-hex -d %t.bolt | FileCheck %s
77

88
// CHECKBOLT: BOLT-INFO: Peephole: 1 double jumps patched.
99

0 commit comments

Comments
 (0)