This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Another GLIBC build error with GCC6


On Tue, 2015-07-21 at 09:31 -0700, Steve Ellcey wrote:
> I just ran into this problem when compiling string/strchr in ILP32 mode
> on MIPS:

To be complete, I ran into 4 problems while building glibc with the
latest top-of-tree GCC.

strchrnul.c has the same problems as strchr.c.  The definition of
DT_EXTRATAGIDX in elf/elf.h also gives a shift overflow warning and
elf/dl-dl-deps.c now gives an array out-of-bounds message.  Here is a
not fully tested, not ready patch that allowed me to do a complete
build.  I think this new definition of DT_EXTRATAGIDX would give the
same result as the old definition.  I couldn't see anything to do with
dl-deps.c except ignore the warning, maybe someone else has a better
idea.

Steve Ellcey
sellcey@imgtec.com


diff --git a/elf/dl-deps.c b/elf/dl-deps.c
index eee146a..d4c5c00 100644
--- a/elf/dl-deps.c
+++ b/elf/dl-deps.c
@@ -30,6 +30,8 @@
 
 #include <dl-dst.h>
 
+#include <libc-internal.h>
+
 /* Whether an shared object references one or more auxiliary objects
    is signaled by the AUXTAG entry in l_info.  */
 #define AUXTAG	(DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
@@ -226,7 +228,11 @@ _dl_map_object_deps (struct link_map *map,
 	  needed = needed_space;
 	}
 
+      /* Blah, blah. */
+      DIAG_PUSH_NEEDS_COMMENT;
+      DIAG_IGNORE_NEEDS_COMMENT (4.6, "-Warray-bounds");
       if (l->l_info[DT_NEEDED] || l->l_info[AUXTAG] || l->l_info[FILTERTAG])
+      DIAG_POP_NEEDS_COMMENT;
 	{
 	  const char *strtab = (const void *) D_PTR (l, l_info[DT_STRTAB]);
 	  struct openaux_args args;
diff --git a/elf/elf.h b/elf/elf.h
index fbadda4..bc33122 100644
--- a/elf/elf.h
+++ b/elf/elf.h
@@ -801,7 +801,7 @@ typedef struct
    range.  Be compatible.  */
 #define DT_AUXILIARY    0x7ffffffd      /* Shared object to load before self */
 #define DT_FILTER       0x7fffffff      /* Shared object to get values from */
-#define DT_EXTRATAGIDX(tag)	((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
+#define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) & 0x7fffffff)-1)
 #define DT_EXTRANUM	3
 
 /* Values of `d_un.d_val' in the DT_FLAGS entry.  */
diff --git a/string/strchr.c b/string/strchr.c
index 5f90075..a6abee0 100644
--- a/string/strchr.c
+++ b/string/strchr.c
@@ -60,22 +60,19 @@ strchr (const char *s, int c_in)
 
      The 1-bits make sure that carries propagate to the next 0-bit.
      The 0-bits provide holes for carries to fall into.  */
-  switch (sizeof (longword))
-    {
-    case 4: magic_bits = 0x7efefeffL; break;
-    case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
-    default:
-      abort ();
-    }
 
-  /* Set up a longword, each of whose bytes is C.  */
+#if __WORDSIZE == 32
+  magic_bits = 0x7efefeffL;
   charmask = c | (c << 8);
   charmask |= charmask << 16;
-  if (sizeof (longword) > 4)
-    /* Do the shift in two steps to avoid a warning if long has 32 bits.  */
-    charmask |= (charmask << 16) << 16;
-  if (sizeof (longword) > 8)
-    abort ();
+#elif __WORDSIZE == 64
+  magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL;
+  charmask = c | (c << 8);
+  charmask |= charmask << 16;
+  charmask |= (charmask << 16) << 16;
+#else
+  #error unexpected integer size strchr()
+#endif
 
   /* Instead of the traditional loop which tests each character,
      we will test a longword at a time.  The tricky part is testing
diff --git a/string/strchrnul.c b/string/strchrnul.c
index 2678f1d..849a990 100644
--- a/string/strchrnul.c
+++ b/string/strchrnul.c
@@ -66,22 +66,19 @@ STRCHRNUL (s, c_in)
 
      The 1-bits make sure that carries propagate to the next 0-bit.
      The 0-bits provide holes for carries to fall into.  */
-  switch (sizeof (longword))
-    {
-    case 4: magic_bits = 0x7efefeffL; break;
-    case 8: magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL; break;
-    default:
-      abort ();
-    }
 
-  /* Set up a longword, each of whose bytes is C.  */
+#if __WORDSIZE == 32
+  magic_bits = 0x7efefeffL;
   charmask = c | (c << 8);
   charmask |= charmask << 16;
-  if (sizeof (longword) > 4)
-    /* Do the shift in two steps to avoid a warning if long has 32 bits.  */
-    charmask |= (charmask << 16) << 16;
-  if (sizeof (longword) > 8)
-    abort ();
+#elif __WORDSIZE == 64
+  magic_bits = ((0x7efefefeL << 16) << 16) | 0xfefefeffL;
+  charmask = c | (c << 8);
+  charmask |= charmask << 16;
+  charmask |= (charmask << 16) << 16;
+#else
+  #error unexpected integer size strchr()
+#endif
 
   /* Instead of the traditional loop which tests each character,
      we will test a longword at a time.  The tricky part is testing



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