summaryrefslogtreecommitdiff
path: root/bolt/lib/Rewrite/RewriteInstance.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'bolt/lib/Rewrite/RewriteInstance.cpp')
-rw-r--r--bolt/lib/Rewrite/RewriteInstance.cpp69
1 files changed, 45 insertions, 24 deletions
diff --git a/bolt/lib/Rewrite/RewriteInstance.cpp b/bolt/lib/Rewrite/RewriteInstance.cpp
index 8b78c53aa99b..958016384cd9 100644
--- a/bolt/lib/Rewrite/RewriteInstance.cpp
+++ b/bolt/lib/Rewrite/RewriteInstance.cpp
@@ -917,9 +917,6 @@ void RewriteInstance::discoverFileObjects() {
bool IsData = false;
uint64_t LastAddr = 0;
for (const auto &SymInfo : SortedSymbols) {
- if (LastAddr == SymInfo.Address) // don't repeat markers
- continue;
-
MarkerSymType MarkerType = BC->getMarkerType(SymInfo.Symbol);
// Treat ST_Function as code.
@@ -929,8 +926,14 @@ void RewriteInstance::discoverFileObjects() {
if (IsData) {
Expected<StringRef> NameOrError = SymInfo.Symbol.getName();
consumeError(NameOrError.takeError());
- BC->errs() << "BOLT-WARNING: function symbol " << *NameOrError
- << " lacks code marker\n";
+ if (LastAddr == SymInfo.Address) {
+ BC->errs() << "BOLT-WARNING: ignoring data marker conflicting with "
+ "function symbol "
+ << *NameOrError << '\n';
+ } else {
+ BC->errs() << "BOLT-WARNING: function symbol " << *NameOrError
+ << " lacks code marker\n";
+ }
}
MarkerType = MarkerSymType::CODE;
}
@@ -1084,7 +1087,7 @@ void RewriteInstance::discoverFileObjects() {
if (SymbolAddress == Section->getAddress() + Section->getSize()) {
assert(SymbolSize == 0 &&
- "unexpect non-zero sized symbol at end of section");
+ "unexpected non-zero sized symbol at end of section");
LLVM_DEBUG(
dbgs()
<< "BOLT-DEBUG: rejecting as symbol points to end of its section\n");
@@ -1511,6 +1514,12 @@ void RewriteInstance::registerFragments() {
}
if (BD) {
BinaryFunction *BF = BC->getFunctionForSymbol(BD->getSymbol());
+ if (BF == &Function) {
+ BC->errs()
+ << "BOLT-WARNING: fragment maps to the same function as parent: "
+ << Function << '\n';
+ continue;
+ }
if (BF) {
BC->registerFragment(Function, *BF);
continue;
@@ -2115,6 +2124,13 @@ void RewriteInstance::adjustCommandLineOptions() {
opts::SplitEH = false;
}
+ if (BC->isAArch64() && !opts::CompactCodeModel &&
+ opts::SplitStrategy == opts::SplitFunctionsStrategy::CDSplit) {
+ BC->errs() << "BOLT-ERROR: CDSplit is not supported with LongJmp. Try with "
+ "'--compact-code-model'\n";
+ exit(1);
+ }
+
if (opts::StrictMode && !BC->HasRelocations) {
BC->errs()
<< "BOLT-WARNING: disabling strict mode (-strict) in non-relocation "
@@ -2274,8 +2290,7 @@ uint32_t getRelocationSymbol(const ELFObjectFileBase *Obj,
bool RewriteInstance::analyzeRelocation(
const RelocationRef &Rel, uint32_t &RType, std::string &SymbolName,
bool &IsSectionRelocation, uint64_t &SymbolAddress, int64_t &Addend,
- uint64_t &ExtractedValue, bool &Skip) const {
- Skip = false;
+ uint64_t &ExtractedValue) const {
if (!Relocation::isSupported(RType))
return false;
@@ -2425,7 +2440,7 @@ void RewriteInstance::processDynamicRelocations() {
}
// The rest of dynamic relocations - DT_RELA.
- // The static executable might have .rela.dyn secion and not have PT_DYNAMIC
+ // The static executable might have .rela.dyn section and not have PT_DYNAMIC
if (!DynamicRelocationsSize && BC->IsStaticExecutable) {
ErrorOr<BinarySection &> DynamicRelSectionOrErr =
BC->getUniqueSectionByName(getRelaDynSectionName());
@@ -2707,9 +2722,8 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
int64_t Addend;
uint64_t ExtractedValue;
bool IsSectionRelocation;
- bool Skip;
if (!analyzeRelocation(Rel, RType, SymbolName, IsSectionRelocation,
- SymbolAddress, Addend, ExtractedValue, Skip)) {
+ SymbolAddress, Addend, ExtractedValue)) {
LLVM_DEBUG({
dbgs() << "BOLT-WARNING: failed to analyze relocation @ offset = "
<< formatv("{0:x}; type name = {1}\n", Rel.getOffset(), TypeName);
@@ -2718,14 +2732,6 @@ void RewriteInstance::handleRelocation(const SectionRef &RelocatedSection,
return;
}
- if (Skip) {
- LLVM_DEBUG({
- dbgs() << "BOLT-DEBUG: skipping relocation @ offset = "
- << formatv("{0:x}; type name = {1}\n", Rel.getOffset(), TypeName);
- });
- return;
- }
-
if (!IsFromCode && !IsWritable && (IsX86 || IsAArch64) &&
Relocation::isPCRelative(RType)) {
BinaryData *BD = BC->getBinaryDataContainingAddress(Rel.getOffset());
@@ -3341,6 +3347,8 @@ void RewriteInstance::initializeMetadataManager() {
MetadataManager.registerRewriter(createPseudoProbeRewriter(*BC));
MetadataManager.registerRewriter(createSDTRewriter(*BC));
+
+ MetadataManager.registerRewriter(createGNUPropertyRewriter(*BC));
}
void RewriteInstance::processSectionMetadata() {
@@ -3522,6 +3530,17 @@ void RewriteInstance::disassembleFunctions() {
}
}
+ // Check if fillCFIInfoFor removed any OpNegateRAState CFIs from the
+ // function.
+ if (Function.containedNegateRAState()) {
+ if (!opts::UpdateBranchProtection) {
+ BC->errs()
+ << "BOLT-ERROR: --update-branch-protection is set to false, but "
+ << Function.getPrintName() << " contains .cfi-negate-ra-state\n";
+ exit(1);
+ }
+ }
+
// Parse LSDA.
if (Function.getLSDAAddress() != 0 &&
!BC->getFragmentsToSkip().count(&Function)) {
@@ -3992,10 +4011,12 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
BC->outs() << '\n';
AllocationDone = true;
} else {
- BC->errs() << "BOLT-WARNING: original .text too small to fit the new code"
- << " using 0x" << Twine::utohexstr(opts::AlignText)
- << " alignment. " << CodeSize << " bytes needed, have "
- << BC->OldTextSectionSize << " bytes available.\n";
+ BC->errs() << "BOLT-WARNING: --use-old-text failed. The original .text "
+ "too small to fit the new code using 0x"
+ << Twine::utohexstr(opts::AlignText) << " alignment. "
+ << CodeSize << " bytes needed, have " << BC->OldTextSectionSize
+ << " bytes available. Rebuilding without --use-old-text may "
+ "produce a smaller binary\n";
opts::UseOldText = false;
}
}
@@ -4996,7 +5017,7 @@ void RewriteInstance::updateELFSymbolTable(
if (!Section)
return false;
- // Remove the section symbol iif the corresponding section was stripped.
+ // Remove the section symbol if the corresponding section was stripped.
if (Symbol.getType() == ELF::STT_SECTION) {
if (!getNewSectionIndex(Symbol.st_shndx))
return true;