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: [PATCH] _dl_exception_create_format: Support %x/%lx/%Zx


On Fri, Nov 23, 2018 at 2:53 AM Szabolcs Nagy <Szabolcs.Nagy@arm.com> wrote:
>
> On 22/11/18 17:38, H.J. Lu wrote:
> > Add support for %x, %lx and %Zx to _dl_exception_create_format and pad
> > to the full width with 0.
> >
> >       * elf/dl-exception.c (_dl_exception_create_format): Support
> >       %x, %lx and %Zx.
>
> why Z and not z?  the glibc man says
>
> " Z   A nonstandard synonym for z that predates the appearance of z.
>   Do not use in new code."

Like this?

-- 
H.J.
From d937bf4bf3b92897b1ff60406ca065e2968bcdbe Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 22 Nov 2018 09:02:40 -0800
Subject: [PATCH] _dl_exception_create_format: Support %x/%lx/%zx

Add support for %x, %lx and %zx to _dl_exception_create_format and pad
to the full width with 0.

	* elf/dl-exception.c (_dl_exception_create_format): Support
	%x, %lx and %zx.
---
 elf/dl-exception.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/elf/dl-exception.c b/elf/dl-exception.c
index 1c63e4a3a6..1e41d89a7d 100644
--- a/elf/dl-exception.c
+++ b/elf/dl-exception.c
@@ -111,6 +111,20 @@ _dl_exception_create_format (struct dl_exception *exception, const char *objname
             case 's':
               length += strlen (va_arg (ap, const char *));
               break;
+	      /* Recognize the l modifier.  It is only important on some
+		 platforms where long and int have a different size.  We
+		 can use the same code for size_t.  */
+	    case 'l':
+	    case 'z':
+	      if (p[1] == 'x')
+		{
+		  length += LONG_WIDTH / 4;
+		  ++p;
+		  break;
+		}
+	    case 'x':
+	      length += INT_WIDTH / 4;
+	      break;
             default:
               /* Assumed to be '%'.  */
               ++length;
@@ -167,6 +181,32 @@ _dl_exception_create_format (struct dl_exception *exception, const char *objname
               *wptr = '%';
               ++wptr;
               break;
+	    case 'x':
+	      {
+		unsigned long int num = va_arg (ap, unsigned int);
+		char *start = wptr;
+		wptr += INT_WIDTH / 4;
+		char *cp = _itoa (num, wptr, 16, 0);
+		/* Pad to the full width with 0.  */
+		while (cp != start)
+		  *--cp = '0';
+	      }
+	      break;
+	    case 'l':
+	    case 'z':
+	      if (p[1] == 'x')
+		{
+		  unsigned long int num = va_arg (ap, unsigned long int);
+		  char *start = wptr;
+		  wptr += LONG_WIDTH / 4;
+		  char *cp = _itoa (num, wptr, 16, 0);
+		  /* Pad to the full width with 0.  */
+		  while (cp != start)
+		    *--cp = '0';
+		  ++p;
+		  break;
+		}
+	       /* FALLTHROUGH */
             default:
               _dl_fatal_printf ("Fatal error:"
                                 " invalid format in exception string\n");
-- 
2.19.1


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