1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-28 00:21:52 +03:00

Avoid ELF lookup race.

On some architectures the update of the l_used field in the lookup
functions races with setting the other bits in the bitfield.  Simply
avoid this and optimize use of l_used in general.
This commit is contained in:
Ulrich Drepper
2009-12-15 12:32:27 -08:00
parent 2510d01ddb
commit 2af6396817
4 changed files with 23 additions and 8 deletions

View File

@ -1,3 +1,11 @@
2009-12-15 Ulrich Drepper <drepper@redhat.com>
* include/link.h (struct link_map): Move l_used into its own word.
* elf/dl-lookup.c (_dl_lookup_symbol_x): Only update l_used when it is
still zero.
* elf/dl-object.c (_dl_new_object): Set dl_used if we know it is
never really used.
2009-12-13 H.J. Lu <hongjiu.lu@intel.com>
* sysdeps/i386/i686/multiarch/strcspn.S Include <init-arch.h>

View File

@ -822,6 +822,7 @@ _dl_lookup_symbol_x (const char *undef_name, struct link_map *undef_map,
version, type_class, flags, skip_map);
/* The object is used. */
if (__builtin_expect (current_value.m->l_used == 0, 0))
current_value.m->l_used = 1;
if (__builtin_expect (GLRO(dl_debug_mask)

View File

@ -1,5 +1,5 @@
/* Storage management for the chain of loaded shared objects.
Copyright (C) 1995-2002,2004,2006,2007,2008 Free Software Foundation, Inc.
Copyright (C) 1995-2002,2004,2006-2008,2009 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
@ -67,6 +67,10 @@ _dl_new_object (char *realname, const char *libname, int type,
new->l_name = realname;
new->l_type = type;
/* If we set the bit now since we know it is never used we avoid
dirtying the cache line later. */
if ((GLRO(dl_debug_mask) & DL_DEBUG_UNUSED) == 0)
new->l_used = 1;
new->l_loader = loader;
#if NO_TLS_OFFSET != 0
new->l_tls_offset = NO_TLS_OFFSET;

View File

@ -1,6 +1,6 @@
/* Data structure for communication from the run-time dynamic linker for
loaded ELF shared objects.
Copyright (C) 1995-2006, 2007 Free Software Foundation, Inc.
Copyright (C) 1995-2006, 2007, 2009 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
@ -180,7 +180,6 @@ struct link_map
unsigned int l_need_tls_init:1; /* Nonzero if GL(dl_init_static_tls)
should be called on this link map
when relocation finishes. */
unsigned int l_used:1; /* Nonzero if the DSO is used. */
unsigned int l_auditing:1; /* Nonzero if the DSO is used in auditing. */
unsigned int l_audit_any_plt:1; /* Nonzero if at least one audit module
is interested in the PLT interception.*/
@ -239,12 +238,15 @@ struct link_map
struct link_map **l_initfini;
/* List of the dependencies introduced through symbol binding. */
unsigned int l_reldepsmax;
struct link_map_reldeps
{
unsigned int act;
struct link_map *list[];
} *l_reldeps;
unsigned int l_reldepsmax;
/* Nonzero if the DSO is used. */
unsigned int l_used;
/* Various flag words. */
ElfW(Word) l_feature_1;