1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

alloc-util: Disallow inlining of expand_to_usable

Explicitly set __attribute__ ((noinline)) so that the compiler does not
attempt to inline expand_to_usable, even with LTO.

(cherry picked from commit 4f79f545b3)
(cherry picked from commit e998c9d7c1)
(cherry picked from commit 4014688458)
This commit is contained in:
Siddhesh Poyarekar 2023-01-07 19:30:32 -05:00 committed by Luca Boccassi
parent 08cf315a04
commit 050a356d04
2 changed files with 5 additions and 3 deletions

View File

@ -171,10 +171,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))

View File

@ -10,6 +10,7 @@
#define _align_(x) __attribute__((__aligned__(x)))
#define _const_ __attribute__((__const__))
#define _noinline_ __attribute__((noinline))
#define _pure_ __attribute__((__pure__))
#define _section_(x) __attribute__((__section__(x)))
#define _packed_ __attribute__((__packed__))