diff mbox

[6/6] aarch64: Add hwcap string routines

Message ID d7bfcd29-af7f-f32d-32b8-b953c0aeffd9@sourceware.org
State New
Headers show

Commit Message

Siddhesh Poyarekar June 9, 2017, 8:56 a.m. UTC
On Friday 09 June 2017 01:54 PM, Szabolcs Nagy wrote:
> please fix the undefined behaviour you introduced.
> 
> and remove the comments with magic numbers so
> on hwcap update comments do not need changes.

Done, I've pushed the attached patch as per your and Andreas' comments.
Sorry I missed your comment about undefined behavior.

Siddhesh
diff mbox

Patch

From 6c85cc2852367ea2db91ff6a1fc0f6fc0653788d Mon Sep 17 00:00:00 2001
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
Date: Fri, 9 Jun 2017 14:18:11 +0530
Subject: [PATCH] aarch64: Fix undefined behavior in _dl_procinfo

1 << 31 is undefined, so replace it with a cleaner check.  Also remove
magic numbers in comments.

	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h: Remove
	mention of magic numbers in comments.
	(_dl_procinfo): Fix undefined behavior
---
 ChangeLog                                     | 6 ++++++
 sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h | 6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6c6ff13..006e7ac 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@ 
+2017-06-09  Siddhesh Poyarekar  <siddhesh@sourceware.org>
+
+	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h: Remove
+	mention of magic numbers in comments.
+	(_dl_procinfo): Fix undefined behavior
+
 2017-06-08  Joseph Myers  <joseph@codesourcery.com>
 
 	* conform/data/sys/wait.h-data (WIFCONTINUED): Do not expect for
diff --git a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
index cdb36d3..04fc6be 100644
--- a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
+++ b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
@@ -40,7 +40,7 @@  _dl_procinfo (unsigned int type, unsigned long int word)
   _dl_printf ("AT_HWCAP:   ");
 
   for (i = 0; i < 32; ++i)
-    if (word & (1 << i))
+    if ((word >> i) & 1)
       _dl_printf (" %s", GLRO(dl_aarch64_cap_flags)[i]);
 
   _dl_printf ("\n");
@@ -56,10 +56,10 @@  _dl_hwcap_string (int idx)
 };
 
 
-/* 13 HWCAP bits set.  */
+/* Number of HWCAP bits set.  */
 #define _DL_HWCAP_COUNT 13
 
-/* Low 13 bits are allocated in HWCAP.  */
+/* Offset of the last bit allocated in HWCAP.  */
 #define _DL_HWCAP_LAST 12
 
 /* HWCAP_CPUID should be available by default to influence IFUNC as well as
-- 
2.7.4