Another GLIBC build error with GCC6

Message ID 55AFCCD9.3040805@cs.ucla.edu
State New, archived
Headers

Commit Message

Paul Eggert July 22, 2015, 5:03 p.m. UTC
  Steve Ellcey wrote:
> I can't seem to find it in my email, can you send it again?

One must read Andreas's messages carefully.  You could try the attached 
(untested) patch, which implements his suggestion.
  

Comments

Steve Ellcey July 22, 2015, 5:23 p.m. UTC | #1
On Wed, 2015-07-22 at 10:03 -0700, Paul Eggert wrote:
> Steve Ellcey wrote:
> > I can't seem to find it in my email, can you send it again?
> 
> One must read Andreas's messages carefully.  You could try the attached 
> (untested) patch, which implements his suggestion.

That seems to work fine for elf/dl-deps.c where we use DT_EXTRATAGIDX
with arguments of either DT_AUXILIARY or DT_FILTER but I see this
macro is also used in elf/get-dynamic-info.h, do we know what values
it may be given there because the macro isn't going to result in the
same results for all inputs.

Steve Ellcey
sellcey@imgtec.com
  
Paul Eggert July 22, 2015, 8:39 p.m. UTC | #2
Steve Ellcey wrote:
> the macro isn't going to result in the
> same results for all inputs.

Why not?  For which input would the patch change behavior?  I don't see how it 
could happen.  The same pattern already works for DT_VERSIONTAGIDX and for 
DT_VALTAGIDX, which suggests it shouldn't be a problem for DT_EXTRATAGIDX.
  
Steve Ellcey July 22, 2015, 9:08 p.m. UTC | #3
On Wed, 2015-07-22 at 13:39 -0700, Paul Eggert wrote:
> Steve Ellcey wrote:
> > the macro isn't going to result in the
> > same results for all inputs.
> 
> Why not?  For which input would the patch change behavior?  I don't see how it 
> could happen.  The same pattern already works for DT_VERSIONTAGIDX and for 
> DT_VALTAGIDX, which suggests it shouldn't be a problem for DT_EXTRATAGIDX.

It looks like it works for any value where the most significant bit is
set to 1.  Otherwise it gives a different value.  I don't know if we can
count on that bit always being set or not.

Steve Ellcey



#include <stdint.h>
#include <stdio.h>

typedef uint32_t Elf32_Word;
typedef	int32_t  Elf32_Sword;

#define DT_AUXILIARY    0x7ffffffd
#define DT_FILTER       0x7fffffff

#define DT_EXTRATAGIDX_OLD(tag)    ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1)
#define DT_EXTRATAGIDX_NEW(tag)    ((Elf32_Sword) (DT_FILTER - (tag)))

inputs[] = {DT_AUXILIARY, DT_FILTER, 0x70000000, 0x70001000, 0x7fffff00,
                0, 1, 99, 100000, -1, -99, -100000};
int main()
{
 int i;
 for (i = 0; i < sizeof(inputs)/sizeof(int); i++)
   printf("%d %d %d\n", inputs[i], DT_EXTRATAGIDX_OLD(inputs[i]), DT_EXTRATAGIDX
_NEW(inputs[i]));
}


% gcc x.c -o x
% ./x
2147483645 2 2
2147483647 0 0
1879048192 268435455 268435455
1879052288 268431359 268431359
2147483392 255 255
0 -1 2147483647
1 -2 2147483646
99 -100 2147483548
100000 -100001 2147383647
-1 0 -2147483648
-99 98 -2147483550
-100000 99999 -2147383649
  
Roland McGrath July 22, 2015, 9:29 p.m. UTC | #4
> It looks like it works for any value where the most significant bit is
> set to 1.  Otherwise it gives a different value.  I don't know if we can
> count on that bit always being set or not.

DT_EXTRATAGIDX will only ever be used with the values near DT_FILTER.  To
follow the other existing models, elf.h should define DT_EXTRARNGLO (same
value as DT_AUXILIARY) and DT_EXTRARNGHI (same value as DT_FILTER) and:
#define DT_EXTRATAGIDX(tag) (DT_EXTRARNGHI - (tag)) /* Reverse order! */

DT_VERSIONRNGLO and DT_VERSIONRNGHI are missing too, though
DT_VERSIONTAGIDX is already defined using the same value that
DT_VERSIONRNGHI should have.
  

Patch

From 6b661c83b411fe5b020c3523ca6cbd29fc63b2b7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 22 Jul 2015 10:00:28 -0700
Subject: [PATCH] Port DT_EXTRATAGIDX to GCC 6.

See Steve Ellcey's bug report in:
https://sourceware.org/ml/libc-alpha/2015-07/msg00690.html
* elf/elf.h (DT_EXTRATAGIDX): Simplify by rewriting it the
same way as DT_VERSIONTAGIDX.  Suggested by Andreas Schwab in:
https://sourceware.org/ml/libc-alpha/2015-07/msg00702.html
---
 ChangeLog | 9 +++++++++
 elf/elf.h | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 9f87cd9..988273c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@ 
+2015-07-22  Paul Eggert  <eggert@cs.ucla.edu>
+
+	Port DT_EXTRATAGIDX to GCC 6.
+	See Steve Ellcey's bug report in:
+	https://sourceware.org/ml/libc-alpha/2015-07/msg00690.html
+	* elf/elf.h (DT_EXTRATAGIDX): Simplify by rewriting it the
+	same way as DT_VERSIONTAGIDX.  Suggested by Andreas Schwab in:
+	https://sourceware.org/ml/libc-alpha/2015-07/msg00702.html
+
 2015-07-21  Paul Eggert  <eggert@cs.ucla.edu>
 
 	Port the 0x7efe...feff pattern to GCC 6.
diff --git a/elf/elf.h b/elf/elf.h
index fbadda4..1d7ccc0 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)	(DT_FILTER - (tag))	/* Reverse order! */
 #define DT_EXTRANUM	3
 
 /* Values of `d_un.d_val' in the DT_FLAGS entry.  */
-- 
2.1.0