NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/59062: jemalloc does not guarantee proper alignment
>Number: 59062
>Category: lib
>Synopsis: jemalloc does not guarantee proper alignment
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Feb 10 14:10:01 +0000 2025
>Originator: Martin Husemann
>Release: NetBSD 10.99.12
>Organization:
The NetBSD Foundation, Inc.
>Environment:
System: NetBSD seven-days-to-the-wolves.aprisoft.de 10.99.12 NetBSD 10.99.12 (GENERIC) #771: Thu Jan 30 09:04:03 CET 2025 martin%seven-days-to-the-wolves.aprisoft.de@localhost:/work/src/sys/arch/amd64/compile/GENERIC amd64
Architecture: x86_64
Machine: amd64
>Description:
It seems that jemalloc guarantees proper alignment for bigger allocations,
but for small ones it only provides 2^3 alignment - which might not be
good enough for some of our architectures.
See src/external/bsd/jemalloc/include/jemalloc/internal/size_classes.h
We ran into this with jemalloc 1.0 before and it is pretty clear that
it violates the C standard:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59958
https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_075.html
https://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_445.htm
We tried to catch this misconfiguration by a hack in gcc, which now is
ineffective and should be removed.
>How-To-Repeat:
Source code inspection
>Fix:
Noting that the relevant MALLOC_ABI_ALIGNMENT in our gcc configs
defaults to register size and only is overriden for arm we get a
simple #ifdef cascade.
The patch also removes the outdated local change in gcc.
Index: gpl3/gcc/dist/gcc/tree-ssa-ccp.cc
===================================================================
RCS file: /cvsroot/src/external/gpl3/gcc/dist/gcc/tree-ssa-ccp.cc,v
retrieving revision 1.4
diff -u -p -r1.4 tree-ssa-ccp.cc
--- gpl3/gcc/dist/gcc/tree-ssa-ccp.cc 1 Jul 2024 05:31:10 -0000 1.4
+++ gpl3/gcc/dist/gcc/tree-ssa-ccp.cc 7 Feb 2025 11:41:44 -0000
@@ -4643,45 +4643,3 @@ make_pass_post_ipa_warn (gcc::context *c
{
return new pass_post_ipa_warn (ctxt);
}
-
-#if defined(__NetBSD__) && defined(NETBSD_NATIVE)
-/*
- * This is a big, ugly, temporary hack:
- * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59958
- * To make sure we have configured all our targets correctly, mimic the
- * #ifdef cascade from src/lib/libc/stdlib/jemalloc.c here and compile
- * time assert that the value matches gcc's MALLOC_ABI_ALIGNMENT here.
- */
-
-#if defined(__hppa__)
-#define JEMALLOC_TINY_MIN_2POW 4
-#elif defined(__alpha__) || defined(__amd64__) || defined(__sparc64__) \
- || (defined(__arm__) && defined(__ARM_EABI__)) \
- || defined(__ia64__) || defined(__powerpc__) \
- || defined(__aarch64__) \
- || ((defined(__mips__) || defined(__riscv__)) && defined(_LP64))
-#define JEMALLOC_TINY_MIN_2POW 3
-#endif
-
-#ifndef JEMALLOC_TINY_MIN_2POW
-#define JEMALLOC_TINY_MIN_2POW 2
-#endif
-
-/* make sure we test the (native) 64bit variant for targets supporting -m32 */
-#undef TARGET_64BIT
-#ifdef _LP64
-#define TARGET_64BIT 1
-#else
-#define TARGET_64BIT 0
-#endif
-
-/* ARM has a non-constant MALLOC_ABI_ALIGNMENT since GCC 5. */
-#if !defined(__arm__)
-#ifdef __CTASSERT
-__CTASSERT((8<<JEMALLOC_TINY_MIN_2POW) == MALLOC_ABI_ALIGNMENT);
-#else
-#error compiling on an older NetBSD version?
-#endif
-#endif
-
-#endif
Index: bsd/jemalloc/include/jemalloc/internal/size_classes.h
===================================================================
RCS file: /cvsroot/src/external/bsd/jemalloc/include/jemalloc/internal/size_classes.h,v
retrieving revision 1.4
diff -u -p -r1.4 size_classes.h
--- bsd/jemalloc/include/jemalloc/internal/size_classes.h 28 Mar 2019 11:56:56 -0000 1.4
+++ bsd/jemalloc/include/jemalloc/internal/size_classes.h 7 Feb 2025 11:43:14 -0000
@@ -35,7 +35,16 @@
*/
#define LG_SIZE_CLASS_GROUP 2
+
+#ifdef __NetBSD__
+#if defined(_LP64) || defined(__arm__)
+#define LG_TINY_MIN 4
+#else
+#define LG_TINY_MIN 3
+#endif
+#else
#define LG_TINY_MIN 3
+#endif
#if (LG_SIZEOF_PTR == 2 && LG_TINY_MIN == 3 && LG_QUANTUM == 3 && LG_PAGE == 12)
#define SIZE_CLASSES \
Home |
Main Index |
Thread Index |
Old Index