This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Support PC-relative relocations with addends
ClosedPublic

Authored by maksfb on Feb 22 2022, 7:11 PM.

Details

Summary

PC-relative memory operand could reference a different object from
the one located at the target address, e.g. when a negative offset
is used. Check relocations for the real referenced object.

Diff Detail

Event Timeline

maksfb requested review of this revision.Feb 22 2022, 7:11 PM
maksfb created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 22 2022, 7:11 PM
maksfb updated this revision to Diff 410698.Feb 22 2022, 7:59 PM

Update comment.

ayermolo added inline comments.Feb 23 2022, 10:24 AM
bolt/lib/Core/BinaryFunction.cpp
1359

I think I miss understand something. Why are we subtracting Addend from the Value of relocation? Isn't it S + A - P?
Presumably Relocation.Vaue is the address of the Symbol?

This comment was removed by maksfb.
maksfb added inline comments.Feb 23 2022, 10:29 AM
bolt/lib/Core/BinaryFunction.cpp
1359

Value is what the expression S + A - P evaluates to.

ayermolo added inline comments.Feb 23 2022, 10:56 AM
bolt/lib/Core/BinaryFunction.cpp
1359

Ah, had it backwards in my mind.

This revision is now accepted and ready to land.Feb 23 2022, 2:43 PM
yota9 added inline comments.Feb 23 2022, 3:12 PM
bolt/lib/Core/BinaryFunction.cpp
1401

Maybe move this code to smth like replaceMemOperandWithSymbolRef, that will use setOperandToSymbolRef ?

maksfb added inline comments.Feb 23 2022, 3:43 PM
bolt/lib/Core/BinaryFunction.cpp
1401

That's a reasonable suggestion. However, I'm in the process of refactoring the code to use MCSymbolizer that will render such effort wasteful. The new code will not be replacing the operand but generating the expression in-place.

This revision was automatically updated to reflect the committed changes.