]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
alloc-util: Disallow inlining of expand_to_usable
authorSiddhesh Poyarekar <siddhesh@gotplt.org>
Sun, 8 Jan 2023 00:30:32 +0000 (19:30 -0500)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 8 Jan 2023 15:26:39 +0000 (16:26 +0100)
Explicitly set __attribute__ ((noinline)) so that the compiler does not
attempt to inline expand_to_usable, even with LTO.

src/basic/alloc-util.h
src/fundamental/macro-fundamental.h

index eb53aae6f3e1469f64b1dff234e0892651a5811f..bf783b15a22bf0e99d4a5a53f33f769e93385a85 100644 (file)
@@ -186,10 +186,11 @@ void* greedy_realloc0(void **p, size_t need, size_t size);
 #endif
 
 /* Dummy allocator to tell the compiler that the new size of p is newsize. The implementation returns the
- * pointer as is; the only reason for its existence is as a conduit for the _alloc_ attribute. This cannot be
- * a static inline because gcc then loses the attributes on the function.
+ * pointer as is; the only reason for its existence is as a conduit for the _alloc_ attribute.  This must not
+ * be inlined (hence a non-static function with _noinline_ because LTO otherwise tries to inline it) because
+ * gcc then loses the attributes on the function.
  * See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96503 */
-void *expand_to_usable(void *p, size_t newsize) _alloc_(2) _returns_nonnull_;
+void *expand_to_usable(void *p, size_t newsize) _alloc_(2) _returns_nonnull_ _noinline_;
 
 static inline size_t malloc_sizeof_safe(void **xp) {
         if (_unlikely_(!xp || !*xp))
index 9400c389ca9d18bb077a1ec3d3cdf6f0b95c2726..10ee46b9c1c2869196b57e2d3834bb2e671f239c 100644 (file)
@@ -20,6 +20,7 @@
 #define _hidden_ __attribute__((__visibility__("hidden")))
 #define _likely_(x) (__builtin_expect(!!(x), 1))
 #define _malloc_ __attribute__((__malloc__))
+#define _noinline_ __attribute__((noinline))
 #define _noreturn_ _Noreturn
 #define _packed_ __attribute__((__packed__))
 #define _printf_(a, b) __attribute__((__format__(printf, a, b)))