* include/link.h: Include sysd-link.h.
	* sysdeps/generic/sysd-link.h: New file.
	* sysdeps/unix/sysv/linux/sysd-link.h: New file.
	* elf/Makefile (distribute): Add sysd-link.h.
	* elf/dl-load.c: Use definitions from sysd-link.h instead of stat
	types and functions directly.
	* elf/dl-misc.c: Likewise.
	* elf/dl-profile.c: Likewise.

	* elf/loadfail.c (main): Close all successfully loaded objects.
This commit is contained in:
Ulrich Drepper 2000-08-15 08:06:15 +00:00
parent 07a3d63e52
commit fc7f617d30
9 changed files with 56 additions and 20 deletions

View File

@ -1,5 +1,16 @@
2000-08-15 Ulrich Drepper <drepper@redhat.com>
* include/link.h: Include sysd-link.h.
* sysdeps/generic/sysd-link.h: New file.
* sysdeps/unix/sysv/linux/sysd-link.h: New file.
* elf/Makefile (distribute): Add sysd-link.h.
* elf/dl-load.c: Use definitions from sysd-link.h instead of stat
types and functions directly.
* elf/dl-misc.c: Likewise.
* elf/dl-profile.c: Likewise.
* elf/loadfail.c (main): Close all successfully loaded objects.
* elf/multiload.c: Add mtrace call. Call dlclose for all handles and
free wd.
* elf/dl-deps.c (_dl_map_object_deps): Don't allocate needed list if

View File

@ -47,7 +47,8 @@ distribute := $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \
vismain.c vismod1.c vismod2.c vismod3.c \
constload2.c constload3.c filtmod1.c filtmod2.c \
nodlopenmod.c nodelete.c nodelmod1.c nodelmod2.c \
nodelmod3.c nodelmod4.c nodlopen.c
nodelmod3.c nodelmod4.c nodlopen.c \
sysd-link.h
include ../Makeconfig

View File

@ -730,10 +730,10 @@ _dl_map_object_from_fd (const char *name, int fd, char *realname,
int type;
char *readbuf;
ssize_t readlength;
struct stat st;
struct elf_stat st;
/* Get file information. */
if (__fxstat (_STAT_VER, fd, &st) < 0)
if (elf_fxstat (_STAT_VER, fd, &st) < 0)
LOSE (errno, N_("cannot stat shared object"));
/* Look again to see if the real name matched another already loaded. */
@ -1260,11 +1260,11 @@ open_path (const char *name, size_t namelen, int preloaded,
{
/* We failed to open machine dependent library. Let's
test whether there is any directory at all. */
struct stat st;
struct elf_stat st;
buf[buflen - namelen - 1] = '\0';
if (__xstat (_STAT_VER, buf, &st) != 0
if (elf_xstat (_STAT_VER, buf, &st) != 0
|| ! S_ISDIR (st.st_mode))
/* The directory does not exist or it is no directory. */
this_dir->status[cnt] = nonexisting;
@ -1281,9 +1281,9 @@ open_path (const char *name, size_t namelen, int preloaded,
/* This is an extra security effort to make sure nobody can
preload broken shared objects which are in the trusted
directories and so exploit the bugs. */
struct stat st;
struct elf_stat st;
if (__fxstat (_STAT_VER, fd, &st) != 0
if (elf_fxstat (_STAT_VER, fd, &st) != 0
|| (st.st_mode & S_ISUID) == 0)
{
/* The shared object cannot be tested for being SUID

View File

@ -1,5 +1,5 @@
/* Miscellaneous support functions for dynamic linker
Copyright (C) 1997, 1998, 1999 Free Software Foundation, Inc.
Copyright (C) 1997, 1998, 1999, 2000 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
@ -19,7 +19,7 @@
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <link.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
@ -45,11 +45,11 @@ void *
_dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
{
void *result;
struct stat st;
struct elf_stat st;
int fd = __open (file, O_RDONLY);
if (fd < 0)
return NULL;
if (__fxstat (_STAT_VER, fd, &st) < 0
if (elf_fxstat (_STAT_VER, fd, &st) < 0
/* No need to map the file if it is empty. */
|| st.st_size == 0)
result = NULL;

View File

@ -175,7 +175,7 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
{
char *filename;
int fd;
struct stat st;
struct elf_stat st;
const ElfW(Phdr) *ph;
ElfW(Addr) mapstart = ~((ElfW(Addr)) 0);
ElfW(Addr) mapend = 0;
@ -267,7 +267,7 @@ _dl_start_profile (struct link_map *map, const char *output_dir)
return;
}
if (fstat (fd, &st) < 0 || !S_ISREG (st.st_mode))
if (elf_fxstat (_STAT_VER, fd, &st) < 0 || !S_ISREG (st.st_mode))
{
/* Not stat'able or not a regular file => don't use it. */
char buf[400];

View File

@ -1,25 +1,36 @@
#include <dlfcn.h>
#include <error.h>
#include <mcheck.h>
#include <stdio.h>
#include <stdlib.h>
int
main (void)
{
void *su[5];
void *h;
int n;
if (dlopen ("testobj1.so", RTLD_GLOBAL | RTLD_NOW) == NULL
|| dlopen ("testobj1.so", RTLD_GLOBAL | RTLD_NOW) == NULL
|| dlopen ("testobj2.so", RTLD_GLOBAL | RTLD_NOW) == NULL
|| dlopen ("testobj3.so", RTLD_GLOBAL | RTLD_NOW) == NULL
|| dlopen ("testobj4.so", RTLD_GLOBAL | RTLD_NOW) == NULL
|| dlopen ("testobj5.so", RTLD_GLOBAL | RTLD_NOW) == NULL)
mtrace ();
if ((su[0] = dlopen ("testobj1.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
|| (su[1] = dlopen ("testobj2.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
|| (su[2] = dlopen ("testobj3.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
|| (su[3] = dlopen ("testobj4.so", RTLD_GLOBAL | RTLD_NOW)) == NULL
|| (su[4] = dlopen ("testobj5.so", RTLD_GLOBAL | RTLD_NOW)) == NULL)
error (EXIT_FAILURE, 0, "failed to load shared object: %s", dlerror ());
h = dlopen ("failobj.so", RTLD_GLOBAL | RTLD_NOW);
printf ("h = %p, %s\n", h, h == NULL ? "ok" : "fail");
for (n = 0; n < 5; ++n)
if (dlclose (su[n]) != 0)
{
printf ("failed to unload su[%d]: %s\n", n, dlerror ());
exit (EXIT_FAILURE);
}
return h != NULL;
}

View File

@ -34,6 +34,9 @@
#include <bits/elfclass.h> /* Defines __ELF_NATIVE_CLASS. */
/* Get some system specific definitions. */
#include <sysd-link.h>
/* Rendezvous structure used by the run-time dynamic linker to communicate
details of shared object loading to the debugger. If the executable's
dynamic section has a DT_DEBUG element, the run-time linker sets that
@ -202,7 +205,7 @@ struct link_map
/* This information is kept to check for sure whether a shared
object is the same as one already loaded. */
dev_t l_dev;
ino_t l_ino;
elf_ino_t l_ino;
/* Collected information about own RUNPATH directories. */
struct r_search_path_elem **l_runpath_dirs;

View File

@ -0,0 +1,5 @@
/* In general we don't have stat64 available. */
#define elf_stat stat
#define elf_fxstat __fxstat
#define elf_xstat __xstat
#define elf_ino_t ino_t

View File

@ -0,0 +1,5 @@
/* On Linux we have stat64 available. */
#define elf_stat stat64
#define elf_fxstat __fxstat64
#define elf_xstat __xstat64
#define elf_ino_t ino64_t