mirror of
https://sourceware.org/git/glibc.git
synced 2025-08-07 06:43:00 +03:00
Update.
* sysdeps/generic/dl-cache.c: Optimize SEARCH_CACHE and HWCAP_CHECK macro code. * elf/dl-misc.c (_dl_sysdep_read_whole_file): Optimize code a bit. Now returns MAP_FAILED on error. * elf/rtld.c: Adjust caller. * sysdeps/generic/dl-cache.c: Likewise. * sysdeps/generic/ldsodefs.h: Adjust description.
This commit is contained in:
@@ -1,5 +1,14 @@
|
|||||||
2001-11-07 Ulrich Drepper <drepper@redhat.com>
|
2001-11-07 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/generic/dl-cache.c: Optimize SEARCH_CACHE and
|
||||||
|
HWCAP_CHECK macro code.
|
||||||
|
|
||||||
|
* elf/dl-misc.c (_dl_sysdep_read_whole_file): Optimize code a bit.
|
||||||
|
Now returns MAP_FAILED on error.
|
||||||
|
* elf/rtld.c: Adjust caller.
|
||||||
|
* sysdeps/generic/dl-cache.c: Likewise.
|
||||||
|
* sysdeps/generic/ldsodefs.h: Adjust description.
|
||||||
|
|
||||||
* elf/dl-version.c (match_symbol): Optimize error handling for size.
|
* elf/dl-version.c (match_symbol): Optimize error handling for size.
|
||||||
(_dl_check_map_versions): Likewise.
|
(_dl_check_map_versions): Likewise.
|
||||||
|
|
||||||
|
@@ -44,25 +44,26 @@ _dl_sysdep_open_zero_fill (void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Read the whole contents of FILE into new mmap'd space with given
|
/* Read the whole contents of FILE into new mmap'd space with given
|
||||||
protections. *SIZEP gets the size of the file. */
|
protections. *SIZEP gets the size of the file. On error MAP_FAILED
|
||||||
|
is returned. */
|
||||||
|
|
||||||
void *
|
void *
|
||||||
internal_function
|
internal_function
|
||||||
_dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
|
_dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
|
||||||
{
|
{
|
||||||
void *result;
|
void *result = MAP_FAILED;
|
||||||
struct stat64 st;
|
struct stat64 st;
|
||||||
int fd = __open (file, O_RDONLY);
|
int fd = __open (file, O_RDONLY);
|
||||||
if (fd < 0)
|
if (fd >= 0)
|
||||||
return NULL;
|
|
||||||
if (__fxstat64 (_STAT_VER, fd, &st) < 0
|
|
||||||
/* No need to map the file if it is empty. */
|
|
||||||
|| st.st_size == 0)
|
|
||||||
result = NULL;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
if (__fxstat64 (_STAT_VER, fd, &st) >= 0)
|
||||||
|
{
|
||||||
|
*sizep = st.st_size;
|
||||||
|
|
||||||
|
/* No need to map the file if it is empty. */
|
||||||
|
if (*sizep != 0)
|
||||||
/* Map a copy of the file contents. */
|
/* Map a copy of the file contents. */
|
||||||
result = __mmap (0, st.st_size, prot,
|
result = __mmap (NULL, *sizep, prot,
|
||||||
#ifdef MAP_COPY
|
#ifdef MAP_COPY
|
||||||
MAP_COPY
|
MAP_COPY
|
||||||
#else
|
#else
|
||||||
@@ -72,12 +73,9 @@ _dl_sysdep_read_whole_file (const char *file, size_t *sizep, int prot)
|
|||||||
| MAP_FILE
|
| MAP_FILE
|
||||||
#endif
|
#endif
|
||||||
, fd, 0);
|
, fd, 0);
|
||||||
if (result == MAP_FAILED)
|
|
||||||
result = NULL;
|
|
||||||
else
|
|
||||||
*sizep = st.st_size;
|
|
||||||
}
|
}
|
||||||
__close (fd);
|
__close (fd);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -710,7 +710,7 @@ of this helper program; chances are you did not intend to run this program.\n\
|
|||||||
/* Read the contents of the file. */
|
/* Read the contents of the file. */
|
||||||
file = _dl_sysdep_read_whole_file ("/etc/ld.so.preload", &file_size,
|
file = _dl_sysdep_read_whole_file ("/etc/ld.so.preload", &file_size,
|
||||||
PROT_READ | PROT_WRITE);
|
PROT_READ | PROT_WRITE);
|
||||||
if (__builtin_expect (file != NULL, 0))
|
if (__builtin_expect (file != MAP_FAILED, 0))
|
||||||
{
|
{
|
||||||
/* Parse the file. It contains names of libraries to be loaded,
|
/* Parse the file. It contains names of libraries to be loaded,
|
||||||
separated by white spaces or `:'. It may also contain
|
separated by white spaces or `:'. It may also contain
|
||||||
|
@@ -53,77 +53,70 @@ do \
|
|||||||
{ \
|
{ \
|
||||||
left = 0; \
|
left = 0; \
|
||||||
right = cache->nlibs - 1; \
|
right = cache->nlibs - 1; \
|
||||||
middle = (left + right) / 2; \
|
|
||||||
cmpres = 1; \
|
|
||||||
\
|
\
|
||||||
while (left <= right) \
|
while (left <= right) \
|
||||||
{ \
|
{ \
|
||||||
|
__typeof__ (cache->libs[0].key) key; \
|
||||||
|
\
|
||||||
|
middle = (left + right) / 2; \
|
||||||
|
\
|
||||||
|
key = cache->libs[middle].key; \
|
||||||
|
\
|
||||||
/* Make sure string table indices are not bogus before using \
|
/* Make sure string table indices are not bogus before using \
|
||||||
them. */ \
|
them. */ \
|
||||||
if (! _dl_cache_verify_ptr (cache->libs[middle].key)) \
|
if (! _dl_cache_verify_ptr (key)) \
|
||||||
{ \
|
{ \
|
||||||
cmpres = 1; \
|
cmpres = 1; \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
/* Actually compare the entry with the key. */ \
|
/* Actually compare the entry with the key. */ \
|
||||||
cmpres = _dl_cache_libcmp (name, \
|
cmpres = _dl_cache_libcmp (name, cache_data + key); \
|
||||||
cache_data + cache->libs[middle].key); \
|
if (__builtin_expect (cmpres == 0, 0)) \
|
||||||
if (cmpres == 0) \
|
|
||||||
/* Found it. */ \
|
|
||||||
break; \
|
|
||||||
\
|
|
||||||
if (cmpres < 0) \
|
|
||||||
left = middle + 1; \
|
|
||||||
else \
|
|
||||||
right = middle - 1; \
|
|
||||||
\
|
|
||||||
middle = (left + right) / 2; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
if (cmpres == 0) \
|
|
||||||
{ \
|
{ \
|
||||||
/* LEFT now marks the last entry for which we know the name is \
|
/* Found it. LEFT now marks the last entry for which we \
|
||||||
correct. */ \
|
know the name is correct. */ \
|
||||||
left = middle; \
|
left = middle; \
|
||||||
\
|
\
|
||||||
/* There might be entries with this name before the one we \
|
/* There might be entries with this name before the one we \
|
||||||
found. So we have to find the beginning. */ \
|
found. So we have to find the beginning. */ \
|
||||||
while (middle > 0 \
|
while (middle > 0) \
|
||||||
|
{ \
|
||||||
|
__typeof__ (cache->libs[0].key) key; \
|
||||||
|
\
|
||||||
|
key = cache->libs[middle - 1].key; \
|
||||||
/* Make sure string table indices are not bogus before \
|
/* Make sure string table indices are not bogus before \
|
||||||
using them. */ \
|
using them. */ \
|
||||||
&& _dl_cache_verify_ptr (cache->libs[middle - 1].key) \
|
if (! _dl_cache_verify_ptr (key) \
|
||||||
/* Actually compare the entry. */ \
|
/* Actually compare the entry. */ \
|
||||||
&& (_dl_cache_libcmp (name, \
|
|| _dl_cache_libcmp (name, cache_data + key) != 0) \
|
||||||
cache_data \
|
break; \
|
||||||
+ cache->libs[middle - 1].key) \
|
|
||||||
== 0)) \
|
|
||||||
--middle; \
|
--middle; \
|
||||||
|
} \
|
||||||
\
|
\
|
||||||
do \
|
do \
|
||||||
{ \
|
{ \
|
||||||
int flags; \
|
int flags; \
|
||||||
|
__typeof__ (cache->libs[0]) *lib = &cache->libs[middle]; \
|
||||||
\
|
\
|
||||||
/* Only perform the name test if necessary. */ \
|
/* Only perform the name test if necessary. */ \
|
||||||
if (middle > left \
|
if (middle > left \
|
||||||
/* We haven't seen this string so far. Test whether the \
|
/* We haven't seen this string so far. Test whether the \
|
||||||
index is ok and whether the name matches. Otherwise \
|
index is ok and whether the name matches. Otherwise \
|
||||||
we are done. */ \
|
we are done. */ \
|
||||||
&& (! _dl_cache_verify_ptr (cache->libs[middle].key) \
|
&& (! _dl_cache_verify_ptr (lib->key) \
|
||||||
|| (_dl_cache_libcmp (name, \
|
|| (_dl_cache_libcmp (name, cache_data + lib->key) \
|
||||||
cache_data \
|
|
||||||
+ cache->libs[middle].key) \
|
|
||||||
!= 0))) \
|
!= 0))) \
|
||||||
break; \
|
break; \
|
||||||
\
|
\
|
||||||
flags = cache->libs[middle].flags; \
|
flags = lib->flags; \
|
||||||
if (_dl_cache_check_flags (flags) \
|
if (_dl_cache_check_flags (flags) \
|
||||||
&& _dl_cache_verify_ptr (cache->libs[middle].value)) \
|
&& _dl_cache_verify_ptr (lib->value)) \
|
||||||
{ \
|
{ \
|
||||||
if (best == NULL || flags == _dl_correct_cache_id) \
|
if (best == NULL || flags == _dl_correct_cache_id) \
|
||||||
{ \
|
{ \
|
||||||
HWCAP_CHECK; \
|
HWCAP_CHECK; \
|
||||||
best = cache_data + cache->libs[middle].value; \
|
best = cache_data + lib->value; \
|
||||||
\
|
\
|
||||||
if (flags == _dl_correct_cache_id) \
|
if (flags == _dl_correct_cache_id) \
|
||||||
/* We've found an exact match for the shared \
|
/* We've found an exact match for the shared \
|
||||||
@@ -134,6 +127,13 @@ do \
|
|||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
while (++middle <= right); \
|
while (++middle <= right); \
|
||||||
|
break; \
|
||||||
|
} \
|
||||||
|
\
|
||||||
|
if (cmpres < 0) \
|
||||||
|
left = middle + 1; \
|
||||||
|
else \
|
||||||
|
right = middle - 1; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
while (0)
|
while (0)
|
||||||
@@ -168,7 +168,7 @@ _dl_load_cache_lookup (const char *name)
|
|||||||
- the old format with the new format in it
|
- the old format with the new format in it
|
||||||
- only the new format
|
- only the new format
|
||||||
The following checks if the cache contains any of these formats. */
|
The following checks if the cache contains any of these formats. */
|
||||||
if (file != NULL && cachesize > sizeof *cache
|
if (file != MAP_FAILED && cachesize > sizeof *cache
|
||||||
&& memcmp (file, CACHEMAGIC, sizeof CACHEMAGIC - 1) == 0)
|
&& memcmp (file, CACHEMAGIC, sizeof CACHEMAGIC - 1) == 0)
|
||||||
{
|
{
|
||||||
size_t offset;
|
size_t offset;
|
||||||
@@ -185,7 +185,7 @@ _dl_load_cache_lookup (const char *name)
|
|||||||
sizeof CACHEMAGIC_VERSION_NEW - 1) != 0)
|
sizeof CACHEMAGIC_VERSION_NEW - 1) != 0)
|
||||||
cache_new = (void *) -1;
|
cache_new = (void *) -1;
|
||||||
}
|
}
|
||||||
else if (file != NULL && cachesize > sizeof *cache_new
|
else if (file != MAP_FAILED && cachesize > sizeof *cache_new
|
||||||
&& memcmp (file, CACHEMAGIC_VERSION_NEW,
|
&& memcmp (file, CACHEMAGIC_VERSION_NEW,
|
||||||
sizeof CACHEMAGIC_VERSION_NEW - 1) == 0)
|
sizeof CACHEMAGIC_VERSION_NEW - 1) == 0)
|
||||||
{
|
{
|
||||||
@@ -194,7 +194,7 @@ _dl_load_cache_lookup (const char *name)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (file != NULL)
|
if (file != MAP_FAILED)
|
||||||
__munmap (file, cachesize);
|
__munmap (file, cachesize);
|
||||||
cache = (void *) -1;
|
cache = (void *) -1;
|
||||||
}
|
}
|
||||||
@@ -231,12 +231,11 @@ _dl_load_cache_lookup (const char *name)
|
|||||||
if (_dl_osversion && cache_new->libs[middle].osversion > _dl_osversion) \
|
if (_dl_osversion && cache_new->libs[middle].osversion > _dl_osversion) \
|
||||||
continue; \
|
continue; \
|
||||||
if (_DL_PLATFORMS_COUNT && platform != -1 \
|
if (_DL_PLATFORMS_COUNT && platform != -1 \
|
||||||
&& (cache_new->libs[middle].hwcap & _DL_HWCAP_PLATFORM) != 0 \
|
&& (lib->hwcap & _DL_HWCAP_PLATFORM) != 0 \
|
||||||
&& (cache_new->libs[middle].hwcap & _DL_HWCAP_PLATFORM) != platform) \
|
&& (lib->hwcap & _DL_HWCAP_PLATFORM) != platform) \
|
||||||
continue; \
|
continue; \
|
||||||
if (hwcap \
|
if (hwcap \
|
||||||
&& ((cache_new->libs[middle].hwcap & *hwcap & ~_DL_HWCAP_PLATFORM) \
|
&& ((lib->hwcap & *hwcap & ~_DL_HWCAP_PLATFORM) > *hwcap)) \
|
||||||
> *hwcap)) \
|
|
||||||
continue
|
continue
|
||||||
SEARCH_CACHE (cache_new);
|
SEARCH_CACHE (cache_new);
|
||||||
}
|
}
|
||||||
|
@@ -495,8 +495,9 @@ extern const char *_dl_load_cache_lookup (const char *name)
|
|||||||
once needed. */
|
once needed. */
|
||||||
extern void _dl_unload_cache (void);
|
extern void _dl_unload_cache (void);
|
||||||
|
|
||||||
/* System-dependent function to read a file's whole contents
|
/* System-dependent function to read a file's whole contents in the
|
||||||
in the most convenient manner available. */
|
most convenient manner available. *SIZEP gets the size of the
|
||||||
|
file. On error MAP_FAILED is returned. */
|
||||||
extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
|
extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
|
||||||
int prot)
|
int prot)
|
||||||
internal_function;
|
internal_function;
|
||||||
|
Reference in New Issue
Block a user