Skip to content

Commit 52cc87d

Browse files
rafaelaulermemfrob
authored andcommitted
[BOLT] Fix bolt_info ELF note
Summary: Small fix - align the end of the descriptor string as well, since readelf will detect when it is not aligned and print an error instead of printing BOLT version and command line. (cherry picked from FBD6023643)
1 parent 5660f48 commit 52cc87d

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

bolt/RewriteInstance.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,17 +3056,21 @@ void RewriteInstance::addBoltInfoSection() {
30563056
raw_string_ostream OS(Str);
30573057
std::string NameStr = "GNU";
30583058
const uint32_t NameSz = NameStr.size() + 1;
3059-
const uint32_t DescSz = DescStr.size() + 1;
3059+
const uint32_t DescSz = DescStr.size();
30603060
const uint32_t Type = 4; // NT_GNU_GOLD_VERSION (gold version)
30613061
OS.write(reinterpret_cast<const char*>(&(NameSz)), 4);
30623062
OS.write(reinterpret_cast<const char*>(&(DescSz)), 4);
30633063
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) {
3064+
OS << NameStr;
3065+
for (uint64_t I = NameStr.size();
3066+
I < RoundUpToAlignment(NameStr.size(), 4); ++I) {
3067+
OS << '\0';
3068+
}
3069+
OS << DescStr;
3070+
for (uint64_t I = DescStr.size();
3071+
I < RoundUpToAlignment(DescStr.size(), 4); ++I) {
30673072
OS << '\0';
30683073
}
3069-
OS << DescStr << '\0';
30703074

30713075
const auto BoltInfo = OS.str();
30723076
const auto SectionSize = BoltInfo.size();

0 commit comments

Comments
 (0)