@@ -568,13 +568,13 @@ struct FunctionDescription {
568
568
// / should be straightforward as most data is POD or an array of POD elements.
569
569
// / This metadata is used to reconstruct function CFGs.
570
570
struct ProfileWriterContext {
571
- IndCallDescription *IndCallDescriptions;
572
- IndCallTargetDescription *IndCallTargets;
573
- uint8_t *FuncDescriptions;
574
- char *Strings; // String table with function names used in this binary
571
+ const IndCallDescription *IndCallDescriptions;
572
+ const IndCallTargetDescription *IndCallTargets;
573
+ const uint8_t *FuncDescriptions;
574
+ const char *Strings; // String table with function names used in this binary
575
575
int FileDesc; // File descriptor for the file on disk backing this
576
576
// information in memory via mmap
577
- void *MMapPtr; // The mmap ptr
577
+ const void *MMapPtr; // The mmap ptr
578
578
int MMapSize; // The mmap size
579
579
580
580
// / Hash table storing all possible call destinations to detect untracked
@@ -721,7 +721,7 @@ static char *getBinaryPath() {
721
721
722
722
ProfileWriterContext readDescriptions () {
723
723
ProfileWriterContext Result;
724
- char *BinPath = getBinaryPath ();
724
+ const char *BinPath = getBinaryPath ();
725
725
assert (BinPath && BinPath[0 ] != ' \0 ' , " failed to find binary path" );
726
726
727
727
uint64_t FD = __open (BinPath, O_RDONLY,
@@ -732,23 +732,24 @@ ProfileWriterContext readDescriptions() {
732
732
733
733
// mmap our binary to memory
734
734
uint64_t Size = __lseek (FD, 0 , SEEK_END);
735
- uint8_t *BinContents = reinterpret_cast <uint8_t *>(
735
+ const uint8_t *BinContents = reinterpret_cast <uint8_t *>(
736
736
__mmap (0 , Size, PROT_READ, MAP_PRIVATE, FD, 0 ));
737
737
assert (BinContents != MAP_FAILED, " readDescriptions: Failed to mmap self!" );
738
738
Result.MMapPtr = BinContents;
739
739
Result.MMapSize = Size;
740
- Elf64_Ehdr *Hdr = reinterpret_cast <Elf64_Ehdr *>(BinContents);
741
- Elf64_Shdr *Shdr = reinterpret_cast <Elf64_Shdr *>(BinContents + Hdr->e_shoff );
742
- Elf64_Shdr *StringTblHeader = reinterpret_cast <Elf64_Shdr *>(
740
+ const Elf64_Ehdr *Hdr = reinterpret_cast <const Elf64_Ehdr *>(BinContents);
741
+ const Elf64_Shdr *Shdr =
742
+ reinterpret_cast <const Elf64_Shdr *>(BinContents + Hdr->e_shoff );
743
+ const Elf64_Shdr *StringTblHeader = reinterpret_cast <const Elf64_Shdr *>(
743
744
BinContents + Hdr->e_shoff + Hdr->e_shstrndx * Hdr->e_shentsize );
744
745
745
746
// Find .bolt.instr.tables with the data we need and set pointers to it
746
747
for (int I = 0 ; I < Hdr->e_shnum ; ++I) {
747
- char *SecName = reinterpret_cast <char *>(
748
+ const char *SecName = reinterpret_cast <const char *>(
748
749
BinContents + StringTblHeader->sh_offset + Shdr->sh_name );
749
750
if (compareStr (SecName, " .bolt.instr.tables" , 64 ) != 0 ) {
750
- Shdr = reinterpret_cast <Elf64_Shdr *>(BinContents + Hdr->e_shoff +
751
- (I + 1 ) * Hdr->e_shentsize );
751
+ Shdr = reinterpret_cast <const Elf64_Shdr *>(BinContents + Hdr->e_shoff +
752
+ (I + 1 ) * Hdr->e_shentsize );
752
753
continue ;
753
754
}
754
755
// Actual contents of the ELF note start after offset 20 decimal:
@@ -758,19 +759,19 @@ ProfileWriterContext readDescriptions() {
758
759
// Offset 12: Producer name (BOLT\0) (5 bytes + align to 4-byte boundary)
759
760
// Offset 20: Contents
760
761
uint32_t IndCallDescSize =
761
- *reinterpret_cast <uint32_t *>(BinContents + Shdr->sh_offset + 20 );
762
- uint32_t IndCallTargetDescSize = *reinterpret_cast <uint32_t *>(
762
+ *reinterpret_cast <const uint32_t *>(BinContents + Shdr->sh_offset + 20 );
763
+ uint32_t IndCallTargetDescSize = *reinterpret_cast <const uint32_t *>(
763
764
BinContents + Shdr->sh_offset + 24 + IndCallDescSize);
764
- uint32_t FuncDescSize =
765
- * reinterpret_cast < uint32_t *>( BinContents + Shdr->sh_offset + 28 +
766
- IndCallDescSize + IndCallTargetDescSize);
767
- Result.IndCallDescriptions = reinterpret_cast <IndCallDescription *>(
765
+ uint32_t FuncDescSize = * reinterpret_cast < const uint32_t *>(
766
+ BinContents + Shdr->sh_offset + 28 + IndCallDescSize +
767
+ IndCallTargetDescSize);
768
+ Result.IndCallDescriptions = reinterpret_cast <const IndCallDescription *>(
768
769
BinContents + Shdr->sh_offset + 24 );
769
- Result.IndCallTargets = reinterpret_cast <IndCallTargetDescription *>(
770
+ Result.IndCallTargets = reinterpret_cast <const IndCallTargetDescription *>(
770
771
BinContents + Shdr->sh_offset + 28 + IndCallDescSize);
771
772
Result.FuncDescriptions = BinContents + Shdr->sh_offset + 32 +
772
773
IndCallDescSize + IndCallTargetDescSize;
773
- Result.Strings = reinterpret_cast <char *>(
774
+ Result.Strings = reinterpret_cast <const char *>(
774
775
BinContents + Shdr->sh_offset + 32 + IndCallDescSize +
775
776
IndCallTargetDescSize + FuncDescSize);
776
777
return Result;
@@ -814,13 +815,14 @@ void printStats(const ProfileWriterContext &Ctx) {
814
815
strCopy (StatPtr,
815
816
" \n BOLT INSTRUMENTATION RUNTIME STATISTICS\n\n IndCallDescSize: " );
816
817
StatPtr = intToStr (StatPtr,
817
- Ctx.FuncDescriptions -
818
- reinterpret_cast < uint8_t *>( Ctx.IndCallDescriptions ),
818
+ Ctx.FuncDescriptions - reinterpret_cast < const uint8_t *>(
819
+ Ctx.IndCallDescriptions ),
819
820
10 );
820
821
StatPtr = strCopy (StatPtr, " \n FuncDescSize: " );
821
- StatPtr = intToStr (
822
- StatPtr,
823
- reinterpret_cast <uint8_t *>(Ctx.Strings ) - Ctx.FuncDescriptions , 10 );
822
+ StatPtr = intToStr (StatPtr,
823
+ reinterpret_cast <const uint8_t *>(Ctx.Strings ) -
824
+ Ctx.FuncDescriptions ,
825
+ 10 );
824
826
StatPtr = strCopy (StatPtr, " \n __bolt_instr_num_ind_calls: " );
825
827
StatPtr = intToStr (StatPtr, __bolt_instr_num_ind_calls, 10 );
826
828
StatPtr = strCopy (StatPtr, " \n __bolt_instr_num_funcs: " );
@@ -1549,7 +1551,7 @@ __bolt_instr_data_dump(int FD) {
1549
1551
Ctx.CallFlowTable ->forEachElement (visitCallFlowEntry, FD, &Ctx);
1550
1552
1551
1553
__fsync (FD);
1552
- __munmap (Ctx.MMapPtr , Ctx.MMapSize );
1554
+ __munmap (( void *) Ctx.MMapPtr , Ctx.MMapSize );
1553
1555
__close (Ctx.FileDesc );
1554
1556
HashAlloc.destroy ();
1555
1557
GlobalWriteProfileMutex->release ();
@@ -1756,7 +1758,7 @@ extern "C" __attribute((naked)) void __bolt_instr_start()
1756
1758
" jal x1, __bolt_instr_setup\n "
1757
1759
RESTORE_ALL
1758
1760
" setup_symbol:\n "
1759
- " auipc x5, %%pcrel_hi(__bolt_start_trampoline)\n "
1761
+ " auipc x5, %%pcrel_hi(__bolt_start_trampoline)\n "
1760
1762
" addi x5, x5, %%pcrel_lo(setup_symbol)\n "
1761
1763
" jr x5\n "
1762
1764
:::);
@@ -1788,8 +1790,8 @@ extern "C" void __bolt_instr_fini() {
1788
1790
__asm__ __volatile__ (
1789
1791
SAVE_ALL
1790
1792
" fini_symbol:\n "
1791
- " auipc x5, %%pcrel_hi(__bolt_fini_trampoline)\n "
1792
- " addi x5, x5, %%pcrel_lo(fini_symbol)\n "
1793
+ " auipc x5, %%pcrel_hi(__bolt_fini_trampoline)\n "
1794
+ " addi x5, x5, %%pcrel_lo(fini_symbol)\n "
1793
1795
" jalr x1, 0(x5)\n "
1794
1796
RESTORE_ALL
1795
1797
:::);
0 commit comments