Thanks for checking! I'm somewhat surprised that it didn't make a much bigger difference . @al45tair wdyt, wouldn't you have expected more too?
No, I don't think so. The majority of the debug information is likely from the libraries rather than from Swift code built with swift build
.
(Also, FWIW, I don't think swift-backtrace
currently knows how to handle -gline-tables-only
. That's on my to-do list.)
We're doing it for both C & Swift in that command which should cover most code, incl. BoringSSL.
Hmm, seems to work for me:
-O -gline-tables-only
works (inlined frames & line numbers), click to see full output
root@380a8d052ac3:/tmp/foo# rm -f test && swiftc -gline-tables-only -O test.swift && ls -lah && SWIFT_BACKTRACE=interactive=no ./test
total 84K
drwxr-xr-x 4 root root 128 Jun 24 11:12 .
drwxrwxrwt 1 root root 4.0K Jun 24 11:12 ..
-rwxr-xr-x 1 root root 74K Jun 24 11:12 test
-rw-r--r-- 1 root root 117 Jun 24 11:10 test.swift
๐ฃ Swift runtime failure: precondition failure
Thread 0 "test" crashed:
0 [inlined] [system] 0x0000aaaaaca10a10 Swift runtime failure: precondition failure in test at /tmp/foo/<compiler-generated>
1 [inlined] 0x0000aaaaaca10a10 bar in test at /tmp/foo/test.swift:2:5
2 [inlined] 0x0000aaaaaca10a10 foo in test at /tmp/foo/test.swift:6:5
3 0x0000aaaaaca10a10 main() in test at /tmp/foo/test.swift:11:5
4 [ra] 0x0000ffff9a8573fc <unknown> in libc.so.6
5 [ra] 0x0000ffff9a8574cc <unknown> in libc.so.6
Registers:
x0 0x0000000000000001 1
x1 0x0000fffff85598e8 45 a8 55 f8 ff ff 00 00 00 00 00 00 00 00 00 00 EยจUรธรฟรฟยทยทยทยทยทยทยทยทยทยท
x2 0x0000fffff85598f8 4c a8 55 f8 ff ff 00 00 6b a8 55 f8 ff ff 00 00 LยจUรธรฟรฟยทยทkยจUรธรฟรฟยทยท
x3 0x0000aaaaaca10a04 fd 7b bf a9 fd 03 00 91 01 00 00 94 20 00 20 d4 รฝ{ยฟยฉรฝยทยทยทยทยทยทยท ยท ร
x4 0x0000000000000000 0
x5 0x9e9203d76bc81010 11426199428353495056
x6 0x0000000000000000 0
x7 0x0000000000000000 0
x8 0x0000000000000000 0
x9 0x0000aaaaaca30048 03 00 00 00 00 00 00 00 30 00 a3 ac aa aa 00 00 ยทยทยทยทยทยทยทยท0ยทยฃยฌยชยชยทยท
x10 0x0000ffff9b2b5490 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
x11 0x0000000000000000 0
x12 0x2020202020202020 2314885530818453536
x13 0x0000000000000000 0
x14 0x0000000000000000 0
x15 0x0000000000000008 8
x16 0x0000ffff9b2c9774 fd 7b bb a9 fd 03 00 91 f7 63 03 a9 37 01 00 f0 รฝ{ยปยฉรฝยทยทยทรทcยทยฉ7ยทยทรฐ
x17 0x0000ffff9a9cb080 74 97 2c 9b ff ff 00 00 c0 96 8c 9a ff ff 00 00 tยท,ยทรฟรฟยทยทรยทยทยทรฟรฟยทยท
x18 0x0000000000000000 0
x19 0x0000fffff85598e8 45 a8 55 f8 ff ff 00 00 00 00 00 00 00 00 00 00 EยจUรธรฟรฟยทยทยทยทยทยทยทยทยทยท
x20 0x0000000000000001 1
x21 0x0000aaaaaca2fd70 03 00 00 00 00 00 00 00 e8 ff a2 ac aa aa 00 00 ยทยทยทยทยทยทยทยทรจรฟยขยฌยชยชยทยท
x22 0x0000ffff9b2f1040 70 23 2f 9b ff ff 00 00 0e 00 00 00 00 00 00 00 p#/ยทรฟรฟยทยทยทยทยทยทยทยทยทยท
x23 0x0000aaaaaca10a04 fd 7b bf a9 fd 03 00 91 01 00 00 94 20 00 20 d4 รฝ{ยฟยฉรฝยทยทยทยทยทยทยท ยท ร
x24 0x0000ffff9a9ca000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
x25 0x0000000000000000 0
x26 0x0000fffff85598f8 4c a8 55 f8 ff ff 00 00 6b a8 55 f8 ff ff 00 00 LยจUรธรฟรฟยทยทkยจUรธรฟรฟยทยท
x27 0x0000aaaaaca2fd70 03 00 00 00 00 00 00 00 e8 ff a2 ac aa aa 00 00 ยทยทยทยทยทยทยทยทรจรฟยขยฌยชยชยทยท
x28 0x0000000000000000 0
fp 0x0000fffff8559760 70 97 55 f8 ff ff 00 00 fc 73 85 9a ff ff 00 00 pยทUรธรฟรฟยทยทรผsยทยทรฟรฟยทยท
lr 0x0000aaaaaca10a10 20 00 20 d4 20 00 20 d4 fd 7b bf a9 fd 03 00 91 ยท ร ยท รรฝ{ยฟยฉรฝยทยทยท
sp 0x0000fffff8559760 70 97 55 f8 ff ff 00 00 fc 73 85 9a ff ff 00 00 pยทUรธรฟรฟยทยทรผsยทยทรฟรฟยทยท
pc 0x0000aaaaaca10a10 20 00 20 d4 20 00 20 d4 fd 7b bf a9 fd 03 00 91 ยท ร ยท รรฝ{ยฟยฉรฝยทยทยท
Images (11 omitted):
0x0000aaaaaca10000โ0x0000aaaaaca10bf8 <no build ID> test /tmp/foo/test
0x0000ffff9a830000โ0x0000ffff9a9b7404 9e27cf97f03940293c6df3b107674ceda9c825d8 libc.so.6 /usr/lib/aarch64-linux-gnu/libc.so.6
Backtrace took 0.00s
Trace/breakpoint trap
Just -O
(no -g...
):
no line numbers, no inlined frames (as expected), click to see full output
root@380a8d052ac3:/tmp/foo# rm -f test && swiftc -O test.swift && ls -lah && SWIFT_BACKTRACE=interactive=no ./test
total 80K
drwxr-xr-x 4 root root 128 Jun 24 11:12 .
drwxrwxrwt 1 root root 4.0K Jun 24 11:12 ..
-rwxr-xr-x 1 root root 72K Jun 24 11:12 test
-rw-r--r-- 1 root root 117 Jun 24 11:10 test.swift
๐ฃ Program crashed: System trap at 0x0000aaaad8400a10
Thread 0 "test" crashed:
0 0x0000aaaad8400a10 main() in test
1 [ra] 0x0000ffffbc7b73fc <unknown> in libc.so.6
2 [ra] 0x0000ffffbc7b74cc <unknown> in libc.so.6
Registers:
x0 0x0000000000000001 1
x1 0x0000ffffe0e569d8 45 78 e5 e0 ff ff 00 00 00 00 00 00 00 00 00 00 Exรฅร รฟรฟยทยทยทยทยทยทยทยทยทยท
x2 0x0000ffffe0e569e8 4c 78 e5 e0 ff ff 00 00 6b 78 e5 e0 ff ff 00 00 Lxรฅร รฟรฟยทยทkxรฅร รฟรฟยทยท
x3 0x0000aaaad8400a04 fd 7b bf a9 fd 03 00 91 01 00 00 94 20 00 20 d4 รฝ{ยฟยฉรฝยทยทยทยทยทยทยท ยท ร
x4 0x0000000000000000 0
x5 0xe6dd9c63859eae5b 16635624549833944667
x6 0x0000000000000000 0
x7 0x0000000000000000 0
x8 0x0000000000000000 0
x9 0x0000aaaad8420048 03 00 00 00 00 00 00 00 30 00 42 d8 aa aa 00 00 ยทยทยทยทยทยทยทยท0ยทBรยชยชยทยท
x10 0x0000ffffbd210490 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
x11 0x0000000000000000 0
x12 0x2020202020202020 2314885530818453536
x13 0x0000000000000000 0
x14 0x0000000000000000 0
x15 0x0000000000000008 8
x16 0x0000ffffbd224774 fd 7b bb a9 fd 03 00 91 f7 63 03 a9 37 01 00 f0 รฝ{ยปยฉรฝยทยทยทรทcยทยฉ7ยทยทรฐ
x17 0x0000ffffbc92b080 74 47 22 bd ff ff 00 00 c0 96 82 bc ff ff 00 00 tG"ยฝรฟรฟยทยทรยทยทยผรฟรฟยทยท
x18 0x0000000000000000 0
x19 0x0000ffffe0e569d8 45 78 e5 e0 ff ff 00 00 00 00 00 00 00 00 00 00 Exรฅร รฟรฟยทยทยทยทยทยทยทยทยทยท
x20 0x0000000000000001 1
x21 0x0000aaaad841fd70 03 00 00 00 00 00 00 00 e8 ff 41 d8 aa aa 00 00 ยทยทยทยทยทยทยทยทรจรฟAรยชยชยทยท
x22 0x0000ffffbd24c040 70 d3 24 bd ff ff 00 00 0e 00 00 00 00 00 00 00 pร$ยฝรฟรฟยทยทยทยทยทยทยทยทยทยท
x23 0x0000aaaad8400a04 fd 7b bf a9 fd 03 00 91 01 00 00 94 20 00 20 d4 รฝ{ยฟยฉรฝยทยทยทยทยทยทยท ยท ร
x24 0x0000ffffbc92a000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
x25 0x0000000000000000 0
x26 0x0000ffffe0e569e8 4c 78 e5 e0 ff ff 00 00 6b 78 e5 e0 ff ff 00 00 Lxรฅร รฟรฟยทยทkxรฅร รฟรฟยทยท
x27 0x0000aaaad841fd70 03 00 00 00 00 00 00 00 e8 ff 41 d8 aa aa 00 00 ยทยทยทยทยทยทยทยทรจรฟAรยชยชยทยท
x28 0x0000000000000000 0
fp 0x0000ffffe0e56850 60 68 e5 e0 ff ff 00 00 fc 73 7b bc ff ff 00 00 `hรฅร รฟรฟยทยทรผs{ยผรฟรฟยทยท
lr 0x0000aaaad8400a10 20 00 20 d4 20 00 20 d4 fd 7b bf a9 fd 03 00 91 ยท ร ยท รรฝ{ยฟยฉรฝยทยทยท
sp 0x0000ffffe0e56850 60 68 e5 e0 ff ff 00 00 fc 73 7b bc ff ff 00 00 `hรฅร รฟรฟยทยทรผs{ยผรฟรฟยทยท
pc 0x0000aaaad8400a10 20 00 20 d4 20 00 20 d4 fd 7b bf a9 fd 03 00 91 ยท ร ยท รรฝ{ยฟยฉรฝยทยทยท
Images (11 omitted):
0x0000aaaad8400000โ0x0000aaaad8400bf8 <no build ID> test /tmp/foo/test
0x0000ffffbc790000โ0x0000ffffbc917404 9e27cf97f03940293c6df3b107674ceda9c825d8 libc.so.6 /usr/lib/aarch64-linux-gnu/libc.so.6
Backtrace took 0.00s
Trace/breakpoint trap
-O -g
(SwiftPM default for -c release
)
works (inline frames and line numbers, as expected), click to see full output
root@380a8d052ac3:/tmp/foo# rm -f test && swiftc -g -O test.swift && ls -lah && SWIFT_BACKTRACE=interactive=no ./test
total 84K
drwxr-xr-x 4 root root 128 Jun 24 11:12 .
drwxrwxrwt 1 root root 4.0K Jun 24 11:12 ..
-rwxr-xr-x 1 root root 74K Jun 24 11:12 test
-rw-r--r-- 1 root root 117 Jun 24 11:10 test.swift
๐ฃ Swift runtime failure: precondition failure
Thread 0 "test" crashed:
0 [inlined] [system] 0x0000aaaab4d40a10 Swift runtime failure: precondition failure in test at /tmp/foo/<compiler-generated>
1 [inlined] 0x0000aaaab4d40a10 bar() in test at /tmp/foo/test.swift:2:5
2 [inlined] 0x0000aaaab4d40a10 foo() in test at /tmp/foo/test.swift:6:5
3 0x0000aaaab4d40a10 main() in test at /tmp/foo/test.swift:11:5
4 [ra] 0x0000ffff95e773fc <unknown> in libc.so.6
5 [ra] 0x0000ffff95e774cc <unknown> in libc.so.6
Registers:
x0 0x0000000000000001 1
x1 0x0000ffffd0185ce8 45 68 18 d0 ff ff 00 00 00 00 00 00 00 00 00 00 Ehยทรรฟรฟยทยทยทยทยทยทยทยทยทยท
x2 0x0000ffffd0185cf8 4c 68 18 d0 ff ff 00 00 6b 68 18 d0 ff ff 00 00 Lhยทรรฟรฟยทยทkhยทรรฟรฟยทยท
x3 0x0000aaaab4d40a04 fd 7b bf a9 fd 03 00 91 01 00 00 94 20 00 20 d4 รฝ{ยฟยฉรฝยทยทยทยทยทยทยท ยท ร
x4 0x0000000000000000 0
x5 0x9f0910e45fa8b4a0 11459709299864417440
x6 0x0000000000000000 0
x7 0x0000000000000000 0
x8 0x0000000000000000 0
x9 0x0000aaaab4d60048 03 00 00 00 00 00 00 00 30 00 d6 b4 aa aa 00 00 ยทยทยทยทยทยทยทยท0ยทรยดยชยชยทยท
x10 0x0000ffff968cc490 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
x11 0x0000000000000000 0
x12 0x2020202020202020 2314885530818453536
x13 0x0000000000000000 0
x14 0x0000000000000000 0
x15 0x0000000000000008 8
x16 0x0000ffff968e0774 fd 7b bb a9 fd 03 00 91 f7 63 03 a9 37 01 00 f0 รฝ{ยปยฉรฝยทยทยทรทcยทยฉ7ยทยทรฐ
x17 0x0000ffff95feb080 74 07 8e 96 ff ff 00 00 c0 96 ee 95 ff ff 00 00 tยทยทยทรฟรฟยทยทรยทรฎยทรฟรฟยทยท
x18 0x0000000000000000 0
x19 0x0000ffffd0185ce8 45 68 18 d0 ff ff 00 00 00 00 00 00 00 00 00 00 Ehยทรรฟรฟยทยทยทยทยทยทยทยทยทยท
x20 0x0000000000000001 1
x21 0x0000aaaab4d5fd70 03 00 00 00 00 00 00 00 e8 ff d5 b4 aa aa 00 00 ยทยทยทยทยทยทยทยทรจรฟรยดยชยชยทยท
x22 0x0000ffff96908040 70 93 90 96 ff ff 00 00 0e 00 00 00 00 00 00 00 pยทยทยทรฟรฟยทยทยทยทยทยทยทยทยทยท
x23 0x0000aaaab4d40a04 fd 7b bf a9 fd 03 00 91 01 00 00 94 20 00 20 d4 รฝ{ยฟยฉรฝยทยทยทยทยทยทยท ยท ร
x24 0x0000ffff95fea000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท
x25 0x0000000000000000 0
x26 0x0000ffffd0185cf8 4c 68 18 d0 ff ff 00 00 6b 68 18 d0 ff ff 00 00 Lhยทรรฟรฟยทยทkhยทรรฟรฟยทยท
x27 0x0000aaaab4d5fd70 03 00 00 00 00 00 00 00 e8 ff d5 b4 aa aa 00 00 ยทยทยทยทยทยทยทยทรจรฟรยดยชยชยทยท
x28 0x0000000000000000 0
fp 0x0000ffffd0185b60 70 5b 18 d0 ff ff 00 00 fc 73 e7 95 ff ff 00 00 p[ยทรรฟรฟยทยทรผsรงยทรฟรฟยทยท
lr 0x0000aaaab4d40a10 20 00 20 d4 20 00 20 d4 fd 7b bf a9 fd 03 00 91 ยท ร ยท รรฝ{ยฟยฉรฝยทยทยท
sp 0x0000ffffd0185b60 70 5b 18 d0 ff ff 00 00 fc 73 e7 95 ff ff 00 00 p[ยทรรฟรฟยทยทรผsรงยทรฟรฟยทยท
pc 0x0000aaaab4d40a10 20 00 20 d4 20 00 20 d4 fd 7b bf a9 fd 03 00 91 ยท ร ยท รรฝ{ยฟยฉรฝยทยทยท
Images (11 omitted):
0x0000aaaab4d40000โ0x0000aaaab4d44b50 <no build ID> test /tmp/foo/test
0x0000ffff95e50000โ0x0000ffff95fd7404 9e27cf97f03940293c6df3b107674ceda9c825d8 libc.so.6 /usr/lib/aarch64-linux-gnu/libc.so.6
Backtrace took 0.00s
Trace/breakpoint trap
My test program:
root@380a8d052ac3:/tmp/foo# cat test.swift
func bar() {
preconditionFailure()
}
func foo() {
bar()
}
@inline(never)
func main() {
foo()
}
main()
Is that on macOS? It'll work there, I think. But not on Linux, I think, at least not presently.
Other than the Swift runtime, the C library, the C++ library, ICU and so onโฆ so there's still quite a bit of code that will have debug information regardless (because it's in the .a
files you're linking with).
That was Linux, specifically the swift:5.10
Docker container.
Other than the Swift runtime, the C library, the C++ library, ICU and so onโฆ so there's still quite a bit of code that will have debug information regardless (because it's in the
.a
files you're linking with).
Of course, yes, that's fair. Do we build those with full debug info?
EDIT: I guess you're saying that whatever savings -gline-tables-only
could make might be dwarfed by the size of the binary libraries we ship with Swift.
You can also try lto with --experimental-lto-mode full
You can also try lto with
--experimental-lto-mode full
Though note that the static libraries in the SDK aren't built with LTO enabled. I did try, but hit some problems; it'd be nice to have an LTO enabled version available in future, for sure, but right now you'll only get LTO for your own code.