[Pitch] Low-level linkage control attributes: @used and @section

In the pitch thread for @convention(thin) function pointers, I had raised the idea of incorporating these sorts of modifiers into a general @symbol attribute, which could potentially be applied multiple times to the same declaration, in order to do things like export both Swift and C calling convention entry points for a Swift function:

@symbolName(swift: "swift_foo", visibility: internal)
@symbolName(c: "c_foo", visibility: public, section: "__TEXT,__fooplugn", used)
func foo(...)

This might fit better within Swift's implementation model, where declarations don't necessarily map 1:1 to a symbol, and we may emit any number of entry points depending on how the declaration was used. Once you talk about multiple different symbols for a declaration, it seems like all of these low level controls, including exact symbol name, visibility, section/segment name, and used-ness, potentially become independently interesting for each entry point.

10 Likes