6363#include < optional>
6464#include < system_error>
6565
66- #undef DEBUG_TYPE
66+ #undef DEBUG_TYPE
6767#define DEBUG_TYPE " bolt"
6868
6969using namespace llvm ;
@@ -109,15 +109,19 @@ cl::opt<bool> DumpDotAll(
109109 " enable '-print-loops' for color-coded blocks" ),
110110 cl::Hidden, cl::cat(BoltCategory));
111111
112- static cl::list<std::string> ForceFunctionNames (
113- " funcs" , cl::CommaSeparated,
114- cl::desc (" limit optimizations to functions from the list" ),
115- cl::value_desc(" func1,func2,func3,..." ), cl::Hidden, cl::cat(BoltCategory));
112+ static cl::list<std::string>
113+ ForceFunctionNames (" funcs" ,
114+ cl::CommaSeparated,
115+ cl::desc (" limit optimizations to functions from the list" ),
116+ cl::value_desc(" func1,func2,func3,..." ),
117+ cl::Hidden,
118+ cl::cat(BoltCategory));
116119
117120static cl::opt<std::string>
118- FunctionNamesFile (" funcs-file" ,
119- cl::desc (" file with list of functions to optimize" ),
120- cl::Hidden, cl::cat(BoltCategory));
121+ FunctionNamesFile (" funcs-file" ,
122+ cl::desc (" file with list of functions to optimize" ),
123+ cl::Hidden,
124+ cl::cat(BoltCategory));
121125
122126static cl::list<std::string> ForceFunctionNamesNR (
123127 " funcs-no-regex" , cl::CommaSeparated,
@@ -129,17 +133,22 @@ static cl::opt<std::string> FunctionNamesFileNR(
129133 cl::desc (" file with list of functions to optimize (non-regex)" ), cl::Hidden,
130134 cl::cat(BoltCategory));
131135
132- cl::opt<bool > KeepTmp (" keep-tmp" , cl::desc(" preserve intermediate .o file" ),
133- cl::Hidden, cl::cat(BoltCategory));
136+ cl::opt<bool >
137+ KeepTmp (" keep-tmp" ,
138+ cl::desc (" preserve intermediate .o file" ),
139+ cl::Hidden,
140+ cl::cat(BoltCategory));
134141
135- static cl::opt<unsigned > LiteThresholdPct (
136- " lite-threshold-pct" ,
137- cl::desc (
138- " threshold (in percent) for selecting functions to process in lite "
139- " mode. Higher threshold means fewer functions to process. E.g "
140- " threshold of 90 means only top 10 percent of functions with "
141- " profile will be processed." ),
142- cl::init(0 ), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltOptCategory));
142+ static cl::opt<unsigned >
143+ LiteThresholdPct (" lite-threshold-pct" ,
144+ cl::desc (" threshold (in percent) for selecting functions to process in lite "
145+ " mode. Higher threshold means fewer functions to process. E.g "
146+ " threshold of 90 means only top 10 percent of functions with "
147+ " profile will be processed." ),
148+ cl::init(0 ),
149+ cl::ZeroOrMore,
150+ cl::Hidden,
151+ cl::cat(BoltOptCategory));
143152
144153static cl::opt<unsigned > LiteThresholdCount (
145154 " lite-threshold-count" ,
@@ -191,35 +200,43 @@ static cl::opt<cl::boolOrDefault> RelocationMode(
191200
192201extern cl::opt<std::string> SaveProfile;
193202
194- static cl::list<std::string> SkipFunctionNames (
195- " skip-funcs" , cl::CommaSeparated, cl::desc(" list of functions to skip" ),
196- cl::value_desc(" func1,func2,func3,..." ), cl::Hidden, cl::cat(BoltCategory));
203+ static cl::list<std::string>
204+ SkipFunctionNames (" skip-funcs" ,
205+ cl::CommaSeparated,
206+ cl::desc (" list of functions to skip" ),
207+ cl::value_desc(" func1,func2,func3,..." ),
208+ cl::Hidden,
209+ cl::cat(BoltCategory));
197210
198211static cl::opt<std::string>
199- SkipFunctionNamesFile (" skip-funcs-file" ,
200- cl::desc (" file with list of functions to skip" ),
201- cl::Hidden, cl::cat(BoltCategory));
212+ SkipFunctionNamesFile (" skip-funcs-file" ,
213+ cl::desc (" file with list of functions to skip" ),
214+ cl::Hidden,
215+ cl::cat(BoltCategory));
202216
203- cl::opt<bool > TrapOldCode (
204- " trap-old-code" ,
205- cl::desc (" insert traps in old function bodies (relocation mode)" ),
206- cl::Hidden, cl::cat(BoltCategory));
217+ cl::opt<bool >
218+ TrapOldCode (" trap-old-code" ,
219+ cl::desc (" insert traps in old function bodies (relocation mode)" ),
220+ cl::Hidden,
221+ cl::cat(BoltCategory));
207222
208223static cl::opt<std::string> DWPPathName (" dwp" ,
209224 cl::desc (" Path and name to DWP file." ),
210225 cl::Hidden, cl::init(" " ),
211226 cl::cat(BoltCategory));
212227
213- static cl::opt<bool > UseGnuStack (
214- " use-gnu-stack" ,
215- cl::desc (" use GNU_STACK program header for new segment (workaround for "
216- " issues with strip/objcopy)" ),
217- cl::ZeroOrMore, cl::cat(BoltCategory));
228+ static cl::opt<bool >
229+ UseGnuStack (" use-gnu-stack" ,
230+ cl::desc (" use GNU_STACK program header for new segment (workaround for "
231+ " issues with strip/objcopy)" ),
232+ cl::ZeroOrMore,
233+ cl::cat(BoltCategory));
218234
219235static cl::opt<bool >
220- SequentialDisassembly (" sequential-disassembly" ,
221- cl::desc (" performs disassembly sequentially" ),
222- cl::init(false ), cl::cat(BoltOptCategory));
236+ SequentialDisassembly (" sequential-disassembly" ,
237+ cl::desc (" performs disassembly sequentially" ),
238+ cl::init(false ),
239+ cl::cat(BoltOptCategory));
223240
224241static cl::opt<bool > WriteBoltInfoSection (
225242 " bolt-info" , cl::desc(" write bolt info section in the output binary" ),
@@ -502,12 +519,12 @@ Error RewriteInstance::discoverStorage() {
502519 for (const ELF64LE::Phdr &Phdr : PHs) {
503520 switch (Phdr.p_type ) {
504521 case ELF::PT_LOAD:
505- BC->FirstAllocAddress =
506- std::min (BC-> FirstAllocAddress , static_cast <uint64_t >(Phdr.p_vaddr ));
507- NextAvailableAddress =
508- std::max (NextAvailableAddress, Phdr.p_vaddr + Phdr.p_memsz );
509- NextAvailableOffset =
510- std::max (NextAvailableOffset, Phdr.p_offset + Phdr.p_filesz );
522+ BC->FirstAllocAddress = std::min (BC-> FirstAllocAddress ,
523+ static_cast <uint64_t >(Phdr.p_vaddr ));
524+ NextAvailableAddress = std::max (NextAvailableAddress,
525+ Phdr.p_vaddr + Phdr.p_memsz );
526+ NextAvailableOffset = std::max (NextAvailableOffset,
527+ Phdr.p_offset + Phdr.p_filesz );
511528
512529 BC->SegmentMapInfo [Phdr.p_vaddr ] = SegmentInfo{
513530 Phdr.p_vaddr , Phdr.p_memsz , Phdr.p_offset ,
@@ -1507,7 +1524,7 @@ void RewriteInstance::registerFragments() {
15071524 }
15081525 }
15091526
1510- registerParent:
1527+ registerParent:
15111528 // No local parent is found, use global parent function.
15121529 if (!ParentAddress)
15131530 if (BinaryData *ParentBD = BC->getBinaryDataByName (ParentName))
@@ -2340,12 +2357,14 @@ void RewriteInstance::readDynamicRelocations(const SectionRef &Section,
23402357 (void )SymbolAddress;
23412358 }
23422359
2343- LLVM_DEBUG (SmallString<16 > TypeName; Rel.getTypeName (TypeName);
2344- dbgs () << " BOLT-DEBUG: dynamic relocation at 0x"
2345- << Twine::utohexstr (Rel.getOffset ()) << " : " << TypeName
2346- << " : " << SymbolName << " : "
2347- << Twine::utohexstr (SymbolAddress) << " : + 0x"
2348- << Twine::utohexstr (Addend) << ' \n ' );
2360+ LLVM_DEBUG (
2361+ SmallString<16 > TypeName;
2362+ Rel.getTypeName (TypeName);
2363+ dbgs () << " BOLT-DEBUG: dynamic relocation at 0x"
2364+ << Twine::utohexstr (Rel.getOffset ()) << " : " << TypeName
2365+ << " : " << SymbolName << " : " << Twine::utohexstr (SymbolAddress)
2366+ << " : + 0x" << Twine::utohexstr (Addend) << ' \n '
2367+ );
23492368
23502369 if (IsJmpRel)
23512370 IsJmpRelocation[RType] = true ;
@@ -3648,8 +3667,9 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
36483667 return Section->getOutputAddress ();
36493668 });
36503669 LLVM_DEBUG (dbgs () << " Code sections in the order of output:\n " ;
3651- for (const BinarySection *Section : CodeSections) dbgs ()
3652- << Section->getName () << ' \n ' ;);
3670+ for (const BinarySection *Section : CodeSections)
3671+ dbgs () << Section->getName () << ' \n ' ;
3672+ );
36533673
36543674 uint64_t PaddingSize = 0 ; // size of padding required at the end
36553675
@@ -3816,9 +3836,13 @@ void RewriteInstance::mapCodeSections(BOLTLinker::SectionMapper MapSection) {
38163836 const unsigned Flags = BinarySection::getFlags (/* IsReadOnly=*/ true ,
38173837 /* IsText=*/ true ,
38183838 /* IsAllocatable=*/ true );
3819- BinarySection &Section = BC->registerOrUpdateSection (
3820- getBOLTTextSectionName (), ELF::SHT_PROGBITS, Flags,
3821- /* Data=*/ nullptr , NewTextSectionSize, 16 );
3839+ BinarySection &Section =
3840+ BC->registerOrUpdateSection (getBOLTTextSectionName (),
3841+ ELF::SHT_PROGBITS,
3842+ Flags,
3843+ /* Data=*/ nullptr ,
3844+ NewTextSectionSize,
3845+ 16 );
38223846 Section.setOutputAddress (NewTextSectionStartAddress);
38233847 Section.setOutputFileOffset (
38243848 getFileOffsetForAddress (NewTextSectionStartAddress));
@@ -4069,7 +4093,7 @@ uint64_t appendPadding(raw_pwrite_stream &OS, uint64_t Offset,
40694093 return Offset + PaddingSize;
40704094}
40714095
4072- } // namespace
4096+ }
40734097
40744098void RewriteInstance::rewriteNoteSections () {
40754099 auto ELF64LEFile = cast<ELF64LEObjectFile>(InputFile);
@@ -4189,9 +4213,12 @@ void RewriteInstance::finalizeSectionStringTable(ELFObjectFile<ELFT> *File) {
41894213 uint8_t *DataCopy = new uint8_t [SHStrTabSize];
41904214 memset (DataCopy, 0 , SHStrTabSize);
41914215 SHStrTab.write (DataCopy);
4192- BC->registerOrUpdateNoteSection (" .shstrtab" , DataCopy, SHStrTabSize,
4216+ BC->registerOrUpdateNoteSection (" .shstrtab" ,
4217+ DataCopy,
4218+ SHStrTabSize,
41934219 /* Alignment=*/ 1 ,
4194- /* IsReadOnly=*/ true , ELF::SHT_STRTAB);
4220+ /* IsReadOnly=*/ true ,
4221+ ELF::SHT_STRTAB);
41954222}
41964223
41974224void RewriteInstance::addBoltInfoSection () {
@@ -4447,9 +4474,11 @@ void RewriteInstance::patchELFSectionHeaderTable(ELFObjectFile<ELFT> *File) {
44474474 std::vector<uint32_t > NewSectionIndex;
44484475 std::vector<ELFShdrTy> OutputSections =
44494476 getOutputSections (File, NewSectionIndex);
4450- LLVM_DEBUG (dbgs () << " BOLT-DEBUG: old to new section index mapping:\n " ;
4451- for (uint64_t I = 0 ; I < NewSectionIndex.size (); ++I) dbgs ()
4452- << " " << I << " -> " << NewSectionIndex[I] << ' \n ' ;);
4477+ LLVM_DEBUG (
4478+ dbgs () << " BOLT-DEBUG: old to new section index mapping:\n " ;
4479+ for (uint64_t I = 0 ; I < NewSectionIndex.size (); ++I)
4480+ dbgs () << " " << I << " -> " << NewSectionIndex[I] << ' \n ' ;
4481+ );
44534482
44544483 // Align starting address for section header table. There's no architecutal
44554484 // need to align this, it is just for pleasant human readability.
@@ -4944,12 +4973,15 @@ void RewriteInstance::patchELFSymTabs(ELFObjectFile<ELFT> *File) {
49444973 if (DynSymSection) {
49454974 updateELFSymbolTable (
49464975 File,
4947- /* IsDynSym=*/ true , *DynSymSection, NewSectionIndex,
4976+ /* IsDynSym=*/ true ,
4977+ *DynSymSection,
4978+ NewSectionIndex,
49484979 [&](size_t Offset, const ELFSymTy &Sym) {
49494980 Out->os ().pwrite (reinterpret_cast <const char *>(&Sym),
4950- sizeof (ELFSymTy), DynSymSection->sh_offset + Offset);
4981+ sizeof (ELFSymTy),
4982+ DynSymSection->sh_offset + Offset);
49514983 },
4952- [](StringRef) -> size_t { return 0 ; });
4984+ [](StringRef) -> size_t { return 0 ; });;
49534985 }
49544986
49554987 if (opts::RemoveSymtab)
@@ -4979,7 +5011,9 @@ void RewriteInstance::patchELFSymTabs(ELFObjectFile<ELFT> *File) {
49795011 NumLocalSymbols = 0 ;
49805012 updateELFSymbolTable (
49815013 File,
4982- /* IsDynSym=*/ false , *SymTabSection, NewSectionIndex,
5014+ /* IsDynSym=*/ false ,
5015+ *SymTabSection,
5016+ NewSectionIndex,
49835017 [&](size_t Offset, const ELFSymTy &Sym) {
49845018 if (Sym.getBinding () == ELF::STB_LOCAL)
49855019 ++NumLocalSymbols;
@@ -4993,15 +5027,19 @@ void RewriteInstance::patchELFSymTabs(ELFObjectFile<ELFT> *File) {
49935027 return Idx;
49945028 });
49955029
4996- BC->registerOrUpdateNoteSection (SecName, copyByteArray (NewContents),
5030+ BC->registerOrUpdateNoteSection (SecName,
5031+ copyByteArray (NewContents),
49975032 NewContents.size (),
49985033 /* Alignment=*/ 1 ,
4999- /* IsReadOnly=*/ true , ELF::SHT_SYMTAB);
5034+ /* IsReadOnly=*/ true ,
5035+ ELF::SHT_SYMTAB);
50005036
5001- BC->registerOrUpdateNoteSection (StrSecName, copyByteArray (NewStrTab),
5037+ BC->registerOrUpdateNoteSection (StrSecName,
5038+ copyByteArray (NewStrTab),
50025039 NewStrTab.size (),
50035040 /* Alignment=*/ 1 ,
5004- /* IsReadOnly=*/ true , ELF::SHT_STRTAB);
5041+ /* IsReadOnly=*/ true ,
5042+ ELF::SHT_STRTAB);
50055043}
50065044
50075045template <typename ELFT>
@@ -5097,8 +5135,8 @@ void RewriteInstance::patchELFAllocatableRelrSection(
50975135}
50985136
50995137template <typename ELFT>
5100- void RewriteInstance::patchELFAllocatableRelaSections (
5101- ELFObjectFile<ELFT> *File) {
5138+ void
5139+ RewriteInstance::patchELFAllocatableRelaSections ( ELFObjectFile<ELFT> *File) {
51025140 using Elf_Rela = typename ELFT::Rela;
51035141 raw_fd_ostream &OS = Out->os ();
51045142 const ELFFile<ELFT> &EF = File->getELFFile ();
0 commit comments