This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: How to use an R_ARM_GOT32 symbol in a S file?
- From: Jeffrey Walton <noloader at gmail dot com>
- To: Binutils <binutils at sourceware dot org>
- Date: Sun, 26 May 2019 17:47:53 -0400
- Subject: Re: How to use an R_ARM_GOT32 symbol in a S file?
- References: <CAH8yC8=p-sGNwFFKzg1FfVgZGC_C90SJXenpFNoP17H7xJeaDg@mail.gmail.com>
- Reply-to: noloader at gmail dot com
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