I donât have a real answer for you here, but I wanted to point you at Determining Why a Symbol is Referenced, which explains the linkerâs -why_live option. Iâm curious to see if these symbols are live because theyâve actually been marked as no_dead_strip, and whether the -internalize-at-link changes that.
Thank you for the pointer to this -why_live option, that was great.
I started with a funky symbol that should not have been there, and it found a root, then I picked that root, and it looks like the dont-dead-strip flag is still the cause:
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
dont-dead-strip
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
_$s10SwiftGodot10OpenXRHandC10BoneUpdateOSYAAMA from OpenXRHand.swift.o
Demangled, it looks like this is:
reflection metadata associated type descriptor SwiftGodot.OpenXRHand.BoneUpdate : Swift.RawRepresentable in SwiftGodot
(Edited for clarity, full version)
There are 607 symbols in this file as reported by nm -m, and 56 of them are flagged with no dead strip according to it raw version:
0000000000008be8 (__TEXT,__swift5_fieldmd) non-external [no dead strip] reflection metadata field descriptor SwiftGodot.OpenXRHand.BoneUpdate
0000000000008708 (__TEXT,__swift5_assocty) non-external [no dead strip] reflection metadata associated type descriptor SwiftGodot.OpenXRHand.BoneUpdate : Swift.RawRepresentable in SwiftGodot
0000000000008720 (__TEXT,__swift5_assocty) non-external [no dead strip] reflection metadata associated type descriptor SwiftGodot.OpenXRHand.BoneUpdate : Swift.CaseIterable in SwiftGodot
0000000000008b80 (__TEXT,__swift5_fieldmd) non-external [no dead strip] reflection metadata field descriptor SwiftGodot.OpenXRHand.MotionRange
00000000000086a8 (__TEXT,__swift5_assocty) non-external [no dead strip] reflection metadata associated type descriptor SwiftGodot.OpenXRHand.MotionRange : Swift.RawRepresentable in SwiftGodot
00000000000086c0 (__TEXT,__swift5_assocty) non-external [no dead strip] reflection metadata associated type descriptor SwiftGodot.OpenXRHand.MotionRange : Swift.CaseIterable in SwiftGodot
0000000000008bb4 (__TEXT,__swift5_fieldmd) non-external [no dead strip] reflection metadata field descriptor SwiftGodot.OpenXRHand.SkeletonRig
00000000000086d8 (__TEXT,__swift5_assocty) non-external [no dead strip] reflection metadata associated type descriptor SwiftGodot.OpenXRHand.SkeletonRig : Swift.RawRepresentable in SwiftGodot
00000000000086f0 (__TEXT,__swift5_assocty) non-external [no dead strip] reflection metadata associated type descriptor SwiftGodot.OpenXRHand.SkeletonRig : Swift.CaseIterable in SwiftGodot
0000000000018e38 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_hand in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018e28 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_hand in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018eb8 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_bone_update in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018ea8 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_bone_update in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018e78 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_motion_range in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018e98 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_skeleton_rig in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018e68 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_motion_range in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018e88 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_skeleton_rig in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018e58 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_hand_skeleton in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018e48 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_hand_skeleton in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000008b4c (__TEXT,__swift5_fieldmd) non-external [no dead strip] reflection metadata field descriptor SwiftGodot.OpenXRHand.Hands
0000000000008678 (__TEXT,__swift5_assocty) non-external [no dead strip] reflection metadata associated type descriptor SwiftGodot.OpenXRHand.Hands : Swift.RawRepresentable in SwiftGodot
0000000000008690 (__TEXT,__swift5_assocty) non-external [no dead strip] reflection metadata associated type descriptor SwiftGodot.OpenXRHand.Hands : Swift.CaseIterable in SwiftGodot
0000000000018e18 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(className in _0B6DE4D26A8E536FD53858E8549F662E) : SwiftGodot.StringName
0000000000008b3c (__TEXT,__swift5_fieldmd) non-external [no dead strip] reflection metadata field descriptor SwiftGodot.OpenXRHand
0000000000008290 (__TEXT,__const) weak private external [no dead strip] ___swift_reflection_version
0000000000008e80 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftCoreFoundation_$_SwiftGodot
0000000000008e88 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftDispatch_$_SwiftGodot
0000000000008e70 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftFoundation_$_SwiftGodot
0000000000008e98 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftIOKit_$_SwiftGodot
0000000000008e78 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftObjectiveC_$_SwiftGodot
0000000000008e68 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_SwiftGodot
0000000000008e90 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftXPC_$_SwiftGodot
0000000000008e60 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swift_Builtin_float_$_SwiftGodot
0000000000008f98 (__DATA,__objc_classlist) non-external [no dead strip] _objc_classestype metadata for SwiftGodot.OpenXRHand
0000000000008f80 (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate
0000000000008f64 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate : Swift.Hashable in SwiftGodot
0000000000008f60 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate : Swift.Equatable in SwiftGodot
0000000000008f68 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate : Swift.RawRepresentable in SwiftGodot
0000000000008f6c (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate : Swift.CaseIterable in SwiftGodot
0000000000008f78 (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange
0000000000008f44 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange : Swift.Hashable in SwiftGodot
0000000000008f40 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange : Swift.Equatable in SwiftGodot
0000000000008f48 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange : Swift.RawRepresentable in SwiftGodot
0000000000008f4c (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange : Swift.CaseIterable in SwiftGodot
0000000000008f7c (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig
0000000000008f54 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig : Swift.Hashable in SwiftGodot
0000000000008f50 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig : Swift.Equatable in SwiftGodot
0000000000008f58 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig : Swift.RawRepresentable in SwiftGodot
0000000000008f5c (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig : Swift.CaseIterable in SwiftGodot
0000000000008f74 (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand.Hands
0000000000008f34 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.Hands : Swift.Hashable in SwiftGodot
0000000000008f30 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.Hands : Swift.Equatable in SwiftGodot
0000000000008f38 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.Hands : Swift.RawRepresentable in SwiftGodot
0000000000008f3c (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.Hands : Swift.CaseIterable in SwiftGodot
0000000000008f70 (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand
0000000000008f84 (__LLVM,__swift_modhash) non-external [no dead strip] l_llvm.swift_module_hash
The version that does not compile the library with -internalize-at-link has 171 symbols that are flagged with no dead strip, it is large, so I pasted it on github instead.
With the information that so much is coming from fields named âreflectionâ, I Googled, and it looks like I can disable reflection in Swift using -disable-reflection-metadata, this reduced the number of symbols flagged as no dead strip from 56 to 42, but the binary remains at 23 megs, so this was not sufficient.
There are the remaining no dead strip that keep pulling the code:
0000000000018be8 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_hand in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018bd8 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_hand in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018c68 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_bone_update in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018c58 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_bone_update in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018c28 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_motion_range in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018c48 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_skeleton_rig in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018c18 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_motion_range in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018c38 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_skeleton_rig in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018c08 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_get_hand_skeleton in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018bf8 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_hand_skeleton in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
0000000000018bc8 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(className in _0B6DE4D26A8E536FD53858E8549F662E) : SwiftGodot.StringName
0000000000008c30 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftCoreFoundation_$_SwiftGodot
0000000000008c38 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftDispatch_$_SwiftGodot
0000000000008c20 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftFoundation_$_SwiftGodot
0000000000008c48 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftIOKit_$_SwiftGodot
0000000000008c28 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftObjectiveC_$_SwiftGodot
0000000000008c18 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftUniformTypeIdentifiers_$_SwiftGodot
0000000000008c40 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swiftXPC_$_SwiftGodot
0000000000008c10 (__DATA,__const) weak private external [no dead strip] __swift_FORCE_LOAD_$_swift_Builtin_float_$_SwiftGodot
0000000000008d48 (__DATA,__objc_classlist) non-external [no dead strip] _objc_classestype metadata for SwiftGodot.OpenXRHand
0000000000008d30 (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate
0000000000008d14 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate : Swift.Hashable in SwiftGodot
0000000000008d10 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate : Swift.Equatable in SwiftGodot
0000000000008d18 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate : Swift.RawRepresentable in SwiftGodot
0000000000008d1c (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.BoneUpdate : Swift.CaseIterable in SwiftGodot
0000000000008d28 (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange
0000000000008cf4 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange : Swift.Hashable in SwiftGodot
0000000000008cf0 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange : Swift.Equatable in SwiftGodot
0000000000008cf8 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange : Swift.RawRepresentable in SwiftGodot
0000000000008cfc (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.MotionRange : Swift.CaseIterable in SwiftGodot
0000000000008d2c (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig
0000000000008d04 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig : Swift.Hashable in SwiftGodot
0000000000008d00 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig : Swift.Equatable in SwiftGodot
0000000000008d08 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig : Swift.RawRepresentable in SwiftGodot
0000000000008d0c (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.SkeletonRig : Swift.CaseIterable in SwiftGodot
0000000000008d24 (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand.Hands
0000000000008ce4 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.Hands : Swift.Hashable in SwiftGodot
0000000000008ce0 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.Hands : Swift.Equatable in SwiftGodot
0000000000008ce8 (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.Hands : Swift.RawRepresentable in SwiftGodot
0000000000008cec (__TEXT,__swift5_proto) non-external [no dead strip] lprotocol conformance descriptor runtime record for SwiftGodot.OpenXRHand.Hands : Swift.CaseIterable in SwiftGodot
0000000000008d20 (__TEXT,__swift5_types) non-external [no dead strip] lnominal type descriptor runtime record for SwiftGodot.OpenXRHand
0000000000008d34 (__LLVM,__swift_modhash) non-external [no dead strip] l_llvm.swift_module_hash
The classification is roughly like this:
- 10 file private methods are flagged in this way
- One private static variable
classNameis flagged in this way
- 8 symbols prefixed
__swift_FORCE_LOAD_$ and suffixed $_SwiftGodot
- 1
_objc_classestype metadata for SwiftGodot.OpenXRHand
- 21 âdescriptor runtime records' for public enums defined inside that class
This is how this one method:
0000000000018bd8 (__DATA,__bss) non-external [no dead strip] static SwiftGodot.OpenXRHand.(method_set_hand in _0B6DE4D26A8E536FD53858E8549F662E) : Swift.UnsafeRawPointer
Is defined in Swift:
fileprivate static let method_set_hand: GDExtensionMethodBindPtr = {
var methodName = FastStringName("set_hand")
return withUnsafePointer(to: &OpenXRHand.godotClassName.content) { classPtr in
withUnsafePointer(to: &methodName.content) { mnamePtr in
gi.classdb_get_method_bind(classPtr, mnamePtr, 1849328560)!
}
}
}()
This method is invoked by the property named hand, which is curiously not flagged as no dead strip, so the property that calls it manages to get yanked, and I can see no trace of it on the resulting executable, but the fileprivate definition for method_set_hand does make it into the final executable. I end up with some 26,000 of those :-)
This does feel like a bug.