This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: inline assembly as PIC code?


Jim Marshall <jim.marshall@wbemsolutions.com> writes:

> Both of these functions are declared with inline assembly (see
> below). When I force the compiler to use the GNU ld it compiles fine
> with out error. I was wondering if anyone here could tell me if there
> is a way to make the compiler generate PIC code for the asm, or is
> this something that has to be done to the asm code for that?

>      asm( ".global sparc_atomic_add_32");
>      asm( ".type sparc_atomic_add_32, #function");
>      asm( "sparc_atomic_add_32:");
>      asm( "    membar #LoadLoad | #LoadStore | #StoreStore | #StoreLoad");
>      asm( "    ld [%o0], %l0");
>      asm( "    add %l0, %o1, %l2");
>      asm( "    cas [%o0], %l0, %l2");
>      asm( "    cmp %l0, %l2");
>      asm( "    bne sparc_atomic_add_32");

Instead of branching to a global symbol, branch to a local one.
E.g. put a local label after the global one, and use that as the
branch target.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]