This is the mail archive of the 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]

[PATCH] Adjust DT_EXTRATAGIDX to avoid undefined shifts

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â
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.


2015-08-04  Richard Henderson  <>

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

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.  */

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