summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibELF/Relocation.cpp
diff options
context:
space:
mode:
authorGunnar Beutner <gbeutner@serenityos.org>2021-07-26 15:04:10 +0200
committerAndreas Kling <kling@serenityos.org>2021-07-27 13:15:16 +0200
commitff292fbe5a8c8a33974c5de8a7e08ffd38753977 (patch)
treef999543189423b66e4c5a20ec3d8dc75ebc56579 /Userland/Libraries/LibELF/Relocation.cpp
parentdaeb371180263f25b2d57c580990f9bf250d8739 (diff)
downloadserenity-ff292fbe5a8c8a33974c5de8a7e08ffd38753977.zip
LibELF: Fix unaligned writes in the relocation code
Diffstat (limited to 'Userland/Libraries/LibELF/Relocation.cpp')
-rw-r--r--Userland/Libraries/LibELF/Relocation.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/Userland/Libraries/LibELF/Relocation.cpp b/Userland/Libraries/LibELF/Relocation.cpp
index f6e25ffcd4..b3c84e4cbf 100644
--- a/Userland/Libraries/LibELF/Relocation.cpp
+++ b/Userland/Libraries/LibELF/Relocation.cpp
@@ -53,10 +53,15 @@ bool perform_relative_relocations(FlatPtr base_address)
#else
VERIFY(ELF64_R_TYPE(relocation->r_info) == R_X86_64_RELATIVE);
#endif
- if (use_addend)
- *(FlatPtr*)(base_address + relocation->r_offset) = base_address + relocation->r_addend;
- else
- *(FlatPtr*)(base_address + relocation->r_offset) += base_address;
+ auto* patch_address = (FlatPtr*)(base_address + relocation->r_offset);
+ FlatPtr relocated_address;
+ if (use_addend) {
+ relocated_address = base_address + relocation->r_addend;
+ } else {
+ __builtin_memcpy(&relocated_address, patch_address, sizeof(relocated_address));
+ relocated_address += base_address;
+ }
+ __builtin_memcpy(patch_address, &relocated_address, sizeof(relocated_address));
}
return true;