# SE-0492: Section Placement Control

**URL:** <https://forums.swift.org/t/se-0492-section-placement-control/82289>\
**Category:** Proposal Reviews\
**Created:** [September 22, 2025, 7:35pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289 "2025-09-22T19:35:19Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![kubamracek](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/kubamracek/32/1171_2.png) [@kubamracek](https://forums.swift.org/u/kubamracek)\
**Post date:** [September 25, 2025, 3:55am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/21 "2025-09-25T03:55:59Z")

</div>

> <https://github.com/swiftlang/swift-evolution/pull/2972>

---

<div class="post-metadata">

**Author:** ![pyrtsa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/pyrtsa/32/740_2.png) [@pyrtsa](https://forums.swift.org/u/pyrtsa)\
**Post date:** [September 25, 2025, 6:16am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/22 "2025-09-25T06:16:15Z")

</div>

> [@kubamracek](#):
>
> Essentially, globals are lazy normally. `@section` makes the global non-lazy. Using the `lazy` keyword gives you the "lazy behavior" back. Inventing a new keyword or a new attribute for that purpose seems completely unnecessary, because the word "lazy" exactly matches the intent.

Thank you, that indeed answers my question! But the reason I’m asking is, it nevertheless feels odd to invert the polarity of global and `static` variables (constants) here by introducing a new place to use the `lazy` keyword.

I think there’s another option (or two) avoiding the `lazy` keyword in this context. Either:

1. just don’t introduce any keyword here and deduce from the expression whether it’s a compile-time constant initialisation expression (such as `= (1, "one")`), and if not (such as `= Int.random(in: 0 ..< 10)`) then make it lazy; or
2. make the non-lazy compile-time constant initialisation ride on the same syntax which is planned for the general feature of constant or literal expressions which Doug and others discussed above.

In both cases, there’d be no `lazy` in these contexts. Option 2, which could turn out to mean no syntax at all, merging into option 1, would IMO keep the language best together.

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [September 25, 2025, 9:16pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/23 "2025-09-25T21:16:55Z")

</div>

> [@pyrtsa](#):
>
> - just don’t introduce any keyword here and deduce from the expression whether it’s a compile-time constant initialisation expression (such as `= (1, "one")`), and if not (such as `= Int.random(in: 0 ..< 10)`) then make it lazy; or

This might result in "spooky action" that produces an ill-formed binary. Consider what might happen if you accidentally emitted non-constant, lazily-constructed data into a section that you read with C (which is a thing Swift Testing must do.) You'd end up with uninitialized data among other potential problems. I'd rather we make laziness opt-in (or perhaps opt-out with `_const` in lieu of a supported solution).

---

<div class="post-metadata">

**Author:** ![Joe\_Groff](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joe_groff/32/1929_2.png) [@Joe\_Groff](https://forums.swift.org/u/Joe_Groff)\
**Post date:** [September 26, 2025, 12:07am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/24 "2025-09-26T00:07:56Z")

</div>

If we don't have an immediate use for it, I'd like to push against making `lazy` available for use with `@section`. The existence of `lazy` local properties as a builtin language feature is a hack that I still hope can be supplanted by a library feature someday. (Maybe property macros with init accessors are up to the task now.) And the implementation for globals has almost nothing in common with the implementation for local properties; we already have trouble explaining that global initialization is thread-safe and referentially transparent for `let`s, whereas it is most definitely not for `lazy` properties, and spelling them the same will only make this harder to communicate. I also don't think global initialization should be thought of as "lazy" but as "happening before the first use", since the optimizer is allowed to move the point of initialization, to get it out of loops or things like that (and, of course, turn constant initializers into fully static values in the binary).

---

<div class="post-metadata">

**Author:** ![pyrtsa](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/pyrtsa/32/740_2.png) [@pyrtsa](https://forums.swift.org/u/pyrtsa)\
**Post date:** [September 26, 2025, 3:28am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/25 "2025-09-26T03:28:46Z")

</div>

Thank you Joe, you worded it better. One lazy is not like the other.

---

<div class="post-metadata">

**Author:** ![rauhul](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rauhul/32/35207_2.png) [@rauhul](https://forums.swift.org/u/rauhul)\
**Post date:** [October 9, 2025, 11:29pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/26 "2025-10-09T23:29:55Z")

</div>

I very much like the proposal as-is. I do _not_ think forcing `@section()` to have `elf, macho, etc` params is a good idea. Often you need to vary the section name for many other reasons than just the object file format. For example on various embedded devices you need to use different section names for the same object format depending on the toolchain used or targeted device (sometimes even between device _revisions_.)

I would much much rather have `#if` conditions which allow me to express the true conditions than pre-baked elf/macho/coff conditions.

This is already an expert feature it _does not_ need sugar, it needs expressivity.

---

<div class="post-metadata">

**Author:** ![Douglas\_Gregor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/douglas_gregor/32/1362_2.png) [@Douglas\_Gregor](https://forums.swift.org/u/Douglas_Gregor)\
**Post date:** [October 10, 2025, 2:12am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/27 "2025-10-10T02:12:16Z")

</div>

Hello all,

The Language Steering Group discussed the feedback on this proposal, and requested a few changes to be proposal based on that feedback. The author has [made these changes](https://github.com/swiftlang/swift-evolution/pull/2991):

- The `#if` condition `objectFileFormat` has been changed to `objectFormat`.
- The use of `lazy` has been removed from the proposal.
- The proposal now uses the alternative syntax discussed here that specifies the object format names in the section attribute, i.e., `@section(ELF: “...”, MachO: “...”, COFF: “...”)`, with the addition of a `default:` label whose name will be used for any object format not otherwise covered by that attribute.

We'll be extending the review until Tuesday, October 14th to gather more feedback on the proposal with these changes.

Thank you  
Doug Gregor  
Review Manager

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [October 10, 2025, 2:44am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/28 "2025-10-10T02:44:27Z")

</div>

For Swift Testing's purposes, we'll be able to adopt even with these adjustments in place. That said… a `default:` label doesn't really make much sense in this context, as there is no universal, standard, or common fallback to use here. Can the LSG provide some more justification for adding it? What is the intended use case?

---

<div class="post-metadata">

**Author:** ![Douglas\_Gregor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/douglas_gregor/32/1362_2.png) [@Douglas\_Gregor](https://forums.swift.org/u/Douglas_Gregor)\
**Post date:** [October 10, 2025, 3:32am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/29 "2025-10-10T03:32:18Z")

</div>

> [@grynspan](#):
>
> For Swift Testing's purposes, we'll be able to adopt even with these adjustments in place. That said… a `default:` label doesn't really make much sense in this context, as there is no universal, standard, or common fallback to use here. Can the LSG provide some more justification for adding it? What is the intended use case?

Intended use cases can include:

1. You're computing the section name somewhere else (say, with a set of `#if objectFormat(...)` checks) and then you put the computed value in `@section(default: theSection`), as [noted above](https://forums.swift.org/t/se-0492-section-placement-control/82289/10).
2. There is an object format that's available in the underlying LLVM but doesn't yet have a suitable label in `@section`.

Doug

---

<div class="post-metadata">

**Author:** ![tali](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tali/32/11346_2.png) [@tali](https://forums.swift.org/u/tali)\
**Post date:** [October 10, 2025, 7:53am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/30 "2025-10-10T07:53:11Z")

</div>

Then maybe provide two ways to specify the section:

```swift
// either with object format names but without `default:`
@section(ELF: “...”, MachO: “...”, COFF: “...”)
// or with just the name (also without having to use `default:`)
@section(precomputedName)

```

---

<div class="post-metadata">

**Author:** ![grynspan](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/grynspan/32/15315_2.png) [@grynspan](https://forums.swift.org/u/grynspan)\
**Post date:** [October 10, 2025, 10:57am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/31 "2025-10-10T10:57:31Z")

</div>

> [@Douglas\_Gregor](#):
>
> - You're computing the section name somewhere else (say, with a set of `#if objectFormat(...)` checks) and then you put the computed value in `@section(default: theSection`), as [noted above](https://forums.swift.org/t/se-0492-section-placement-control/82289/10).

That's not possible under the proposal since you must use a string literal. So it's impossible to use this part of the API correctly.

> [@Douglas\_Gregor](#):
>
> - There is an object format that's available in the underlying LLVM but doesn't yet have a suitable label in `@section`.

Perhaps `_default` would be appropriate then? You'd be dealing with an unsupported corner of the compiler stack. Once the compiler is updated to "learn" of the new object format, we could easily add a new label for it.

---

<div class="post-metadata">

**Author:** ![j-f1](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/j-f1/32/12287_2.png) [@j-f1](https://forums.swift.org/u/j-f1)\
**Post date:** [October 10, 2025, 4:02pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/32 "2025-10-10T16:02:46Z")

</div>

What’s the rationale behind naming the object formats with an uppercase first letter (`MachO`, `ELF`) rather than the lowercase first letter used with variables, enum cases, and function parameters (`machO`, `elf`)?

---

<div class="post-metadata">

**Author:** ![compnerd](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/compnerd/32/2165_2.png) [@compnerd](https://forums.swift.org/u/compnerd)\
**Post date:** [October 10, 2025, 4:39pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/33 "2025-10-10T16:39:25Z")

</div>

They are proper names, and the spelling for them is `MachO`, `ELF`, and `COFF`. So it does make sense to use the proper spelling here.

---

<div class="post-metadata">

**Author:** ![Douglas\_Gregor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/douglas_gregor/32/1362_2.png) [@Douglas\_Gregor](https://forums.swift.org/u/Douglas_Gregor)\
**Post date:** [October 10, 2025, 9:22pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/34 "2025-10-10T21:22:20Z")

</div>

> [@grynspan](#):
>
> > [@Douglas\_Gregor](#):
> >
> > - You're computing the section name somewhere else (say, with a set of `#if objectFormat(...)` checks) and then you put the computed value in `@section(default: theSection`), as [noted above](https://forums.swift.org/t/se-0492-section-placement-control/82289/10).
> 
> That's not possible under the proposal since you must use a string literal. So it's impossible to use this part of the API correctly.

One can use this in the form allowed by the original proposal, i.e.,

```swift
#if objectFormat(MachO)
@section(default: "...")
#else
@section(default: "...")
#endif
var globalThing = 0

```

Additionally, we expect a feature that allows the use of a named constant here in lieu of a string literal to become available in the not-too-distant future, and want to support both use cases.

Doug

---

<div class="post-metadata">

**Author:** ![beccadax](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/beccadax/32/34217_2.png) [@beccadax](https://forums.swift.org/u/beccadax)\
**Post date:** [October 10, 2025, 9:33pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/35 "2025-10-10T21:33:18Z")

</div>

> [@j-f1](#):
>
> What’s the rationale behind naming the object formats with an uppercase first letter (`MachO`, `ELF`) rather than the lowercase first letter used with variables, enum cases, and function parameters (`machO`, `elf`)?

I see these as similar to platform names, where we adopt the capitalization preferred by the platform owner (`Windows`, `FreeBSD`, `macOS`). These technologies have names, those names use capitalization in sometimes idiosyncratic ways, and there's no compelling reason to ignore their decisions.

---

<div class="post-metadata">

**Author:** ![scanon](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scanon/32/2445_2.png) [@scanon](https://forums.swift.org/u/scanon)\
**Post date:** [October 11, 2025, 9:12pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/36 "2025-10-11T21:12:11Z")

</div>

Would it be feasible to drop the `default:` when we're just providing a single value?

```swift
#if objectFormat(MachO)
@section(" __TEXT,__ butt")
#else
@section(" __TEXT,__ jawn")
#endif
var globalThing = 0

```

@rauhul would that alleviate your concerns?

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [October 11, 2025, 10:51pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/37 "2025-10-11T22:51:01Z")

</div>

> [@compnerd](#):
>
> They are proper names, and the spelling for them is `MachO`, `ELF`, and `COFF`. So it does make sense to use the proper spelling here.

FTM we didn't follow this approach with `@objc` name, and we plan not to follow it with `@c` name either.

---

<div class="post-metadata">

**Author:** ![rauhul](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/rauhul/32/35207_2.png) [@rauhul](https://forums.swift.org/u/rauhul)\
**Post date:** [October 13, 2025, 3:56pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/38 "2025-10-13T15:56:41Z")

</div>

yes! though I still disagree with the premise of providing `elf:macho:coff:` arguments.

(Composable features are both more teachable and extensible)

---

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [October 14, 2025, 7:44am UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/39 "2025-10-14T07:44:22Z")

</div>

Are these two fragments equivalent?

```swift
#if objectFormat(MachO) || objectFormat(ELF)
@section(MachO: "__DATA_CONST,mysection", ELF: "mysection")
#endif

```

```swift
#if objectFormat(MachO)
@section(default: "__DATA_CONST,mysection")
#elif objectFormat(ELF)
@section(default: "mysection")
#endif

```

* * *

Can't `@used` be a parameter of `@section`?

```swift
@section(MachO: "__DATA,mysection", used)
or
@section(MachO: "__DATA,mysection", used: true)
or
@section(MachO: "__DATA,mysection", dontDeadStrip: true)

```

---

<div class="post-metadata">

**Author:** ![Douglas\_Gregor](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/douglas_gregor/32/1362_2.png) [@Douglas\_Gregor](https://forums.swift.org/u/Douglas_Gregor)\
**Post date:** [October 14, 2025, 3:05pm UTC](https://forums.swift.org/t/se-0492-section-placement-control/82289/40 "2025-10-14T15:05:48Z")

</div>

> [@tera](#):
>
> Are these two fragments equivalent?
> 
> ```swift
> #if objectFormat(MachO) || objectFormat(ELF)
> @section(MachO: "__DATA_CONST,mysection", ELF: "mysection")
> #endif
> 
> ```
> 
> ```swift
> #if objectFormat(MachO)
> @section(default: "__DATA_CONST,mysection")
> #elif objectFormat(ELF)
> @section(default: "mysection")
> #endif
> 
> ```

Yes.

> [@tera](#):
>
> Can't `@used` be a parameter of `@section`?
> 
> ```swift
> @section(MachO: "__DATA,mysection", used)
> or
> @section(MachO: "__DATA,mysection", used: true)
> or
> @section(MachO: "__DATA,mysection", dontDeadStrip: true)
> 
> ```

It's possible. The proposal [makes the point](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0492-section-control.md#umbrella-attribute-for-linkage-properties) that these are separate notions.

Doug

[Previous page](https://forums.swift.org/t/se-0492-section-placement-control/82289.md?page=1)

[Next page](https://forums.swift.org/t/se-0492-section-placement-control/82289.md?page=3)
