1

When an empty file is supplied to the Swift compiler, it only generates a couple of fairly obvious symbols:

echo '' > test.swift
swiftc -c -parse-as-library -o test.o ./test.swift
nm test.o

prints this:

0000000000000000 S ___swift_reflection_version
0000000000000002 s l_llvm.swift_module_hash

But when we try to compile this empty file as Swift standard library, more symbols with inscrutable names are added automatically:

swiftc -c -parse-as-library -parse-stdlib -module-name Swift -o test.o ./test.swift
nm test.o

prints this:

000000000000006c s _$SBBMB
0000000000000030 s _$SBOMB
0000000000000044 s _$SBbMB
000000000000001c s _$SBoMB
0000000000000058 s _$SBpMB
0000000000000094 s _$SypXpMB
0000000000000080 s _$SyyXfMB
00000000000000a8 S ___swift_reflection_version
000000000000000c S _symbolic BB
0000000000000003 S _symbolic BO
0000000000000006 S _symbolic Bb
0000000000000000 S _symbolic Bo
0000000000000009 S _symbolic Bp
0000000000000014 S _symbolic ypXp
000000000000000f S _symbolic yyXf
00000000000000aa s l_llvm.swift_module_hash

Further search leads to Swift runtime documentation which lists very similar symbols at "Standard metadata" title:

The Swift runtime exports standard metadata objects for Builtin types as well as standard value witness tables that can be freely adopted by types with common layout attributes. Note that, unlike public-facing types, the runtime does not guarantee a 1:1 mapping of Builtin types to metadata objects, and will reuse metadata objects to represent builtins with the same layout characteristics.

Under that explanation follows a longer list of symbols:

000000000004faa8 S __TMBB
000000000004fab8 S __TMBO
000000000004f9f8 S __TMBb
000000000004f9c8 S __TMBi128_
000000000004f998 S __TMBi16_
000000000004f9d8 S __TMBi256_
000000000004f9a8 S __TMBi32_
000000000004f9b8 S __TMBi64_
000000000004f988 S __TMBi8_
000000000004f9e8 S __TMBo
000000000004fac8 S __TMT_
000000000004f568 S __TWVBO
000000000004f4b0 S __TWVBb
000000000004f0a8 S __TWVBi128_
000000000004eec8 S __TWVBi16_
000000000004f148 S __TWVBi256_
000000000004ef68 S __TWVBi32_
000000000004f008 S __TWVBi64_
000000000004ee28 S __TWVBi8_
000000000004f1e8 S __TWVBo
000000000004f778 S __TWVFT_T_
000000000004f3f8 S __TWVMBo
000000000004f8e8 S __TWVT_
000000000004f830 S __TWVXfT_T_
000000000004f620 S __TWVXoBO
000000000004f2a0 S __TWVXoBo
000000000004f6d8 S __TWVXwGSqBO_
000000000004f358 S __TWVXwGSqBo_

This still doesn't explain what each of those symbols mean, how are they used and why they have these short names? Was anyone able to find more public documentation on these symbols? Why are only some of those symbols are included when compiling an empty file as Swift standard library?

Max Desiatov
  • 5,087
  • 3
  • 48
  • 56
  • 1
    The symbols you're looking at [are mangled](https://github.com/apple/swift/blob/master/docs/ABI/Mangling.rst) – you can run the symbols through `swift-demangle` in order to get a readable description of them, e.g `xcrun swift-demangle "SBpMB"` -> `$SBpMB ---> reflection metadata builtin descriptor Builtin.RawPointer`. – Hamish Nov 09 '18 at 10:39
  • thanks @Hamish, it would be very interesting to find a more detailed explanation of what "metadata builtin descriptor" means and how exactly it's used – Max Desiatov Nov 09 '18 at 11:55

0 Answers0