Skip to content

Commit 425fe33

Browse files
authored
[lldb] Fix unaligned writes in ObjectFileELF (#165759)
The code to apply relocations was sometimes creating unaligned destination pointers. Instead of giving them an explicit type (i.e. `uint64_t *`) and forcing the compiler to generate unaligned stores, mark the pointer as `void *`. The compiler will figure out the correct series of store instructions.
1 parent 84a9ed2 commit 425fe33

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,9 +2735,8 @@ static void ApplyELF64ABS64Relocation(Symtab *symtab, ELFRelocation &rel,
27352735
// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
27362736
WritableDataBuffer *data_buffer =
27372737
llvm::cast<WritableDataBuffer>(data_buffer_sp.get());
2738-
uint64_t *dst = reinterpret_cast<uint64_t *>(
2739-
data_buffer->GetBytes() + rel_section->GetFileOffset() +
2740-
ELFRelocation::RelocOffset64(rel));
2738+
void *const dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
2739+
ELFRelocation::RelocOffset64(rel);
27412740
uint64_t val_offset = value + ELFRelocation::RelocAddend64(rel);
27422741
memcpy(dst, &val_offset, sizeof(uint64_t));
27432742
}
@@ -2762,9 +2761,8 @@ static void ApplyELF64ABS32Relocation(Symtab *symtab, ELFRelocation &rel,
27622761
// ObjectFileELF creates a WritableDataBuffer in CreateInstance.
27632762
WritableDataBuffer *data_buffer =
27642763
llvm::cast<WritableDataBuffer>(data_buffer_sp.get());
2765-
uint32_t *dst = reinterpret_cast<uint32_t *>(
2766-
data_buffer->GetBytes() + rel_section->GetFileOffset() +
2767-
ELFRelocation::RelocOffset32(rel));
2764+
void *const dst = data_buffer->GetBytes() + rel_section->GetFileOffset() +
2765+
ELFRelocation::RelocOffset32(rel);
27682766
memcpy(dst, &truncated_addr, sizeof(uint32_t));
27692767
}
27702768
}

0 commit comments

Comments
 (0)