From 2ba9f2eb978b27ddfa39cd769b73136d0ac4c4ae Mon Sep 17 00:00:00 2001 From: Zack Weinberg Date: Fri, 1 Jun 2018 12:53:59 -0400 Subject: Convert __builtin_expect to __glibc_(un)likely throughout elf/. 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. --- elf/dl-error-skeleton.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'elf/dl-error-skeleton.c') diff --git a/elf/dl-error-skeleton.c b/elf/dl-error-skeleton.c index d5f418ab18..ca80c790d2 100644 --- a/elf/dl-error-skeleton.c +++ b/elf/dl-error-skeleton.c @@ -131,8 +131,8 @@ void _dl_signal_cexception (int errcode, struct dl_exception *exception, const char *occasion) { - if (__builtin_expect (GLRO(dl_debug_mask) - & ~(DL_DEBUG_STATISTICS|DL_DEBUG_PRELINK), 0)) + if (__glibc_unlikely ((GLRO(dl_debug_mask) + & ~(DL_DEBUG_STATISTICS|DL_DEBUG_PRELINK)) != 0)) _dl_debug_printf ("%s: error: %s: %s (%s)\n", exception->objname, occasion, exception->errstring, receiver ? "continued" : "fatal"); @@ -152,8 +152,8 @@ void _dl_signal_cerror (int errcode, const char *objname, const char *occation, const char *errstring) { - if (__builtin_expect (GLRO(dl_debug_mask) - & ~(DL_DEBUG_STATISTICS|DL_DEBUG_PRELINK), 0)) + if (__glibc_unlikely ((GLRO(dl_debug_mask) + & ~(DL_DEBUG_STATISTICS|DL_DEBUG_PRELINK)) != 0)) _dl_debug_printf ("%s: error: %s: %s (%s)\n", objname, occation, errstring, receiver ? "continued" : "fatal"); @@ -191,7 +191,7 @@ _dl_catch_exception (struct dl_exception *exception, catch_hook = &c; /* Do not save the signal mask. */ - if (__builtin_expect (__sigsetjmp (c.env, 0), 0) == 0) + if (__glibc_likely (__sigsetjmp (c.env, 0) == 0)) { (*operate) (args); catch_hook = old; -- cgit v1.2.3-70-g09d2