Thank you Andrew.  The pc relative addressing mode was the trick!

        movl $1, EXCEPTION_EXECUTE_HANDLER(%rip)

Regards,

Stephen


Andrew Fish wrote:
> 
> On Nov 19, 2013, at 9:34 AM, Stephen Polkowski <step...@centtech.com 
> <mailto: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?
>>
> 
> 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


-- 
Stephen Polkowski
Centaur Technology
Austin, TX
(512) 418-5730

------------------------------------------------------------------------------
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

Reply via email to