diff options
author | Zack Weinberg <zackw@panix.com> | 2018-06-01 12:53:59 -0400 |
---|---|---|
committer | Zack Weinberg <zackw@panix.com> | 2018-06-12 10:02:27 -0400 |
commit | 2ba9f2eb978b27ddfa39cd769b73136d0ac4c4ae (patch) | |
tree | fabc08af34d8fbe8227e072ade54be411c6a4123 /elf/rtld.c | |
parent | 329ea513b451ae8322aa7a24ed84da13992af2dd (diff) | |
download | glibc-zack/elf-builtin-expect-conversion.tar glibc-zack/elf-builtin-expect-conversion.tar.gz glibc-zack/elf-builtin-expect-conversion.tar.bz2 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/rtld.c')
-rw-r--r-- | elf/rtld.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/elf/rtld.c b/elf/rtld.c index 8c732adb68..98ba82d15c 100644 --- a/elf/rtld.c +++ b/elf/rtld.c @@ -1030,7 +1030,7 @@ of this helper program; chances are you did not intend to run this program.\n\ break; } - if (__builtin_expect (mode, normal) == verify) + if (__glibc_unlikely (mode == verify)) { const char *objname; const char *err_str = NULL; @@ -1060,7 +1060,7 @@ of this helper program; chances are you did not intend to run this program.\n\ /* Now the map for the main executable is available. */ main_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded; - if (__builtin_expect (mode, normal) == normal + if (__glibc_likely (mode == normal) && GL(dl_rtld_map).l_info[DT_SONAME] != NULL && main_map->l_info[DT_SONAME] != NULL && strcmp ((const char *) D_PTR (&GL(dl_rtld_map), l_info[DT_STRTAB]) @@ -1291,7 +1291,7 @@ of this helper program; chances are you did not intend to run this program.\n\ _dl_setup_hash (main_map); } - if (__builtin_expect (mode, normal) == verify) + if (__glibc_unlikely (mode == verify)) { /* We were called just to verify that this is a dynamic executable using us as the program interpreter. Exit with an @@ -1749,7 +1749,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", rtld_multiple_ref = true; GL(dl_rtld_map).l_prev = main_map->l_searchlist.r_list[i - 1]; - if (__builtin_expect (mode, normal) == normal) + if (__glibc_likely (mode == normal)) { GL(dl_rtld_map).l_next = (i + 1 < main_map->l_searchlist.r_nlist ? main_map->l_searchlist.r_list[i + 1] @@ -1803,7 +1803,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", earlier. */ security_init (); - if (__builtin_expect (mode, normal) != normal) + if (__glibc_unlikely (mode != normal)) { /* We were run just to list the shared libraries. It is important that we do this before real relocation, because the @@ -1905,7 +1905,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", (size_t) l->l_map_start); } - if (__builtin_expect (mode, trace) != trace) + if (__glibc_unlikely (mode != trace)) for (i = 1; i < (unsigned int) _dl_argc; ++i) { const ElfW(Sym) *ref = NULL; @@ -2034,8 +2034,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", } if (main_map->l_info[ADDRIDX (DT_GNU_LIBLIST)] - && ! __builtin_expect (GLRO(dl_profile) != NULL, 0) - && ! __builtin_expect (GLRO(dl_dynamic_weak), 0)) + && __glibc_likely (GLRO(dl_profile) == NULL && GLRO(dl_dynamic_weak) == 0)) { ElfW(Lib) *liblist, *liblistend; struct link_map **r_list, **r_listend, *l; @@ -2176,7 +2175,7 @@ ERROR: ld.so: object '%s' cannot be loaded as audit interface: %s; ignored.\n", implementation in ld.so. */ struct libname_list *lnp = l->l_libname->next; - while (__builtin_expect (lnp != NULL, 0)) + while (__glibc_unlikely (lnp != NULL)) { lnp->dont_free = 1; lnp = lnp->next; @@ -2630,7 +2629,7 @@ process_envvars (enum mode *modep) /* Extra security for SUID binaries. Remove all dangerous environment variables. */ - if (__builtin_expect (__libc_enable_secure, 0)) + if (__glibc_unlikely (__libc_enable_secure)) { static const char unsecure_envvars[] = #ifdef EXTRA_UNSECURE_ENVVARS |