Add a special case for trivial alignment.

Normally to find the offset of a value in a section, we have to
compute the value since the alignment is defined on the final address.

If the alignment is trivial, we can skip the value computation. This
allows us to know the offset even in cases where we cannot yet know
the value.

llvm-svn: 313777
This commit is contained in:
Rafael Espindola
2017-09-20 17:43:44 +00:00
parent 5beb2c3ab3
commit 8b250344e9
2 changed files with 15 additions and 4 deletions

View File

@@ -71,6 +71,11 @@ uint64_t ExprValue::getSecAddr() const {
}
uint64_t ExprValue::getSectionOffset() const {
// If the alignment is trivial, we don't have to compute the full
// value to know the offset. This allows this function to succeed in
// cases where the output section is not yet known.
if (Alignment == 1)
return Val;
return getValue() - getSecAddr();
}