[llvm-dev] RFC: Absolute or "fixed address" symbols as immediate operands

Rafael EspĂ­ndola via llvm-dev llvm-dev at lists.llvm.org
Tue Oct 25 14:48:18 PDT 2016


On 25 October 2016 at 17:07, Reid Kleckner <rnk at google.com> wrote:
> On Tue, Oct 25, 2016 at 1:48 PM, Rafael EspĂ­ndola via llvm-dev
> <llvm-dev at lists.llvm.org> wrote:
>>
>> So, for the declaration, do you expect to know the value? If not just
>> a declaration to a GlobalVariable should be sufficient.
>
>
> No, the value will be discovered at link time, but we want instruction
> selection to treat the symbol as an immediate, not a GlobalAddress that will
> receive PIC and GOT treatment.
>
> If we use a declaration as you suggest, this example will compile awkwardly:
>
> @foo = external global i8
> define i64 @addfoo(i64 %v) {
>   %cast = ptrtoint i8* @foo to i64
>   %v1 = add i64 %v, %cast
>   ret i64 %v1
> }
>
> The ideal code is:
> addfoo:
>   leaq foo(%rdi), %rax
>   retq
>
> Today we select:
> addfoo:
>         addq    foo at GOTPCREL(%rip), %rdi
>         movq    %rdi, %rax
>         retq


You get the code you want with

@foo = external hidden global i8

or

@foo = external protected global i8


Cheers,
Rafael


More information about the llvm-dev mailing list