[swift-dev] Porting swift to FreeBSD

Davide Italiano dccitaliano at gmail.com
Sat Dec 12 23:32:19 CST 2015


On Sun, Dec 13, 2015 at 12:26 AM, Davide Italiano <dccitaliano at gmail.com> wrote:
> On Sun, Dec 13, 2015 at 12:22 AM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>> On Sat, Dec 12, 2015 at 9:09 PM, Davide Italiano <dccitaliano at gmail.com> wrote:
>>> On Sat, Dec 12, 2015 at 11:45 PM, Dmitri Gribenko <gribozavr at gmail.com> wrote:
>>>> On Sat, Dec 12, 2015 at 8:29 PM, Davide Italiano via swift-dev
>>>> <swift-dev at swift.org> wrote:
>>>>> Hi,
>>>>> I'm a FreeBSD developer who has been working on porting swift to FreeBSD.
>>>>> I'm at a point where with a local patch (
>>>>> https://people.freebsd.org/~davide/swift/build_freebsd.diff ) to fix
>>>>> build errors I'm able to build the compiler itself on FreeBSD 11
>>>>> (-CURRENT).
>>>>
>>>> +Doug for this patch.
>>>>
>>>>> The compiler itself seems to work fine (at least semantic analysis is
>>>>> able to produce the correct result for toy examples).
>>>>> Example:
>>>>>
>>>>> % cat hello.swift
>>>>> let number = 4
>>>>> println(number)
>>>>>
>>>>> % ./swiftc hello.swift -o hello
>>>>> hello.swift:2:1: error: 'println' has been renamed to 'print'
>>>>> println(number)
>>>>> ^~~~~~~
>>>>> [...]
>>>>>
>>>>> The executables generated seem to have some problems, though.
>>>>> This is what I see:
>>>>>
>>>>> % cat hello2.swift
>>>>> let number = 4
>>>>> print(number)
>>>>> % ./swiftc hello2.swift -o hello2
>>>>>  % ./hello2
>>>>> Int(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(String(Stri
>>>>
>>>> The reason is that the program can't find the protocol conformance
>>>> tables.  On Linux, we are using a linker script to collect all
>>>> conformances into one section, and insert symbols at the beginning and
>>>> at the end, see stdlib/public/runtime/swift.ld.  The code that reads
>>>> these sections is in stdlib/public/runtime/Casting.cpp.
>>>>
>>>
>>> Thanks Dmitri.
>>> The linker script is actually executed on FreeBSD as well (with a
>>> recent version of GNU ld, with the old ld shipped with FreeBSD or gold
>>> the parsing of the linker script fails)
>>>
>>> and the section is created (as objdump -h witnesses):
>>>
>>>  20 .dtors        00000010  0000000000603218  0000000000603218  00003218  2**3
>>>                   CONTENTS, ALLOC, LOAD, DATA
>>>  21 .swift2_protocol_conformances 00000008  0000000000603228
>>> 0000000000603228  00003228  2**0
>>>                   CONTENTS, ALLOC, LOAD, DATA
>>>  22 .jcr          00000008  0000000000603230  0000000000603230  00003230  2**3
>>>                   CONTENTS, ALLOC, LOAD, DATA
>>>
>>> % objdump -t ./hello | grep conformances
>>> 0000000000603228 l    d  .swift2_protocol_conformances
>>> 0000000000000000              .swift2_protocol_conformances
>>> 0000000000603228 g       .swift2_protocol_conformances
>>> 0000000000000000              .swift2_protocol_conformances_start
>>>
>>> Although the section seems to be empty/corrupted:
>>
>> It should be empty in the binary (since this simple program does not
>> define any new conformances to protocols).  Could you try checking the
>> standard library, libswiftCore.so:
>>
>
>  % objdump -t ./lib/swift/freebsd/x86_64/libswiftCore.so | grep conformances
> 0000000000833710 l    d  .swift2_protocol_conformances
> 0000000000000000              .swift2_protocol_conformances
> 0000000000833710 l     O .swift2_protocol_conformances
> 0000000000002eb0              l_protocol_conformances
> 00000000008365c0 g       .swift2_protocol_conformances
> 0000000000000000              _edata
>
>  % objdump -s -j .swift2_protocol_conformances
> ./lib/swift/freebsd/libswiftCore.so |head -n 10
>
> ./lib/swift/freebsd/libswiftCore.so:     file format elf64-x86-64-freebsd
>
> Contents of section .swift2_protocol_conformances:
>  833710 00000000 00000000 00000000 04000000  ................
>  833720 00000000 00000000 00000000 04000000  ................
>  833730 00000000 00000000 00000000 04000000  ................
>  833740 00000000 00000000 00000000 04000000  ................
>  833750 00000000 00000000 00000000 04000000  ................
>  833760 00000000 00000000 00000000 04000000  ................
>

The main/only difference seem to be in the first 8 bytes of the section.
I'll check why the linker script does not honour this.

Contents of section .swift2_protocol_conformances:
 602b10 b02e0000 00000000 00000000 00000000  ................
 602b20 00000000 04000000 00000000 00000000  ................


More information about the swift-dev mailing list