@@ -3043,25 +3043,42 @@ void RewriteInstance::finalizeSectionStringTable(ELFObjectFile<ELFT> *File) {
3043
3043
3044
3044
void RewriteInstance::addBoltInfoSection () {
3045
3045
if (opts::AddBoltInfo) {
3046
- std::string Str ;
3047
- raw_string_ostream OS (Str );
3046
+ std::string DescStr ;
3047
+ raw_string_ostream DescOS (DescStr );
3048
3048
3049
- OS << " BOLT revision: " << BoltRevision << " , " << " command line:" ;
3049
+ DescOS << " BOLT revision: " << BoltRevision << " , " << " command line:" ;
3050
3050
for (auto I = 0 ; I < Argc; ++I) {
3051
- OS << " " << Argv[I];
3051
+ DescOS << " " << Argv[I];
3052
3052
}
3053
+ DescOS.flush ();
3054
+
3055
+ std::string Str;
3056
+ raw_string_ostream OS (Str);
3057
+ std::string NameStr = " GNU" ;
3058
+ const uint32_t NameSz = NameStr.size () + 1 ;
3059
+ const uint32_t DescSz = DescStr.size () + 1 ;
3060
+ const uint32_t Type = 4 ; // NT_GNU_GOLD_VERSION (gold version)
3061
+ OS.write (reinterpret_cast <const char *>(&(NameSz)), 4 );
3062
+ OS.write (reinterpret_cast <const char *>(&(DescSz)), 4 );
3063
+ OS.write (reinterpret_cast <const char *>(&(Type)), 4 );
3064
+ OS << NameStr << ' \0 ' ;
3065
+ for (uint64_t I = NameStr.size () + 1 ;
3066
+ I < RoundUpToAlignment (NameStr.size () + 1 , 4 ); ++I) {
3067
+ OS << ' \0 ' ;
3068
+ }
3069
+ OS << DescStr << ' \0 ' ;
3053
3070
3054
3071
const auto BoltInfo = OS.str ();
3055
3072
const auto SectionSize = BoltInfo.size ();
3056
3073
uint8_t *SectionData = new uint8_t [SectionSize];
3057
3074
memcpy (SectionData, BoltInfo.data (), SectionSize);
3058
- EFMM->NoteSectionInfo [" .bolt_info" ] =
3059
- SectionInfo (reinterpret_cast <uint64_t >(SectionData),
3060
- SectionSize ,
3061
- /* Alignment =*/ 1 ,
3062
- /* IsCode =*/ false ,
3063
- /* IsReadOnly =*/ true ,
3064
- /* IsLocal =*/ false );
3075
+ EFMM->NoteSectionInfo [" .note. bolt_info" ] =
3076
+ SectionInfo (reinterpret_cast <uint64_t >(SectionData), SectionSize ,
3077
+ /* Alignment= */ 1 ,
3078
+ /* IsCode =*/ false ,
3079
+ /* IsReadOnly =*/ true ,
3080
+ /* IsLocal =*/ false , 0 , 0 , 0 ,
3081
+ /* IsELFNote =*/ true );
3065
3082
}
3066
3083
}
3067
3084
@@ -3223,7 +3240,9 @@ RewriteInstance::getOutputSections(ELFObjectFile<ELFT> *File,
3223
3240
outs () << " BOLT-INFO: writing section header for " << SectionName << ' \n ' ;
3224
3241
ELFShdrTy NewSection;
3225
3242
NewSection.sh_name = SHStrTab.getOffset (SectionName);
3226
- NewSection.sh_type = (SI.IsStrTab ? ELF::SHT_STRTAB : ELF::SHT_PROGBITS);
3243
+ NewSection.sh_type =
3244
+ (SI.IsStrTab ? ELF::SHT_STRTAB
3245
+ : SI.IsELFNote ? ELF::SHT_NOTE : ELF::SHT_PROGBITS);
3227
3246
NewSection.sh_addr = 0 ;
3228
3247
NewSection.sh_offset = SI.FileOffset ;
3229
3248
NewSection.sh_size = SI.Size ;
0 commit comments