On Nov 19, 2013, at 10:34 AM, Andrew Fish <af...@apple.com> wrote:
>
> On Nov 19, 2013, at 9:34 AM, Stephen Polkowski <step...@centtech.com> wrote:
>
>> Hello,
>>
>> I'm building a #GP fault handler for a shell application. I named my
>> file __gp_fault_handler.S and I added it to my inf file. Everything
>> compiles and
>> the exception handler actually works.
>>
>> However, now I want to set a global variable that is declared in a
>> separate "C" file. When I assemble my file GAS uses a R_X86_64_32S offset
>> to the
>> variable. In my other "C" files I see that the compiler uses a R_X86_64_64
>> offset
>> to my variable instead.
>>
>> How can I get the GNU assembler to output a R_X86_64_64 offset in the
>> EDK2 build?
>>
>
I forgot to mention that clang does not support R_X86_64_* so PC relative
addressing is required in the X64 edk2 assembly files to be compatible with
clang. The PC relative addressing avoids the relocation all together. But a PC
relative access would solve your issue, and make your code more portable.
Thanks,
Andrew Fish
> Well I use clang so the answer may not be exactly the same….
>
> There are pseudo addressing modes for dealing with GOT (Global Offset Table)
> in the assembler. So I’m guessing you just need to use that addressing mode.
> So you can use something like _gGlobalName@GOTPCREL(%rip) to get the address
> of the global address into a register and then you can read the data. The
> offset will get resolved a link time.
>
> Here is a clang example (-S means make assemble file, -Os is optimize for
> size).
>
> ~/work/Compiler>cat global.c
>
> extern int gX;
>
> int main()
> {
> return gX;
> }
>
> ~/work/Compiler>clang -S global.c -Os
> ~/work/Compiler>cat global.S
> .section __TEXT,__text,regular,pure_instructions
> .globl _main
> _main: ## @main
> .cfi_startproc
> ## BB#0:
> pushq %rbp
> Ltmp2:
> .cfi_def_cfa_offset 16
> Ltmp3:
> .cfi_offset %rbp, -16
> movq %rsp, %rbp
> Ltmp4:
> .cfi_def_cfa_register %rbp
> movq _gX@GOTPCREL(%rip), %rax
> movl (%rax), %eax
> popq %rbp
> ret
> .cfi_endproc
>
>
> .subsections_via_symbols
>
> I don’t know of any code in the edk2 that does this, as it is much simpler to
> just place the global in the assembly file. Then all you have to do is
> _gGlobalName(%rip) to get the address of the global.
>
> Thanks,
>
> Andrew Fish
>
> ------------------------------------------------------------------------------
> Shape the Mobile Experience: Free Subscription
> Software experts and developers: Be at the forefront of tech innovation.
> Intel(R) Software Adrenaline delivers strategic insight and game-changing
> conversations that shape the rapidly evolving mobile landscape. Sign up now.
> http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk_______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
Shape the Mobile Experience: Free Subscription
Software experts and developers: Be at the forefront of tech innovation.
Intel(R) Software Adrenaline delivers strategic insight and game-changing
conversations that shape the rapidly evolving mobile landscape. Sign up now.
http://pubads.g.doubleclick.net/gampad/clk?id=63431311&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel