[Lldb-commits] [lldb] r346244 - [ObjectFileELF] Fix misaligned read/writes caught by UBSan.
Davide Italiano via lldb-commits
lldb-commits at lists.llvm.org
Tue Nov 6 09:11:34 PST 2018
Author: davide
Date: Tue Nov 6 09:11:34 2018
New Revision: 346244
URL: http://llvm.org/viewvc/llvm-project?rev=346244&view=rev
Log:
[ObjectFileELF] Fix misaligned read/writes caught by UBSan.
Modified:
lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
Modified: lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp?rev=346244&r1=346243&r2=346244&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (original)
+++ lldb/trunk/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp Tue Nov 6 09:11:34 2018
@@ -2712,7 +2712,8 @@ unsigned ObjectFileELF::ApplyRelocations
uint64_t *dst = reinterpret_cast<uint64_t *>(
data_buffer_sp->GetBytes() + rel_section->GetFileOffset() +
ELFRelocation::RelocOffset64(rel));
- *dst = value + ELFRelocation::RelocAddend64(rel);
+ uint64_t val_offset = value + ELFRelocation::RelocAddend64(rel);
+ memcpy(dst, &val_offset, sizeof(uint64_t));
}
break;
}
@@ -2738,7 +2739,7 @@ unsigned ObjectFileELF::ApplyRelocations
uint32_t *dst = reinterpret_cast<uint32_t *>(
data_buffer_sp->GetBytes() + rel_section->GetFileOffset() +
ELFRelocation::RelocOffset32(rel));
- *dst = truncated_addr;
+ memcpy(dst, &truncated_addr, sizeof(uint32_t));
}
break;
}
Modified: lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp?rev=346244&r1=346243&r2=346244&view=diff
==============================================================================
--- lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp (original)
+++ lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp Tue Nov 6 09:11:34 2018
@@ -143,10 +143,17 @@ TEST_F(ObjectFileELFTest, GetModuleSpeci
EXPECT_EQ(Spec.GetUUID(), Uuid);
}
-#define CHECK_ABS32(offset, addend) \
- ASSERT_EQ((uint32_t)addend, *(uint32_t *)(bytes + offset))
-#define CHECK_ABS64(offset, addend) \
- ASSERT_EQ((uint64_t)addend, *(uint64_t *)(bytes + offset))
+static void CHECK_ABS32(uint8_t *bytes, uint32_t offset, uint32_t addend) {
+ uint32_t res;
+ memcpy(&res, (uint32_t *)(bytes + offset), sizeof(uint32_t));
+ ASSERT_EQ(addend, res);
+}
+
+static void CHECK_ABS64(uint8_t *bytes, uint64_t offset, uint64_t addend) {
+ uint64_t res;
+ memcpy(&res, (uint64_t *)(bytes + offset), sizeof(uint64_t));
+ ASSERT_EQ(addend, res);
+}
TEST_F(ObjectFileELFTest, TestAARCH64Relocations) {
std::string yaml = GetInputFilePath("debug-info-relocations.pcm.yaml");
@@ -193,13 +200,13 @@ TEST_F(ObjectFileELFTest, TestAARCH64Rel
// .rela.debug_info contains 9 relocations:
// 7 R_AARCH64_ABS32 - 2 R_AARCH64_ABS64
// None have a value. Four have addends.
- CHECK_ABS32(0x6, 0);
- CHECK_ABS32(0xC, 0);
- CHECK_ABS32(0x12, 45);
- CHECK_ABS32(0x16, 0);
- CHECK_ABS32(0x1A, 55);
- CHECK_ABS64(0x1E, 0);
- CHECK_ABS64(0x2B, 0);
- CHECK_ABS32(0x39, 73);
- CHECK_ABS32(0x44, 75);
+ CHECK_ABS32(bytes, 0x6, 0);
+ CHECK_ABS32(bytes, 0xC, 0);
+ CHECK_ABS32(bytes, 0x12, 45);
+ CHECK_ABS32(bytes, 0x16, 0);
+ CHECK_ABS32(bytes, 0x1A, 55);
+ CHECK_ABS64(bytes, 0x1E, 0);
+ CHECK_ABS64(bytes, 0x2B, 0);
+ CHECK_ABS32(bytes, 0x39, 73);
+ CHECK_ABS32(bytes, 0x44, 75);
}
More information about the lldb-commits
mailing list