[BOLT] Don't use section relocations when computing hash for data from other section
authorDenis Revunov <revunov.denis@huawei-partners.com>
Fri, 24 Mar 2023 18:50:07 +0000 (21:50 +0300)
committerDenis Revunov <rnovds@gmail.com>
Fri, 24 Mar 2023 18:59:50 +0000 (21:59 +0300)
commit22a4aaf2b0d2f54a4db79777273938fc5de75b39
tree880a5a80e1ee7fe97a19781b9a8c46c62f12bf2e
parentb4b4950f7f71c9f3bca457ddd1ca76da001a16fa
[BOLT] Don't use section relocations when computing hash for data from other section

When computing symbol hashes in BinarySection::hash, we try to find relocations
in the section which reference the passed BinaryData. We do so by doing
lower_bound on data begin offset and upper_bound on data end offset. Since
offsets are relative to the current section, if it is a data from the previous
section, we get underflow when computing offset and lower_bound returns
Relocations.end(). If this data also ends where current section begins,
upper_bound on zero offset will return some valid iterator if we have any
relocations after the first byte. Then we'll try to iterate from lower_bound to
upper_bound, since they're not equal, which in that case means we'll dereference
Relocations.end(), increment it, and try to do so until we reach the second
valid iterator. Of course we reach segfault earlier. In this patch we stop BOLT
from searching relocations for symbols outside of the current section.

Reviewed By: rafauler

Differential Revision: https://reviews.llvm.org/D146620
bolt/lib/Core/BinarySection.cpp
bolt/test/AArch64/Inputs/symbol-hashes.yaml [new file with mode: 0644]
bolt/test/AArch64/symbol-hashes.test [new file with mode: 0644]