You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The experimental @_section attribute relocates a variable into a specific section, with some constraints. Notably, the current implementation requires that the expression be applied to global functions and variables. This is not the case in other languages such as C or C++, where it can be applied to a number of constructs that are guaranteed to only have a single definition. It would be nice if Swift could also support this where appropriate.
Proposed solution
Allow @_section in more places. For example, this should be well-formed:
There is only going to be one of these in the entire program, so this should be technically feasible. And by allowing this it means that bar doesn't have to be a global but can be scoped as appropriate to where it makes sense in the program. Of note, this means that it can be generated from a macro, which cannot inject expressions into the global scope.
Alternatives considered
There's not much else you can do here while maintaining the spirit of the request
Additional information
I am working on a logging library very similar to os_log, which means I need to stick strings into a specific section in the binary using a macro. The Swift compiler has a hard-coded feature to move os_log strings into its own section. However, with this feature I can do this myself from a normal macro.
The text was updated successfully, but these errors were encountered:
Motivation
The experimental
@_section
attribute relocates a variable into a specific section, with some constraints. Notably, the current implementation requires that the expression be applied to global functions and variables. This is not the case in other languages such as C or C++, where it can be applied to a number of constructs that are guaranteed to only have a single definition. It would be nice if Swift could also support this where appropriate.Proposed solution
Allow
@_section
in more places. For example, this should be well-formed:There is only going to be one of these in the entire program, so this should be technically feasible. And by allowing this it means that
bar
doesn't have to be a global but can be scoped as appropriate to where it makes sense in the program. Of note, this means that it can be generated from a macro, which cannot inject expressions into the global scope.Alternatives considered
There's not much else you can do here while maintaining the spirit of the request
Additional information
I am working on a logging library very similar to os_log, which means I need to stick strings into a specific section in the binary using a macro. The Swift compiler has a hard-coded feature to move os_log strings into its own section. However, with this feature I can do this myself from a normal macro.
The text was updated successfully, but these errors were encountered: