mailing list of musl libc
 help / color / mirror / code / Atom feed
* Am I using PRIxPTR wrong?  Musl-libc complains, glibc doesn't
@ 2014-01-14 20:36 David Wuertele
  2014-01-14 20:59 ` Rich Felker
  2014-01-14 21:06 ` Szabolcs Nagy
  0 siblings, 2 replies; 7+ messages in thread
From: David Wuertele @ 2014-01-14 20:36 UTC (permalink / raw)
  To: musl

/* test.c - demo difference between glibc and musl-libc wrt PRIxPTR
**
** Both native (x86_64 glibc) and target (arm musl-libc) define
** PRIxPTR as "lx", but uintptr_t as unsigned int:
**
**   $ gcc -E test.c | grep uintptr_t
**   typedef unsigned long int uintptr_t;
**     printf ("main is at 0x%""l" "x""\n", (uintptr_t) main);
**
**   $ arm-linux-musleabishf-gcc -E test.c | grep uintptr_t
**   typedef unsigned int uintptr_t;
**     printf ("main is at 0x%""lx""\n", (uintptr_t) main);
**
** While native gcc doesn't complain, target gcc does:
** 
**   $ gcc -c test.c -Wformat
**
**   $ arm-linux-musleabishf-gcc -c test.c -Wformat
**   test.c: In function ‘main’:
**   test.c:6:3: warning: format ‘%lx’ expects argument of type
** ‘long unsigned int’, but argument 2 has type ‘unsigned int’ [-Wformat]
*/

#include <stdio.h>
#include <inttypes.h>
int
main (int ac, char *av[])
{
  printf ("main is at 0x%"PRIxPTR"\n", (uintptr_t) main);
  return 0;
}




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Am I using PRIxPTR wrong?  Musl-libc complains, glibc doesn't
  2014-01-14 20:36 Am I using PRIxPTR wrong? Musl-libc complains, glibc doesn't David Wuertele
@ 2014-01-14 20:59 ` Rich Felker
  2014-01-14 21:06 ` Szabolcs Nagy
  1 sibling, 0 replies; 7+ messages in thread
From: Rich Felker @ 2014-01-14 20:59 UTC (permalink / raw)
  To: musl

On Tue, Jan 14, 2014 at 08:36:36PM +0000, David Wuertele wrote:
> /* test.c - demo difference between glibc and musl-libc wrt PRIxPTR
> **
> ** Both native (x86_64 glibc) and target (arm musl-libc) define
> ** PRIxPTR as "lx", but uintptr_t as unsigned int:
> **
> **   $ gcc -E test.c | grep uintptr_t
> **   typedef unsigned long int uintptr_t;
> **     printf ("main is at 0x%""l" "x""\n", (uintptr_t) main);
> **
> **   $ arm-linux-musleabishf-gcc -E test.c | grep uintptr_t
> **   typedef unsigned int uintptr_t;
> **     printf ("main is at 0x%""lx""\n", (uintptr_t) main);
> **
> ** While native gcc doesn't complain, target gcc does:
> ** 
> **   $ gcc -c test.c -Wformat
> **
> **   $ arm-linux-musleabishf-gcc -c test.c -Wformat
> **   test.c: In function ‘main’:
> **   test.c:6:3: warning: format ‘%lx’ expects argument of type
> ** ‘long unsigned int’, but argument 2 has type ‘unsigned int’ [-Wformat]
> */
> 
> #include <stdio.h>
> #include <inttypes.h>
> int
> main (int ac, char *av[])
> {
>   printf ("main is at 0x%"PRIxPTR"\n", (uintptr_t) main);
>   return 0;
> }
> 

I suspect your compiler was miscompiled for a non-EABI ARM
configuration; perhaps putting "shf" on the end of the maching tuple
string messed it up. I can't find the exact logic for UINTPTR_TYPE,
but my copy of gcc-4.7.3/gcc/config/arm/arm.h contains:

#define SIZE_TYPE (TARGET_AAPCS_BASED ? "unsigned int" : "long unsigned int")

suggesting that for AAPCS-based (EABI) targets, the correct type for
pointer-sized integer types is int, whereas on legacy targets, a long
type was used.

Note that if your compiler was miscompiled for non-EABI, many other
things will be wrong, like alignment/padding of 64-bit arguments, etc.

Rich


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Am I using PRIxPTR wrong?  Musl-libc complains, glibc doesn't
  2014-01-14 20:36 Am I using PRIxPTR wrong? Musl-libc complains, glibc doesn't David Wuertele
  2014-01-14 20:59 ` Rich Felker
@ 2014-01-14 21:06 ` Szabolcs Nagy
  2014-01-14 21:20   ` Rich Felker
  2014-01-14 21:34   ` David Wuertele
  1 sibling, 2 replies; 7+ messages in thread
From: Szabolcs Nagy @ 2014-01-14 21:06 UTC (permalink / raw)
  To: musl

* David Wuertele <dave+gmane@wuertele.com> [2014-01-14 20:36:36 +0000]:
> ** Both native (x86_64 glibc) and target (arm musl-libc) define
> ** PRIxPTR as "lx", but uintptr_t as unsigned int:

musl defines it to "x" on 32bit archs

please check

 arm-linux-musleabishf-gcc -E -dD inttypes.h

in particular UINTPTR_MAX should be set to UINT32_MAX
and __PRIPTR to ""


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Am I using PRIxPTR wrong?  Musl-libc complains, glibc doesn't
  2014-01-14 21:06 ` Szabolcs Nagy
@ 2014-01-14 21:20   ` Rich Felker
  2014-01-14 21:37     ` David Wuertele
  2014-01-14 21:34   ` David Wuertele
  1 sibling, 1 reply; 7+ messages in thread
From: Rich Felker @ 2014-01-14 21:20 UTC (permalink / raw)
  To: musl

On Tue, Jan 14, 2014 at 10:06:01PM +0100, Szabolcs Nagy wrote:
> * David Wuertele <dave+gmane@wuertele.com> [2014-01-14 20:36:36 +0000]:
> > ** Both native (x86_64 glibc) and target (arm musl-libc) define
> > ** PRIxPTR as "lx", but uintptr_t as unsigned int:
> 
> musl defines it to "x" on 32bit archs
> 
> please check
> 
>  arm-linux-musleabishf-gcc -E -dD inttypes.h
> 
> in particular UINTPTR_MAX should be set to UINT32_MAX
> and __PRIPTR to ""

Maybe I misread; it looks like David's problem is finding "lx" in the
header while the actual type is "unsigned int". Perhaps this is due to
using an older version of musl where the "lx" was there incorrectly?

Rich


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Am I using PRIxPTR wrong?  Musl-libc complains, glibc doesn't
  2014-01-14 21:06 ` Szabolcs Nagy
  2014-01-14 21:20   ` Rich Felker
@ 2014-01-14 21:34   ` David Wuertele
  1 sibling, 0 replies; 7+ messages in thread
From: David Wuertele @ 2014-01-14 21:34 UTC (permalink / raw)
  To: musl

Szabolcs Nagy <nsz <at> port70.net> writes:
> * David Wuertele <dave+gmane <at> wuertele.com> [2014-01-14 20:36:36 +0000]:
> > ** Both native (x86_64 glibc) and target (arm musl-libc) define
> > ** PRIxPTR as "lx", but uintptr_t as unsigned int:
> 
> musl defines it to "x" on 32bit archs
> 
> please check
> 
>  arm-linux-musleabishf-gcc -E -dD inttypes.h
> 
> in particular UINTPTR_MAX should be set to UINT32_MAX
> and __PRIPTR to ""
> 
> 

Here's what it says.  I don't see __PRIPTR in there.

$ PATH=PATH:../bin arm-linux-musleabishf-gcc -E -dD inttypes.h | grep UINTPTR_MAX
#define __UINTPTR_MAX__ 4294967295U
#define UINTPTR_MAX UINT32_MAX
$ PATH=PATH:../bin arm-linux-musleabishf-gcc -E -dD inttypes.h | grep __PRIPTR
$ PATH=PATH:../bin arm-linux-musleabishf-gcc -E -dD inttypes.h | grep __PRI
#define __PRI64 "ll"
#define PRId64 __PRI64 "d"
#define PRIdLEAST64 __PRI64 "d"
#define PRIdFAST64 __PRI64 "d"
#define PRIi64 __PRI64 "i"
#define PRIiLEAST64 __PRI64 "i"
#define PRIiFAST64 __PRI64 "i"
#define PRIo64 __PRI64 "o"
#define PRIoLEAST64 __PRI64 "o"
#define PRIoFAST64 __PRI64 "o"
#define PRIu64 __PRI64 "u"
#define PRIuLEAST64 __PRI64 "u"
#define PRIuFAST64 __PRI64 "u"
#define PRIx64 __PRI64 "x"
#define PRIxLEAST64 __PRI64 "x"
#define PRIxFAST64 __PRI64 "x"
#define PRIX64 __PRI64 "X"
#define PRIXLEAST64 __PRI64 "X"
#define PRIXFAST64 __PRI64 "X"
#define PRIdMAX __PRI64 "d"
#define PRIiMAX __PRI64 "i"
#define PRIoMAX __PRI64 "o"
#define PRIuMAX __PRI64 "u"
#define PRIxMAX __PRI64 "x"
#define PRIXMAX __PRI64 "X"
#define SCNd64 __PRI64 "d"
#define SCNdLEAST64 __PRI64 "d"
#define SCNdFAST64 __PRI64 "d"
#define SCNi64 __PRI64 "i"
#define SCNiLEAST64 __PRI64 "i"
#define SCNiFAST64 __PRI64 "i"
#define SCNu64 __PRI64 "u"
#define SCNuLEAST64 __PRI64 "u"
#define SCNuFAST64 __PRI64 "u"
#define SCNo64 __PRI64 "o"
#define SCNoLEAST64 __PRI64 "o"
#define SCNoFAST64 __PRI64 "o"
#define SCNx64 __PRI64 "x"
#define SCNxLEAST64 __PRI64 "x"
#define SCNxFAST64 __PRI64 "x"
#define SCNdMAX __PRI64 "d"
#define SCNiMAX __PRI64 "i"
#define SCNoMAX __PRI64 "o"
#define SCNuMAX __PRI64 "u"
#define SCNxMAX __PRI64 "x"
$ 




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Am I using PRIxPTR wrong?  Musl-libc complains, glibc doesn't
  2014-01-14 21:20   ` Rich Felker
@ 2014-01-14 21:37     ` David Wuertele
  2014-01-14 21:45       ` Rich Felker
  0 siblings, 1 reply; 7+ messages in thread
From: David Wuertele @ 2014-01-14 21:37 UTC (permalink / raw)
  To: musl

Rich Felker <dalias <at> aerifal.cx> writes:
> On Tue, Jan 14, 2014 at 10:06:01PM +0100, Szabolcs Nagy wrote:
> > * David Wuertele <dave+gmane <at> wuertele.com> [2014-01-14 20:36:36 +0000]:
> > > ** Both native (x86_64 glibc) and target (arm musl-libc) define
> > > ** PRIxPTR as "lx", but uintptr_t as unsigned int:
> > 
> > musl defines it to "x" on 32bit archs
> 
> Maybe I misread; it looks like David's problem is finding "lx" in the
> header while the actual type is "unsigned int". Perhaps this is due to
> using an older version of musl where the "lx" was there incorrectly?

I'm using musl-0.9.14, I see that 9.15 just came out this month.
Did 0.9.14 have the problem?

Dave




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Re: Am I using PRIxPTR wrong?  Musl-libc complains, glibc doesn't
  2014-01-14 21:37     ` David Wuertele
@ 2014-01-14 21:45       ` Rich Felker
  0 siblings, 0 replies; 7+ messages in thread
From: Rich Felker @ 2014-01-14 21:45 UTC (permalink / raw)
  To: musl

On Tue, Jan 14, 2014 at 09:37:28PM +0000, David Wuertele wrote:
> Rich Felker <dalias <at> aerifal.cx> writes:
> > On Tue, Jan 14, 2014 at 10:06:01PM +0100, Szabolcs Nagy wrote:
> > > * David Wuertele <dave+gmane <at> wuertele.com> [2014-01-14 20:36:36 +0000]:
> > > > ** Both native (x86_64 glibc) and target (arm musl-libc) define
> > > > ** PRIxPTR as "lx", but uintptr_t as unsigned int:
> > > 
> > > musl defines it to "x" on 32bit archs
> > 
> > Maybe I misread; it looks like David's problem is finding "lx" in the
> > header while the actual type is "unsigned int". Perhaps this is due to
> > using an older version of musl where the "lx" was there incorrectly?
> 
> I'm using musl-0.9.14, I see that 9.15 just came out this month.
> Did 0.9.14 have the problem?

I know a problem like this was fixed sometime not too long ago, and it
was probably between the 0.9.14 and 0.9.15 releases.

Rich


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-01-14 21:45 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-14 20:36 Am I using PRIxPTR wrong? Musl-libc complains, glibc doesn't David Wuertele
2014-01-14 20:59 ` Rich Felker
2014-01-14 21:06 ` Szabolcs Nagy
2014-01-14 21:20   ` Rich Felker
2014-01-14 21:37     ` David Wuertele
2014-01-14 21:45       ` Rich Felker
2014-01-14 21:34   ` David Wuertele

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).