about summary refs log tree commit diff
path: root/elf/dl-version.c
diff options
context:
space:
mode:
authorZack Weinberg <zackw@panix.com>2018-06-01 12:53:59 -0400
committerZack Weinberg <zackw@panix.com>2018-06-12 10:02:27 -0400
commit2ba9f2eb978b27ddfa39cd769b73136d0ac4c4ae (patch)
treefabc08af34d8fbe8227e072ade54be411c6a4123 /elf/dl-version.c
parent329ea513b451ae8322aa7a24ed84da13992af2dd (diff)
downloadglibc-zack/elf-builtin-expect-conversion.tar.gz
glibc-zack/elf-builtin-expect-conversion.tar.xz
glibc-zack/elf-builtin-expect-conversion.zip
Convert __builtin_expect to __glibc_(un)likely throughout elf/. zack/elf-builtin-expect-conversion
In the previous patch I didn't change a use of __builtin_expect to
__glibc_(un)likely that happened to be right next to the code I was
actually working on; Andreas asked why not, and I said that there were
a bunch more uses of __builtin_expect in that file and I would convert
them all in a separate patch.  This is that patch, converting all of
elf/.

I would appreciate someone checking over this patch very carefully
indeed.  In a whole bunch of places, __builtin_expect was used in a
way that did not map mechanically to the newer convention.  The test
suite caught one mistake; I'm not confident I didn't make any more.

Writing this patch gave me a deeper appreciation for why we _want_ to
switch to __glibc_(un)likely, but also for how difficult it can be.  I
now think that people should _not_ be asked to change existing uses of
__builtin_expect in a patch whose purpose is something else.

	* elf/dl-addr.c, elf/dl-cache.c, elf/dl-close.c, elf/dl-deps.c
	* elf/dl-environ.c, elf/dl-error-skeleton.c, elf/dl-fini.c
	* elf/dl-fptr.c, elf/dl-init.c, elf/dl-libc.c, elf/dl-minimal.c
	* elf/dl-open.c, elf/dl-reloc.c, elf/dl-runtime.c
	* elf/dl-sysdep.c, elf/dl-tls.c, elf/dl-version.c, elf/ldconfig.c
	* elf/rtld.c: Replace __builtin_expect with __glibc_likely or
	__glibc_unlikely, as appropriate, throughout.
Diffstat (limited to 'elf/dl-version.c')
-rw-r--r--elf/dl-version.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/elf/dl-version.c b/elf/dl-version.c
index 7860cc817e..a08af6c746 100644
--- a/elf/dl-version.c
+++ b/elf/dl-version.c
@@ -92,7 +92,7 @@ checking for version `%s' in file %s [%lu] required by file %s [%lu]\n",
     {
       /* Currently the version number of the definition entry is 1.
 	 Make sure all we see is this version.  */
-      if (__builtin_expect (def->vd_version, 1) != 1)
+      if (__glibc_unlikely (def->vd_version != 1))
 	{
 	  char buf[20];
 	  buf[sizeof (buf) - 1] = '\0';
@@ -111,8 +111,7 @@ checking for version `%s' in file %s [%lu] required by file %s [%lu]\n",
 	  ElfW(Verdaux) *aux = (ElfW(Verdaux) *) ((char *) def + def->vd_aux);
 
 	  /* To be safe, compare the string as well.  */
-	  if (__builtin_expect (strcmp (string, strtab + aux->vda_name), 0)
-	      == 0)
+	  if (__glibc_likely (strcmp (string, strtab + aux->vda_name) == 0))
 	    /* Bingo!  */
 	    return 0;
 	}
@@ -182,7 +181,7 @@ _dl_check_map_versions (struct link_map *map, int verbose, int trace_mode)
 
       /* Currently the version number of the needed entry is 1.
 	 Make sure all we see is this version.  */
-      if (__builtin_expect (ent->vn_version, 1) != 1)
+      if (__glibc_unlikely (ent->vn_version != 1))
 	{
 	  char buf[20];
 	  buf[sizeof (buf) - 1] = '\0';
@@ -206,8 +205,8 @@ _dl_check_map_versions (struct link_map *map, int verbose, int trace_mode)
 
 	  /* Make sure this is no stub we created because of a missing
 	     dependency.  */
-	  if (__builtin_expect (! trace_mode, 1)
-	      || ! __builtin_expect (needed->l_faked, 0))
+	  if (__glibc_likely (! trace_mode)
+	      || __glibc_likely (! needed->l_faked))
 	    {
 	      /* NEEDED is the map for the file we need.  Now look for the
 		 dependency symbols.  */