[PATCH] D15965: Add support for dumping relocations in non-relocatable files

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 24 12:04:55 PDT 2016


On 24 March 2016 at 14:33, Colin LeMahieu <colinl at codeaurora.org> wrote:
> colinl added a comment.
>
>> The assert is correct. Whatever is calling getRelocationOffset should
>
>>  instead be trying to get the address.
>
>
> I disagree, the assertion isn't correct.
>

The spec is very explicit:

-----------------------------------------------------------------------------------
r_offset This member gives the location at which to apply the
relocation action. For a relocatable file, the value is the byte
offset from the beginning of the section to the storage unit affected
by the relocation. For an executable file or a shared object, the
value is the virtual address of the storage unit affected by the
relocation.
-----------------------------------------------------------------------------------

and

--------------------------------------------------
 Files used during linking must have a section header table; other
object files may or may not have one.
------------------------------------------------------

So the "offset in a section" might not even be defined.

> I'm not looking for the address, I'm looking for precisely the relocation offset.

Which may not exist and can only be computed by searching for the
*address* in the list of sections (if it exists).

So, you cannot remove the assert. You have to change the caller to
know that it can only get addresses out of relocations if the file is
an executable or shared object. *If* it is the case that there happens
to be a section covering that address, the caller can compute the
offset. If such a section doesn't exist, it has to do something
reasonable.

Cheers,
Rafael


More information about the llvm-commits mailing list