This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

An optimization bug in egcs 1.0.2?


Hi,

While compiling glibc 2.0.7 with egcs 1.0.2, I noticed that egcs 1.0.2
turns

if (imap->l_global)
  {
   /* This object is in the global scope list.  Remove it.  */
   struct link_map **tail = _dl_global_scope_end;
   do
     --tail;
    while (*tail != imap);
    --_dl_global_scope_end;
    memcpy (tail, tail + 1,
      (void *) _dl_global_scope_end -  (void *) tail);
    _dl_global_scope_end[0] = NULL;
    _dl_global_scope_end[1] = NULL;
  }

into

if (imap->l_global)
  {
   /* This object is in the global scope list.  Remove it.  */
   struct link_map **tail = _dl_global_scope_end;
   do
     --tail;
    while (*tail != imap);
    --_dl_global_scope_end;
    _dl_global_scope_end[0] = NULL;
    _dl_global_scope_end[1] = NULL;
    memcpy (tail, tail + 1,
      (void *) _dl_global_scope_end -  (void *) tail);
    _dl_global_scope_end[1] = NULL;
  }

when I use -O2 -fPIC. As the result, the resuling binary doesn't work
since _dl_global_scope_end[0] is within (void *) tail + 1 and 
(void *) tail + 1 + (void *) _dl_global_scope_end -  (void *) tail.
Is that normal for a C compiler to do it?

BTW, I changed it to

if (imap->l_global)
  {
   /* This object is in the global scope list.  Remove it.  */
   struct link_map **tail = _dl_global_scope_end;
   do
     --tail;
    while (*tail != imap);
    memcpy (tail, tail + 1,
      (void *) _dl_global_scope_end -  (void *) tail);
    --_dl_global_scope_end;
  }

since _dl_global_scope_end [0] and _dl_global_scope_end [1] are
always NULL to begin with. It works fine for me.

Thanks.


-- 
H.J. Lu (hjl@gnu.org)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]