-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add @_used and @_section attributes for global variables and top-level functions #65901
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
Conversation
6f5aa77
to
42dfc1f
Compare
include/swift/SIL/SILFunction.h
Outdated
|
||
/// Returns a SectionAttr if this function belongs to a declaration that | ||
/// has `@_section` attribute. | ||
SectionAttr *getSectionAttr() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to think about inlining behavior. What should happen if a function with a section attribute is inlined into a function without (or a different) section attribute? Should inlining be prevented in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. My sense is that we should mirror what __attribute__((section))
does in Clang: It does not prevent inlining or interact with it in any way. What the attribute does is that it makes sure that the standalone/top-level function is emitted into that section, but other functions are still free to inline the code from it (as long as we also emit the standalone function that is in the right section). If the user wants to prevent inlining, they can use another attribute for that, __attribute__((noinline))
/ @inline(never)
.
WDYT?
42dfc1f
to
edcf6b8
Compare
7d2e1e5
to
888f675
Compare
@swift-ci please test |
As @jckarter pointed out to me, it's needed to use different section names for different platforms / object file formats, but luckily this can already be done by conditionalizing the attribute:
|
Notes to self: I need to also update (1) UnderscoredAttributes.md, (2) the attribute list in SwiftSyntax. |
I don't see a new experimental feature for these attributes. Can you please gate them behind a new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Added. |
@swift-ci please test |
…l functions This adds: - @_used attribute that flags as a global variable or a top-level function as "do not dead-strip" via llvm.used, roughly the equivalent of __attribute__((used)) in C/C++. - @_section("...") attribute that places a global variable or a top-level function into a section with that name, roughly the equivalent of __attribute__((section("..."))) in C/C++.
8a08c37
to
a8e8c41
Compare
@swift-ci please test |
Finally😂 |
Add @_used and @_section attributes for global variables and top-level functions
This adds:
__attribute__((used))
in C/C++.__attribute__((section("...")))
in C/C++.