[LLVMdev] MCFixup for distance from instruction to end of .text section

Tom Stellard tom at stellard.net
Tue Jul 15 07:14:28 PDT 2014


On Mon, Jul 14, 2014 at 07:17:16PM -0700, Eric Christopher wrote:
> On Sun, Jul 13, 2014 at 12:55 AM, Tim Northover <t.p.northover at gmail.com> wrote:
> > Hi Tom,
> >
> > On 12 July 2014 22:52, Tom Stellard <tom at stellard.net> wrote:
> >> 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).
> >
> 
> 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 ;) and then just use subtraction for the expression.
> 

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



More information about the llvm-dev mailing list