# SwiftPM products Windows PE executables with trailing data

**URL:** <https://forums.swift.org/t/swiftpm-products-windows-pe-executables-with-trailing-data/85483>\
**Category:** Using Swift\
**Tags:** windows, packagemanager\
**Created:** [March 22, 2026, 1:49am UTC](https://forums.swift.org/t/swiftpm-products-windows-pe-executables-with-trailing-data/85483 "2026-03-22T01:49:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stackotter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stackotter/32/20670_2.png) [@stackotter](https://forums.swift.org/u/stackotter)\
**Post date:** [March 22, 2026, 1:49am UTC](https://forums.swift.org/t/swiftpm-products-windows-pe-executables-with-trailing-data/85483/1 "2026-03-22T01:49:05Z")

</div>

## Background

I’ve been looking into adding icons to Swift executables on Windows. The standard way is to compile the icon into a resource object file and pass it to the linker (`-Xlinker icon.res`). For technical reasons I wanted to instead add the icon after compilation, which is a standard approach used by many including Electron.

Tools such [rcedit](https://github.com/electron/rcedit) and [Resource Hacker](https://www.angusj.com/resourcehacker/) can generally be used to set the icons of pre-compiled Windows executable files. For the most part they also work fine on executables produced by Swift Package Manager, but they break a few developer tools such as Visual Studio’s `dumpbin` (with `missing string table`) and LLVM’s objdump (with other string table related errors).

After much investigation, it seems that the issue is that SwiftPM produces executable with trailing data attached (after the end of the main PE executable structure). This is known to mess up tools such as rcedit and Resource Hacker, because they of course can’t know how such trailing data is meant to be treated when they have to expand the PE structure; is the program expect the data to be after the PE structure? does is expect the data to be at a constant offset from the start of the file?

I haven’t yet figured out what the trailing data is, but it seems related to debug or symbol information, as it has a lot of symbol names closely packed together.

I’ve tried to remove this data through various official means; such as `llvm-strip -x program.exe`, and compiling the program with `-c release` (in the hopes that it was debug info) or `-Xswiftc -debug-info-format=codeview` (in the hopes that the data was specifically DWARF related). Those options did all change the size of the resulting executable but left that trailing data in place.

If I remove the trailing data then my relatively complicated program (which uses quite a few dynamic features of Swift) seems to function perfectly fine, leading me to think that the data is purely for debugging?

Interestingly, when I compile a test program with `swiftc` I don’t get the trailing data, which may in part be due to `swiftc` using `link.exe` from the Visual Studio toolchain instead of using `lld-link.exe` from the Swift toolchain like SwiftPM does.

## Questions

1. What is this trailing data?
2. Should this trailing data be added as a section of the PE executable to better support PE editing tools such as rcedit and Resource Hacker? Or is there some technical reason forcing this to be trailing data?

* * *

During my testing I’ve been using the following Python script to analyse the executables and pull them apart.

```python
import pefile

exe_file = "stripped-vvp.exe"
size = 0
with pefile.PE(exe_file, fast_load=True) as pe:
    size = pe.OPTIONAL_HEADER.SizeOfHeaders
    for section in pe.sections:
        size += section.SizeOfRawData

print("PE size:", size)
print("True file size:", len(open(exe_file, "rb").read()))

contents = None
with open(exe_file, "rb") as f:
    contents = f.read()

with open("out.bin", "wb") as outfile:
    outfile.write(contents[size:])

with open("base.exe", "wb") as outfile:
    outfile.write(contents[:size])

```

* * *

For my original use case, I’ve ended up just compiling the icon into the executable as a resource object file, which has some drawbacks because SwiftPM’s incremental builds don’t seem to like arbitrary custom linker arguments (quite understandably), but it’s okay for now. This investigation was more out of interest than necessity.

---

<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:** [March 22, 2026, 3:08pm UTC](https://forums.swift.org/t/swiftpm-products-windows-pe-executables-with-trailing-data/85483/2 "2026-03-22T15:08:06Z")

</div>

If the suspicion is that it is lld vs link, `-use-ld=link` should make the issue disappear. I think that you might be able to use `/MAP` to figure out the contribution that you are trying to identify. See [/MAP (Generate Mapfile) | Microsoft Learn](https://learn.microsoft.com/en-us/cpp/build/reference/map-generate-mapfile?view=msvc-170)

---

<div class="post-metadata">

**Author:** ![stackotter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stackotter/32/20670_2.png) [@stackotter](https://forums.swift.org/u/stackotter)\
**Post date:** [March 25, 2026, 8:04am UTC](https://forums.swift.org/t/swiftpm-products-windows-pe-executables-with-trailing-data/85483/3 "2026-03-25T08:04:03Z")

</div>

> [@compnerd](#):
>
> -use-ld=link

I’ve tried rebuilding my test project with `swift build -Xswiftc -use-ld=link`, but unfortunately got this error;

```swift
LINK : fatal error LNK1117: syntax error in option 'debug:dwarf'

```

I get the same error if I run the command with `-Xswiftc -debug-info-format=codeview` tacked on the end.

---

<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:** [March 25, 2026, 2:47pm UTC](https://forums.swift.org/t/swiftpm-products-windows-pe-executables-with-trailing-data/85483/4 "2026-03-25T14:47:33Z")

</div>

`-debug-info-format` should be passed to SPM directly, `swift build -debug-info-format codeview`. This will become the default in the future, the supporting work is on going.

---

<div class="post-metadata">

**Author:** ![stackotter](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/stackotter/32/20670_2.png) [@stackotter](https://forums.swift.org/u/stackotter)\
**Post date:** [March 25, 2026, 2:53pm UTC](https://forums.swift.org/t/swiftpm-products-windows-pe-executables-with-trailing-data/85483/5 "2026-03-25T14:53:56Z")

</div>

Amazing, thanks! That worked a charm. And I don’t have to supply `-use-ld=link` either, the trailing data disappears with `swift build -debug-info-format codeview`. I didn’t realise that it was supported as a SwiftPM argument, but given that it is, it makes sense that I was running into strange behaviour and getting both debug info formats mixed together.
