Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add __attribute__((retain)) to LLVM_DUMP_METHOD #133025

Merged
merged 2 commits into from
Mar 26, 2025

Conversation

MatzeB
Copy link
Contributor

@MatzeB MatzeB commented Mar 26, 2025

Without the retain attribute the dump functions will be stripped when
LLVM is compiled with -ffunction-section -Wl,--gc-sections on
ELF-based systems.

Without the retain attribute the dump functions will be stripped when
LLVM is compiled with `-ffunction-section -Wl,--gc-sections` on
ELF-based systems.
@MatzeB MatzeB requested a review from MaskRay March 26, 2025 01:19
@MatzeB
Copy link
Contributor Author

MatzeB commented Mar 26, 2025

Some of our internal builds use -ffunction-sections -Wl,--gc-sections and I just noticed that we need an additional __attribute__((retain)) to keep the LLVM dump functions around.

Is there any downside to using this attribute in LLVM?

@MatzeB MatzeB marked this pull request as ready for review March 26, 2025 01:20
@MatzeB MatzeB requested a review from smeenai March 26, 2025 01:20
@llvmbot
Copy link
Member

llvmbot commented Mar 26, 2025

@llvm/pr-subscribers-llvm-support

Author: Matthias Braun (MatzeB)

Changes

Without the retain attribute the dump functions will be stripped when
LLVM is compiled with -ffunction-section -Wl,--gc-sections on
ELF-based systems.


Full diff: https://github.com/llvm/llvm-project/pull/133025.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/Compiler.h (+3-1)
diff --git a/llvm/include/llvm/Support/Compiler.h b/llvm/include/llvm/Support/Compiler.h
index dc8b5389069eb..b6d06238f8d83 100644
--- a/llvm/include/llvm/Support/Compiler.h
+++ b/llvm/include/llvm/Support/Compiler.h
@@ -224,7 +224,9 @@
 #define LLVM_PREFETCH(addr, rw, locality)
 #endif
 
-#if __has_attribute(used)
+#if __has_attribute(used) && __has_attribute(retain)
+#define LLVM_ATTRIBUTE_USED __attribute__((__used__, __retain__))
+#elif __has_attribute(used)
 #define LLVM_ATTRIBUTE_USED __attribute__((__used__))
 #else
 #define LLVM_ATTRIBUTE_USED

@MaskRay
Copy link
Member

MaskRay commented Mar 26, 2025

Some of our internal builds use -ffunction-sections -Wl,--gc-sections and I just noticed that we need an additional __attribute__((retain)) to keep the LLVM dump functions around.

Is there any downside to using this attribute in LLVM?

Perhaps we should just add retained to LLVM_DUMP_METHOD?

This will enable USED functions to be garbage-collectable on ELF platforms, where this behavior has been consistently present.

@MatzeB
Copy link
Contributor Author

MatzeB commented Mar 26, 2025

Are you saying you rather have a separate macro for retain? Updated the PR to do that.

@MatzeB MatzeB force-pushed the dump_method_retain branch from 0121c39 to 584a2db Compare March 26, 2025 17:00
Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, the title needs an adjustment now.

@MatzeB MatzeB changed the title Add __attribute__((__retain__)) to LLVM_ATTRIBUTE_USED Add __attribute__((__retain__)) to LLVM_DUMP_METHOD Mar 26, 2025
@MatzeB MatzeB changed the title Add __attribute__((__retain__)) to LLVM_DUMP_METHOD Add __attribute__((retain)) to LLVM_DUMP_METHOD Mar 26, 2025
@MatzeB MatzeB merged commit d2a7a24 into llvm:main Mar 26, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants