MCFixup for distance from instruction to end of .text section

Hi,

I would like to use a MCFixup to encode the distance in number of bytes
from an instruction to the end of the .text section. Is there an
existing MCFixup type I can use for this? If not, does anyone have any
suggestions for how to add a new MCFixup type that will do this?

Thanks,
Tom

Hi Tom,

I would like to use a MCFixup to encode the distance in number of bytes
from an instruction to the end of the .text section. Is there an
existing MCFixup type I can use for this? If not, does anyone have any
suggestions for how to add a new MCFixup type that will do this?

If that end-point is going to be resolved at compile-time, I think
we'd usually create a dummy (local) label and then emit it at the
correct place; you'd probably just need a generic FK_PCRel_N fixup.

Otherwise, it's probably a target-specific FixupKind that gets emitted
as a relocation and some assembly syntax that you make up. I suppose
you could do the same trick with a real symbol and demand that the
linker defines it (similar to how "_GLOBAL_OFFSET_TABLE_" gets
defined, for example).

Cheers.

Tim.

In addition to what Tim has said I'm curious why you need or want to
do it at that time? Can you describe more of your aims/goals/etc with
this? I'd probably just set up a temporary for the end of the text
section and make sure it's emitted (take a look at what debug info
does here :wink: and then just use subtraction for the expression.

-eric

I was able to implement what I wanted using Tim's suggestion of adding a
dummy label. See the last patch in this email:
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20140714/225733.html

I was working on improved support for constant initializers, and I wanted
to store the constants after the program code and then use a fixup to
help calculate the address of the start of the constant data. Something
like:

s[0:1] = S_GETPC ; Get the program counter for the next instruction.
s0 = S_ADD_I32 s0, TextEndLabel ; Add the offset to the end of the text section.
s1 = S_ADDC_U32 s1, 0

This gives us a pointer to the start of the constants which we can use
to retrieve them.

For AMD GPU targets we extract relevant sections from the ELF binary and
upload them to the GPU to execute. So it doesn't matter if the .text
and .rodata are next to each other in the ELF file, because we will
place the data from those sections next to each other when we submit
the code to the device.

-Tom