!584 backport上游补丁修复riscv上的错误

From: @laokz 
Reviewed-by: @liqingqing_1229 
Signed-off-by: @liqingqing_1229
This commit is contained in:
openeuler-ci-bot 2023-05-09 00:48:07 +00:00 committed by Gitee
commit b08716ce38
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
4 changed files with 1058 additions and 1 deletions

View File

@ -0,0 +1,658 @@
From 8ee878592c4a642937152c8308b8faef86bcfc40 Mon Sep 17 00:00:00 2001
From: "Lucas A. M. Magalhaes" <lamm@linux.ibm.com>
Date: Thu, 14 Jul 2022 14:37:22 -0300
Subject: [PATCH] Assume only FLAG_ELF_LIBC6 suport
The older libc versions are obsolete for over twenty years now.
This patch removes the special flags for libc5 and libc4 and assumes
that all libraries cached are libc6 compatible and use FLAG_ELF_LIBC6.
Checked with a build for all affected architectures.
Co-authored-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
elf/cache.c | 6 +-
elf/ldconfig.c | 63 ++-----------------
elf/readelflib.c | 46 ++------------
elf/readlib.c | 25 +-------
sysdeps/unix/sysv/linux/aarch64/ldconfig.h | 30 ---------
sysdeps/unix/sysv/linux/arc/ldconfig.h | 27 --------
sysdeps/unix/sysv/linux/arm/ldconfig.h | 25 --------
sysdeps/unix/sysv/linux/csky/ldconfig.h | 34 ----------
sysdeps/unix/sysv/linux/i386/ldconfig.h | 6 --
sysdeps/unix/sysv/linux/ia64/ldconfig.h | 24 -------
sysdeps/unix/sysv/linux/m68k/ldconfig.h | 1 -
.../unix/sysv/linux/mips/mips64/ldconfig.h | 25 --------
sysdeps/unix/sysv/linux/powerpc/ldconfig.h | 27 --------
sysdeps/unix/sysv/linux/riscv/ldconfig.h | 36 -----------
sysdeps/unix/sysv/linux/s390/ldconfig.h | 7 ---
sysdeps/unix/sysv/linux/x86_64/ldconfig.h | 26 --------
16 files changed, 14 insertions(+), 394 deletions(-)
delete mode 100644 sysdeps/unix/sysv/linux/aarch64/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/arc/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/arm/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/csky/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/ia64/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/m68k/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/mips/mips64/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/powerpc/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/riscv/ldconfig.h
delete mode 100644 sysdeps/unix/sysv/linux/x86_64/ldconfig.h
diff --git a/elf/cache.c b/elf/cache.c
index 3d7d3a67bf..f5f3ef8c4d 100644
--- a/elf/cache.c
+++ b/elf/cache.c
@@ -157,6 +157,7 @@ struct cache_entry
/* List of all cache entries. */
static struct cache_entry *entries;
+/* libc4, ELF and libc5 are unsupported. */
static const char *flag_descr[] =
{ "libc4", "ELF", "libc5", "libc6"};
@@ -168,14 +169,11 @@ print_entry (const char *lib, int flag, uint64_t hwcap,
printf ("\t%s (", lib);
switch (flag & FLAG_TYPE_MASK)
{
- case FLAG_LIBC4:
- case FLAG_ELF:
- case FLAG_ELF_LIBC5:
case FLAG_ELF_LIBC6:
fputs (flag_descr[flag & FLAG_TYPE_MASK], stdout);
break;
default:
- fputs (_("unknown"), stdout);
+ fputs (_("unknown or unsupported flag"), stdout);
break;
}
switch (flag & FLAG_REQUIRED_MASK)
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 9394ac6438..6f37f38f35 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -65,19 +65,6 @@
#define PACKAGE _libc_intl_domainname
-static const struct
-{
- const char *name;
- int flag;
-} lib_types[] =
-{
- {"libc4", FLAG_LIBC4},
- {"libc5", FLAG_ELF_LIBC5},
- {"libc6", FLAG_ELF_LIBC6},
- {"glibc2", FLAG_ELF_LIBC6}
-};
-
-
/* List of directories to handle. */
struct dir_entry
{
@@ -469,27 +456,8 @@ add_dir_1 (const char *line, const char *from_file, int from_line)
entry->from_file = strdup (from_file);
entry->from_line = from_line;
- /* Search for an '=' sign. */
entry->path = xstrdup (line);
- char *equal_sign = strchr (entry->path, '=');
- if (equal_sign)
- {
- *equal_sign = '\0';
- ++equal_sign;
- entry->flag = FLAG_ANY;
- for (i = 0; i < sizeof (lib_types) / sizeof (lib_types[0]); ++i)
- if (strcmp (equal_sign, lib_types[i].name) == 0)
- {
- entry->flag = lib_types[i].flag;
- break;
- }
- if (entry->flag == FLAG_ANY)
- error (0, 0, _("%s is not a known library type"), equal_sign);
- }
- else
- {
- entry->flag = FLAG_ANY;
- }
+ entry->flag = FLAG_ELF_LIBC6;
/* Canonify path: for now only remove leading and trailing
whitespace and the trailing slashes. */
@@ -1054,23 +1022,11 @@ search_dir (const struct dir_entry *entry)
soname = xstrdup (direntry->d_name);
}
- if (flag == FLAG_ELF
- && (entry->flag == FLAG_ELF_LIBC5
- || entry->flag == FLAG_ELF_LIBC6))
- flag = entry->flag;
-
/* Some sanity checks to print warnings. */
if (opt_verbose)
{
- if (flag == FLAG_ELF_LIBC5 && entry->flag != FLAG_ELF_LIBC5
- && entry->flag != FLAG_ANY)
- error (0, 0, _("libc5 library %s in wrong directory"), file_name);
- if (flag == FLAG_ELF_LIBC6 && entry->flag != FLAG_ELF_LIBC6
- && entry->flag != FLAG_ANY)
+ if (flag == FLAG_ELF_LIBC6 && entry->flag != FLAG_ELF_LIBC6)
error (0, 0, _("libc6 library %s in wrong directory"), file_name);
- if (flag == FLAG_LIBC4 && entry->flag != FLAG_LIBC4
- && entry->flag != FLAG_ANY)
- error (0, 0, _("libc4 library %s in wrong directory"), file_name);
}
/* Add library to list. */
@@ -1089,19 +1045,8 @@ search_dir (const struct dir_entry *entry)
/* It's newer - add it. */
/* Flag should be the same - sanity check. */
if (dlib_ptr->flag != flag)
- {
- if (dlib_ptr->flag == FLAG_ELF
- && (flag == FLAG_ELF_LIBC5 || flag == FLAG_ELF_LIBC6))
- dlib_ptr->flag = flag;
- else if ((dlib_ptr->flag == FLAG_ELF_LIBC5
- || dlib_ptr->flag == FLAG_ELF_LIBC6)
- && flag == FLAG_ELF)
- dlib_ptr->flag = flag;
- else
- error (0, 0, _("libraries %s and %s in directory %s have same soname but different type."),
- dlib_ptr->name, direntry->d_name,
- entry->path);
- }
+ error (0, 0, _("libraries %s and %s in directory %s have same soname but different type."),
+ dlib_ptr->name, direntry->d_name, entry->path);
free (dlib_ptr->name);
dlib_ptr->name = xstrdup (direntry->d_name);
dlib_ptr->is_link = is_link;
diff --git a/elf/readelflib.c b/elf/readelflib.c
index 771182b5d0..5f43e0230d 100644
--- a/elf/readelflib.c
+++ b/elf/readelflib.c
@@ -44,7 +44,6 @@ process_elf_file (const char *file_name, const char *lib, int *flag,
size_t file_length)
{
int i;
- unsigned int j;
unsigned int dynamic_addr;
size_t dynamic_size;
char *program_interpreter;
@@ -81,9 +80,8 @@ process_elf_file (const char *file_name, const char *lib, int *flag,
elf_pheader = (ElfW(Phdr) *) (elf_header->e_phoff + file_contents);
check_ptr (elf_pheader);
- /* The library is an elf library, now search for soname and
- libc5/libc6. */
- *flag = FLAG_ELF;
+ /* The library is an elf library. */
+ *flag = FLAG_ELF_LIBC6;
/* The default ISA level is 0. */
*isa_level = 0;
@@ -110,16 +108,6 @@ process_elf_file (const char *file_name, const char *lib, int *flag,
program_interpreter = (char *) (file_contents + segment->p_offset);
check_ptr (program_interpreter);
- /* Check if this is enough to classify the binary. */
- for (j = 0; j < sizeof (interpreters) / sizeof (interpreters [0]);
- ++j)
- if (strcmp (program_interpreter, interpreters[j].soname) == 0)
- {
- *flag = interpreters[j].flag;
- break;
- }
- break;
-
case PT_GNU_PROPERTY:
/* The NT_GNU_PROPERTY_TYPE_0 note must be aligned to 4 bytes
in 32-bit objects and to 8 bytes in 64-bit objects. Skip
@@ -244,38 +232,16 @@ done:
if (dynamic_strings == NULL)
return 1;
- /* Now read the DT_NEEDED and DT_SONAME entries. */
+ /* Now read the DT_SONAME entries. */
for (dyn_entry = dynamic_segment; dyn_entry->d_tag != DT_NULL;
++dyn_entry)
{
- if (dyn_entry->d_tag == DT_NEEDED || dyn_entry->d_tag == DT_SONAME)
+ if (dyn_entry->d_tag == DT_SONAME)
{
char *name = dynamic_strings + dyn_entry->d_un.d_val;
check_ptr (name);
-
- if (dyn_entry->d_tag == DT_NEEDED)
- {
-
- if (*flag == FLAG_ELF)
- {
- /* Check if this is enough to classify the binary. */
- for (j = 0;
- j < sizeof (known_libs) / sizeof (known_libs [0]);
- ++j)
- if (strcmp (name, known_libs [j].soname) == 0)
- {
- *flag = known_libs [j].flag;
- break;
- }
- }
- }
-
- else if (dyn_entry->d_tag == DT_SONAME)
- *soname = xstrdup (name);
-
- /* Do we have everything we need? */
- if (*soname && *flag != FLAG_ELF)
- return 0;
+ *soname = xstrdup (name);
+ return 0;
}
}
diff --git a/elf/readlib.c b/elf/readlib.c
index ed42fbd48e..be65e3d0e9 100644
--- a/elf/readlib.c
+++ b/elf/readlib.c
@@ -43,24 +43,6 @@ struct known_names
int flag;
};
-static struct known_names interpreters[] =
-{
- { "/lib/" LD_SO, FLAG_ELF_LIBC6 },
-#ifdef SYSDEP_KNOWN_INTERPRETER_NAMES
- SYSDEP_KNOWN_INTERPRETER_NAMES
-#endif
-};
-
-static struct known_names known_libs[] =
-{
- { LIBC_SO, FLAG_ELF_LIBC6 },
- { LIBM_SO, FLAG_ELF_LIBC6 },
-#ifdef SYSDEP_KNOWN_LIBRARY_NAMES
- SYSDEP_KNOWN_LIBRARY_NAMES
-#endif
-};
-
-
/* Check if string corresponds to a GDB Python file. */
static bool
is_gdb_python_file (const char *name)
@@ -83,7 +65,8 @@ process_file (const char *real_file_name, const char *file_name,
struct exec *aout_header;
ret = 0;
- *flag = FLAG_ANY;
+ /* Just set FLAG_ELF_LIBC6 as old formats are not supported anymore. */
+ *flag = FLAG_ELF_LIBC6;
*soname = NULL;
file = fopen (real_file_name, "rb");
@@ -150,7 +133,6 @@ process_file (const char *real_file_name, const char *file_name,
*dot = '\0';
}
*soname = copy;
- *flag = FLAG_LIBC4;
goto done;
}
@@ -191,9 +173,6 @@ implicit_soname (const char *lib, int flag)
{
char *soname = xstrdup (lib);
- if ((flag & FLAG_TYPE_MASK) != FLAG_LIBC4)
- return soname;
-
/* Aout files don't have a soname, just return the name
including the major number. */
char *major = strstr (soname, ".so.");
diff --git a/sysdeps/unix/sysv/linux/aarch64/ldconfig.h b/sysdeps/unix/sysv/linux/aarch64/ldconfig.h
deleted file mode 100644
index 5cbfb32714..0000000000
--- a/sysdeps/unix/sysv/linux/aarch64/ldconfig.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Copyright (C) 2009-2022 Free Software Foundation, Inc.
-
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public License as
- published by the Free Software Foundation; either version 2.1 of the
- License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib/ld-linux-aarch64.so.1", FLAG_ELF_LIBC6 }, \
- { "/lib/ld-linux-aarch64_be.so.1", FLAG_ELF_LIBC6 }, \
- { "/lib/ld-linux-aarch64_ilp32.so.1", FLAG_ELF_LIBC6 }, \
- { "/lib/ld-linux-aarch64_be_ilp32.so.1", FLAG_ELF_LIBC6 }, \
- { "/lib/ld-linux.so.3", FLAG_ELF_LIBC6 }, \
- { "/lib/ld-linux-armhf.so.3", FLAG_ELF_LIBC6 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/arc/ldconfig.h b/sysdeps/unix/sysv/linux/arc/ldconfig.h
deleted file mode 100644
index f673170e59..0000000000
--- a/sysdeps/unix/sysv/linux/arc/ldconfig.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* ldconfig default paths and libraries. Linux/RISC-V version.
- Copyright (C) 2020-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library. If not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib/ld-linux-arc.so.2", FLAG_ELF_LIBC6 }, \
- { "/lib/ld-linux-arceb.so.2", FLAG_ELF_LIBC6 },
-
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/arm/ldconfig.h b/sysdeps/unix/sysv/linux/arm/ldconfig.h
deleted file mode 100644
index d1253993ea..0000000000
--- a/sysdeps/unix/sysv/linux/arm/ldconfig.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib/ld-linux.so.3", FLAG_ELF_LIBC6 }, \
- { "/lib/ld-linux-armhf.so.3", FLAG_ELF_LIBC6 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/csky/ldconfig.h b/sysdeps/unix/sysv/linux/csky/ldconfig.h
deleted file mode 100644
index fbe17e3dc8..0000000000
--- a/sysdeps/unix/sysv/linux/csky/ldconfig.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/* ldconfig default paths and libraries. Linux/C-SKY version.
- Copyright (C) 2018-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define LD_SO_PREFIX "/lib/ld-linux-"
-#define LD_SO_SUFFIX ".so.1"
-
-#ifdef __CSKY_HARD_FLOAT__
-# define LD_SO_ABI "cskyv2-hf"
-#else
-# define LD_SO_ABI "cskyv2"
-#endif
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { LD_SO_PREFIX LD_SO_ABI LD_SO_SUFFIX, FLAG_ELF_LIBC6 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/i386/ldconfig.h b/sysdeps/unix/sysv/linux/i386/ldconfig.h
index bafbec1231..9afda09cca 100644
--- a/sysdeps/unix/sysv/linux/i386/ldconfig.h
+++ b/sysdeps/unix/sysv/linux/i386/ldconfig.h
@@ -16,9 +16,3 @@
<https://www.gnu.org/licenses/>. */
#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib/ld-linux.so.1", FLAG_ELF_LIBC5 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.5", FLAG_ELF_LIBC5 }, \
- { "libm.so.5", FLAG_ELF_LIBC5 },
diff --git a/sysdeps/unix/sysv/linux/ia64/ldconfig.h b/sysdeps/unix/sysv/linux/ia64/ldconfig.h
deleted file mode 100644
index 4731419bf8..0000000000
--- a/sysdeps/unix/sysv/linux/ia64/ldconfig.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib/ld-linux.so.2", FLAG_ELF_LIBC6 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/m68k/ldconfig.h b/sysdeps/unix/sysv/linux/m68k/ldconfig.h
deleted file mode 100644
index 953f192bcd..0000000000
--- a/sysdeps/unix/sysv/linux/m68k/ldconfig.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <sysdeps/unix/sysv/linux/i386/ldconfig.h>
diff --git a/sysdeps/unix/sysv/linux/mips/mips64/ldconfig.h b/sysdeps/unix/sysv/linux/mips/mips64/ldconfig.h
deleted file mode 100644
index ac82941aff..0000000000
--- a/sysdeps/unix/sysv/linux/mips/mips64/ldconfig.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library. If not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib32/ld.so.1", FLAG_ELF_LIBC6 }, \
- { "/lib64/ld.so.1", FLAG_ELF_LIBC6 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/powerpc/ldconfig.h b/sysdeps/unix/sysv/linux/powerpc/ldconfig.h
deleted file mode 100644
index 1d70657838..0000000000
--- a/sysdeps/unix/sysv/linux/powerpc/ldconfig.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/* ldconfig default paths and libraries. Linux/PowerPC version.
- Copyright (C) 2002-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib/ld.so.1", FLAG_ELF_LIBC6 }, \
- { "/lib64/ld64.so.1", FLAG_ELF_LIBC6 }, \
- { "/lib64/ld64.so.2", FLAG_ELF_LIBC6 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/riscv/ldconfig.h b/sysdeps/unix/sysv/linux/riscv/ldconfig.h
deleted file mode 100644
index e3847f116e..0000000000
--- a/sysdeps/unix/sysv/linux/riscv/ldconfig.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* ldconfig default paths and libraries. Linux/RISC-V version.
- Copyright (C) 2001-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library. If not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define LD_SO_PREFIX "/lib/ld-linux-"
-#define LD_SO_SUFFIX ".so.1"
-
-#if __riscv_xlen == 64
-# define LD_SO_ABI "riscv64-lp64"
-#else
-# define LD_SO_ABI "riscv32-ilp32"
-#endif
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { LD_SO_PREFIX LD_SO_ABI "d" LD_SO_SUFFIX, FLAG_ELF_LIBC6 }, \
- { LD_SO_PREFIX LD_SO_ABI LD_SO_SUFFIX, FLAG_ELF_LIBC6 },
-
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/s390/ldconfig.h b/sysdeps/unix/sysv/linux/s390/ldconfig.h
index f564a6eaf6..9afda09cca 100644
--- a/sysdeps/unix/sysv/linux/s390/ldconfig.h
+++ b/sysdeps/unix/sysv/linux/s390/ldconfig.h
@@ -16,10 +16,3 @@
<https://www.gnu.org/licenses/>. */
#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib/ld.so.1", FLAG_ELF_LIBC6 }, \
- { "/lib/ld64.so.1", FLAG_ELF_LIBC6 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
diff --git a/sysdeps/unix/sysv/linux/x86_64/ldconfig.h b/sysdeps/unix/sysv/linux/x86_64/ldconfig.h
deleted file mode 100644
index b67203e017..0000000000
--- a/sysdeps/unix/sysv/linux/x86_64/ldconfig.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Copyright (C) 2001-2022 Free Software Foundation, Inc.
- This file is part of the GNU C Library.
-
- The GNU C Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- The GNU C Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with the GNU C Library; if not, see
- <https://www.gnu.org/licenses/>. */
-
-#include <sysdeps/generic/ldconfig.h>
-
-#define SYSDEP_KNOWN_INTERPRETER_NAMES \
- { "/lib/ld-linux.so.2", FLAG_ELF_LIBC6 }, \
- { "/libx32/ld-linux-x32.so.2", FLAG_ELF_LIBC6 }, \
- { "/lib64/ld-linux-x86-64.so.2", FLAG_ELF_LIBC6 },
-#define SYSDEP_KNOWN_LIBRARY_NAMES \
- { "libc.so.6", FLAG_ELF_LIBC6 }, \
- { "libm.so.6", FLAG_ELF_LIBC6 },
--
2.39.2

View File

@ -0,0 +1,214 @@
From 1b0ea8c5d886fedabd611a569b5ec58a6f5153e6 Mon Sep 17 00:00:00 2001
From: Joan Bruguera <joanbrugueram@gmail.com>
Date: Sat, 18 Feb 2023 21:52:15 +0000
Subject: [PATCH] elf: Restore ldconfig libc6 implicit soname logic [BZ #30125]
While cleaning up old libc version support, the deprecated libc4 code was
accidentally kept in `implicit_soname`, instead of the libc6 code.
This causes additional symlinks to be created by `ldconfig` for libraries
without a soname, e.g. a library `libsomething.123.456.789` without a soname
will create a `libsomething.123` -> `libsomething.123.456.789` symlink.
As the libc6 version of the `implicit_soname` code is a trivial `xstrdup`,
just inline it and remove `implicit_soname` altogether.
Some further simplification looks possible (e.g. the call to `create_links`
looks like a no-op if `soname == NULL`, other than the verbose printfs), but
logic is kept as-is for now.
Fixes: BZ #30125
Fixes: 8ee878592c4a ("Assume only FLAG_ELF_LIBC6 suport")
Signed-off-by: Joan Bruguera <joanbrugueram@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
Rebased-by: laokz <zhangkai@iscas.ac.cn>
---
elf/Makefile | 14 ++++++
elf/ldconfig.c | 4 +-
elf/readlib.c | 19 --------
elf/tst-ldconfig-soname-lib-with-soname.c | 1 +
elf/tst-ldconfig-soname-lib-without-soname.c | 1 +
elf/tst-ldconfig-soname.sh | 49 ++++++++++++++++++++
sysdeps/generic/ldconfig.h | 2 -
7 files changed, 67 insertions(+), 23 deletions(-)
create mode 100644 elf/tst-ldconfig-soname-lib-with-soname.c
create mode 100644 elf/tst-ldconfig-soname-lib-without-soname.c
create mode 100644 elf/tst-ldconfig-soname.sh
diff --git a/elf/Makefile b/elf/Makefile
index 2fc6391183..0d19964d42 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -627,6 +627,7 @@ ifeq ($(run-built-tests),yes)
tests-special += \
$(objpfx)noload-mem.out \
$(objpfx)tst-ldconfig-X.out \
+ $(objpfx)tst-ldconfig-soname.out \
$(objpfx)tst-leaks1-mem.out \
$(objpfx)tst-rtld-help.out \
# tests-special
@@ -859,6 +860,8 @@ modules-names += \
tst-initorderb2 \
tst-latepthreadmod \
tst-ldconfig-ld-mod \
+ tst-ldconfig-soname-lib-with-soname \
+ tst-ldconfig-soname-lib-without-soname \
tst-main1mod \
tst-nodelete2mod \
tst-nodelete-dlclose-dso \
@@ -2402,6 +2405,17 @@ $(objpfx)tst-ldconfig-p.out : tst-ldconfig-p.sh $(objpfx)ldconfig
'$(run-program-env)' > $@; \
$(evaluate-test)
+LDFLAGS-tst-ldconfig-soname-lib-with-soname.so = \
+ -Wl,-soname,libtst-ldconfig-soname-lib-with-soname.so.1
+
+$(objpfx)tst-ldconfig-soname.out : tst-ldconfig-soname.sh \
+ $(objpfx)ldconfig \
+ $(objpfx)tst-ldconfig-soname-lib-with-soname.so \
+ $(objpfx)tst-ldconfig-soname-lib-without-soname.so
+ $(SHELL) $< '$(common-objpfx)' '$(test-wrapper-env)' \
+ '$(run-program-env)' > $@; \
+ $(evaluate-test)
+
# Test static linking of all the libraries we can possibly link
# together. Note that in some configurations this may be less than the
# complete list of libraries we build but we try to maxmimize this list.
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 3f1b30c570..2fc45ad825 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -616,7 +616,7 @@ manual_link (char *library)
goto out;
}
if (soname == NULL)
- soname = implicit_soname (libname, flag);
+ soname = xstrdup (libname);
create_links (real_path, path, libname, soname);
free (soname);
out:
@@ -849,7 +849,7 @@ search_dir (const struct dir_entry *entry)
}
if (soname == NULL)
- soname = implicit_soname (direntry->d_name, flag);
+ soname = xstrdup (direntry->d_name);
/* A link may just point to itself. */
if (is_link)
diff --git a/elf/readlib.c b/elf/readlib.c
index c5c3591eef..bc13d9acc6 100644
--- a/elf/readlib.c
+++ b/elf/readlib.c
@@ -166,24 +166,5 @@ process_file (const char *real_file_name, const char *file_name,
return ret;
}
-/* Returns made up soname if lib doesn't have explicit DT_SONAME. */
-
-char *
-implicit_soname (const char *lib, int flag)
-{
- char *soname = xstrdup (lib);
-
- /* Aout files don't have a soname, just return the name
- including the major number. */
- char *major = strstr (soname, ".so.");
- if (major)
- {
- char *dot = strstr (major + 4, ".");
- if (dot)
- *dot = '\0';
- }
- return soname;
-}
-
/* Get architecture specific version of process_elf_file. */
#include <readelflib.c>
diff --git a/elf/tst-ldconfig-soname-lib-with-soname.c b/elf/tst-ldconfig-soname-lib-with-soname.c
new file mode 100644
index 0000000000..d1ab56ad58
--- /dev/null
+++ b/elf/tst-ldconfig-soname-lib-with-soname.c
@@ -0,0 +1 @@
+/* This file intentionally left blank */
diff --git a/elf/tst-ldconfig-soname-lib-without-soname.c b/elf/tst-ldconfig-soname-lib-without-soname.c
new file mode 100644
index 0000000000..d1ab56ad58
--- /dev/null
+++ b/elf/tst-ldconfig-soname-lib-without-soname.c
@@ -0,0 +1 @@
+/* This file intentionally left blank */
diff --git a/elf/tst-ldconfig-soname.sh b/elf/tst-ldconfig-soname.sh
new file mode 100644
index 0000000000..406f526dbf
--- /dev/null
+++ b/elf/tst-ldconfig-soname.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# Test that ldconfig creates symlinks according to the library's soname
+# (and in particular, does not create symlinks for libraries without a soname)
+# Copyright (C) 2000-2023 Free Software Foundation, Inc.
+# Copyright The GNU Toolchain Authors.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public
+# License along with the GNU C Library; if not, see
+# <https://www.gnu.org/licenses/>.
+
+set -ex
+
+common_objpfx=$1
+test_wrapper_env=$2
+run_program_env=$3
+
+testroot="${common_objpfx}elf/bug30125-test-directory"
+cleanup () {
+ rm -rf "$testroot"
+}
+trap cleanup 0
+
+rm -rf "$testroot"
+mkdir -p $testroot/lib
+cp "${common_objpfx}elf/tst-ldconfig-soname-lib-with-soname.so" \
+ $testroot/lib/libtst-ldconfig-soname-lib-with-soname.so.1.2.3
+cp "${common_objpfx}elf/tst-ldconfig-soname-lib-without-soname.so" \
+ $testroot/lib/libtst-ldconfig-soname-lib-without-soname.so.1.2.3
+
+${test_wrapper_env} \
+${run_program_env} \
+${common_objpfx}elf/ldconfig -vn $testroot/lib
+
+LINKS=$(cd $testroot/lib && find . -type l)
+if [ "$LINKS" != "./libtst-ldconfig-soname-lib-with-soname.so.1" ]; then
+ echo "error: $0 - extra symlinks found"
+ exit 1
+fi
diff --git a/sysdeps/generic/ldconfig.h b/sysdeps/generic/ldconfig.h
index 0e1a9a9515..e9e9e19d0f 100644
--- a/sysdeps/generic/ldconfig.h
+++ b/sysdeps/generic/ldconfig.h
@@ -90,8 +90,6 @@ extern int process_file (const char *real_file_name, const char *file_name,
const char *lib, int *flag, unsigned int *isa_level,
char **soname, int is_link, struct stat *stat_buf);
-extern char *implicit_soname (const char *lib, int flag);
-
/* Declared in readelflib.c. */
extern int process_elf_file (const char *file_name, const char *lib,
int *flag, unsigned int *isa_level, char **soname,
--
2.39.2

View File

@ -65,7 +65,7 @@
##############################################################################
Name: glibc
Version: 2.36
Release: 13
Release: 14
Summary: The GNU libc libraries
License: %{all_license}
URL: http://www.gnu.org/software/glibc/
@ -93,6 +93,9 @@ Patch6: 0001-gconv-Use-64-bit-interfaces-in-gconv_parseconfdir-bu.patch
Patch7: 0001-syslog-Remove-extra-whitespace-between-timestamp-and.patch
Patch8: Makerules-fix-MAKEFLAGS-assignment-for-upcoming-make.patch
Patch9: gmon-Fix-allocated-buffer-overflow-bug-29444.patch
Patch10: stdlib-strfrom-Add-copysign-to-fix-NAN-issue-on-risc.patch
Patch11: Assume-only-FLAG_ELF_LIBC6-suport.patch
Patch12: elf-Restore-ldconfig-libc6-implicit-soname-logic-BZ-.patch
Patch9000: turn-default-value-of-x86_rep_stosb_threshold_form_2K_to_1M.patch
Patch9001: locale-delete-no-hard-link-to-avoid-all_language-pac.patch
@ -1269,6 +1272,12 @@ fi
%endif
%changelog
* Mon May 08 2023 laokz <zhangkai@iscas.ac.cn> - 2.36-14
- Backport RISC-V patches:
- stdlib/strfrom: Add copysign to fix NAN issue (from v2.37)
- Assume only FLAG_ELF_LIBC6 suport (from v2.37)
- Restore libc6 implicit soname logic (from v2.38)
* Thu Feb 23 2023 Qingqing Li <liqingqing3@huawei.com> - 2.36-13
- gmon: Fix allocated buffer overflow (bug 29444)

View File

@ -0,0 +1,176 @@
From 0cc0033ef19bd3378445c2b851e53d7255cb1b1e Mon Sep 17 00:00:00 2001
From: Letu Ren <fantasquex@gmail.com>
Date: Fri, 21 Oct 2022 22:54:50 +0800
Subject: [PATCH] stdlib/strfrom: Add copysign to fix NAN issue on riscv (BZ
#29501)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
According to the specification of ISO/IEC TS 18661-1:2014,
The strfromd, strfromf, and strfroml functions are equivalent to
snprintf(s, n, format, fp) (7.21.6.5), except the format string contains only
the character %, an optional precision that does not contain an asterisk *, and
one of the conversion specifiers a, A, e, E, f, F, g, or G, which applies to
the type (double, float, or long double) indicated by the function suffix
(rather than by a length modifier). Use of these functions with any other 20
format string results in undefined behavior.
strfromf will convert the arguement with type float to double first.
According to the latest version of IEEE754 which is published in 2019,
Conversion of a quiet NaN from a narrower format to a wider format in the same
radix, and then back to the same narrower format, should not change the quiet
NaN payload in any way except to make it canonical.
When either an input or result is a NaN, this standard does not interpret the
sign of a NaN. However, operations on bit strings—copy, negate, abs,
copySign—specify the sign bit of a NaN result, sometimes based upon the sign
bit of a NaN operand. The logical predicates totalOrder and isSignMinus are
also affected by the sign bit of a NaN operand. For all other operations, this
standard does not specify the sign bit of a NaN result, even when there is only
one input NaN, or when the NaN is produced from an invalid operation.
converting NAN or -NAN with type float to double doesn't need to keep
the signbit. As a result, this test case isn't mandatory.
The problem is that according to RISC-V ISA manual in chapter 11.3 of
riscv-isa-20191213,
Except when otherwise stated, if the result of a floating-point operation is
NaN, it is the canonical NaN. The canonical NaN has a positive sign and all
significand bits clear except the MSB, a.k.a. the quiet bit. For
single-precision floating-point, this corresponds to the pattern 0x7fc00000.
which means that conversion -NAN from float to double won't keep the signbit.
Since glibc ought to be consistent here between types and architectures, this
patch adds copysign to fix this problem if the string is NAN. This patch
adds two different functions under sysdeps directory to work around the
issue.
This patch has been tested on x86_64 and riscv64.
Resolves: BZ #29501
v2: Change from macros to different inline functions.
v3: Add unlikely check to isnan.
v4: Fix wrong commit message header.
v5: Fix style: add space before parentheses.
v6: Add copyright.
Signed-off-by: Letu Ren <fantasquex@gmail.com>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
---
stdlib/strfrom-skeleton.c | 3 +-
.../generic/fix-float-double-convert-nan.h | 31 ++++++++++++++++
.../riscv/rvd/fix-float-double-convert-nan.h | 37 +++++++++++++++++++
3 files changed, 70 insertions(+), 1 deletion(-)
create mode 100644 sysdeps/generic/fix-float-double-convert-nan.h
create mode 100644 sysdeps/riscv/rvd/fix-float-double-convert-nan.h
diff --git a/stdlib/strfrom-skeleton.c b/stdlib/strfrom-skeleton.c
index 1fba04bf6a..36e9adcad5 100644
--- a/stdlib/strfrom-skeleton.c
+++ b/stdlib/strfrom-skeleton.c
@@ -27,6 +27,7 @@
#include <printf.h>
#include <string.h>
#include <locale/localeinfo.h>
+#include <fix-float-double-convert-nan.h>
#define UCHAR_T char
#define L_(Str) Str
@@ -61,7 +62,7 @@ STRFROM (char *dest, size_t size, const char *format, FLOAT f)
because __printf_fp and __printf_fphex only accept double and long double
as the floating-point argument. */
if (__builtin_types_compatible_p (FLOAT, float))
- fpnum.flt = f;
+ fpnum.flt = keep_sign_conversion (f);
else
fpnum.value = f;
diff --git a/sysdeps/generic/fix-float-double-convert-nan.h b/sysdeps/generic/fix-float-double-convert-nan.h
new file mode 100644
index 0000000000..66692262fc
--- /dev/null
+++ b/sysdeps/generic/fix-float-double-convert-nan.h
@@ -0,0 +1,31 @@
+/* Fix for conversion of float NAN to double. Generic version.
+ Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef FIX_FLOAT_DOUBLE_CONVERT_NAN_H
+#define FIX_FLOAT_DOUBLE_CONVERT_NAN_H
+
+/* This function aims to work around conversions of float -NAN
+ to double returning NAN instead of the correct -NAN in some
+ architectures. */
+static inline double __attribute__ ((always_inline))
+keep_sign_conversion (float flt)
+{
+ return flt;
+}
+
+#endif
diff --git a/sysdeps/riscv/rvd/fix-float-double-convert-nan.h b/sysdeps/riscv/rvd/fix-float-double-convert-nan.h
new file mode 100644
index 0000000000..cab003f3c1
--- /dev/null
+++ b/sysdeps/riscv/rvd/fix-float-double-convert-nan.h
@@ -0,0 +1,37 @@
+/* Fix for conversion of float NAN to double. RISC-V version..
+ Copyright (C) 2022 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library. If not, see
+ <https://www.gnu.org/licenses/>. */
+
+#ifndef FIX_FLOAT_DOUBLE_CONVERT_NAN_H
+#define FIX_FLOAT_DOUBLE_CONVERT_NAN_H
+
+#include <math.h>
+
+/* RISC-V rvd instructions do not preserve the signbit of NAN
+ when converting from float to double. */
+static inline double
+keep_sign_conversion (float flt)
+{
+ if (__glibc_unlikely (isnan (flt)))
+ {
+ float x = copysignf (1.f, flt);
+ return copysign ((double) flt, (double) x);
+ }
+ return flt;
+}
+
+#endif
--
2.39.2