diff options
| author | Pete Cooper <peter_cooper@apple.com> | 2016-03-24 01:03:44 +0000 |
|---|---|---|
| committer | Pete Cooper <peter_cooper@apple.com> | 2016-03-24 01:03:44 +0000 |
| commit | a13f62f5f822aa7ea0e394c267b25400f8b88976 (patch) | |
| tree | 71666f4646ee85fdce17ca9e9c15d708e62a59c8 | |
| parent | 6278f933a87c40bcfd95e23c91574d9f245c0b5e (diff) | |
| download | bcm5719-llvm-a13f62f5f822aa7ea0e394c267b25400f8b88976.tar.gz bcm5719-llvm-a13f62f5f822aa7ea0e394c267b25400f8b88976.zip | |
Use unaligned read to fix UB. NFC.
We were casting a potentially unaligned pointer to uint32_t and
dereferencing. As the pointer ultimately comes from the object file,
there's no way to guarantee alignment, so use the little32_t read instead.
Also, little32_t knows about endianness, so in theory this may have broken on
big endian machines.
llvm-svn: 264231
| -rw-r--r-- | lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp index f7f37dc7bfe..103365fc3e6 100644 --- a/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp +++ b/lld/lib/ReaderWriter/MachO/ArchHandler_arm64.cpp @@ -477,7 +477,6 @@ std::error_code ArchHandler_arm64::getPairReferenceInfo( FindAtomBySymbolIndex atomFromSymbolIndex, Reference::KindValue *kind, const lld::Atom **target, Reference::Addend *addend) { const uint8_t *fixupContent = &inAtom->rawContent()[offsetInAtom]; - const uint32_t *cont32 = reinterpret_cast<const uint32_t *>(fixupContent); switch (relocPattern(reloc1) << 16 | relocPattern(reloc2)) { case ((ARM64_RELOC_ADDEND | rLength4) << 16 | ARM64_RELOC_BRANCH26 | rPcRel | rExtern | rLength4): @@ -496,13 +495,15 @@ std::error_code ArchHandler_arm64::getPairReferenceInfo( *addend = reloc1.symbol; return std::error_code(); case ((ARM64_RELOC_ADDEND | rLength4) << 16 | - ARM64_RELOC_PAGEOFF12 | rExtern | rLength4): + ARM64_RELOC_PAGEOFF12 | rExtern | rLength4): { // ex: ldr w0, [x1, _foo@PAGEOFF] - *kind = offset12KindFromInstruction(*cont32); + uint32_t cont32 = (int32_t)*(const little32_t *)fixupContent; + *kind = offset12KindFromInstruction(cont32); if (auto ec = atomFromSymbolIndex(reloc2.symbol, target)) return ec; *addend = reloc1.symbol; return std::error_code(); + } case ((ARM64_RELOC_SUBTRACTOR | rExtern | rLength8) << 16 | ARM64_RELOC_UNSIGNED | rExtern | rLength8): // ex: .quad _foo - . |

