aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2024-12-23 05:11:58 +0800
committerH.J. Lu <hjl.tools@gmail.com>2024-12-23 06:28:55 +0800
commita2b0ff98a0d44259cc5f6bd7d3a3676ae9f8996a (patch)
tree7816983cdeea6e6c32dd005c76da785811ea3047
parent3fb895ac88e99201573352b1abc18db4340ecede (diff)
downloadglibc-a2b0ff98a0d44259cc5f6bd7d3a3676ae9f8996a.tar.xz
glibc-a2b0ff98a0d44259cc5f6bd7d3a3676ae9f8996a.zip
include/sys/cdefs.h: Add __attribute_optimization_barrier__
Add __attribute_optimization_barrier__ to disable inlining and cloning on a function. For Clang, expand it to __attribute__ ((optnone)) Otherwise, expand it to __attribute__ ((noinline, clone)) Co-Authored-By: H.J. Lu <hjl.tools@gmail.com> Reviewed-by: Sam James <sam@gentoo.org>
-rw-r--r--benchtests/bench-hash-funcs-kernel.h4
-rw-r--r--benchtests/bench-hash-funcs.c2
-rw-r--r--benchtests/bench-strchr.c4
-rw-r--r--debug/tst-backtrace.h2
-rw-r--r--debug/tst-ssp-1.c2
-rw-r--r--elf/tst-p_alignmod-base.c2
-rw-r--r--gmon/tst-gmon.c8
-rw-r--r--gmon/tst-mcount-overflow.c10
-rw-r--r--include/sys/cdefs.h7
-rw-r--r--malloc/tst-malloc-thread-exit.c2
-rw-r--r--malloc/tst-malloc-thread-fail.c2
-rw-r--r--malloc/tst-mallocstate.c2
-rw-r--r--misc/tst-syscalls.c14
-rw-r--r--nptl/tst-minstack-throw.cc8
-rw-r--r--nptl/tst-thread-exit-clobber.cc12
-rw-r--r--nptl/tst-thread_local1.cc12
-rw-r--r--stdlib/tst-makecontext-align.c20
-rw-r--r--stdlib/tst-quick_exit.cc2
-rw-r--r--stdlib/tst-setcontext10.c6
-rw-r--r--stdlib/tst-setcontext11.c2
-rw-r--r--stdlib/tst-setcontext5.c4
-rw-r--r--stdlib/tst-setcontext8.c2
-rw-r--r--stdlib/tst-setcontext9.c2
-rw-r--r--stdlib/tst-swapcontext1.c8
-rw-r--r--stdlib/tst-swapcontext2.c8
-rw-r--r--stdlib/tst-thread-quick_exit.cc2
-rw-r--r--string/tst-xbzero-opt.c2
-rw-r--r--sysdeps/generic/tst-stack-align.h2
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/tst-cet-property-2.c2
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/tst-cet-setcontext-1.c2
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/tst-cet-vfork-1.c2
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/tst-gnu2-tls2-amx.c2
-rw-r--r--sysdeps/x86/tst-ldbl-nonnormal-printf.c2
-rw-r--r--sysdeps/x86/tst-memchr-rtm.c4
-rw-r--r--sysdeps/x86/tst-memcmp-rtm.c4
-rw-r--r--sysdeps/x86/tst-memmove-rtm.c4
-rw-r--r--sysdeps/x86/tst-memrchr-rtm.c4
-rw-r--r--sysdeps/x86/tst-memset-rtm.c4
-rw-r--r--sysdeps/x86/tst-strchr-rtm.c4
-rw-r--r--sysdeps/x86/tst-strcmp-rtm.c4
-rw-r--r--sysdeps/x86/tst-strcpy-rtm.c4
-rw-r--r--sysdeps/x86/tst-strlen-rtm.c4
-rw-r--r--sysdeps/x86/tst-strncmp-rtm.c8
-rw-r--r--sysdeps/x86/tst-strrchr-rtm.c4
-rw-r--r--sysdeps/x86_64/tst-rsi-strlen.c2
45 files changed, 112 insertions, 101 deletions
diff --git a/benchtests/bench-hash-funcs-kernel.h b/benchtests/bench-hash-funcs-kernel.h
index 7eaa3665b6..3e58fde084 100644
--- a/benchtests/bench-hash-funcs-kernel.h
+++ b/benchtests/bench-hash-funcs-kernel.h
@@ -35,7 +35,7 @@
#define PRIMITIVE_CAT(x, y) x ## y
#define CAT(x, y) PRIMITIVE_CAT (x, y)
-static double __attribute__ ((noinline, noclone))
+static double __attribute_optimization_barrier__
CAT (do_one_test_kernel, POSTFIX) (const char *s, size_t len)
{
@@ -58,7 +58,7 @@ CAT (do_one_test_kernel, POSTFIX) (const char *s, size_t len)
return (double) cur / (double) NFIXED_ITERS;
}
-static double __attribute__ ((noinline, noclone))
+static double __attribute_optimization_barrier__
CAT (do_rand_test_kernel, POSTFIX) (char const *bufs,
unsigned int const *sizes)
{
diff --git a/benchtests/bench-hash-funcs.c b/benchtests/bench-hash-funcs.c
index 8dd88c9e39..3d15029278 100644
--- a/benchtests/bench-hash-funcs.c
+++ b/benchtests/bench-hash-funcs.c
@@ -67,7 +67,7 @@ do_one_test (json_ctx_t *json_ctx, size_t len)
json_element_object_end (json_ctx);
}
-static void __attribute__ ((noinline, noclone))
+static void __attribute_optimization_barrier__
do_rand_test (json_ctx_t *json_ctx)
{
size_t i, sz, offset;
diff --git a/benchtests/bench-strchr.c b/benchtests/bench-strchr.c
index eed6882085..fed3b9b223 100644
--- a/benchtests/bench-strchr.c
+++ b/benchtests/bench-strchr.c
@@ -92,7 +92,7 @@ IMPL (generic_strchrnul, 0)
branch coming we want to test the case where a potential branch in
strchr can be used to skip a later mispredict because of the
relationship between the two branches. */
-static void __attribute__ ((noinline, noclone))
+static void __attribute_optimization_barrier__
do_one_rand_plus_branch_test (json_ctx_t *json_ctx, impl_t *impl,
const CHAR *s, const CHAR *c)
{
@@ -117,7 +117,7 @@ do_one_rand_plus_branch_test (json_ctx_t *json_ctx, impl_t *impl,
json_element_double (json_ctx, (double)cur / (double)iters);
}
-static void __attribute__ ((noinline, noclone))
+static void __attribute_optimization_barrier__
do_one_rand_test (json_ctx_t *json_ctx, impl_t *impl, const CHAR *s,
const CHAR *c)
{
diff --git a/debug/tst-backtrace.h b/debug/tst-backtrace.h
index 53239dad59..0ed38b6892 100644
--- a/debug/tst-backtrace.h
+++ b/debug/tst-backtrace.h
@@ -33,7 +33,7 @@ volatile int x;
/* Use this attribute to prevent inlining, so that all expected frames
are present. */
-#define NO_INLINE __attribute__ ((noinline, noclone, weak))
+#define NO_INLINE __attribute__ ((weak)) __attribute_optimization_barrier__
/* Look for a match in SYM from backtrace_symbols to NAME, a fragment
of a function name. Ignore the filename before '(', but presume
diff --git a/debug/tst-ssp-1.c b/debug/tst-ssp-1.c
index a1e4fb0630..2c8861ae59 100644
--- a/debug/tst-ssp-1.c
+++ b/debug/tst-ssp-1.c
@@ -21,7 +21,7 @@
#include <signal.h>
static void
-__attribute__ ((noinline, noclone))
+__attribute_optimization_barrier__
test (char *foo)
{
int i;
diff --git a/elf/tst-p_alignmod-base.c b/elf/tst-p_alignmod-base.c
index d6930b9f16..23b20f12db 100644
--- a/elf/tst-p_alignmod-base.c
+++ b/elf/tst-p_alignmod-base.c
@@ -26,7 +26,7 @@
int foo __attribute__ ((aligned (ALIGN))) = 1;
bool
-__attribute__ ((weak, noclone, noinline))
+__attribute__ ((weak)) __attribute_optimization_barrier__
is_aligned_p (void *p, int align)
{
return (((uintptr_t) p) & (align - 1)) == 0;
diff --git a/gmon/tst-gmon.c b/gmon/tst-gmon.c
index 9de4e7f85f..eca8246a5c 100644
--- a/gmon/tst-gmon.c
+++ b/gmon/tst-gmon.c
@@ -16,15 +16,17 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <sys/cdefs.h>
+
/* This program does not use the test harness because we want tight
control over the call graph. */
-__attribute__ ((noinline, noclone, weak)) void
+__attribute__ ((weak)) __attribute_optimization_barrier__ void
f1 (void)
{
}
-__attribute__ ((noinline, noclone, weak)) void
+__attribute__ ((weak)) __attribute_optimization_barrier__ void
f2 (void)
{
f1 ();
@@ -32,7 +34,7 @@ f2 (void)
asm volatile ("");
}
-__attribute__ ((noinline, noclone, weak)) void
+__attribute__ ((weak)) __attribute_optimization_barrier__ void
f3 (int count)
{
for (int i = 0; i < count; ++i)
diff --git a/gmon/tst-mcount-overflow.c b/gmon/tst-mcount-overflow.c
index 0e60f7e2e6..a681872bf7 100644
--- a/gmon/tst-mcount-overflow.c
+++ b/gmon/tst-mcount-overflow.c
@@ -16,6 +16,8 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
+#include <sys/cdefs.h>
+
/* Program with sufficiently complex, yet pointless, call graph
that it will trigger an mcount overflow, when you set the
minarcs/maxarcs tunables to very low values. */
@@ -31,12 +33,12 @@
/* Defines 16 leaf functions named f1_0 to f1_15 */
#define REP(n) \
- __attribute__ ((noinline, noclone, weak)) void f1_##n (void) {};
+ __attribute__ ((weak)) __attribute_optimization_barrier__ void f1_##n (void) {};
REPS
#undef REP
/* Calls all 16 leaf functions f1_* in succession */
-__attribute__ ((noinline, noclone, weak)) void
+__attribute__ ((weak)) __attribute_optimization_barrier__ void
f2 (void)
{
# define REP(n) f1_##n();
@@ -47,12 +49,12 @@ f2 (void)
/* Defines 16 functions named f2_0 to f2_15, which all just call f2 */
#define REP(n) \
- __attribute__ ((noinline, noclone, weak)) void \
+ __attribute__ ((weak)) __attribute_optimization_barrier__ void \
f2_##n (void) { f2(); PREVENT_TAIL_CALL; };
REPS
#undef REP
-__attribute__ ((noinline, noclone, weak)) void
+__attribute__ ((weak)) __attribute_optimization_barrier__ void
f3 (int count)
{
for (int i = 0; i < count; ++i)
diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h
index b84ad34a70..a676f75f62 100644
--- a/include/sys/cdefs.h
+++ b/include/sys/cdefs.h
@@ -56,4 +56,11 @@ rtld_hidden_proto (__chk_fail)
#endif /* !defined _ISOMAC */
+/* Prevents a function from being considered for inlining and cloning. */
+#ifdef __clang__
+# define __attribute_optimization_barrier__ __attribute__ ((optnone))
+#else
+# define __attribute_optimization_barrier__ __attribute__ ((noinline, noclone))
+#endif
+
#endif
diff --git a/malloc/tst-malloc-thread-exit.c b/malloc/tst-malloc-thread-exit.c
index aec3897087..269abcea8c 100644
--- a/malloc/tst-malloc-thread-exit.c
+++ b/malloc/tst-malloc-thread-exit.c
@@ -42,7 +42,7 @@ static int inner_thread_count = 4;
static size_t malloc_size = 32;
static void
-__attribute__ ((noinline, noclone))
+__attribute_optimization_barrier__
unoptimized_free (void *ptr)
{
free (ptr);
diff --git a/malloc/tst-malloc-thread-fail.c b/malloc/tst-malloc-thread-fail.c
index f698871876..56553dd299 100644
--- a/malloc/tst-malloc-thread-fail.c
+++ b/malloc/tst-malloc-thread-fail.c
@@ -33,7 +33,7 @@
/* Wrapper for calloc with an optimization barrier. */
static void *
-__attribute__ ((noinline, noclone))
+__attribute_optimization_barrier__
allocate_zeroed (size_t a, size_t b)
{
return calloc (a, b);
diff --git a/malloc/tst-mallocstate.c b/malloc/tst-mallocstate.c
index f72e1a1b28..3664fcda01 100644
--- a/malloc/tst-mallocstate.c
+++ b/malloc/tst-mallocstate.c
@@ -366,7 +366,7 @@ full_heap_check (void)
}
/* Used as an optimization barrier to force a heap allocation. */
-__attribute__ ((noinline, noclone))
+__attribute_optimization_barrier__
static void
my_free (void *ptr)
{
diff --git a/misc/tst-syscalls.c b/misc/tst-syscalls.c
index d060b125c9..ac1e1014e1 100644
--- a/misc/tst-syscalls.c
+++ b/misc/tst-syscalls.c
@@ -37,7 +37,7 @@ struct Array
static int error_count;
-__attribute__ ((noclone, noinline))
+__attribute_optimization_barrier__
struct Array
allocate (size_t bytes)
{
@@ -52,7 +52,7 @@ allocate (size_t bytes)
return __extension__ (struct Array) {bytes, p};
}
-__attribute__ ((noclone, noinline))
+__attribute_optimization_barrier__
void
deallocate (struct Array b)
{
@@ -66,7 +66,7 @@ deallocate (struct Array b)
}
}
-__attribute__ ((noclone, noinline))
+__attribute_optimization_barrier__
void *
do_mmap (void *addr, size_t length)
{
@@ -74,7 +74,7 @@ do_mmap (void *addr, size_t length)
MAP_PRIVATE | MAP_ANON, -1, 0);
}
-__attribute__ ((noclone, noinline))
+__attribute_optimization_barrier__
void *
reallocate (struct Array b)
{
@@ -86,7 +86,7 @@ reallocate (struct Array b)
return NULL;
}
-__attribute__ ((noclone, noinline))
+__attribute_optimization_barrier__
void
protect (struct Array b)
{
@@ -104,7 +104,7 @@ protect (struct Array b)
}
}
-__attribute__ ((noclone, noinline))
+__attribute_optimization_barrier__
ssize_t
do_read (int fd, void *ptr, struct Array b)
{
@@ -116,7 +116,7 @@ do_read (int fd, void *ptr, struct Array b)
return 0;
}
-__attribute__ ((noclone, noinline))
+__attribute_optimization_barrier__
ssize_t
do_write (int fd, void *ptr, struct Array b)
{
diff --git a/nptl/tst-minstack-throw.cc b/nptl/tst-minstack-throw.cc
index b729091ec4..ff0d3d39da 100644
--- a/nptl/tst-minstack-throw.cc
+++ b/nptl/tst-minstack-throw.cc
@@ -24,7 +24,7 @@
#include <support/xthread.h>
/* Throw a std::runtime_exception. */
-__attribute__ ((noinline, noclone, weak))
+__attribute__ ((weak)) __attribute_optimization_barrier__
void
do_throw_exception ()
{
@@ -38,17 +38,17 @@ struct class_with_destructor
~class_with_destructor ();
};
-__attribute__ ((noinline, noclone, weak))
+__attribute__ ((weak)) __attribute_optimization_barrier__
class_with_destructor::class_with_destructor ()
{
}
-__attribute__ ((noinline, noclone, weak))
+__attribute__ ((weak)) __attribute_optimization_barrier__
class_with_destructor::~class_with_destructor ()
{
}
-__attribute__ ((noinline, noclone, weak))
+__attribute__ ((weak)) __attribute_optimization_barrier__
void
function_with_destructed_object ()
{
diff --git a/nptl/tst-thread-exit-clobber.cc b/nptl/tst-thread-exit-clobber.cc
index b3b6989268..9a50848ef8 100644
--- a/nptl/tst-thread-exit-clobber.cc
+++ b/nptl/tst-thread-exit-clobber.cc
@@ -73,7 +73,7 @@ enum { no_check = -1 };
/* Check that VALUE is the magic value for INDEX, behind a compiler
barrier. */
-__attribute__ ((noinline, noclone, weak))
+__attribute__ ((weak)) __attribute_optimization_barrier__
void
check_magic (int index, unsigned int value)
{
@@ -103,7 +103,7 @@ check_magic (int index, unsigned int value)
/* Check that VALUE is the magic value for INDEX, behind a compiler
barrier. Double variant. */
-__attribute__ ((noinline, noclone, weak))
+__attribute__ ((weak)) __attribute_optimization_barrier__
void
check_magic (int index, double value)
{
@@ -