Commit b2fa6047 authored by David 'Digit' Turner's avatar David 'Digit' Turner Committed by Commit Bot

android: crazy-linker: Fix 64-bit RELR relocation support.

When shifting a constant integer more than 32 bits, ensure
that it is a 64-bit constant, or chaos will ensue.

BUG=895194
R=pasko@chromium.org, agrieve@chromium.org, rmcilroy@chromium.org

Change-Id: I1fc334fc77b2f5f518b690936b60a0a7e0d78956
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1563997Reviewed-by: default avatarEgor Pasko <pasko@chromium.org>
Reviewed-by: default avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: David Turner <digit@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649849}
parent 571767b9
......@@ -4,6 +4,8 @@
#include "crazy_linker_relr_relocations.h"
#include <type_traits>
namespace crazy {
// Apply a single RELR relocation at virtual |offset| address, using
......@@ -35,6 +37,12 @@ void RelrRelocations::Apply(size_t load_bias) {
// An odd value corresponds to a bitmap of 31 or 63 words, based
// on the CPU bitness / word_size.
ELF::Addr offset = base;
// Right shift of signed integers has undefined behaviour before C++20.
static_assert(
std::is_unsigned<decltype(entry)>::value,
"The ELF::Relr type should be unsigned to avoid undefined behaviour");
while (entry != 0) {
entry >>= 1;
if ((entry & 1) != 0)
......
......@@ -71,7 +71,7 @@ TEST(RelrRelocations, ApplyWithSimpleBitmaps) {
ELF::Relr relr_table[kRelrSize] = {};
for (size_t n = 0; n < kDataSize; ++n) {
if ((n % 3) == 0)
relr_table[n / kBitsPerWord] |= (1 | (2 << (n % kBitsPerWord)));
relr_table[n / kBitsPerWord] |= 1U | (ELF::Relr(2) << (n % kBitsPerWord));
}
RelrRelocations relr;
relr.SetAddress(reinterpret_cast<uintptr_t>(relr_table));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment