2019-01-01 00:11:28 +00:00
|
|
|
/* Copyright (C) 1999-2019 Free Software Foundation, Inc.
|
1999-12-04 08:00:00 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
Contributed by Andreas Jaeger <aj@suse.de>, 1999 and
|
|
|
|
Jakub Jelinek <jakub@redhat.com>, 1999.
|
|
|
|
|
2005-12-07 05:49:17 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
2007-07-16 00:56:07 +00:00
|
|
|
it under the terms of the GNU General Public License as published
|
|
|
|
by the Free Software Foundation; version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
1999-12-04 08:00:00 +00:00
|
|
|
|
2005-12-07 05:49:17 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
1999-12-04 08:00:00 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2005-12-07 05:49:17 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
1999-12-04 08:00:00 +00:00
|
|
|
|
2005-12-07 05:49:17 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
2012-02-09 23:18:22 +00:00
|
|
|
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
1999-12-04 08:00:00 +00:00
|
|
|
|
|
|
|
/* The code in this file and in readelflib is a heavily simplified
|
|
|
|
version of the readelf program that's part of the current binutils
|
|
|
|
development version. Besides the simplification, it has also been
|
|
|
|
modified to read some other file formats. */
|
|
|
|
|
2003-07-22 21:35:06 +00:00
|
|
|
#include <a.out.h>
|
1999-12-04 08:00:00 +00:00
|
|
|
#include <elf.h>
|
|
|
|
#include <error.h>
|
|
|
|
#include <libintl.h>
|
2003-07-22 21:35:06 +00:00
|
|
|
#include <link.h>
|
1999-12-04 08:00:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/mman.h>
|
2003-07-22 21:35:06 +00:00
|
|
|
#include <sys/param.h>
|
1999-12-04 08:00:00 +00:00
|
|
|
#include <sys/stat.h>
|
2000-05-26 10:23:45 +00:00
|
|
|
#include <gnu/lib-names.h>
|
1999-12-04 08:00:00 +00:00
|
|
|
|
2005-12-21 22:16:34 +00:00
|
|
|
#include <ldconfig.h>
|
1999-12-04 08:00:00 +00:00
|
|
|
|
|
|
|
#define Elf32_CLASS ELFCLASS32
|
|
|
|
#define Elf64_CLASS ELFCLASS64
|
|
|
|
|
|
|
|
struct known_names
|
|
|
|
{
|
|
|
|
const char *soname;
|
|
|
|
int flag;
|
|
|
|
};
|
|
|
|
|
Update.
2001-03-12 Jakub Jelinek <jakub@redhat.com>
* csu/Makefile (abi-tag.h): Define OS and version separately, allow
version to be overriden from config.h.
* csu/abi-note.S: Use OS and version separately, include config.h.
* elf/dl-load.c (_dl_osversion): New.
(_dl_map_object_from_fd): Kill some warnings.
(open_verify): Check .note.ABI-tag of the library if present.
* elf/Makefile (CPPFLAGS-dl-load.c): Add -I$(csu-objpfx).
* elf/cache.c (struct cache_entry): Add osversion.
(print_entry): Print osversion.
(print_cache): Pass osversion to it.
(compare): Sort according to osversion.
(save_cache): Set osversion.
(add_to_cache): Add osversion argument.
* sysdeps/generic/ldconfig.h (add_to_cache, process_file,
process_elf_file): Add osversion argument.
* elf/readlib.c (process_file): Likewise.
* sysdeps/generic/readelflib.c (process_elf_file): Likewise.
* sysdeps/unix/sysv/linux/ia64/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/i386/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/sparc/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* elf/ldconfig.c (manual_link): Pass it.
(search_dir): Issue diagnostic if two libs with the same soname in
the same directory have different .note.ABI-tag. Record osversion in
dlib_entry and use it from there.
(struct lib_entry): Remove.
(struct dlib_entry): Add osversion.
* sysdeps/generic/dl-cache.c (_dl_load_cache_lookup): Check
osversion.
* sysdeps/generic/dl-cache.h (struct file_entry_new): Replace __unused
field with osversion.
* sysdeps/generic/ldsodefs.h (_dl_osversion): Declare.
* sysdeps/unix/sysv/linux/init-first.c: Include ldsodefs.h.
* sysdeps/unix/sysv/linux/dl-osinfo.h (DL_SYSDEP_OSCHECK): Save kernel
version in _dl_osversion.
* sysdeps/unix/sysv/linux/configure.in: Define __ABI_TAG_VERSION.
* Makerules (build-shlib-helper, build-module-helper): New.
(build-shlib, build-module-helper): Make sure .note.ABI-tag comes
early.
* config.h.in (__ABI_TAG_VERSION): Add.
* elf/dl-minimal.c (__strtoul_internal): Set endptr on return.
* sysdeps/unix/sysv/linux/i386/dl-librecon.h (EXTRA_LD_ENVVARS):
Handle LD_ASSUME_KERNEL.
* sysdeps/unix/sysv/linux/dl-librecon.h: New.
2001-03-16 07:40:05 +00:00
|
|
|
static struct known_names interpreters[] =
|
1999-12-04 08:00:00 +00:00
|
|
|
{
|
Update.
2001-03-12 Jakub Jelinek <jakub@redhat.com>
* csu/Makefile (abi-tag.h): Define OS and version separately, allow
version to be overriden from config.h.
* csu/abi-note.S: Use OS and version separately, include config.h.
* elf/dl-load.c (_dl_osversion): New.
(_dl_map_object_from_fd): Kill some warnings.
(open_verify): Check .note.ABI-tag of the library if present.
* elf/Makefile (CPPFLAGS-dl-load.c): Add -I$(csu-objpfx).
* elf/cache.c (struct cache_entry): Add osversion.
(print_entry): Print osversion.
(print_cache): Pass osversion to it.
(compare): Sort according to osversion.
(save_cache): Set osversion.
(add_to_cache): Add osversion argument.
* sysdeps/generic/ldconfig.h (add_to_cache, process_file,
process_elf_file): Add osversion argument.
* elf/readlib.c (process_file): Likewise.
* sysdeps/generic/readelflib.c (process_elf_file): Likewise.
* sysdeps/unix/sysv/linux/ia64/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/i386/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/sparc/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* elf/ldconfig.c (manual_link): Pass it.
(search_dir): Issue diagnostic if two libs with the same soname in
the same directory have different .note.ABI-tag. Record osversion in
dlib_entry and use it from there.
(struct lib_entry): Remove.
(struct dlib_entry): Add osversion.
* sysdeps/generic/dl-cache.c (_dl_load_cache_lookup): Check
osversion.
* sysdeps/generic/dl-cache.h (struct file_entry_new): Replace __unused
field with osversion.
* sysdeps/generic/ldsodefs.h (_dl_osversion): Declare.
* sysdeps/unix/sysv/linux/init-first.c: Include ldsodefs.h.
* sysdeps/unix/sysv/linux/dl-osinfo.h (DL_SYSDEP_OSCHECK): Save kernel
version in _dl_osversion.
* sysdeps/unix/sysv/linux/configure.in: Define __ABI_TAG_VERSION.
* Makerules (build-shlib-helper, build-module-helper): New.
(build-shlib, build-module-helper): Make sure .note.ABI-tag comes
early.
* config.h.in (__ABI_TAG_VERSION): Add.
* elf/dl-minimal.c (__strtoul_internal): Set endptr on return.
* sysdeps/unix/sysv/linux/i386/dl-librecon.h (EXTRA_LD_ENVVARS):
Handle LD_ASSUME_KERNEL.
* sysdeps/unix/sysv/linux/dl-librecon.h: New.
2001-03-16 07:40:05 +00:00
|
|
|
{ "/lib/" LD_SO, FLAG_ELF_LIBC6 },
|
2001-03-10 16:40:59 +00:00
|
|
|
#ifdef SYSDEP_KNOWN_INTERPRETER_NAMES
|
|
|
|
SYSDEP_KNOWN_INTERPRETER_NAMES
|
|
|
|
#endif
|
1999-12-04 08:00:00 +00:00
|
|
|
};
|
|
|
|
|
Update.
2001-03-12 Jakub Jelinek <jakub@redhat.com>
* csu/Makefile (abi-tag.h): Define OS and version separately, allow
version to be overriden from config.h.
* csu/abi-note.S: Use OS and version separately, include config.h.
* elf/dl-load.c (_dl_osversion): New.
(_dl_map_object_from_fd): Kill some warnings.
(open_verify): Check .note.ABI-tag of the library if present.
* elf/Makefile (CPPFLAGS-dl-load.c): Add -I$(csu-objpfx).
* elf/cache.c (struct cache_entry): Add osversion.
(print_entry): Print osversion.
(print_cache): Pass osversion to it.
(compare): Sort according to osversion.
(save_cache): Set osversion.
(add_to_cache): Add osversion argument.
* sysdeps/generic/ldconfig.h (add_to_cache, process_file,
process_elf_file): Add osversion argument.
* elf/readlib.c (process_file): Likewise.
* sysdeps/generic/readelflib.c (process_elf_file): Likewise.
* sysdeps/unix/sysv/linux/ia64/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/i386/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/sparc/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* elf/ldconfig.c (manual_link): Pass it.
(search_dir): Issue diagnostic if two libs with the same soname in
the same directory have different .note.ABI-tag. Record osversion in
dlib_entry and use it from there.
(struct lib_entry): Remove.
(struct dlib_entry): Add osversion.
* sysdeps/generic/dl-cache.c (_dl_load_cache_lookup): Check
osversion.
* sysdeps/generic/dl-cache.h (struct file_entry_new): Replace __unused
field with osversion.
* sysdeps/generic/ldsodefs.h (_dl_osversion): Declare.
* sysdeps/unix/sysv/linux/init-first.c: Include ldsodefs.h.
* sysdeps/unix/sysv/linux/dl-osinfo.h (DL_SYSDEP_OSCHECK): Save kernel
version in _dl_osversion.
* sysdeps/unix/sysv/linux/configure.in: Define __ABI_TAG_VERSION.
* Makerules (build-shlib-helper, build-module-helper): New.
(build-shlib, build-module-helper): Make sure .note.ABI-tag comes
early.
* config.h.in (__ABI_TAG_VERSION): Add.
* elf/dl-minimal.c (__strtoul_internal): Set endptr on return.
* sysdeps/unix/sysv/linux/i386/dl-librecon.h (EXTRA_LD_ENVVARS):
Handle LD_ASSUME_KERNEL.
* sysdeps/unix/sysv/linux/dl-librecon.h: New.
2001-03-16 07:40:05 +00:00
|
|
|
static struct known_names known_libs[] =
|
1999-12-04 08:00:00 +00:00
|
|
|
{
|
Update.
2001-03-12 Jakub Jelinek <jakub@redhat.com>
* csu/Makefile (abi-tag.h): Define OS and version separately, allow
version to be overriden from config.h.
* csu/abi-note.S: Use OS and version separately, include config.h.
* elf/dl-load.c (_dl_osversion): New.
(_dl_map_object_from_fd): Kill some warnings.
(open_verify): Check .note.ABI-tag of the library if present.
* elf/Makefile (CPPFLAGS-dl-load.c): Add -I$(csu-objpfx).
* elf/cache.c (struct cache_entry): Add osversion.
(print_entry): Print osversion.
(print_cache): Pass osversion to it.
(compare): Sort according to osversion.
(save_cache): Set osversion.
(add_to_cache): Add osversion argument.
* sysdeps/generic/ldconfig.h (add_to_cache, process_file,
process_elf_file): Add osversion argument.
* elf/readlib.c (process_file): Likewise.
* sysdeps/generic/readelflib.c (process_elf_file): Likewise.
* sysdeps/unix/sysv/linux/ia64/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/i386/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/sparc/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* elf/ldconfig.c (manual_link): Pass it.
(search_dir): Issue diagnostic if two libs with the same soname in
the same directory have different .note.ABI-tag. Record osversion in
dlib_entry and use it from there.
(struct lib_entry): Remove.
(struct dlib_entry): Add osversion.
* sysdeps/generic/dl-cache.c (_dl_load_cache_lookup): Check
osversion.
* sysdeps/generic/dl-cache.h (struct file_entry_new): Replace __unused
field with osversion.
* sysdeps/generic/ldsodefs.h (_dl_osversion): Declare.
* sysdeps/unix/sysv/linux/init-first.c: Include ldsodefs.h.
* sysdeps/unix/sysv/linux/dl-osinfo.h (DL_SYSDEP_OSCHECK): Save kernel
version in _dl_osversion.
* sysdeps/unix/sysv/linux/configure.in: Define __ABI_TAG_VERSION.
* Makerules (build-shlib-helper, build-module-helper): New.
(build-shlib, build-module-helper): Make sure .note.ABI-tag comes
early.
* config.h.in (__ABI_TAG_VERSION): Add.
* elf/dl-minimal.c (__strtoul_internal): Set endptr on return.
* sysdeps/unix/sysv/linux/i386/dl-librecon.h (EXTRA_LD_ENVVARS):
Handle LD_ASSUME_KERNEL.
* sysdeps/unix/sysv/linux/dl-librecon.h: New.
2001-03-16 07:40:05 +00:00
|
|
|
{ LIBC_SO, FLAG_ELF_LIBC6 },
|
|
|
|
{ LIBM_SO, FLAG_ELF_LIBC6 },
|
2001-03-10 16:40:59 +00:00
|
|
|
#ifdef SYSDEP_KNOWN_LIBRARY_NAMES
|
|
|
|
SYSDEP_KNOWN_LIBRARY_NAMES
|
|
|
|
#endif
|
1999-12-04 08:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-06-24 10:21:29 +00:00
|
|
|
/* Check if string corresponds to a GDB Python file. */
|
|
|
|
static bool
|
|
|
|
is_gdb_python_file (const char *name)
|
|
|
|
{
|
|
|
|
size_t len = strlen (name);
|
|
|
|
return len > 7 && strcmp (name + len - 7, "-gdb.py") == 0;
|
|
|
|
}
|
1999-12-04 08:00:00 +00:00
|
|
|
|
|
|
|
/* Returns 0 if everything is ok, != 0 in case of error. */
|
|
|
|
int
|
2000-09-30 00:54:42 +00:00
|
|
|
process_file (const char *real_file_name, const char *file_name,
|
Update.
2001-03-12 Jakub Jelinek <jakub@redhat.com>
* csu/Makefile (abi-tag.h): Define OS and version separately, allow
version to be overriden from config.h.
* csu/abi-note.S: Use OS and version separately, include config.h.
* elf/dl-load.c (_dl_osversion): New.
(_dl_map_object_from_fd): Kill some warnings.
(open_verify): Check .note.ABI-tag of the library if present.
* elf/Makefile (CPPFLAGS-dl-load.c): Add -I$(csu-objpfx).
* elf/cache.c (struct cache_entry): Add osversion.
(print_entry): Print osversion.
(print_cache): Pass osversion to it.
(compare): Sort according to osversion.
(save_cache): Set osversion.
(add_to_cache): Add osversion argument.
* sysdeps/generic/ldconfig.h (add_to_cache, process_file,
process_elf_file): Add osversion argument.
* elf/readlib.c (process_file): Likewise.
* sysdeps/generic/readelflib.c (process_elf_file): Likewise.
* sysdeps/unix/sysv/linux/ia64/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/i386/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/sparc/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* elf/ldconfig.c (manual_link): Pass it.
(search_dir): Issue diagnostic if two libs with the same soname in
the same directory have different .note.ABI-tag. Record osversion in
dlib_entry and use it from there.
(struct lib_entry): Remove.
(struct dlib_entry): Add osversion.
* sysdeps/generic/dl-cache.c (_dl_load_cache_lookup): Check
osversion.
* sysdeps/generic/dl-cache.h (struct file_entry_new): Replace __unused
field with osversion.
* sysdeps/generic/ldsodefs.h (_dl_osversion): Declare.
* sysdeps/unix/sysv/linux/init-first.c: Include ldsodefs.h.
* sysdeps/unix/sysv/linux/dl-osinfo.h (DL_SYSDEP_OSCHECK): Save kernel
version in _dl_osversion.
* sysdeps/unix/sysv/linux/configure.in: Define __ABI_TAG_VERSION.
* Makerules (build-shlib-helper, build-module-helper): New.
(build-shlib, build-module-helper): Make sure .note.ABI-tag comes
early.
* config.h.in (__ABI_TAG_VERSION): Add.
* elf/dl-minimal.c (__strtoul_internal): Set endptr on return.
* sysdeps/unix/sysv/linux/i386/dl-librecon.h (EXTRA_LD_ENVVARS):
Handle LD_ASSUME_KERNEL.
* sysdeps/unix/sysv/linux/dl-librecon.h: New.
2001-03-16 07:40:05 +00:00
|
|
|
const char *lib, int *flag, unsigned int *osversion,
|
2007-08-01 Andreas Jaeger <aj@suse.de>
Jakub Jelinek <jakub@redhat.com>
* elf/ldconfig.c (opt_ignore_aux_cache): Add new option.
(options): Add option.
(parse_opt): Handle option.
(manual_link): Adjust process_file caller. Call implicit_soname.
(search_dir): Formatting. Use and populate auxiliary cache.
(main): Load and save auxiliary cache.
* elf/readlib.c (process_file): Add stat_buf argument. Pass struct
stat64 from fstat64 to caller.
(implicit_soname): New function.
* elf/readelflib.c (process_elf_file): If DT_SONAME is not present,
leave *soname as NULL.
* elf/cache.c: Include libgen.h.
(print_entry, print_cache, compare, save_cache, add_to_cache):
Formatting and cleanups.
(aux_cache_entry_id, aux_cache_entry, aux_cache_file_entry,
aux_cache_file): New structures.
(AUX_CACHEMAGIC): Define.
(primes): New array.
(aux_hash_size, aux_hash): New variables.
(aux_cache_entry_id_hash, nextprime, init_aux_cache,
search_aux_cache, insert_to_aux_cache, add_to_aux_cache,
load_aux_cache, save_aux_cache): New functions.
* sysdeps/generic/ldconfig.h (_PATH_LDCONFIG_AUX_CACHE): Define.
(init_aux_cache, search_aux_cache, add_to_aux_cache,
load_aux_cache, save_aux_cache, implicit_soname): New prototypes.
(process_file): Adjust prototype.
2007-08-12 20:09:16 +00:00
|
|
|
char **soname, int is_link, struct stat64 *stat_buf)
|
1999-12-04 08:00:00 +00:00
|
|
|
{
|
|
|
|
FILE *file;
|
2000-09-30 00:54:42 +00:00
|
|
|
struct stat64 statbuf;
|
1999-12-04 08:00:00 +00:00
|
|
|
void *file_contents;
|
|
|
|
int ret;
|
|
|
|
ElfW(Ehdr) *elf_header;
|
|
|
|
struct exec *aout_header;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
*flag = FLAG_ANY;
|
|
|
|
*soname = NULL;
|
|
|
|
|
2000-09-30 00:54:42 +00:00
|
|
|
file = fopen (real_file_name, "rb");
|
1999-12-04 08:00:00 +00:00
|
|
|
if (file == NULL)
|
|
|
|
{
|
|
|
|
/* No error for stale symlink. */
|
2000-09-16 23:00:38 +00:00
|
|
|
if (is_link && strstr (file_name, ".so") != NULL)
|
1999-12-04 08:00:00 +00:00
|
|
|
return 1;
|
|
|
|
error (0, 0, _("Input file %s not found.\n"), file_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-09-30 00:54:42 +00:00
|
|
|
if (fstat64 (fileno (file), &statbuf) < 0)
|
1999-12-04 08:00:00 +00:00
|
|
|
{
|
|
|
|
error (0, 0, _("Cannot fstat file %s.\n"), file_name);
|
2000-04-11 16:27:38 +00:00
|
|
|
fclose (file);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that the file is large enough so that we can access the
|
|
|
|
information. We're only checking the size of the headers here. */
|
2002-08-25 04:51:08 +00:00
|
|
|
if ((size_t) statbuf.st_size < sizeof (struct exec)
|
|
|
|
|| (size_t) statbuf.st_size < sizeof (ElfW(Ehdr)))
|
2000-04-11 16:27:38 +00:00
|
|
|
{
|
2004-09-26 13:39:25 +00:00
|
|
|
if (statbuf.st_size == 0)
|
|
|
|
error (0, 0, _("File %s is empty, not checked."), file_name);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
char buf[SELFMAG];
|
|
|
|
size_t n = MIN (statbuf.st_size, SELFMAG);
|
|
|
|
if (fread (buf, n, 1, file) == 1 && memcmp (buf, ELFMAG, n) == 0)
|
|
|
|
error (0, 0, _("File %s is too small, not checked."), file_name);
|
|
|
|
}
|
2000-04-11 16:27:38 +00:00
|
|
|
fclose (file);
|
1999-12-04 08:00:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2000-04-11 16:27:38 +00:00
|
|
|
file_contents = mmap (0, statbuf.st_size, PROT_READ, MAP_SHARED,
|
|
|
|
fileno (file), 0);
|
1999-12-04 08:00:00 +00:00
|
|
|
if (file_contents == MAP_FAILED)
|
|
|
|
{
|
|
|
|
error (0, 0, _("Cannot mmap file %s.\n"), file_name);
|
|
|
|
fclose (file);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* First check if this is an aout file. */
|
|
|
|
aout_header = (struct exec *) file_contents;
|
|
|
|
if (N_MAGIC (*aout_header) == ZMAGIC
|
2002-09-05 18:52:18 +00:00
|
|
|
#ifdef QMAGIC /* Linuxism. */
|
|
|
|
|| N_MAGIC (*aout_header) == QMAGIC
|
|
|
|
#endif
|
|
|
|
)
|
1999-12-04 08:00:00 +00:00
|
|
|
{
|
2000-04-11 16:27:38 +00:00
|
|
|
/* Aout files don't have a soname, just return the name
|
2007-08-01 Andreas Jaeger <aj@suse.de>
Jakub Jelinek <jakub@redhat.com>
* elf/ldconfig.c (opt_ignore_aux_cache): Add new option.
(options): Add option.
(parse_opt): Handle option.
(manual_link): Adjust process_file caller. Call implicit_soname.
(search_dir): Formatting. Use and populate auxiliary cache.
(main): Load and save auxiliary cache.
* elf/readlib.c (process_file): Add stat_buf argument. Pass struct
stat64 from fstat64 to caller.
(implicit_soname): New function.
* elf/readelflib.c (process_elf_file): If DT_SONAME is not present,
leave *soname as NULL.
* elf/cache.c: Include libgen.h.
(print_entry, print_cache, compare, save_cache, add_to_cache):
Formatting and cleanups.
(aux_cache_entry_id, aux_cache_entry, aux_cache_file_entry,
aux_cache_file): New structures.
(AUX_CACHEMAGIC): Define.
(primes): New array.
(aux_hash_size, aux_hash): New variables.
(aux_cache_entry_id_hash, nextprime, init_aux_cache,
search_aux_cache, insert_to_aux_cache, add_to_aux_cache,
load_aux_cache, save_aux_cache): New functions.
* sysdeps/generic/ldconfig.h (_PATH_LDCONFIG_AUX_CACHE): Define.
(init_aux_cache, search_aux_cache, add_to_aux_cache,
load_aux_cache, save_aux_cache, implicit_soname): New prototypes.
(process_file): Adjust prototype.
2007-08-12 20:09:16 +00:00
|
|
|
including the major number. */
|
1999-12-04 08:00:00 +00:00
|
|
|
char *copy, *major, *dot;
|
|
|
|
copy = xstrdup (lib);
|
|
|
|
major = strstr (copy, ".so.");
|
|
|
|
if (major)
|
|
|
|
{
|
|
|
|
dot = strstr (major + 4, ".");
|
|
|
|
if (dot)
|
|
|
|
*dot = '\0';
|
|
|
|
}
|
|
|
|
*soname = copy;
|
|
|
|
*flag = FLAG_LIBC4;
|
|
|
|
goto done;
|
|
|
|
}
|
1999-12-09 01:39:16 +00:00
|
|
|
|
1999-12-04 08:00:00 +00:00
|
|
|
elf_header = (ElfW(Ehdr) *) file_contents;
|
Update.
2001-03-12 Jakub Jelinek <jakub@redhat.com>
* csu/Makefile (abi-tag.h): Define OS and version separately, allow
version to be overriden from config.h.
* csu/abi-note.S: Use OS and version separately, include config.h.
* elf/dl-load.c (_dl_osversion): New.
(_dl_map_object_from_fd): Kill some warnings.
(open_verify): Check .note.ABI-tag of the library if present.
* elf/Makefile (CPPFLAGS-dl-load.c): Add -I$(csu-objpfx).
* elf/cache.c (struct cache_entry): Add osversion.
(print_entry): Print osversion.
(print_cache): Pass osversion to it.
(compare): Sort according to osversion.
(save_cache): Set osversion.
(add_to_cache): Add osversion argument.
* sysdeps/generic/ldconfig.h (add_to_cache, process_file,
process_elf_file): Add osversion argument.
* elf/readlib.c (process_file): Likewise.
* sysdeps/generic/readelflib.c (process_elf_file): Likewise.
* sysdeps/unix/sysv/linux/ia64/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/i386/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* sysdeps/unix/sysv/linux/sparc/readelflib.c (process_elf_file,
process_elf32_file, process_elf64_file): Likewise.
* elf/ldconfig.c (manual_link): Pass it.
(search_dir): Issue diagnostic if two libs with the same soname in
the same directory have different .note.ABI-tag. Record osversion in
dlib_entry and use it from there.
(struct lib_entry): Remove.
(struct dlib_entry): Add osversion.
* sysdeps/generic/dl-cache.c (_dl_load_cache_lookup): Check
osversion.
* sysdeps/generic/dl-cache.h (struct file_entry_new): Replace __unused
field with osversion.
* sysdeps/generic/ldsodefs.h (_dl_osversion): Declare.
* sysdeps/unix/sysv/linux/init-first.c: Include ldsodefs.h.
* sysdeps/unix/sysv/linux/dl-osinfo.h (DL_SYSDEP_OSCHECK): Save kernel
version in _dl_osversion.
* sysdeps/unix/sysv/linux/configure.in: Define __ABI_TAG_VERSION.
* Makerules (build-shlib-helper, build-module-helper): New.
(build-shlib, build-module-helper): Make sure .note.ABI-tag comes
early.
* config.h.in (__ABI_TAG_VERSION): Add.
* elf/dl-minimal.c (__strtoul_internal): Set endptr on return.
* sysdeps/unix/sysv/linux/i386/dl-librecon.h (EXTRA_LD_ENVVARS):
Handle LD_ASSUME_KERNEL.
* sysdeps/unix/sysv/linux/dl-librecon.h: New.
2001-03-16 07:40:05 +00:00
|
|
|
if (memcmp (elf_header->e_ident, ELFMAG, SELFMAG) != 0)
|
1999-12-04 08:00:00 +00:00
|
|
|
{
|
2003-07-22 21:35:06 +00:00
|
|
|
/* The file is neither ELF nor aout. Check if it's a linker
|
|
|
|
script, like libc.so - otherwise complain. Only search the
|
|
|
|
beginning of the file. */
|
|
|
|
size_t len = MIN (statbuf.st_size, 512);
|
1999-12-04 08:00:00 +00:00
|
|
|
if (memmem (file_contents, len, "GROUP", 5) == NULL
|
2015-06-24 10:21:29 +00:00
|
|
|
&& memmem (file_contents, len, "GNU ld script", 13) == NULL
|
|
|
|
&& !is_gdb_python_file (file_name))
|
1999-12-04 08:00:00 +00:00
|
|
|
error (0, 0, _("%s is not an ELF file - it has the wrong magic bytes at the start.\n"),
|
|
|
|
file_name);
|
|
|
|
ret = 1;
|
|
|
|
}
|
2003-07-22 20:00:48 +00:00
|
|
|
/* Libraries have to be shared object files. */
|
|
|
|
else if (elf_header->e_type != ET_DYN)
|
|
|
|
ret = 1;
|
|
|
|
else if (process_elf_file (file_name, lib, flag, osversion, soname,
|
|
|
|
file_contents, statbuf.st_size))
|
1999-12-04 08:00:00 +00:00
|
|
|
ret = 1;
|
|
|
|
|
|
|
|
done:
|
|
|
|
/* Clean up allocated memory and resources. */
|
|
|
|
munmap (file_contents, statbuf.st_size);
|
|
|
|
fclose (file);
|
|
|
|
|
2007-08-01 Andreas Jaeger <aj@suse.de>
Jakub Jelinek <jakub@redhat.com>
* elf/ldconfig.c (opt_ignore_aux_cache): Add new option.
(options): Add option.
(parse_opt): Handle option.
(manual_link): Adjust process_file caller. Call implicit_soname.
(search_dir): Formatting. Use and populate auxiliary cache.
(main): Load and save auxiliary cache.
* elf/readlib.c (process_file): Add stat_buf argument. Pass struct
stat64 from fstat64 to caller.
(implicit_soname): New function.
* elf/readelflib.c (process_elf_file): If DT_SONAME is not present,
leave *soname as NULL.
* elf/cache.c: Include libgen.h.
(print_entry, print_cache, compare, save_cache, add_to_cache):
Formatting and cleanups.
(aux_cache_entry_id, aux_cache_entry, aux_cache_file_entry,
aux_cache_file): New structures.
(AUX_CACHEMAGIC): Define.
(primes): New array.
(aux_hash_size, aux_hash): New variables.
(aux_cache_entry_id_hash, nextprime, init_aux_cache,
search_aux_cache, insert_to_aux_cache, add_to_aux_cache,
load_aux_cache, save_aux_cache): New functions.
* sysdeps/generic/ldconfig.h (_PATH_LDCONFIG_AUX_CACHE): Define.
(init_aux_cache, search_aux_cache, add_to_aux_cache,
load_aux_cache, save_aux_cache, implicit_soname): New prototypes.
(process_file): Adjust prototype.
2007-08-12 20:09:16 +00:00
|
|
|
*stat_buf = statbuf;
|
1999-12-04 08:00:00 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-01 Andreas Jaeger <aj@suse.de>
Jakub Jelinek <jakub@redhat.com>
* elf/ldconfig.c (opt_ignore_aux_cache): Add new option.
(options): Add option.
(parse_opt): Handle option.
(manual_link): Adjust process_file caller. Call implicit_soname.
(search_dir): Formatting. Use and populate auxiliary cache.
(main): Load and save auxiliary cache.
* elf/readlib.c (process_file): Add stat_buf argument. Pass struct
stat64 from fstat64 to caller.
(implicit_soname): New function.
* elf/readelflib.c (process_elf_file): If DT_SONAME is not present,
leave *soname as NULL.
* elf/cache.c: Include libgen.h.
(print_entry, print_cache, compare, save_cache, add_to_cache):
Formatting and cleanups.
(aux_cache_entry_id, aux_cache_entry, aux_cache_file_entry,
aux_cache_file): New structures.
(AUX_CACHEMAGIC): Define.
(primes): New array.
(aux_hash_size, aux_hash): New variables.
(aux_cache_entry_id_hash, nextprime, init_aux_cache,
search_aux_cache, insert_to_aux_cache, add_to_aux_cache,
load_aux_cache, save_aux_cache): New functions.
* sysdeps/generic/ldconfig.h (_PATH_LDCONFIG_AUX_CACHE): Define.
(init_aux_cache, search_aux_cache, add_to_aux_cache,
load_aux_cache, save_aux_cache, implicit_soname): New prototypes.
(process_file): Adjust prototype.
2007-08-12 20:09:16 +00:00
|
|
|
/* Returns made up soname if lib doesn't have explicit DT_SONAME. */
|
|
|
|
|
|
|
|
char *
|
|
|
|
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.");
|
|
|
|
if (major)
|
|
|
|
{
|
|
|
|
char *dot = strstr (major + 4, ".");
|
|
|
|
if (dot)
|
|
|
|
*dot = '\0';
|
|
|
|
}
|
|
|
|
return soname;
|
|
|
|
}
|
|
|
|
|
1999-12-04 08:00:00 +00:00
|
|
|
/* Get architecture specific version of process_elf_file. */
|
2005-12-21 15:31:50 +00:00
|
|
|
#include <readelflib.c>
|