[BOLT] Avoid UB due to misaligned access. (#174990)

There is no guarantee that PatchOffset is suitably aligned for uint32_t,
and in BOLT's own tests, it is not aligned for uint32_t.

Fixes test failures seen with LLVM_USE_SANITIZER=Undefined.
This commit is contained in:
Harald van Dijk 2026-01-10 03:45:13 +00:00 committed by GitHub
parent a3f395484b
commit e720636120
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -648,9 +648,9 @@ void DWARF5AcceleratorTable::writeEntries() {
if (const auto Iter = EntryRelativeOffsets.find(*ParentOffset);
Iter != EntryRelativeOffsets.end()) {
const uint64_t PatchOffset = Entry->getPatchOffset();
uint32_t *Ptr =
reinterpret_cast<uint32_t *>(&EntriesBuffer->data()[PatchOffset]);
*Ptr = Iter->second;
uint32_t RelativeOffset = Iter->second;
memcpy(&EntriesBuffer->data()[PatchOffset], &RelativeOffset,
sizeof(uint32_t));
} else {
BC.errs() << "BOLT-WARNING: [internal-dwarf-warning]: Could not find "
"entry with offset "