446cf2
commit edd8d70b91e1ccef549a7c668499596cc4d56ad1
446cf2
Author: Mihailo Stojanovic <mihailo.stojanovic@rt-rk.com>
446cf2
Date:   Fri Aug 23 16:47:27 2019 +0000
446cf2
446cf2
    [MIPS] Raise highest supported EI_ABIVERSION value [BZ #24916]
446cf2
    
446cf2
    This bumps the highest valid EI_ABIVERSION value to ABSOLUTE ABI.
446cf2
    
446cf2
    New testcase loads the symbol from the GOT with the "lb" instruction
446cf2
    so that the EI_ABIVERSION header field of the shared object is set
446cf2
    to ABSOLUTE (it doesn't actually check the value of the symbol), and
446cf2
    makes sure that the main executable is executed without "ABI version
446cf2
    invalid" error.
446cf2
    
446cf2
    Tested for all three ABIs (o32, n32, n64) using both static linker which
446cf2
    handles undefined weak symbols correctly [1] (and sets the EI_ABIVERSION
446cf2
    of the test module) and the one that doesn't (EI_ABIVERSION left as 0).
446cf2
    
446cf2
    [1] https://sourceware.org/ml/binutils/2018-07/msg00268.html
446cf2
    
446cf2
            [BZ #24916]
446cf2
            * sysdeps/mips/Makefile [$(subdir) = elf] (tests): Add
446cf2
            tst-undefined-weak.
446cf2
            [$(subdir) = elf] (modules-names): Add tst-undefined-weak-lib.
446cf2
            [$(subdir) = elf] ($(objpfx)tst-undefined-weak): Add dependency.
446cf2
            * sysdeps/mips/tst-undefined-weak-lib.S: New file.
446cf2
            * sysdeps/mips/tst-undefined-weak.c: Likewise.
446cf2
            * sysdeps/unix/sysv/linux/mips/ldsodefs.h (VALID_ELF_ABIVERSION):
446cf2
            Increment highest valid ABIVERSION value.
446cf2
446cf2
diff --git a/sysdeps/mips/Makefile b/sysdeps/mips/Makefile
446cf2
index 7ac6fa50311d60b7..6ad69e9ef9e88728 100644
446cf2
--- a/sysdeps/mips/Makefile
446cf2
+++ b/sysdeps/mips/Makefile
446cf2
@@ -82,3 +82,10 @@ $(objpfx)tst-mode-switch-2: $(shared-thread-library)
446cf2
 endif
446cf2
 endif
446cf2
 endif
446cf2
+
446cf2
+ifeq ($(subdir),elf)
446cf2
+tests += tst-undefined-weak
446cf2
+modules-names += tst-undefined-weak-lib
446cf2
+
446cf2
+$(objpfx)tst-undefined-weak: $(objpfx)tst-undefined-weak-lib.so
446cf2
+endif
446cf2
diff --git a/sysdeps/mips/tst-undefined-weak-lib.S b/sysdeps/mips/tst-undefined-weak-lib.S
446cf2
new file mode 100644
446cf2
index 0000000000000000..a175ebf90e01b372
446cf2
--- /dev/null
446cf2
+++ b/sysdeps/mips/tst-undefined-weak-lib.S
446cf2
@@ -0,0 +1,43 @@
446cf2
+/* Undefined weak symbol loading shared module.
446cf2
+   Copyright (C) 2019 Free Software Foundation, Inc.
446cf2
+   This file is part of the GNU C Library.
446cf2
+
446cf2
+   The GNU C Library is free software; you can redistribute it and/or
446cf2
+   modify it under the terms of the GNU Lesser General Public
446cf2
+   License as published by the Free Software Foundation; either
446cf2
+   version 2.1 of the License, or (at your option) any later version.
446cf2
+
446cf2
+   The GNU C Library is distributed in the hope that it will be useful,
446cf2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
+   Lesser General Public License for more details.
446cf2
+
446cf2
+   You should have received a copy of the GNU Lesser General Public
446cf2
+   License along with the GNU C Library; if not, see
446cf2
+   <http://www.gnu.org/licenses/>.  */
446cf2
+
446cf2
+#include <sgidefs.h>
446cf2
+
446cf2
+    .text
446cf2
+    .globl	x
446cf2
+    .set	nomips16
446cf2
+    .set	nomicromips
446cf2
+    .ent	x
446cf2
+    .type	x, @function
446cf2
+x:
446cf2
+    .set noreorder
446cf2
+#if _MIPS_SIM == _ABIO32
446cf2
+    .cpload  $25
446cf2
+    jr  $31
446cf2
+    lb  $2,%got(a)($28)
446cf2
+#else
446cf2
+    .cpsetup  $25,$24,x
446cf2
+    lb  $2,%got_disp(a)($28)
446cf2
+    jr  $31
446cf2
+    .cpreturn
446cf2
+#endif
446cf2
+    .set reorder
446cf2
+    .end	x
446cf2
+    .size	x, .-x
446cf2
+    .weak	a
446cf2
+    .hidden	a
446cf2
diff --git a/sysdeps/mips/tst-undefined-weak.c b/sysdeps/mips/tst-undefined-weak.c
446cf2
new file mode 100644
446cf2
index 0000000000000000..1231da6912508c19
446cf2
--- /dev/null
446cf2
+++ b/sysdeps/mips/tst-undefined-weak.c
446cf2
@@ -0,0 +1,28 @@
446cf2
+/* Undefined weak symbol loading main executable.
446cf2
+   Copyright (C) 2019 Free Software Foundation, Inc.
446cf2
+   This file is part of the GNU C Library.
446cf2
+
446cf2
+   The GNU C Library is free software; you can redistribute it and/or
446cf2
+   modify it under the terms of the GNU Lesser General Public
446cf2
+   License as published by the Free Software Foundation; either
446cf2
+   version 2.1 of the License, or (at your option) any later version.
446cf2
+
446cf2
+   The GNU C Library is distributed in the hope that it will be useful,
446cf2
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
446cf2
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
446cf2
+   Lesser General Public License for more details.
446cf2
+
446cf2
+   You should have received a copy of the GNU Lesser General Public
446cf2
+   License along with the GNU C Library; if not, see
446cf2
+   <http://www.gnu.org/licenses/>.  */
446cf2
+
446cf2
+int *x (void);
446cf2
+
446cf2
+int
446cf2
+do_test (void)
446cf2
+{
446cf2
+  x ();
446cf2
+  return 0;
446cf2
+}
446cf2
+
446cf2
+#include <support/test-driver.c>
446cf2
diff --git a/sysdeps/unix/sysv/linux/mips/ldsodefs.h b/sysdeps/unix/sysv/linux/mips/ldsodefs.h
446cf2
index 68a0a99bb1f1ec85..d2912cadabfd6877 100644
446cf2
--- a/sysdeps/unix/sysv/linux/mips/ldsodefs.h
446cf2
+++ b/sysdeps/unix/sysv/linux/mips/ldsodefs.h
446cf2
@@ -34,7 +34,7 @@ extern void _dl_static_init (struct link_map *map);
446cf2
 #undef VALID_ELF_ABIVERSION
446cf2
 #define VALID_ELF_ABIVERSION(osabi,ver)			\
446cf2
   (ver == 0						\
446cf2
-   || (osabi == ELFOSABI_SYSV && ver < 4)		\
446cf2
+   || (osabi == ELFOSABI_SYSV && ver < 5)		\
446cf2
    || (osabi == ELFOSABI_GNU && ver < LIBC_ABI_MAX))
446cf2
 
446cf2
 #endif /* ldsodefs.h */