Skip to content

Commit

Permalink
Clarify use of static inline functions in headers
Browse files Browse the repository at this point in the history
In C++ it generally does not make sense to use static inline functions in headers.
If a function is outlined, 'inline' indicates that the function should be
deduplicated at link time (via COMDAT) and we do not end up with multiple
copies.

However, for the per-CPU "static inline" helpers we need "static" to avoid
ODR violations due to different labels emitted for the prologue for each
copy of the function.

PiperOrigin-RevId: 702759097
Change-Id: Icc82faadf30aa937e50a791c35a1de2d63dd77f7
  • Loading branch information
melver authored and copybara-github committed Dec 4, 2024
1 parent f1a0d43 commit fcc9101
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tcmalloc/internal/optimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace tcmalloc_internal {
#define TCMALLOC_MUSTTAIL
#endif

static inline void* AssumeNotNull(void* p) {
inline void* AssumeNotNull(void* p) {
ASSUME(p != nullptr);
return p;
}
Expand Down
2 changes: 2 additions & 0 deletions tcmalloc/internal/percpu_tcmalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,8 @@ inline ABSL_ATTRIBUTE_ALWAYS_INLINE void PrefetchSlabMemory(uintptr_t ptr) {
}

#if TCMALLOC_INTERNAL_PERCPU_USE_RSEQ && defined(__x86_64__)
// Note: These helpers must be "static inline" to avoid ODR violations due to
// different labels emitted in TCMALLOC_RSEQ_PROLOGUE.
static inline ABSL_ATTRIBUTE_ALWAYS_INLINE bool TcmallocSlab_Internal_Push(
size_t size_class, void* item) {
uintptr_t scratch, current;
Expand Down

0 comments on commit fcc9101

Please sign in to comment.