[swift-dev] Metadata Representation
Saleem Abdulrasool
compnerd at compnerd.org
Thu Sep 21 11:32:15 CDT 2017
Hello,
The current layout for the swift metadata for structure types, as emitted,
seems to be unrepresentable in PE/COFF (at least for x86_64). There is a
partial listing of the generated code following the message for reference.
When building the standard library, LLVM encounters a relocation which
cannot be represented. Tracking down the relocation led to the type
metadata for SwiftNSOperatingSystemVersion. The metadata here is
_T0SC30_SwiftNSOperatingSystemVersionVN. At +32-bytes we find the Kind
(1). So, this is a struct metadata type. Thus at Offset 1 (+40 bytes) we
have the nominal type descriptor reference. This is the relocation which
we fail to represent correctly. If I'm not mistaken, it seems that the
field is supposed to be a relative offset to the nominal type descriptor.
However, currently, the nominal type descriptor is emitted in a different
section (.rodata) as opposed to the type descriptor (.data). This
cross-section relocation cannot be represented in the file format.
My understanding is that the type metadata will be adjusted during the load
for the field offsets. Furthermore, my guess is that the relative offset
is used to encode the location to avoid a relocation for the load address
base. In the case of windows, the based relocations are a given, and I'm
not sure if there is a better approach to be taken. There are a couple of
solutions which immediately spring to mind: moving the nominal type
descriptor into the (RW) data segment and the other is to adjust the ABI to
use an absolute relocation which would be rebased. Given that the type
metadata may be adjusted means that we cannot emit it into the RO data
segment. Is there another solution that I am overlooking which may be
simpler or better?
Thanks!
```
.section .rdata,"dr"
...
.globl _T0SC30_SwiftNSOperatingSystemVersionVMn #
@_T0SC30_SwiftNSOperatingSystemVersionVMn
.p2align 3
_T0SC30_SwiftNSOperatingSystemVersionVMn:
.long .L__unnamed_1056-_T0SC30_SwiftNSOperatingSystemVersionVMn
.long 3 # 0x3
.long 3 # 0x3
.long
(.L__unnamed_1057-_T0SC30_SwiftNSOperatingSystemVersionVMn)-12
.long
(.Lget_field_types__SwiftNSOperatingSystemVersion-_T0SC30_SwiftNSOperatingSystemVersionVMn)-16
.long 1 # 0x1
.long 0 # 0x0
.long 6 # 0x6
.long 0 # 0x0
.long 0 # 0x0
.long 0 # 0x0
.data
.globl _T0SC30_SwiftNSOperatingSystemVersionVN #
@_T0SC30_SwiftNSOperatingSystemVersionVN
.p2align 3
_T0SC30_SwiftNSOperatingSystemVersionVN:
.quad .L__unnamed_1056
.quad 0
.quad 0 # 0x0
.quad _T0SC30_SwiftNSOperatingSystemVersionVWV
.quad 1 # 0x1
.quad
(_T0SC30_SwiftNSOperatingSystemVersionVMn-_T0SC30_SwiftNSOperatingSystemVersionVN)-40
.quad 0
.quad 0 # 0x0
.quad 8 # 0x8
.quad 16 # 0x10
```
--
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20170921/2aa2455b/attachment.html>
More information about the swift-dev
mailing list