This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: How to use an R_ARM_GOT32 symbol in a S file?


On Sun, May 26, 2019 at 5:35 PM Jeffrey Walton <noloader@gmail.com> wrote:
>
> I'm having a heck of a time accessing a symbol in a project built with -fPIC.
>
> The symbol of interest is in a.c:
>
>     extern "C" unsigned int my_symbol;
>     unsigned int my_symbol = 0;
>
> Then, in b.S:
>
>     .extern my_symbol
>     ...
>     ldr    r12,=my_symbol
>     ldr    r12,[r12]
>
> Or:
>
>     .extern my_symbol
>     ...
>     adr    r12,my_symbol
>     ldr    r12,[r12]
>
> Or:
>
>     <other variations, including literal pool tricks>
>
> I can provide a bunch of different variations in b.S. Some of the
> failed attempts result in my_symbol as R_ARM_REL32 (which fails to
> runtime link in a shared object), R_ARM_ABS32 (which lacks position
> independence), or fails to compile/assemble.

My bad, I should have provided this. This is the dominant use case
that has to work for users:

    gcc -fPIC -march=armv7-a a.c -c
    gcc -fPIC  -march=armv7-a b.S -c
    gcc -shared -fPIC a.o b.o -o test.so

The compiler can be GCC or Clang. Additional compiler options can
include -mthumb or -marm. (GCC is -mthumb by default, and Clang is
-marm by default).

Jeff


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