[swift-dev] [RFC] Moving to gold linker

William Dillon william at housedillon.com
Tue Jan 19 10:31:49 CST 2016


>> 
>> Second, Orlando believes that it’s possible to use C++ to generate the object files rather that assembler.  This would make these source files much more portable and easier to maintain.  There is a catch, however. In the assembler version there is no runtime impact at all; the C++ version requires a subtraction at load time.  The cost is pretty minimal, but it’s worth considering.  Changing from one implementation to another is very simple.
> 
> How different is the .s file across platforms? I'd expect it to just contain data directives.
> 

There are very minor differences.  Here are the current files:

swift_begin.S:

#if defined(__arm__)
.section .swift2_protocol_conformances, "aw",%progbits
#else
.section .swift2_protocol_conformances, "aw", at progbits
#endif
.global .swift2_protocol_conformances_start
.swift2_protocol_conformances_start:

#if defined(__x86_64__)
.quad (.swift2_protocol_conformances_end - .swift2_protocol_conformances_start) - 8
#else
.long (.swift2_protocol_conformances_end - .swift2_protocol_conformances_start) - 8
.long 0
#endif


swift_end.S:

#if defined(__arm__)
.section .swift2_protocol_conformances, "aw",%progbits
#else
.section .swift2_protocol_conformances, "aw", at progbits
#endif
.global .swift2_protocol_conformances_end
.swift2_protocol_conformances_end:

Whereas the C++ version would be something like this (for begin):

__attribute__((section(".swift2_protocol_conformances")))
extern char swift2_protocol_conformances_end[] __asm__(".swift2_protocol_conformances_end");

__attribute__((section(".swift2_protocol_conformances")))
long long swift2_protocol_conformances_start __asm__(".swift2_protocol_conformances_start") =
(long long)((char *)&swift2_protocol_conformances_end - (char *)&swift2_protocol_conformances_start - sizeof(swift2_protocol_conformances_start));

So, it’s not necessary to break-out the different sections, the generated initializer for swift2_protocol_conformances_start would have a subtraction.

- Will


More information about the swift-dev mailing list