[PATCH] MIPS: support PCREL GOT access
Maciej W. Rozycki
macro@orcam.me.uk
Fri Mar 1 17:38:29 GMT 2024
On Mon, 26 Feb 2024, YunQiang Su wrote:
> > We can try and do our best to produce correctly linked executables and
> > shared libraries and provide testsuite coverage for what we do, and then
>
> What my plan is (although I have no idea how to archive it with dejagnu):
> 1. f.c
> int f() {return 0;}
> mipsel-linux-gnu-gcc -O2 -mabi=32 f.c -shared -o libf.so
> 2. f1.c
> extern int f();
> int f1 () {return f();}
> mipsel-linux-gnu-gcc -O2 f1.c -shared -L. -lf -o libf1.so
But why do you want to write this code in C? It's so trivial you can
produce assembly for all the ABIs you want to cover (you can even start
with compiler output if you don't want to handcode it from scratch) and
use that as the test sources. We'll be able to verify it reliably then,
without a need for external components.
> 3. Let's inspect libf1.so with `objdump -DTC`
> 3.1 We can see the symbol 'f' is in an address, 00000520.
> 00000520 DF *UND* 00000000 f
> 3.2 We can see a line "00000520 <_MIPS_STUBS_>"
> 3.3 We can see the address of .got is "00010570 <__TMC_END__>"
> 3.3 We can see " 50c: 8f998040 lw t9,-32704(gp)"
> in <f1>, and
> GOT_ADR + GP_MAGIC + LW_OFFSET = GOT_SLOT_OF_F
> 0x00010570 + 0x7ff0 + (-32704) = 0x105a0
> 3.4 The content of address GOT_SLOT_OF_F (0x105a0) is 0x00000520.
There are existing test cases in ld/testsuite/ld-mips-elf/mips-elf.exp
that do various kinds of checks, including running multiple dump tools on
single linker output. Check the various `run_ld_link_tests' invocations.
You can examine GOT entries in a cooked way with `readelf -A' BTW.
Maciej
More information about the Binutils
mailing list