b1dca6
commit 50a2d83c08a94a10f88a1fedeb7a6e3667a6b732
b1dca6
Author: Florian Weimer <fweimer@redhat.com>
b1dca6
Date:   Fri Apr 24 22:13:03 2020 +0200
b1dca6
b1dca6
    elf: Introduce <elf_machine_sym_no_match.h>
b1dca6
    
b1dca6
    MIPS needs to ignore certain existing symbols during symbol lookup.
b1dca6
    The old scheme uses the ELF_MACHINE_SYM_NO_MATCH macro, with an
b1dca6
    inline function, within its own header, with a sysdeps override for
b1dca6
    MIPS.  This allows re-use of the function from another file (without
b1dca6
    having to include <dl-machine.h> or providing the default definition
b1dca6
    for ELF_MACHINE_SYM_NO_MATCH).
b1dca6
    
b1dca6
    Reviewed-by: Carlos O'Donell <carlos@redhat.com>
b1dca6
b1dca6
diff --git a/elf/dl-lookup.c b/elf/dl-lookup.c
b1dca6
index e4c479de9a1fd6ec..47acd134600b44b5 100644
b1dca6
--- a/elf/dl-lookup.c
b1dca6
+++ b/elf/dl-lookup.c
b1dca6
@@ -28,18 +28,12 @@
b1dca6
 #include <libc-lock.h>
b1dca6
 #include <tls.h>
b1dca6
 #include <atomic.h>
b1dca6
+#include <elf_machine_sym_no_match.h>
b1dca6
 
b1dca6
 #include <assert.h>
b1dca6
 
b1dca6
-/* Return nonzero if check_match should consider SYM to fail to match a
b1dca6
-   symbol reference for some machine-specific reason.  */
b1dca6
-#ifndef ELF_MACHINE_SYM_NO_MATCH
b1dca6
-# define ELF_MACHINE_SYM_NO_MATCH(sym) 0
b1dca6
-#endif
b1dca6
-
b1dca6
 #define VERSTAG(tag)	(DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (tag))
b1dca6
 
b1dca6
-
b1dca6
 struct sym_val
b1dca6
   {
b1dca6
     const ElfW(Sym) *s;
b1dca6
@@ -78,7 +72,7 @@ check_match (const char *const undef_name,
b1dca6
   if (__glibc_unlikely ((sym->st_value == 0 /* No value.  */
b1dca6
 			 && sym->st_shndx != SHN_ABS
b1dca6
 			 && stt != STT_TLS)
b1dca6
-			|| ELF_MACHINE_SYM_NO_MATCH (sym)
b1dca6
+			|| elf_machine_sym_no_match (sym)
b1dca6
 			|| (type_class & (sym->st_shndx == SHN_UNDEF))))
b1dca6
     return NULL;
b1dca6
 
b1dca6
diff --git a/sysdeps/generic/elf_machine_sym_no_match.h b/sysdeps/generic/elf_machine_sym_no_match.h
b1dca6
new file mode 100644
b1dca6
index 0000000000000000..27155de4c0358460
b1dca6
--- /dev/null
b1dca6
+++ b/sysdeps/generic/elf_machine_sym_no_match.h
b1dca6
@@ -0,0 +1,34 @@
b1dca6
+/* Function to ignore certain symbol matches for machine-specific reasons.
b1dca6
+   Copyright (C) 2020 Free Software Foundation, Inc.
b1dca6
+   This file is part of the GNU C Library.
b1dca6
+
b1dca6
+   The GNU C Library is free software; you can redistribute it and/or
b1dca6
+   modify it under the terms of the GNU Lesser General Public
b1dca6
+   License as published by the Free Software Foundation; either
b1dca6
+   version 2.1 of the License, or (at your option) any later version.
b1dca6
+
b1dca6
+   The GNU C Library is distributed in the hope that it will be useful,
b1dca6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b1dca6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b1dca6
+   Lesser General Public License for more details.
b1dca6
+
b1dca6
+   You should have received a copy of the GNU Lesser General Public
b1dca6
+   License along with the GNU C Library; if not, see
b1dca6
+   <https://www.gnu.org/licenses/>.  */
b1dca6
+
b1dca6
+#ifndef _ELF_MACHINE_SYM_NO_MATCH_H
b1dca6
+#define _ELF_MACHINE_SYM_NO_MATCH_H
b1dca6
+
b1dca6
+#include <link.h>
b1dca6
+#include <stdbool.h>
b1dca6
+
b1dca6
+/* This can be customized to ignore certain symbols during lookup in
b1dca6
+   case there are machine-specific rules to disregard some
b1dca6
+   symbols.  */
b1dca6
+static inline bool
b1dca6
+elf_machine_sym_no_match (const ElfW(Sym) *sym)
b1dca6
+{
b1dca6
+  return false;
b1dca6
+}
b1dca6
+
b1dca6
+#endif /* _ELF_MACHINE_SYM_NO_MATCH_H */
b1dca6
diff --git a/sysdeps/mips/dl-machine.h b/sysdeps/mips/dl-machine.h
b1dca6
index 91fc640388a735c7..b41e10647d81843b 100644
b1dca6
--- a/sysdeps/mips/dl-machine.h
b1dca6
+++ b/sysdeps/mips/dl-machine.h
b1dca6
@@ -467,21 +467,6 @@ elf_machine_plt_value (struct link_map *map, const ElfW(Rel) *reloc,
b1dca6
   return value;
b1dca6
 }
b1dca6
 
b1dca6
-/* The semantics of zero/non-zero values of undefined symbols differs
b1dca6
-   depending on whether the non-PIC ABI is in use.  Under the non-PIC
b1dca6
-   ABI, a non-zero value indicates that there is an address reference
b1dca6
-   to the symbol and thus it must always be resolved (except when
b1dca6
-   resolving a jump slot relocation) to the PLT entry whose address is
b1dca6
-   provided as the symbol's value; a zero value indicates that this
b1dca6
-   canonical-address behaviour is not required.  Yet under the classic
b1dca6
-   MIPS psABI, a zero value indicates that there is an address
b1dca6
-   reference to the function and the dynamic linker must resolve the
b1dca6
-   symbol immediately upon loading.  To avoid conflict, symbols for
b1dca6
-   which the dynamic linker must assume the non-PIC ABI semantics are
b1dca6
-   marked with the STO_MIPS_PLT flag.  */
b1dca6
-#define ELF_MACHINE_SYM_NO_MATCH(sym) \
b1dca6
-  ((sym)->st_shndx == SHN_UNDEF && !((sym)->st_other & STO_MIPS_PLT))
b1dca6
-
b1dca6
 #endif /* !dl_machine_h */
b1dca6
 
b1dca6
 #ifdef RESOLVE_MAP
b1dca6
diff --git a/sysdeps/mips/elf_machine_sym_no_match.h b/sysdeps/mips/elf_machine_sym_no_match.h
b1dca6
new file mode 100644
b1dca6
index 0000000000000000..9d09e5fa2db1ff6c
b1dca6
--- /dev/null
b1dca6
+++ b/sysdeps/mips/elf_machine_sym_no_match.h
b1dca6
@@ -0,0 +1,43 @@
b1dca6
+/* MIPS-specific handling of undefined symbols.
b1dca6
+   Copyright (C) 2008-2020 Free Software Foundation, Inc.
b1dca6
+   This file is part of the GNU C Library.
b1dca6
+
b1dca6
+   The GNU C Library is free software; you can redistribute it and/or
b1dca6
+   modify it under the terms of the GNU Lesser General Public
b1dca6
+   License as published by the Free Software Foundation; either
b1dca6
+   version 2.1 of the License, or (at your option) any later version.
b1dca6
+
b1dca6
+   The GNU C Library is distributed in the hope that it will be useful,
b1dca6
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
b1dca6
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
b1dca6
+   Lesser General Public License for more details.
b1dca6
+
b1dca6
+   You should have received a copy of the GNU Lesser General Public
b1dca6
+   License along with the GNU C Library; if not, see
b1dca6
+   <https://www.gnu.org/licenses/>.  */
b1dca6
+
b1dca6
+#ifndef _ELF_MACHINE_SYM_NO_MATCH_H
b1dca6
+#define _ELF_MACHINE_SYM_NO_MATCH_H
b1dca6
+
b1dca6
+#include <link.h>
b1dca6
+#include <stdbool.h>
b1dca6
+
b1dca6
+/* The semantics of zero/non-zero values of undefined symbols differs
b1dca6
+   depending on whether the non-PIC ABI is in use.  Under the non-PIC
b1dca6
+   ABI, a non-zero value indicates that there is an address reference
b1dca6
+   to the symbol and thus it must always be resolved (except when
b1dca6
+   resolving a jump slot relocation) to the PLT entry whose address is
b1dca6
+   provided as the symbol's value; a zero value indicates that this
b1dca6
+   canonical-address behaviour is not required.  Yet under the classic
b1dca6
+   MIPS psABI, a zero value indicates that there is an address
b1dca6
+   reference to the function and the dynamic linker must resolve the
b1dca6
+   symbol immediately upon loading.  To avoid conflict, symbols for
b1dca6
+   which the dynamic linker must assume the non-PIC ABI semantics are
b1dca6
+   marked with the STO_MIPS_PLT flag.  */
b1dca6
+static inline bool
b1dca6
+elf_machine_sym_no_match (const ElfW(Sym) *sym)
b1dca6
+{
b1dca6
+  return sym->st_shndx == SHN_UNDEF && !(sym->st_other & STO_MIPS_PLT);
b1dca6
+}
b1dca6
+
b1dca6
+#endif /* _ELF_MACHINE_SYM_NO_MATCH_H */