[v4,5/7] MIPS: Fix some ld testcases with compiler

Message ID 20230616063412.1715024-6-yunqiang.su@cipunited.com
State Unresolved
Headers
Series Some MIPS changes and testsuite fixes |

Checks

Context Check Description
snail/binutils-gdb-check warning Git am fail log

Commit Message

YunQiang Su June 16, 2023, 6:34 a.m. UTC
  1. config/default.exp:
	use -mabi=32 not for -gnuabi64;
	xfail_from_runlist: remove an element and mark it xfail.
2. ld-elf/indirect.exp: xfail
	indirect5a, indirect5b, indirect6a, indirect6b,
	indirect5c, indirect5d, indirect6c, indirect6d.
3. ld-elf/pr23658-2: mips output is not common.
4. ld-elf/shared.exp: non-run on mips: Build libpr16496b.so.
5. ld-elfvers/vers.exp:
	xfail vers4, vers4b;
	no-run on mips: vers24a, vers24b, vers24c.
6. ld-gc/gc.exp: add -KPIC into asflags for pr13683, pr14265, pr19161.
7. ld-mips-elf/mips-elf.exp:
	use noarch for mips16-local-stubs-1, since it use -mips4.
8. ld-plugin/lto.exp:
	no-run on mips/linux: PR ld/12982;
	add -KPIC into asflags for lto-3r, lto-5r, PR ld/19317 (2);
	xfail PR ld/15323 (4), PR ld/19317 (3).
9. ld-plugin/plugin.exp: xfail
	plugin claimfile lost symbol,
	plugin claimfile replace symbol,
	plugin claimfile replace symbol,
	plugin claimfile lost symbol with source,
	plugin claimfile replace symbol with source,
	plugin claimfile resolve symbol with source,
	plugin 2 with source lib,
	load plugin 2 with source,
	plugin 3 with source lib,
	load plugin 3 with source.
11. ld-selective/selective.exp: add -fno-PIC, which is needed for -mno-abicalls.
12. ld-shared/shared.exp: xfail shared (non PIC), shared (PIC main, non PIC so).
---
 ld/testsuite/config/default.exp         | 20 +++++++++++++++++++-
 ld/testsuite/ld-elf/indirect.exp        |  8 ++++++--
 ld/testsuite/ld-elf/pr23658-2.rd        |  2 +-
 ld/testsuite/ld-elf/shared.exp          | 12 +++++++++---
 ld/testsuite/ld-elfvers/vers.exp        | 12 +++++++-----
 ld/testsuite/ld-gc/gc.exp               |  5 +++++
 ld/testsuite/ld-mips-elf/mips-elf.exp   |  2 +-
 ld/testsuite/ld-plugin/lto.exp          | 11 ++++++++++-
 ld/testsuite/ld-plugin/plugin.exp       | 15 +++++++++++++++
 ld/testsuite/ld-selective/selective.exp |  2 +-
 ld/testsuite/ld-shared/shared.exp       |  4 +++-
 11 files changed, 77 insertions(+), 16 deletions(-)
  

Comments

Alan Modra June 19, 2023, 6:44 a.m. UTC | #1
Hi YunQiang Su,
I thought I'd take a detailed look at your patch modifying the generic
ELF tests for mips, despite not really being familiar enough with mips
to properly review mips changes.  Most of this review is not about
details of the patch but rather questioning whether you have done the
necessary analysis before xfailing tests.  It is reasonable to xfail a
test if for some reason a problem cannot be fixed, or even if a
problem is too difficult to be fixed.  On the other hand we don't want
a clean testsuite result if there are problems that should be fixed.

On Fri, Jun 16, 2023 at 02:34:10PM +0800, YunQiang Su wrote:
> 1. config/default.exp:
> 	use -mabi=32 not for -gnuabi64;
> 	xfail_from_runlist: remove an element and mark it xfail.

I dislike the use of xfail here.  xfail should only be used after
running a test, to record an expected fail.  Don't use it when a test
is not run.

> 2. ld-elf/indirect.exp: xfail
> 	indirect5a, indirect5b, indirect6a, indirect6b,
> 	indirect5c, indirect5d, indirect6c, indirect6d.

Can you explain why is it correct to xfail these for mips?  The first
four pass for me on mips-linux.  Is there a reason why the last four
must make "bar" dynamic on mips?

> 3. ld-elf/pr23658-2: mips output is not common.

The purpose of this test is to check the placement of orphan loaded
note sections.  These ought to be placed near the start of the first
PT_LOAD segment, so that they can be accessed by the kernel without
reading many disk pages.  Ideally they would be placed in the same
page as the file header.  This isn't happening for mips64, and I see
the standard scripts don't even mention .interp, a section that also
should be placed near the start of the first PT_LOAD.  Why not?!

> 4. ld-elf/shared.exp: non-run on mips: Build libpr16496b.so.

OK, seems like we will actually generate a correct .so here for mips,
so not much is lost by not running the testcase for mips.

> 5. ld-elfvers/vers.exp:
> 	xfail vers4, vers4b;

I see a ld segfault in _bfd_mips_elf_generic_reloc due to
symbol->section->output_section being NULL prior to this patch series.
I'd hope that someone making changes to the testsuite would have seen
this, and not ignored it.  No one expects you to make linking
non-native object files work, but not segfaulting it fairly important.

> 	no-run on mips: vers24a, vers24b, vers24c.

OK, fair enough.  Mips is different enough that it isn't expected to
pass these tests.

> 6. ld-gc/gc.exp: add -KPIC into asflags for pr13683, pr14265, pr19161.

OK.

> 7. ld-mips-elf/mips-elf.exp:
> 	use noarch for mips16-local-stubs-1, since it use -mips4.

I'll leave this for the mips maintainers to OK.

> 8. ld-plugin/lto.exp:
> 	no-run on mips/linux: PR ld/12982;

Please add a comment to lto.exp as to why mips requires an executable
stack.

> 	add -KPIC into asflags for lto-3r, lto-5r, PR ld/19317 (2);

OK.

> 	xfail PR ld/15323 (4), PR ld/19317 (3).

Please explain why the lto plugin won't handle the objects.

> 9. ld-plugin/plugin.exp: xfail
> 	plugin claimfile lost symbol,
> 	plugin claimfile replace symbol,
> 	plugin claimfile replace symbol,
> 	plugin claimfile lost symbol with source,
> 	plugin claimfile replace symbol with source,
> 	plugin claimfile resolve symbol with source,
> 	plugin 2 with source lib,
> 	load plugin 2 with source,
> 	plugin 3 with source lib,
> 	load plugin 3 with source.

These all pass on mips-linux, and on mips64-linux.  Why disable them?
Yes, I see fails on mips64-linux-gnuabi64 but that looks like a gcc
problem to me.

> 11. ld-selective/selective.exp: add -fno-PIC, which is needed for -mno-abicalls.

OK.

> 12. ld-shared/shared.exp: xfail shared (non PIC), shared (PIC main, non PIC so).

OK, and thanks for tweaking the xcoff test message.
  
YunQiang Su June 19, 2023, 10:43 a.m. UTC | #2
Alan Modra via Binutils <binutils@sourceware.org> 于2023年6月19日周一 14:44写道:
>
> Hi YunQiang Su,
> I thought I'd take a detailed look at your patch modifying the generic
> ELF tests for mips, despite not really being familiar enough with mips
> to properly review mips changes.  Most of this review is not about
> details of the patch but rather questioning whether you have done the
> necessary analysis before xfailing tests.  It is reasonable to xfail a
> test if for some reason a problem cannot be fixed, or even if a
> problem is too difficult to be fixed.  On the other hand we don't want
> a clean testsuite result if there are problems that should be fixed.
>
> On Fri, Jun 16, 2023 at 02:34:10PM +0800, YunQiang Su wrote:
> > 1. config/default.exp:
> >       use -mabi=32 not for -gnuabi64;
> >       xfail_from_runlist: remove an element and mark it xfail.
>
> I dislike the use of xfail here.  xfail should only be used after
> running a test, to record an expected fail.  Don't use it when a test
> is not run.
>

Maybe, kfail is better?

> > 2. ld-elf/indirect.exp: xfail
> >       indirect5a, indirect5b, indirect6a, indirect6b,
> >       indirect5c, indirect5d, indirect6c, indirect6d.
>
> Can you explain why is it correct to xfail these for mips?  The first
> four pass for me on mips-linux.  Is there a reason why the last four
> must make "bar" dynamic on mips?
>

Do you have a cross compiler installed?
These tests won't even try to run without a  corresponding cross
compiler installed.

The real problem seems due to the output of nm -D.

objdump -D on aarch64:
Disassembly of section .bss:
0000000000011038 <completed.0>:
        ...
0000000000011040 <bar>:
        ...

objdump -D on mips32el:
Disassembly of section .bss:
00010a70 <completed.1>:
   10a70:       00000000        nop
00010a74 <dtor_idx.0>:
        ...
00010a80 <bar>:
        ...

While the outputs of NM -D are different. Let me have a more dig about it.


> > 3. ld-elf/pr23658-2: mips output is not common.
>
> The purpose of this test is to check the placement of orphan loaded
> note sections.  These ought to be placed near the start of the first
> PT_LOAD segment, so that they can be accessed by the kernel without
> reading many disk pages.  Ideally they would be placed in the same
> page as the file header.  This isn't happening for mips64, and I see
> the standard scripts don't even mention .interp, a section that also
> should be placed near the start of the first PT_LOAD.  Why not?!
>

Oh, yes. This tiny patch can solve this problem.
I have no idea why it doesn't like that.
Maybe somebody forgot this in history.

@Maciej W. Rozycki Any ideas?

```
diff --git a/ld/emulparams/elf64bmip-defs.sh b/ld/emulparams/elf64bmip-defs.sh
index 4165f51e9e5..19d782d8e7a 100644
--- a/ld/emulparams/elf64bmip-defs.sh
+++ b/ld/emulparams/elf64bmip-defs.sh
@@ -1,6 +1,10 @@
 source_sh ${srcdir}/emulparams/elf32bmipn32-defs.sh
 COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
-INITIAL_READONLY_SECTIONS="
+INITIAL_READONLY_SECTIONS=
+if test -z "${CREATE_SHLIB}"; then
+  INITIAL_READONLY_SECTIONS=".interp       ${RELOCATING-0} : { *(.interp) }"
+fi
+INITIAL_READONLY_SECTIONS="${INITIAL_READONLY_SECTIONS}
   .MIPS.abiflags      ${RELOCATING-0} : { *(.MIPS.abiflags) }
   .MIPS.xhash      ${RELOCATING-0} : { *(.MIPS.xhash) }
   .MIPS.options : { *(.MIPS.options) }
```

> > 4. ld-elf/shared.exp: non-run on mips: Build libpr16496b.so.
>
> OK, seems like we will actually generate a correct .so here for mips,
> so not much is lost by not running the testcase for mips.
>

Should we add a pr16496b-mips.od file?

> > 5. ld-elfvers/vers.exp:
> >       xfail vers4, vers4b;
>
> I see a ld segfault in _bfd_mips_elf_generic_reloc due to
> symbol->section->output_section being NULL prior to this patch series.
> I'd hope that someone making changes to the testsuite would have seen
> this, and not ignored it.  No one expects you to make linking
> non-native object files work, but not segfaulting it fairly important.
>

Maybe we should grep segfault in the log files on our CI system.
I will try to do so.

FYI: I run my test here:
https://oss.cipunited.com/ci/job/Toolchain/job/binutils-cross/

> >       no-run on mips: vers24a, vers24b, vers24c.
>
> OK, fair enough.  Mips is different enough that it isn't expected to
> pass these tests.
>
> > 6. ld-gc/gc.exp: add -KPIC into asflags for pr13683, pr14265, pr19161.
>
> OK.
>
> > 7. ld-mips-elf/mips-elf.exp:
> >       use noarch for mips16-local-stubs-1, since it use -mips4.
>
> I'll leave this for the mips maintainers to OK.
>
> > 8. ld-plugin/lto.exp:
> >       no-run on mips/linux: PR ld/12982;
>
> Please add a comment to lto.exp as to why mips requires an executable
> stack.
>
> >       add -KPIC into asflags for lto-3r, lto-5r, PR ld/19317 (2);
>
> OK.
>
> >       xfail PR ld/15323 (4), PR ld/19317 (3).
>
> Please explain why the lto plugin won't handle the objects.
>
> > 9. ld-plugin/plugin.exp: xfail
> >       plugin claimfile lost symbol,
> >       plugin claimfile replace symbol,
> >       plugin claimfile replace symbol,
> >       plugin claimfile lost symbol with source,
> >       plugin claimfile replace symbol with source,
> >       plugin claimfile resolve symbol with source,
> >       plugin 2 with source lib,
> >       load plugin 2 with source,
> >       plugin 3 with source lib,
> >       load plugin 3 with source.
>
> These all pass on mips-linux, and on mips64-linux.  Why disable them?
> Yes, I see fails on mips64-linux-gnuabi64 but that looks like a gcc
> problem to me.
>

Do you really install C/C++ compilers?

> > 11. ld-selective/selective.exp: add -fno-PIC, which is needed for -mno-abicalls.
>
> OK.
>
> > 12. ld-shared/shared.exp: xfail shared (non PIC), shared (PIC main, non PIC so).
>
> OK, and thanks for tweaking the xcoff test message.
>
> --
> Alan Modra
> Australia Development Lab, IBM
  
Alan Modra June 20, 2023, midnight UTC | #3
On Mon, Jun 19, 2023 at 06:43:05PM +0800, YunQiang Su wrote:
> Alan Modra via Binutils <binutils@sourceware.org> 于2023年6月19日周一 14:44写道:
> >
> > Hi YunQiang Su,
> > I thought I'd take a detailed look at your patch modifying the generic
> > ELF tests for mips, despite not really being familiar enough with mips
> > to properly review mips changes.  Most of this review is not about
> > details of the patch but rather questioning whether you have done the
> > necessary analysis before xfailing tests.  It is reasonable to xfail a
> > test if for some reason a problem cannot be fixed, or even if a
> > problem is too difficult to be fixed.  On the other hand we don't want
> > a clean testsuite result if there are problems that should be fixed.
> >
> > On Fri, Jun 16, 2023 at 02:34:10PM +0800, YunQiang Su wrote:
> > > 1. config/default.exp:
> > >       use -mabi=32 not for -gnuabi64;
> > >       xfail_from_runlist: remove an element and mark it xfail.
> >
> > I dislike the use of xfail here.  xfail should only be used after
> > running a test, to record an expected fail.  Don't use it when a test
> > is not run.
> >
> 
> Maybe, kfail is better?

Perhaps, but we don't use kfail in the binutils testsuite.

> > > 2. ld-elf/indirect.exp: xfail
> > >       indirect5a, indirect5b, indirect6a, indirect6b,
> > >       indirect5c, indirect5d, indirect6c, indirect6d.
> >
> > Can you explain why is it correct to xfail these for mips?  The first
> > four pass for me on mips-linux.  Is there a reason why the last four
> > must make "bar" dynamic on mips?
> >
> 
> Do you have a cross compiler installed?

Yes.  I wouldn't be reporting passes if I didn't.
  
YunQiang Su June 20, 2023, 1:40 a.m. UTC | #4
Alan Modra <amodra@gmail.com> 于2023年6月20日周二 08:00写道:
>
> On Mon, Jun 19, 2023 at 06:43:05PM +0800, YunQiang Su wrote:
> > Alan Modra via Binutils <binutils@sourceware.org> 于2023年6月19日周一 14:44写道:
> > >
> > > Hi YunQiang Su,
> > > I thought I'd take a detailed look at your patch modifying the generic
> > > ELF tests for mips, despite not really being familiar enough with mips
> > > to properly review mips changes.  Most of this review is not about
> > > details of the patch but rather questioning whether you have done the
> > > necessary analysis before xfailing tests.  It is reasonable to xfail a
> > > test if for some reason a problem cannot be fixed, or even if a
> > > problem is too difficult to be fixed.  On the other hand we don't want
> > > a clean testsuite result if there are problems that should be fixed.
> > >
> > > On Fri, Jun 16, 2023 at 02:34:10PM +0800, YunQiang Su wrote:
> > > > 1. config/default.exp:
> > > >       use -mabi=32 not for -gnuabi64;
> > > >       xfail_from_runlist: remove an element and mark it xfail.
> > >
> > > I dislike the use of xfail here.  xfail should only be used after
> > > running a test, to record an expected fail.  Don't use it when a test
> > > is not run.
> > >
> >
> > Maybe, kfail is better?
>
> Perhaps, but we don't use kfail in the binutils testsuite.
>
> > > > 2. ld-elf/indirect.exp: xfail
> > > >       indirect5a, indirect5b, indirect6a, indirect6b,
> > > >       indirect5c, indirect5d, indirect6c, indirect6d.
> > >
> > > Can you explain why is it correct to xfail these for mips?  The first
> > > four pass for me on mips-linux.  Is there a reason why the last four
> > > must make "bar" dynamic on mips?
> > >
> >
> > Do you have a cross compiler installed?
>
> Yes.  I wouldn't be reporting passes if I didn't.
>

Thank you.
How do you build your cross toolchain?
All of my cross toolchain make

> > 2. ld-elf/indirect.exp: xfail
> >       indirect5a, indirect5b, indirect6a, indirect6b,

> > 9. ld-plugin/plugin.exp: xfail
> >       plugin claimfile lost symbol,
> >       plugin claimfile replace symbol,
> >       plugin claimfile replace symbol,
> >       plugin claimfile lost symbol with source,
> >       plugin claimfile replace symbol with source,
> >       plugin claimfile resolve symbol with source,
> >       plugin 2 with source lib,
> >       load plugin 2 with source,
> >       plugin 3 with source lib,
> >       load plugin 3 with source.

fail on mipsel-linux-gnu and mips64el-linux-gnu.

> --
> Alan Modra
> Australia Development Lab, IBM
  
Alan Modra June 20, 2023, 2:34 a.m. UTC | #5
On Tue, Jun 20, 2023 at 09:40:19AM +0800, YunQiang Su wrote:
> How do you build your cross toolchain?

mips64-linux-gnuabi64-gcc (GCC) 13.0.0 20220910 (experimental) was
built using this configuration:
~/src/gcc/configure \
--with-sysroot=/home/gnu/mips64-linux-gnuabi64 \
--prefix=/usr/local \
--target=mips64-linux-gnuabi64 \
--enable-targets=mips-linux-gnu \
--with-mips-plt \
--disable-nls \
--enable-__cxa_atexit \
--enable-initfini-array \
--disable-libsanitizer \
--disable-bootstrap \
--enable-languages=c,c++

glibc64 with
dest=/home/gnu/mips64-linux-gnuabi64
echo slibdir="${dest}"/lib64 > configparms
echo sysconfdir="${dest}"/etc >> configparms
echo sbindir="${dest}"/usr/sbin >> configparms
echo rootsbindir="${dest}"/sbin >> configparms
echo localedir="${dest}"/usr/lib64 >> configparms

libc_cv_forced_unwind=yes \
libc_cv_c_cleanup=yes \
CC="mips64-linux-gnuabi64-gcc" \
~/src/glibc-current/configure \
    --build=x86_64-linux-gnu \
    --host=mips64-linux-gnuabi64 \
    --prefix="${dest}"/usr \
    --libdir="${dest}"/usr/lib64 \
    --with-headers="${dest}"/usr/include \
    --enable-add-ons \
    --with-tls \
    --enable-kernel=4.0

glibc32 with
dest=/home/gnu/mips64-linux-gnuabi64
echo slibdir="${dest}"/lib > configparms
echo sysconfdir="${dest}"/etc >> configparms
echo sbindir="${dest}"/usr/sbin >> configparms
echo rootsbindir="${dest}"/sbin >> configparms
echo localedir="${dest}"/usr/lib >> configparms

libc_cv_forced_unwind=yes \
libc_cv_c_cleanup=yes \
CC="mips64-linux-gnuabi64-gcc -mabi=32" \
~/src/glibc-current/configure \
    --build=x86_64-linux-gnu \
    --host=mips-linux-gnu \
    --prefix="${dest}"/usr \
    --libdir="${dest}"/usr/lib \
    --with-headers="${dest}"/usr/include \
    --enable-add-ons \
    --with-tls \
    --enable-kernel=4.0

glibcn32 with
dest=/home/gnu/mips64-linux-gnuabi64
echo slibdir="${dest}"/lib32 > configparms
echo sysconfdir="${dest}"/etc >> configparms
echo sbindir="${dest}"/usr/sbin >> configparms
echo rootsbindir="${dest}"/sbin >> configparms
echo localedir="${dest}"/usr/lib32 >> configparms

libc_cv_forced_unwind=yes \
libc_cv_c_cleanup=yes \
CC="mips64-linux-gnuabi64-gcc -mabi=n32" \
~/src/glibc-current/configure \
    --build=x86_64-linux-gnu \
    --host=mips64-linux-gnuabi64 \
    --prefix="${dest}"/usr \
    --libdir="${dest}"/usr/lib32 \
    --with-headers="${dest}"/usr/include \
    --enable-add-ons \
    --with-tls \
    --enable-kernel=4.0

mips-linux-gnu-gcc (GCC) 13.0.0 20220910 (experimental) was built with
~/src/gcc/configure \
--with-sysroot=/home/gnu/mips-linux-gnu \
--prefix=/usr/local \
--target=mips-linux-gnu \
--with-mips-plt \
--disable-nls \
--enable-__cxa_atexit \
--disable-libsanitizer \
--disable-bootstrap \
--enable-languages=c,c++

glibc with
dest=/home/gnu/mips-linux-gnu
libc_cv_forced_unwind=yes \
libc_cv_c_cleanup=yes \
libc_cv_ssp=no \
~/src/glibc-current/configure \
    --build=x86_64-linux-gnu \
    --host=mips-linux-gnu \
    --prefix="${dest}"/usr \
    --with-headers="${dest}"/usr/include \
    --enable-add-ons \
    --with-tls \
    --enable-kernel=4.0 \
    --without-selinux \
    --enable-obsolete-rpc \
    --disable-werror
  
Alan Modra June 20, 2023, 2:58 a.m. UTC | #6
On Mon, Jun 19, 2023 at 04:14:17PM +0930, Alan Modra wrote:
> I see a ld segfault in _bfd_mips_elf_generic_reloc due to
> symbol->section->output_section being NULL prior to this patch series.

I'm applying this patch to correct these segfaults.

A symbol defined in a section from a shared library will have a NULL
section->output_section during linking.

	* elf32-mips.c (gprel32_with_gp): Don't segfault on NULL
	symbol->section->output_section.
	* elf64-mips.c (mips_elf64_gprel32_reloc): Likewise.
	* elfn32-mips.c (mips_elf_gprel16_reloc): Likewise.
	(mips_elf_literal_reloc, mips_elf_gprel32_reloc): Likewise.
	(gprel32_with_gp, mips16_gprel_reloc): Likewise.
	* elfxx-mips.c (_bfd_mips_elf_gprel16_with_gp): Likewise.
	(_bfd_mips_elf_generic_reloc): Likewise.

diff --git a/bfd/elf32-mips.c b/bfd/elf32-mips.c
index 34ffa67edec..03be42e845c 100644
--- a/bfd/elf32-mips.c
+++ b/bfd/elf32-mips.c
@@ -1858,8 +1858,11 @@ gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
   else
     relocation = symbol->value;
 
-  relocation += symbol->section->output_section->vma;
-  relocation += symbol->section->output_offset;
+  if (symbol->section->output_section != NULL)
+    {
+      relocation += symbol->section->output_section->vma;
+      relocation += symbol->section->output_offset;
+    }
 
   if (!_bfd_mips_reloc_offset_in_range (abfd, input_section, reloc_entry,
 					check_inplace))
diff --git a/bfd/elf64-mips.c b/bfd/elf64-mips.c
index 0530be1253f..9af4e4047e3 100644
--- a/bfd/elf64-mips.c
+++ b/bfd/elf64-mips.c
@@ -3577,8 +3577,11 @@ mips_elf64_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   else
     relocation = symbol->value;
 
-  relocation += symbol->section->output_section->vma;
-  relocation += symbol->section->output_offset;
+  if (symbol->section->output_section != NULL)
+    {
+      relocation += symbol->section->output_section->vma;
+      relocation += symbol->section->output_offset;
+    }
 
   if (!_bfd_mips_reloc_offset_in_range (abfd, input_section, reloc_entry,
 					check_inplace))
diff --git a/bfd/elfn32-mips.c b/bfd/elfn32-mips.c
index 3ae11e2f992..ab3b58994ba 100644
--- a/bfd/elfn32-mips.c
+++ b/bfd/elfn32-mips.c
@@ -3300,7 +3300,8 @@ mips_elf_gprel16_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
   else
     {
       relocatable = false;
-      output_bfd = symbol->section->output_section->owner;
+      if (symbol->section->output_section != NULL)
+	output_bfd = symbol->section->output_section->owner;
     }
 
   ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
@@ -3340,7 +3341,8 @@ mips_elf_literal_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   else
     {
       relocatable = false;
-      output_bfd = symbol->section->output_section->owner;
+      if (symbol->section->output_section != NULL)
+	output_bfd = symbol->section->output_section->owner;
     }
 
   ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
@@ -3383,7 +3385,8 @@ mips_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   else
     {
       relocatable = false;
-      output_bfd = symbol->section->output_section->owner;
+      if (symbol->section->output_section != NULL)
+	output_bfd = symbol->section->output_section->owner;
 
       ret = mips_elf_final_gp (output_bfd, symbol, relocatable,
 			       error_message, &gp);
@@ -3408,8 +3411,11 @@ gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
   else
     relocation = symbol->value;
 
-  relocation += symbol->section->output_section->vma;
-  relocation += symbol->section->output_offset;
+  if (symbol->section->output_section != NULL)
+    {
+      relocation += symbol->section->output_section->vma;
+      relocation += symbol->section->output_offset;
+    }
 
   if (!bfd_reloc_offset_in_range (reloc_entry->howto, abfd, input_section,
 				  reloc_entry->address))
@@ -3484,7 +3490,8 @@ mips16_gprel_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
   else
     {
       relocatable = false;
-      output_bfd = symbol->section->output_section->owner;
+       if (symbol->section->output_section != NULL)
+	 output_bfd = symbol->section->output_section->owner;
     }
 
   ret = mips_elf_final_gp (output_bfd, symbol, relocatable, error_message,
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 4dfd8d04610..71f2dc9d779 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -2481,8 +2481,11 @@ _bfd_mips_elf_gprel16_with_gp (bfd *abfd, asymbol *symbol,
   else
     relocation = symbol->value;
 
-  relocation += symbol->section->output_section->vma;
-  relocation += symbol->section->output_offset;
+  if (symbol->section->output_section != NULL)
+    {
+      relocation += symbol->section->output_section->vma;
+      relocation += symbol->section->output_offset;
+    }
 
   /* Set val to the offset into the section or symbol.  */
   val = reloc_entry->addend;
@@ -2673,7 +2676,8 @@ _bfd_mips_elf_generic_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
 
   /* Build up the field adjustment in VAL.  */
   val = 0;
-  if (!relocatable || (symbol->flags & BSF_SECTION_SYM) != 0)
+  if ((!relocatable || (symbol->flags & BSF_SECTION_SYM) != 0)
+      && symbol->section->output_section != NULL)
     {
       /* Either we're calculating the final field value or we have a
 	 relocation against a section symbol.  Add in the section's
  
YunQiang Su June 20, 2023, 3:17 a.m. UTC | #7
Alan Modra <amodra@gmail.com> 于2023年6月20日周二 10:34写道:
>
> On Tue, Jun 20, 2023 at 09:40:19AM +0800, YunQiang Su wrote:
> > How do you build your cross toolchain?
>
> mips64-linux-gnuabi64-gcc (GCC) 13.0.0 20220910 (experimental) was
> built using this configuration:
> ~/src/gcc/configure \
> --with-sysroot=/home/gnu/mips64-linux-gnuabi64 \
> --prefix=/usr/local \
> --target=mips64-linux-gnuabi64 \
> --enable-targets=mips-linux-gnu \
> --with-mips-plt \
> --disable-nls \
> --enable-__cxa_atexit \
> --enable-initfini-array \
> --disable-libsanitizer \
> --disable-bootstrap \
> --enable-languages=c,c++
>

You have no `--enable-plugin` option here, so
> > 9. ld-plugin/plugin.exp: xfail
> >       plugin claimfile lost symbol,
> >       plugin claimfile replace symbol,
> >       plugin claimfile replace symbol,
> >       plugin claimfile lost symbol with source,
> >       plugin claimfile replace symbol with source,
> >       plugin claimfile resolve symbol with source,
> >       plugin 2 with source lib,
> >       load plugin 2 with source,
> >       plugin 3 with source lib,
> >       load plugin 3 with source.

won't run.

I am using the cross toolchain in Debian:
you can
apt install g++-multilib-mipsel-linux-gnu g++-multilib-mips-linux-gnu
and link them as N32/N64 ones

For example, you can create a script with name
`mips64el-linux-gnu`

#!/bin/sh
exec mipsel-linux-gnu-gcc -mabi=n32 $@

> glibc64 with
> dest=/home/gnu/mips64-linux-gnuabi64
> echo slibdir="${dest}"/lib64 > configparms
> echo sysconfdir="${dest}"/etc >> configparms
> echo sbindir="${dest}"/usr/sbin >> configparms
> echo rootsbindir="${dest}"/sbin >> configparms
> echo localedir="${dest}"/usr/lib64 >> configparms
>
> libc_cv_forced_unwind=yes \
> libc_cv_c_cleanup=yes \
> CC="mips64-linux-gnuabi64-gcc" \
> ~/src/glibc-current/configure \
>     --build=x86_64-linux-gnu \
>     --host=mips64-linux-gnuabi64 \
>     --prefix="${dest}"/usr \
>     --libdir="${dest}"/usr/lib64 \
>     --with-headers="${dest}"/usr/include \
>     --enable-add-ons \
>     --with-tls \
>     --enable-kernel=4.0
>
> glibc32 with
> dest=/home/gnu/mips64-linux-gnuabi64
> echo slibdir="${dest}"/lib > configparms
> echo sysconfdir="${dest}"/etc >> configparms
> echo sbindir="${dest}"/usr/sbin >> configparms
> echo rootsbindir="${dest}"/sbin >> configparms
> echo localedir="${dest}"/usr/lib >> configparms
>
> libc_cv_forced_unwind=yes \
> libc_cv_c_cleanup=yes \
> CC="mips64-linux-gnuabi64-gcc -mabi=32" \
> ~/src/glibc-current/configure \
>     --build=x86_64-linux-gnu \
>     --host=mips-linux-gnu \
>     --prefix="${dest}"/usr \
>     --libdir="${dest}"/usr/lib \
>     --with-headers="${dest}"/usr/include \
>     --enable-add-ons \
>     --with-tls \
>     --enable-kernel=4.0
>
> glibcn32 with
> dest=/home/gnu/mips64-linux-gnuabi64
> echo slibdir="${dest}"/lib32 > configparms
> echo sysconfdir="${dest}"/etc >> configparms
> echo sbindir="${dest}"/usr/sbin >> configparms
> echo rootsbindir="${dest}"/sbin >> configparms
> echo localedir="${dest}"/usr/lib32 >> configparms
>
> libc_cv_forced_unwind=yes \
> libc_cv_c_cleanup=yes \
> CC="mips64-linux-gnuabi64-gcc -mabi=n32" \
> ~/src/glibc-current/configure \
>     --build=x86_64-linux-gnu \
>     --host=mips64-linux-gnuabi64 \
>     --prefix="${dest}"/usr \
>     --libdir="${dest}"/usr/lib32 \
>     --with-headers="${dest}"/usr/include \
>     --enable-add-ons \
>     --with-tls \
>     --enable-kernel=4.0
>
> mips-linux-gnu-gcc (GCC) 13.0.0 20220910 (experimental) was built with
> ~/src/gcc/configure \
> --with-sysroot=/home/gnu/mips-linux-gnu \
> --prefix=/usr/local \
> --target=mips-linux-gnu \
> --with-mips-plt \
> --disable-nls \
> --enable-__cxa_atexit \
> --disable-libsanitizer \
> --disable-bootstrap \
> --enable-languages=c,c++
>
> glibc with
> dest=/home/gnu/mips-linux-gnu
> libc_cv_forced_unwind=yes \
> libc_cv_c_cleanup=yes \
> libc_cv_ssp=no \
> ~/src/glibc-current/configure \
>     --build=x86_64-linux-gnu \
>     --host=mips-linux-gnu \
>     --prefix="${dest}"/usr \
>     --with-headers="${dest}"/usr/include \
>     --enable-add-ons \
>     --with-tls \
>     --enable-kernel=4.0 \
>     --without-selinux \
>     --enable-obsolete-rpc \
>     --disable-werror
>
> --
> Alan Modra
> Australia Development Lab, IBM
  
Alan Modra June 20, 2023, 3:57 a.m. UTC | #8
On Tue, Jun 20, 2023 at 11:17:00AM +0800, YunQiang Su wrote:
> Alan Modra <amodra@gmail.com> 于2023年6月20日周二 10:34写道:
> >
> > On Tue, Jun 20, 2023 at 09:40:19AM +0800, YunQiang Su wrote:
> > > How do you build your cross toolchain?
> >
> > mips64-linux-gnuabi64-gcc (GCC) 13.0.0 20220910 (experimental) was
> > built using this configuration:
> > ~/src/gcc/configure \
> > --with-sysroot=/home/gnu/mips64-linux-gnuabi64 \
> > --prefix=/usr/local \
> > --target=mips64-linux-gnuabi64 \
> > --enable-targets=mips-linux-gnu \
> > --with-mips-plt \
> > --disable-nls \
> > --enable-__cxa_atexit \
> > --enable-initfini-array \
> > --disable-libsanitizer \
> > --disable-bootstrap \
> > --enable-languages=c,c++
> >
> 
> You have no `--enable-plugin` option here, so

That shouldn't be necessary.

> > > 9. ld-plugin/plugin.exp: xfail
> > >       plugin claimfile lost symbol,
> > >       plugin claimfile replace symbol,
> > >       plugin claimfile replace symbol,
> > >       plugin claimfile lost symbol with source,
> > >       plugin claimfile replace symbol with source,
> > >       plugin claimfile resolve symbol with source,
> > >       plugin 2 with source lib,
> > >       load plugin 2 with source,
> > >       plugin 3 with source lib,
> > >       load plugin 3 with source.
> 
> won't run.

It's true they don't run for mips64-linux-gnuabi64 for reasons I have
not investigated, but they do for --target=mips64-linux using the same
mips64-linux-gnuabi16 compiler.
  
YunQiang Su June 21, 2023, 5:05 a.m. UTC | #9
Alan Modra <amodra@gmail.com> 于2023年6月20日周二 11:57写道:
>
> On Tue, Jun 20, 2023 at 11:17:00AM +0800, YunQiang Su wrote:
> > Alan Modra <amodra@gmail.com> 于2023年6月20日周二 10:34写道:
> > >
> > > On Tue, Jun 20, 2023 at 09:40:19AM +0800, YunQiang Su wrote:
> > > > How do you build your cross toolchain?
> > >
> > > mips64-linux-gnuabi64-gcc (GCC) 13.0.0 20220910 (experimental) was
> > > built using this configuration:
> > > ~/src/gcc/configure \
> > > --with-sysroot=/home/gnu/mips64-linux-gnuabi64 \
> > > --prefix=/usr/local \
> > > --target=mips64-linux-gnuabi64 \
> > > --enable-targets=mips-linux-gnu \
> > > --with-mips-plt \
> > > --disable-nls \
> > > --enable-__cxa_atexit \
> > > --enable-initfini-array \
> > > --disable-libsanitizer \
> > > --disable-bootstrap \
> > > --enable-languages=c,c++
> > >
> >
> > You have no `--enable-plugin` option here, so
>
> That shouldn't be necessary.
>
> > > > 9. ld-plugin/plugin.exp: xfail
> > > >       plugin claimfile lost symbol,
> > > >       plugin claimfile replace symbol,
> > > >       plugin claimfile replace symbol,
> > > >       plugin claimfile lost symbol with source,
> > > >       plugin claimfile replace symbol with source,
> > > >       plugin claimfile resolve symbol with source,
> > > >       plugin 2 with source lib,
> > > >       load plugin 2 with source,
> > > >       plugin 3 with source lib,
> > > >       load plugin 3 with source.
> >
> > won't run.
>
> It's true they don't run for mips64-linux-gnuabi64 for reasons I have
> not investigated, but they do for --target=mips64-linux using the same
> mips64-linux-gnuabi16 compiler.
>

You are right. In  fact the real problem is that my compiler is too
old (GCC 12).

> --
> Alan Modra
> Australia Development Lab, IBM
  
YunQiang Su June 21, 2023, 10:53 a.m. UTC | #10
YunQiang Su <wzssyqa@gmail.com> 于2023年6月21日周三 13:05写道:
>
> Alan Modra <amodra@gmail.com> 于2023年6月20日周二 11:57写道:
> >
> > On Tue, Jun 20, 2023 at 11:17:00AM +0800, YunQiang Su wrote:
> > > Alan Modra <amodra@gmail.com> 于2023年6月20日周二 10:34写道:
> > > >
> > > > On Tue, Jun 20, 2023 at 09:40:19AM +0800, YunQiang Su wrote:
> > > > > How do you build your cross toolchain?
> > > >
> > > > mips64-linux-gnuabi64-gcc (GCC) 13.0.0 20220910 (experimental) was
> > > > built using this configuration:
> > > > ~/src/gcc/configure \
> > > > --with-sysroot=/home/gnu/mips64-linux-gnuabi64 \
> > > > --prefix=/usr/local \
> > > > --target=mips64-linux-gnuabi64 \
> > > > --enable-targets=mips-linux-gnu \
> > > > --with-mips-plt \
> > > > --disable-nls \
> > > > --enable-__cxa_atexit \
> > > > --enable-initfini-array \
> > > > --disable-libsanitizer \
> > > > --disable-bootstrap \
> > > > --enable-languages=c,c++
> > > >
> > >
> > > You have no `--enable-plugin` option here, so
> >
> > That shouldn't be necessary.
> >
> > > > > 9. ld-plugin/plugin.exp: xfail
> > > > >       plugin claimfile lost symbol,
> > > > >       plugin claimfile replace symbol,
> > > > >       plugin claimfile replace symbol,
> > > > >       plugin claimfile lost symbol with source,
> > > > >       plugin claimfile replace symbol with source,
> > > > >       plugin claimfile resolve symbol with source,
> > > > >       plugin 2 with source lib,
> > > > >       load plugin 2 with source,
> > > > >       plugin 3 with source lib,
> > > > >       load plugin 3 with source.
> > >
> > > won't run.
> >
> > It's true they don't run for mips64-linux-gnuabi64 for reasons I have
> > not investigated, but they do for --target=mips64-linux using the same
> > mips64-linux-gnuabi16 compiler.
> >
>
> You are right. In  fact the real problem is that my compiler is too
> old (GCC 12).
>

ohhh, no.
It's due to there is no --with-mips-plt build option for my gcc.

> > --
> > Alan Modra
> > Australia Development Lab, IBM
>
>
>
> --
> YunQiang Su
  
Xi Ruoyao June 21, 2023, 10:59 a.m. UTC | #11
On Wed, 2023-06-21 at 18:53 +0800, YunQiang Su via Binutils wrote:
> YunQiang Su <wzssyqa@gmail.com> 于2023年6月21日周三 13:05写道:
> > 
> > Alan Modra <amodra@gmail.com> 于2023年6月20日周二 11:57写道:
> > > 
> > > On Tue, Jun 20, 2023 at 11:17:00AM +0800, YunQiang Su wrote:
> > > > Alan Modra <amodra@gmail.com> 于2023年6月20日周二 10:34写道:
> > > > > 
> > > > > On Tue, Jun 20, 2023 at 09:40:19AM +0800, YunQiang Su wrote:
> > > > > > How do you build your cross toolchain?
> > > > > 
> > > > > mips64-linux-gnuabi64-gcc (GCC) 13.0.0 20220910 (experimental) was
> > > > > built using this configuration:
> > > > > ~/src/gcc/configure \
> > > > > --with-sysroot=/home/gnu/mips64-linux-gnuabi64 \
> > > > > --prefix=/usr/local \
> > > > > --target=mips64-linux-gnuabi64 \
> > > > > --enable-targets=mips-linux-gnu \
> > > > > --with-mips-plt \
> > > > > --disable-nls \
> > > > > --enable-__cxa_atexit \
> > > > > --enable-initfini-array \
> > > > > --disable-libsanitizer \
> > > > > --disable-bootstrap \
> > > > > --enable-languages=c,c++
> > > > > 
> > > > 
> > > > You have no `--enable-plugin` option here, so
> > > 
> > > That shouldn't be necessary.
> > > 
> > > > > > 9. ld-plugin/plugin.exp: xfail
> > > > > >        plugin claimfile lost symbol,
> > > > > >        plugin claimfile replace symbol,
> > > > > >        plugin claimfile replace symbol,
> > > > > >        plugin claimfile lost symbol with source,
> > > > > >        plugin claimfile replace symbol with source,
> > > > > >        plugin claimfile resolve symbol with source,
> > > > > >        plugin 2 with source lib,
> > > > > >        load plugin 2 with source,
> > > > > >        plugin 3 with source lib,
> > > > > >        load plugin 3 with source.
> > > > 
> > > > won't run.
> > > 
> > > It's true they don't run for mips64-linux-gnuabi64 for reasons I have
> > > not investigated, but they do for --target=mips64-linux using the same
> > > mips64-linux-gnuabi16 compiler.
> > > 
> > 
> > You are right. In  fact the real problem is that my compiler is too
> > old (GCC 12).
> > 
> 
> ohhh, no.
> It's due to there is no --with-mips-plt build option for my gcc.

Then should we just add -mplt to override the default for those test
cases?
  
YunQiang Su June 21, 2023, 11:03 a.m. UTC | #12
Xi Ruoyao <xry111@xry111.site> 于2023年6月21日周三 18:59写道:
>
> On Wed, 2023-06-21 at 18:53 +0800, YunQiang Su via Binutils wrote:
> > YunQiang Su <wzssyqa@gmail.com> 于2023年6月21日周三 13:05写道:
> > >
> > > Alan Modra <amodra@gmail.com> 于2023年6月20日周二 11:57写道:
> > > >
> > > > On Tue, Jun 20, 2023 at 11:17:00AM +0800, YunQiang Su wrote:
> > > > > Alan Modra <amodra@gmail.com> 于2023年6月20日周二 10:34写道:
> > > > > >
> > > > > > On Tue, Jun 20, 2023 at 09:40:19AM +0800, YunQiang Su wrote:
> > > > > > > How do you build your cross toolchain?
> > > > > >
> > > > > > mips64-linux-gnuabi64-gcc (GCC) 13.0.0 20220910 (experimental) was
> > > > > > built using this configuration:
> > > > > > ~/src/gcc/configure \
> > > > > > --with-sysroot=/home/gnu/mips64-linux-gnuabi64 \
> > > > > > --prefix=/usr/local \
> > > > > > --target=mips64-linux-gnuabi64 \
> > > > > > --enable-targets=mips-linux-gnu \
> > > > > > --with-mips-plt \
> > > > > > --disable-nls \
> > > > > > --enable-__cxa_atexit \
> > > > > > --enable-initfini-array \
> > > > > > --disable-libsanitizer \
> > > > > > --disable-bootstrap \
> > > > > > --enable-languages=c,c++
> > > > > >
> > > > >
> > > > > You have no `--enable-plugin` option here, so
> > > >
> > > > That shouldn't be necessary.
> > > >
> > > > > > > 9. ld-plugin/plugin.exp: xfail
> > > > > > >        plugin claimfile lost symbol,
> > > > > > >        plugin claimfile replace symbol,
> > > > > > >        plugin claimfile replace symbol,
> > > > > > >        plugin claimfile lost symbol with source,
> > > > > > >        plugin claimfile replace symbol with source,
> > > > > > >        plugin claimfile resolve symbol with source,
> > > > > > >        plugin 2 with source lib,
> > > > > > >        load plugin 2 with source,
> > > > > > >        plugin 3 with source lib,
> > > > > > >        load plugin 3 with source.
> > > > >
> > > > > won't run.
> > > >
> > > > It's true they don't run for mips64-linux-gnuabi64 for reasons I have
> > > > not investigated, but they do for --target=mips64-linux using the same
> > > > mips64-linux-gnuabi16 compiler.
> > > >
> > >
> > > You are right. In  fact the real problem is that my compiler is too
> > > old (GCC 12).
> > >
> >
> > ohhh, no.
> > It's due to there is no --with-mips-plt build option for my gcc.
>
> Then should we just add -mplt to override the default for those test
> cases?
>

In fact I have no idea. I don't understand why it's support binary
with PLT only (yet).

> --
> Xi Ruoyao <xry111@xry111.site>
> School of Aerospace Science and Technology, Xidian University
  
YunQiang Su June 29, 2023, 2:17 p.m. UTC | #13
YunQiang Su <wzssyqa@gmail.com> 于2023年6月19日周一 18:43写道:
>
> Alan Modra via Binutils <binutils@sourceware.org> 于2023年6月19日周一 14:44写道:
> >
> > Hi YunQiang Su,
> > I thought I'd take a detailed look at your patch modifying the generic
> > ELF tests for mips, despite not really being familiar enough with mips
> > to properly review mips changes.  Most of this review is not about
> > details of the patch but rather questioning whether you have done the
> > necessary analysis before xfailing tests.  It is reasonable to xfail a
> > test if for some reason a problem cannot be fixed, or even if a
> > problem is too difficult to be fixed.  On the other hand we don't want
> > a clean testsuite result if there are problems that should be fixed.
> >
> > On Fri, Jun 16, 2023 at 02:34:10PM +0800, YunQiang Su wrote:
> > > 1. config/default.exp:
> > >       use -mabi=32 not for -gnuabi64;
> > >       xfail_from_runlist: remove an element and mark it xfail.
> >
> > I dislike the use of xfail here.  xfail should only be used after
> > running a test, to record an expected fail.  Don't use it when a test
> > is not run.
> >
>
> Maybe, kfail is better?
>
> > > 2. ld-elf/indirect.exp: xfail
> > >       indirect5a, indirect5b, indirect6a, indirect6b,
> > >       indirect5c, indirect5d, indirect6c, indirect6d.
> >
> > Can you explain why is it correct to xfail these for mips?  The first
> > four pass for me on mips-linux.  Is there a reason why the last four
> > must make "bar" dynamic on mips?
> >
>
> Do you have a cross compiler installed?
> These tests won't even try to run without a  corresponding cross
> compiler installed.
>
> The real problem seems due to the output of nm -D.
>
> objdump -D on aarch64:
> Disassembly of section .bss:
> 0000000000011038 <completed.0>:
>         ...
> 0000000000011040 <bar>:
>         ...
>
> objdump -D on mips32el:
> Disassembly of section .bss:
> 00010a70 <completed.1>:
>    10a70:       00000000        nop
> 00010a74 <dtor_idx.0>:
>         ...
> 00010a80 <bar>:
>         ...
>
> While the outputs of NM -D are different. Let me have a more dig about it.
>
>
> > > 3. ld-elf/pr23658-2: mips output is not common.
> >
> > The purpose of this test is to check the placement of orphan loaded
> > note sections.  These ought to be placed near the start of the first
> > PT_LOAD segment, so that they can be accessed by the kernel without
> > reading many disk pages.  Ideally they would be placed in the same
> > page as the file header.  This isn't happening for mips64, and I see
> > the standard scripts don't even mention .interp, a section that also
> > should be placed near the start of the first PT_LOAD.  Why not?!
> >
>
> Oh, yes. This tiny patch can solve this problem.
> I have no idea why it doesn't like that.
> Maybe somebody forgot this in history.
>
> @Maciej W. Rozycki Any ideas?
>
> ```
> diff --git a/ld/emulparams/elf64bmip-defs.sh b/ld/emulparams/elf64bmip-defs.sh
> index 4165f51e9e5..19d782d8e7a 100644
> --- a/ld/emulparams/elf64bmip-defs.sh
> +++ b/ld/emulparams/elf64bmip-defs.sh
> @@ -1,6 +1,10 @@
>  source_sh ${srcdir}/emulparams/elf32bmipn32-defs.sh
>  COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
> -INITIAL_READONLY_SECTIONS="
> +INITIAL_READONLY_SECTIONS=
> +if test -z "${CREATE_SHLIB}"; then
> +  INITIAL_READONLY_SECTIONS=".interp       ${RELOCATING-0} : { *(.interp) }"
> +fi
> +INITIAL_READONLY_SECTIONS="${INITIAL_READONLY_SECTIONS}
>    .MIPS.abiflags      ${RELOCATING-0} : { *(.MIPS.abiflags) }
>    .MIPS.xhash      ${RELOCATING-0} : { *(.MIPS.xhash) }
>    .MIPS.options : { *(.MIPS.options) }
> ```
>

@Maciej W. Rozycki Any idea about this change?
Will it cause some other problems?

> > > 4. ld-elf/shared.exp: non-run on mips: Build libpr16496b.so.
> >
> > OK, seems like we will actually generate a correct .so here for mips,
> > so not much is lost by not running the testcase for mips.
> >
>
> Should we add a pr16496b-mips.od file?
>
> > > 5. ld-elfvers/vers.exp:
> > >       xfail vers4, vers4b;
> >
> > I see a ld segfault in _bfd_mips_elf_generic_reloc due to
> > symbol->section->output_section being NULL prior to this patch series.
> > I'd hope that someone making changes to the testsuite would have seen
> > this, and not ignored it.  No one expects you to make linking
> > non-native object files work, but not segfaulting it fairly important.
> >
>
> Maybe we should grep segfault in the log files on our CI system.
> I will try to do so.
>
> FYI: I run my test here:
> https://oss.cipunited.com/ci/job/Toolchain/job/binutils-cross/
>
> > >       no-run on mips: vers24a, vers24b, vers24c.
> >
> > OK, fair enough.  Mips is different enough that it isn't expected to
> > pass these tests.
> >
> > > 6. ld-gc/gc.exp: add -KPIC into asflags for pr13683, pr14265, pr19161.
> >
> > OK.
> >
> > > 7. ld-mips-elf/mips-elf.exp:
> > >       use noarch for mips16-local-stubs-1, since it use -mips4.
> >
> > I'll leave this for the mips maintainers to OK.
> >
> > > 8. ld-plugin/lto.exp:
> > >       no-run on mips/linux: PR ld/12982;
> >
> > Please add a comment to lto.exp as to why mips requires an executable
> > stack.
> >
> > >       add -KPIC into asflags for lto-3r, lto-5r, PR ld/19317 (2);
> >
> > OK.
> >
> > >       xfail PR ld/15323 (4), PR ld/19317 (3).
> >
> > Please explain why the lto plugin won't handle the objects.
> >
> > > 9. ld-plugin/plugin.exp: xfail
> > >       plugin claimfile lost symbol,
> > >       plugin claimfile replace symbol,
> > >       plugin claimfile replace symbol,
> > >       plugin claimfile lost symbol with source,
> > >       plugin claimfile replace symbol with source,
> > >       plugin claimfile resolve symbol with source,
> > >       plugin 2 with source lib,
> > >       load plugin 2 with source,
> > >       plugin 3 with source lib,
> > >       load plugin 3 with source.
> >
> > These all pass on mips-linux, and on mips64-linux.  Why disable them?
> > Yes, I see fails on mips64-linux-gnuabi64 but that looks like a gcc
> > problem to me.
> >
>
> Do you really install C/C++ compilers?
>
> > > 11. ld-selective/selective.exp: add -fno-PIC, which is needed for -mno-abicalls.
> >
> > OK.
> >
> > > 12. ld-shared/shared.exp: xfail shared (non PIC), shared (PIC main, non PIC so).
> >
> > OK, and thanks for tweaking the xcoff test message.
> >
> > --
> > Alan Modra
> > Australia Development Lab, IBM
>
>
>
> --
> YunQiang Su
  
YunQiang Su July 3, 2023, 4 a.m. UTC | #14
Alan Modra via Binutils <binutils@sourceware.org> 于2023年6月19日周一 14:44写道:
>
> Hi YunQiang Su,
> I thought I'd take a detailed look at your patch modifying the generic
> ELF tests for mips, despite not really being familiar enough with mips
> to properly review mips changes.  Most of this review is not about
> details of the patch but rather questioning whether you have done the
> necessary analysis before xfailing tests.  It is reasonable to xfail a
> test if for some reason a problem cannot be fixed, or even if a
> problem is too difficult to be fixed.  On the other hand we don't want
> a clean testsuite result if there are problems that should be fixed.
>
> On Fri, Jun 16, 2023 at 02:34:10PM +0800, YunQiang Su wrote:
> > 1. config/default.exp:
> >       use -mabi=32 not for -gnuabi64;
> >       xfail_from_runlist: remove an element and mark it xfail.
>
> I dislike the use of xfail here.  xfail should only be used after
> running a test, to record an expected fail.  Don't use it when a test
> is not run.
>
> > 2. ld-elf/indirect.exp: xfail
> >       indirect5a, indirect5b, indirect6a, indirect6b,
> >       indirect5c, indirect5d, indirect6c, indirect6d.
>
> Can you explain why is it correct to xfail these for mips?  The first
> four pass for me on mips-linux.  Is there a reason why the last four
> must make "bar" dynamic on mips?
>
> > 3. ld-elf/pr23658-2: mips output is not common.
>
> The purpose of this test is to check the placement of orphan loaded
> note sections.  These ought to be placed near the start of the first
> PT_LOAD segment, so that they can be accessed by the kernel without
> reading many disk pages.  Ideally they would be placed in the same
> page as the file header.  This isn't happening for mips64, and I see
> the standard scripts don't even mention .interp, a section that also
> should be placed near the start of the first PT_LOAD.  Why not?!
>
> > 4. ld-elf/shared.exp: non-run on mips: Build libpr16496b.so.
>
> OK, seems like we will actually generate a correct .so here for mips,
> so not much is lost by not running the testcase for mips.
>
> > 5. ld-elfvers/vers.exp:
> >       xfail vers4, vers4b;
>
> I see a ld segfault in _bfd_mips_elf_generic_reloc due to
> symbol->section->output_section being NULL prior to this patch series.
> I'd hope that someone making changes to the testsuite would have seen
> this, and not ignored it.  No one expects you to make linking
> non-native object files work, but not segfaulting it fairly important.
>
> >       no-run on mips: vers24a, vers24b, vers24c.
>
> OK, fair enough.  Mips is different enough that it isn't expected to
> pass these tests.
>
> > 6. ld-gc/gc.exp: add -KPIC into asflags for pr13683, pr14265, pr19161.
>
> OK.
>
> > 7. ld-mips-elf/mips-elf.exp:
> >       use noarch for mips16-local-stubs-1, since it use -mips4.
>
> I'll leave this for the mips maintainers to OK.
>
> > 8. ld-plugin/lto.exp:
> >       no-run on mips/linux: PR ld/12982;
>
> Please add a comment to lto.exp as to why mips requires an executable
> stack.
>
> >       add -KPIC into asflags for lto-3r, lto-5r, PR ld/19317 (2);
>
> OK.
>
> >       xfail PR ld/15323 (4), PR ld/19317 (3).
>
> Please explain why the lto plugin won't handle the objects.
>

Thank you. It seems really a bug: ld -r cannot work with LTO objects.
I am trying to find the real problem.

> > 9. ld-plugin/plugin.exp: xfail
> >       plugin claimfile lost symbol,
> >       plugin claimfile replace symbol,
> >       plugin claimfile replace symbol,
> >       plugin claimfile lost symbol with source,
> >       plugin claimfile replace symbol with source,
> >       plugin claimfile resolve symbol with source,
> >       plugin 2 with source lib,
> >       load plugin 2 with source,
> >       plugin 3 with source lib,
> >       load plugin 3 with source.
>
> These all pass on mips-linux, and on mips64-linux.  Why disable them?
> Yes, I see fails on mips64-linux-gnuabi64 but that looks like a gcc
> problem to me.
>
> > 11. ld-selective/selective.exp: add -fno-PIC, which is needed for -mno-abicalls.
>
> OK.
>
> > 12. ld-shared/shared.exp: xfail shared (non PIC), shared (PIC main, non PIC so).
>
> OK, and thanks for tweaking the xcoff test message.
>
> --
> Alan Modra
> Australia Development Lab, IBM
  

Patch

diff --git a/ld/testsuite/config/default.exp b/ld/testsuite/config/default.exp
index 5c925476e23..1bc8760e72b 100644
--- a/ld/testsuite/config/default.exp
+++ b/ld/testsuite/config/default.exp
@@ -155,7 +155,7 @@  if {! [info exists env(CCC_OVERRIDE_OPTIONS)]} {
 # installed, but to the O32 ABI in the build tree, because of some
 # specs-file hacks.  Make sure we use an ABI that is compatible with
 # the one we expect.
-if {[istarget mips64*-*-linux*] &&
+if {[istarget mips*64*-*-linux*] && ![istarget mips*64*-*-linux-gnuabi64] &&
     (![board_info [target_info name] exists multilib_flags] ||
      ![string match "*-mabi" [board_info [target_info name] multilib_flags]])
    } {
@@ -263,6 +263,24 @@  proc ld_exec { target output } {
 	default_ld_exec $target $output
 }
 
+#
+# xfail_from_runlist
+# 	mark a test xfail and remove it from the runlist
+proc xfail_from_runlist { runlist name } {
+  set i 0
+  set rtl $runlist
+  foreach t $runlist {
+    set tn [lindex $t 0]
+    if [string equal $name $tn] {
+      xfail $tn
+      set rtl [lreplace $rtl $i $i]
+    }
+    incr i
+  }
+  return $rtl
+}
+
+
 # From gas-defs.exp, to support run_dump_test.
 if ![info exists AS] then {
     set AS $as
diff --git a/ld/testsuite/ld-elf/indirect.exp b/ld/testsuite/ld-elf/indirect.exp
index ce4771371dd..dfbb097378b 100644
--- a/ld/testsuite/ld-elf/indirect.exp
+++ b/ld/testsuite/ld-elf/indirect.exp
@@ -219,7 +219,9 @@  proc check_dynamic_syms { test } {
 
 foreach t [list indirect5a indirect5b indirect6a indirect6b] {
     set testname [concat $t "dynsym"]
-    if { [check_dynamic_syms tmpdir/$t] } {
+    if { [istarget mips*] } {
+	xfail $testname
+    } elseif { [check_dynamic_syms tmpdir/$t] } {
 	pass $testname
     } else {
 	fail $testname
@@ -252,7 +254,9 @@  run_ld_link_exec_tests $pie_tests
 
 foreach t [list indirect5c indirect5d indirect6c indirect6d] {
     set testname [concat $t "dynsym"]
-    if { [check_dynamic_syms tmpdir/$t] } {
+    if { [istarget mips*] } {
+	xfail $testname
+    } elseif { [check_dynamic_syms tmpdir/$t] } {
 	pass $testname
     } else {
 	fail $testname
diff --git a/ld/testsuite/ld-elf/pr23658-2.rd b/ld/testsuite/ld-elf/pr23658-2.rd
index 9f89c4b40ae..e414ae3250d 100644
--- a/ld/testsuite/ld-elf/pr23658-2.rd
+++ b/ld/testsuite/ld-elf/pr23658-2.rd
@@ -1,5 +1,5 @@ 
 #...
- +[0-9]+ +\.interp \.note.4 \.note.1 \.note.2 \.note.3.*
+ +[0-9]+ +(\.MIPS\.abiflags \.MIPS\.options \.dynamic \.hash \.dynsym \.dynstr \.text |)\.interp \.note.4 \.note.1 \.note.2 \.note.3.*
 #...
  +[0-9]+ +\.note\.4 \.note\.1 +
  +[0-9]+ +\.note\.2 .note\.3 +
diff --git a/ld/testsuite/ld-elf/shared.exp b/ld/testsuite/ld-elf/shared.exp
index 1eef9f45667..2019275dda3 100644
--- a/ld/testsuite/ld-elf/shared.exp
+++ b/ld/testsuite/ld-elf/shared.exp
@@ -774,9 +774,6 @@  set build_tests {
   {"Build libpr16496b.a"
    "" "-fPIC"
    {pr16496b.c} {} "libpr16496b.a"}
-  {"Build libpr16496b.so"
-   "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
-   {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
   {"Build libpr16452a.so"
    "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
    {pr16452a.c} {} "libpr16452a.so"}
@@ -797,6 +794,15 @@  set build_tests {
    {pr18458b.c} {} "libpr18458b.so"}
 }
 
+# MIPS PIC uses different way: .MIPS.stub
+if { ![istarget mips*-linux*] } {
+    append build_tests {
+       {"Build libpr16496b.so"
+	"-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
+	{dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
+    }
+}
+
 run_cc_link_tests [list \
     [list \
 	"Build libpr2404a.so" \
diff --git a/ld/testsuite/ld-elfvers/vers.exp b/ld/testsuite/ld-elfvers/vers.exp
index b266cc0226f..2ab5487d440 100644
--- a/ld/testsuite/ld-elfvers/vers.exp
+++ b/ld/testsuite/ld-elfvers/vers.exp
@@ -801,13 +801,13 @@  build_exec "vers3" vers3.c vers3 "-Wl,--no-as-needed" vers1.so vers3.ver vers3.d
 
 # This test fails on MIPS.  On the MIPS we must put foo in the dynamic
 # symbol table, which the test does not expect.
-setup_xfail "mips*-*-irix*"
+setup_xfail "mips*-*-irix*" "mips*-linux-*"
 build_exec "vers4" vers4.c vers4 "" "" "" "" vers4.sym
 
 build_exec "vers4a" vers4.c vers4a "-Wl,-export-dynamic" "" vers4a.ver vers4a.dsym vers4a.sym
 
 # Verify that --no-export-dynamic undoes the effect of --export-dynamic.
-setup_xfail "mips*-*-irix*"
+setup_xfail "mips*-*-irix*" "mips*-linux-*"
 build_exec "vers4b" vers4.c vers4b "-Wl,-export-dynamic -Wl,--no-export-dynamic" "" "" "" vers4.sym
 
 
@@ -932,18 +932,20 @@  set as_pic_flags ""
 if [istarget sparc*-*-*] {
   set as_pic_flags "-K PIC"
 }
-run_ld_link_tests [list "\"vers24a\"
+if { ![istarget mips*-*-*] } {
+  run_ld_link_tests [list "\"vers24a\"
 			 \"-shared --version-script $srcdir/$subdir/vers24.map\" \"\"
 			 \"$as_pic_flags $as_options\" {vers24a.c vers24b.c} { { readelf -Wrs vers24.rd } }
 			 \"libvers24a.so\" \"-fpic\""]
-run_ld_link_tests [list "\"vers24b\"
+  run_ld_link_tests [list "\"vers24b\"
 			 \"-shared --version-script $srcdir/$subdir/vers24.map\" \"\"
 			 \"$as_pic_flags $as_options\" {vers24b.c vers24a.c} { { readelf -Wrs vers24.rd } }
 			 \"libvers24b.so\" \"-fpic\""]
-run_ld_link_tests [list "\"vers24c\"
+  run_ld_link_tests [list "\"vers24c\"
 			 \"-shared --version-script $srcdir/$subdir/vers24.map\" \"\"
 			 \"$as_pic_flags $as_options\" {vers24c.c} { { readelf -Wrs vers24.rd } }
 			 \"libvers24c.so\" \"-fpic\""]
+}
 
 # Test versioned definition vs. normal definition in different files.
 if [string match "yes" $pic] then {
diff --git a/ld/testsuite/ld-gc/gc.exp b/ld/testsuite/ld-gc/gc.exp
index bca0397ee02..e342c3ba2fe 100644
--- a/ld/testsuite/ld-gc/gc.exp
+++ b/ld/testsuite/ld-gc/gc.exp
@@ -151,6 +151,10 @@  if { [check_compiler_available] } {
     }
 }
 
+set save_asflags $ASFLAGS
+if { [istarget "mips*-*-linux*"] } {
+    append ASFLAGS " -KPIC"
+}
 set symdefs ""
 if [is_pecoff_format] {
     set symdefs {{ld {--defsym __main=main --defsym ___main=main}}}
@@ -174,6 +178,7 @@  if { [check_compiler_available] } {
     }
     run_dump_test "pr19161" $symdefs
 }
+set ASFLAGS $save_asflags
 
 if { [is_elf_format] && [check_shared_lib_support] \
      && [check_compiler_available] } {
diff --git a/ld/testsuite/ld-mips-elf/mips-elf.exp b/ld/testsuite/ld-mips-elf/mips-elf.exp
index ee0522b073f..4565bc9570c 100644
--- a/ld/testsuite/ld-mips-elf/mips-elf.exp
+++ b/ld/testsuite/ld-mips-elf/mips-elf.exp
@@ -1101,7 +1101,7 @@  if { $has_abi(o32) } {
 }
 
 run_dump_test_o32 "mips16-local-stubs-1"
-run_dump_test_n32 "mips16-local-stubs-1"
+run_dump_test_n32 "mips16-local-stubs-1" noarch
 
 set mips16_fp_stub_test [list \
     [list "Floating-point stub for mips16 functions" \
diff --git a/ld/testsuite/ld-plugin/lto.exp b/ld/testsuite/ld-plugin/lto.exp
index e7e7952bb1b..a4b546d4253 100644
--- a/ld/testsuite/ld-plugin/lto.exp
+++ b/ld/testsuite/ld-plugin/lto.exp
@@ -557,7 +557,7 @@  if { ! [istarget "arm*-*-*"] } {
 # when using the LTO plugin.  The HPPA target however requires an
 # executable stack for syscall restarts and signal returns, so we
 # skip this test for that target.
-if { ! [istarget "hppa*-*-*"] } {
+if { ! [istarget "hppa*-*-*"] && ! [istarget "mips*-linux*"] } {
     lappend lto_link_elf_tests \
   [list "PR ld/12982" \
    "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
@@ -909,6 +909,10 @@  if { [at_least_gcc_version 4 7] } {
     }
 }
 
+set save_asflags $ASFLAGS
+if { [istarget "mips*-*-linux*"] } {
+    append ASFLAGS " -KPIC"
+}
 # Run "ld -r" to generate inputs for complex LTO tests.
 run_dump_test "lto-3r"
 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
@@ -922,7 +926,12 @@  run_ld_link_tests [list \
    "-r tmpdir/pr19317.o" "" "" \
    {dummy.s} {} "pr19317-r.o"] \
 ]
+set ASFLAGS $save_asflags
 
+if { [istarget "mips*-*-linux*"] } {
+  set lto_run_tests [xfail_from_runlist $lto_run_tests "PR ld/15323 (4)"]
+  set lto_run_tests [xfail_from_runlist $lto_run_tests "PR ld/19317 (3)"]
+}
 run_ld_link_exec_tests $lto_run_tests
 
 if { [is_elf_format] } {
diff --git a/ld/testsuite/ld-plugin/plugin.exp b/ld/testsuite/ld-plugin/plugin.exp
index bbb8cedbc2c..ce7d406c998 100644
--- a/ld/testsuite/ld-plugin/plugin.exp
+++ b/ld/testsuite/ld-plugin/plugin.exp
@@ -295,6 +295,15 @@  if { !$can_compile || $failed_compile } {
     return
 }
 
+if { [istarget "mips*-*-linux*"] } {
+  set plugin_tests [xfail_from_runlist $plugin_tests "plugin claimfile lost symbol"]
+  set plugin_tests [xfail_from_runlist $plugin_tests "plugin claimfile replace symbol"]
+  set plugin_tests [xfail_from_runlist $plugin_tests "plugin claimfile resolve symbol"]
+  set plugin_tests [xfail_from_runlist $plugin_tests "plugin claimfile lost symbol with source"]
+  set plugin_tests [xfail_from_runlist $plugin_tests "plugin claimfile replace symbol with source"]
+  set plugin_tests [xfail_from_runlist $plugin_tests "plugin claimfile resolve symbol with source"]
+  set plugin_tests [xfail_from_runlist $plugin_tests "plugin claimfile resolve symbol with source"]
+}
 run_ld_link_tests $plugin_tests
 
 if { [is_elf_format] \
@@ -355,6 +364,12 @@  if { [regexp "0+ T func" "$plugin_nm_output"] &&
 
 # Check if ar --plugin works.
 file delete tmpdir/libfunc.a
+if { [istarget "mips*-*-linux*"] } {
+  set plugin_src_tests [xfail_from_runlist $plugin_src_tests "plugin 2 with source lib"]
+  set plugin_src_tests [xfail_from_runlist $plugin_src_tests "load plugin 2 with source"]
+  set plugin_src_tests [xfail_from_runlist $plugin_src_tests "plugin 3 with source lib"]
+  set plugin_src_tests [xfail_from_runlist $plugin_src_tests "load plugin 3 with source"]
+}
 if [ar_simple_create $ar "--plugin $plugin2_path" "tmpdir/libfunc.a" \
 			 "tmpdir/main.o $srcdir/$subdir/func.c"] {
     set testname "ar --plugin"
diff --git a/ld/testsuite/ld-selective/selective.exp b/ld/testsuite/ld-selective/selective.exp
index 813a52d54de..2531a5e5df8 100644
--- a/ld/testsuite/ld-selective/selective.exp
+++ b/ld/testsuite/ld-selective/selective.exp
@@ -52,7 +52,7 @@  set ldflags "--gc-sections -Bstatic"
 
 if [istarget mips*-*] {
     # MIPS16 doesn't support PIC code.
-    set cflags "-mno-abicalls $cflags"
+    set cflags "-mno-abicalls -fno-PIC $cflags"
     # MIPS ELF uses __start by default, we override it.
     set ldflags "-e _start $ldflags"
 }
diff --git a/ld/testsuite/ld-shared/shared.exp b/ld/testsuite/ld-shared/shared.exp
index f56e42f667b..3b0adddf023 100644
--- a/ld/testsuite/ld-shared/shared.exp
+++ b/ld/testsuite/ld-shared/shared.exp
@@ -220,7 +220,7 @@  if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.
 	 || ![ld_compile "$CC_FOR_TARGET $PLT_CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
 	unsupported "shared (non PIC)"
     } else { if { [is_xcoff_format] } {
-	shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
+	shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o xcoff
     } else {
 	# Solaris defaults to -z text.
 	setup_xfail "*-*-solaris2*"
@@ -242,6 +242,7 @@  if ![ld_compile "$CC_FOR_TARGET $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.
 	    setup_xfail "arm*-*-linux*"
 	}
 	setup_xfail "aarch64*-*-linux*"
+	setup_xfail "mips*-*-linux*"
 	shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
 
 	# Test ELF shared library relocations with a non-zero load
@@ -323,6 +324,7 @@  if ![ld_compile "$CC_FOR_TARGET $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdi
 		setup_xfail "arm*-*-linux*"
 	    }
 	    setup_xfail "aarch64*-*-linux*"
+	    setup_xfail "mips*-*-linux*"
 	    shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
 	}
     } else {