Skip to content

Commit d2a7a24

Browse files
authored
Add __attribute__((retain)) to LLVM_DUMP_METHOD (#133025)
Without the retain attribute the dump functions will be stripped when LLVM is compiled with `-ffunction-section -Wl,--gc-sections` on ELF-based systems.
1 parent a942d7f commit d2a7a24

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

llvm/include/llvm/Support/Compiler.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,12 @@
230230
#define LLVM_ATTRIBUTE_USED
231231
#endif
232232

233+
#if __has_attribute(retain)
234+
#define LLVM_ATTRIBUTE_RETAIN __attribute__((__retain__))
235+
#else
236+
#define LLVM_ATTRIBUTE_RETAIN
237+
#endif
238+
233239
#if defined(__clang__)
234240
#define LLVM_DEPRECATED(MSG, FIX) __attribute__((deprecated(MSG, FIX)))
235241
#else
@@ -619,7 +625,8 @@ void AnnotateIgnoreWritesEnd(const char *file, int line);
619625
/// get stripped in release builds.
620626
// FIXME: Move this to a private config.h as it's not usable in public headers.
621627
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
622-
#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED
628+
#define LLVM_DUMP_METHOD \
629+
LLVM_ATTRIBUTE_NOINLINE LLVM_ATTRIBUTE_USED LLVM_ATTRIBUTE_RETAIN
623630
#else
624631
#define LLVM_DUMP_METHOD LLVM_ATTRIBUTE_NOINLINE
625632
#endif

0 commit comments

Comments
 (0)