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 6:12 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Mai 26 2019, Jeffrey Walton <noloader@gmail.com> wrote:
>
> > 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
>
> Try looking at the gcc output.

Thanks Andreas. I haven't gotten that far due to compile/assembler errors.

According to the ARM manual on LDR [1], it _does not_ produce position
independent code. And according to the manual, ADR [2] does produce
position independent code and data. So I must use ADR or ADRL.

So, using ADR (and also ADRL):

    .extern my_symbol
    ...
    adr    r12,my_symbol
    ldr    r12,[r12]
    ...

    gcc -fPIC  -march=armv7-a b.S -c

Results in:

    b.S: Assembler messages:
    b.S:98: Error: undefined symbol my_symbol used as an immediate value

So I am obviously doing something wrong.

The bigger problem I am finding is, there's little documentation on
position independent code. I bought two books on ARM assembly language
and neither treats the subject.

[1] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0068b/Babbfdih.html
[2] http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0068b/Babcjaii.html


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