[PATCH] MIPS: support PCREL GOT access

YunQiang Su syq@gcc.gnu.org
Sun Feb 25 16:00:47 GMT 2024


Maciej W. Rozycki <macro@orcam.me.uk> 于2024年2月7日周三 03:48写道:
>
> On Wed, 7 Feb 2024, YunQiang Su wrote:
>
> > >  The proper way to handle such verification is to tighten the test cases.
> > > Relocations have well-defined semantics, so you can prepare sources such
> > > as to get reproducible output you can then match against.  That means
> > > verifying exact bit patterns in files produced, and you can arrange for
> > > boundary cases, such as carry/borrow or overflow, to be verified where
> > > applicable too.  We have such detailed cases in our testsuite already.
> > >
> >
> > In fact I am worried that we use the wrong GOT slot, and the ldso
> > set the GOT incorrectly for use., which is not easy to test statically.
> > Bit by bit comparison is not easy, due to that the final executables
> > contains something from libc, which may have quite different versions.
>
>  You don't have to use libc at link time and using components from outside
> binutils is what makes compiled tests so problematic in our testsuite.  We
> avoid using external components where feasible.
>
>  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
   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.

@Maciej W. Rozycki Is this correct?

> if you want to verify ld.so, then do it with the testsuite for the
> relevant project: glibc, uClibc, musl, whatever.
>
>   Maciej


More information about the Binutils mailing list