[PATCH] D148217: [BOLT][NFC] Fix UB due to unaligned load in DebugStrOffsetsWriter

Job Noorman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 13 05:14:44 PDT 2023


jobnoorman created this revision.
jobnoorman added reviewers: rafauler, maksfb, yota9, Amir.
Herald added subscribers: asb, treapster, pmatos, ayermolo, pengfei, kristof.beyls.
Herald added a project: All.
jobnoorman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The following tests fail when enabling UBSan due to an unaligned memory
load:

> runtime error: load of misaligned address 0x620000000643 for type
> 'const uint32_t' (aka 'const unsigned int'), which requires 4 byte
> alignment



  BOLT :: AArch64/asm-func-debug.test
  BOLT :: AArch64/update-debug-reloc.test
  BOLT :: X86/asm-func-debug.test
  BOLT :: X86/dwarf5-df-dualcu.test
  BOLT :: X86/dwarf5-df-mono-dualcu.test
  BOLT :: X86/dwarf5-ftypes-dwp-input-dwo-output.test
  BOLT :: X86/dwarf5-locaddrx.test
  BOLT :: X86/dwarf5-split-dwarf4-monolithic.test
  BOLT :: X86/inlined-function-mixed.test
  BOLT :: non-empty-debug-line.test

This patch fixes this by using read32le for the load.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D148217

Files:
  bolt/lib/Core/DebugData.cpp


Index: bolt/lib/Core/DebugData.cpp
===================================================================
--- bolt/lib/Core/DebugData.cpp
+++ bolt/lib/Core/DebugData.cpp
@@ -1166,7 +1166,7 @@
          "Dwarf String Offsets Byte Size is not supported.");
   uint32_t Index = 0;
   for (uint64_t Offset = 0; Offset < Contr->Size; Offset += DwarfOffsetByteSize)
-    IndexToAddressMap[Index++] = *reinterpret_cast<const uint32_t *>(
+    IndexToAddressMap[Index++] = support::endian::read32le(
         StrOffsetsSection.Data.data() + Contr->Base + Offset);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D148217.513180.patch
Type: text/x-patch
Size: 558 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230413/2d91b402/attachment.bin>


More information about the llvm-commits mailing list