Adjust DT_EXTRATAGIDX to avoid undefined shifts

Message ID 1438716772-2250-1-git-send-email-rth@twiddle.net
State Dropped
Headers

Commit Message

Richard Henderson Aug. 4, 2015, 7:32 p.m. UTC
  Building alphaev67-linux with gcc6 results in Werror:

In file included from ../include/elf.h:2:0,
                 from ../sysdeps/alpha/stackinfo.h:24,
                 from ../include/stackinfo.h:24,
                 from ../include/alloca.h:4,
                 from ../stdlib/stdlib.h:492,
                 from ../include/stdlib.h:10,
                 from ../include/atomic.h:48,
                 from dl-deps.c:19:
dl-deps.c: In function ‘_dl_map_object_deps’:
../elf/elf.h:804:64: error: result of ‘2147483645 << 1’ requires 33 bits to represent, but ‘int’ only has 32 bits [-Werror=shift-overflow=]
 #define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
                                                                ^
dl-deps.c:36:6: note: in expansion of macro ‘DT_EXTRATAGIDX’
    + DT_EXTRATAGIDX (DT_AUXILIARY))
      ^
dl-deps.c:229:45: note: in expansion of macro ‘AUXTAG’
       if (l->l_info[DT_NEEDED] || l->l_info[AUXTAG] || l->l_info[FILTERTAG])
                                             ^
---
I believe my previous round of testing was done with gcc 4.9.1,
which is why I'm a bit late with this report.  I haven't tested
with gcc5 to see if this is a problem with a released compiler,
or if the warning is restricted to the development tree.

Given that it affects an installed header, I don't even know if
we want to change anything for this release at this date.


r~


2015-08-04  Richard Henderson  <rth@redhat.com>

	* elf/elf.h (DT_EXTRATAGIDX): Reformulate to avoid undefined shift.
  

Comments

Richard Henderson Aug. 4, 2015, 8:30 p.m. UTC | #1
On 08/04/2015 12:32 PM, Richard Henderson wrote:
> Building alphaev67-linux with gcc6 results in Werror...

Ignore this, and follow up on the "Another GLIBC build error with GCC6" thread
that Steve Ellcey started, and I just (attempted to) reply to.


r~
  

Patch

diff --git a/elf/elf.h b/elf/elf.h
index fbadda4..daab08f 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_Sword)((Elf32_Word)(tag) * 2) / 2 + 1))
 #define DT_EXTRANUM	3
 
 /* Values of `d_un.d_val' in the DT_FLAGS entry.  */