digitalmars.D - Alignment of symbol is not kept during linking
- Yuxuan Shui (16/16) Aug 09 2018 I'm trying to build LDC with dmd and Musl, but the result ldc
- Yuxuan Shui (5/10) Aug 09 2018 SIMD is generated by the C++ compiler, the unaligned read happens
- Kagamin (2/5) Aug 09 2018 The alignment should be specified for section.
- Yuxuan Shui (4/9) Aug 09 2018 The alignment is specified for the section, and it apparently
- Kagamin (4/7) Aug 10 2018 If the section is aligned at 16 bytes and the symbol is aligned
- Yuxuan Shui (4/11) Aug 10 2018 I think you are correct. And I finally found out what is the
I'm trying to build LDC with dmd and Musl, but the result ldc will always crash. I track that down to an unalignment SIMD access to a global variable. Apparently C++ compiler thinks the variable should be aligned to 16 bytes, but it's only aligned to 8 bytes. After some more digging, I find out dmd does try to do the right thing here. In the .o file, the offending symbol is indeed aligned to 16 bytes. But, after linking, that symbol got bumped 8 bytes for some reason. I searched around, and there seems to be no way to specify alignment on symbol, so I don't think the linker is in the wrong here. C compilers would not put variables like that in .data, instead they use SHN_COMMON, and specify alignment there. LDC will just put every symbol into their own section, which also supports alignment. dmd should probably do the same.
Aug 09 2018
Clarifications: On Thursday, 9 August 2018 at 13:30:38 UTC, Yuxuan Shui wrote:I'm trying to build LDC with dmd and Musl, but the result ldc will always crash. I track that down to an unalignment SIMD access to a global variable. Apparently C++ compiler thinks the variable should be aligned to 16 bytes, but it's only aligned to 8 bytes.SIMD is generated by the C++ compiler, the unaligned read happens in C++ code. The accessed variable is a __gshared global variable.
Aug 09 2018
On Thursday, 9 August 2018 at 13:30:38 UTC, Yuxuan Shui wrote:I searched around, and there seems to be no way to specify alignment on symbol, so I don't think the linker is in the wrong here.The alignment should be specified for section.
Aug 09 2018
On Thursday, 9 August 2018 at 13:50:00 UTC, Kagamin wrote:On Thursday, 9 August 2018 at 13:30:38 UTC, Yuxuan Shui wrote:The alignment is specified for the section, and it apparently kept. problem is individual symbols in the section don't have a alignment.I searched around, and there seems to be no way to specify alignment on symbol, so I don't think the linker is in the wrong here.The alignment should be specified for section.
Aug 09 2018
On Thursday, 9 August 2018 at 14:15:31 UTC, Yuxuan Shui wrote:The alignment is specified for the section, and it apparently kept. problem is individual symbols in the section don't have a alignment.If the section is aligned at 16 bytes and the symbol is aligned at 16 bytes in the section, then the symbol will be aligned at 16 bytes, I don't thunk this can go wrong.
Aug 10 2018
On Friday, 10 August 2018 at 08:46:46 UTC, Kagamin wrote:On Thursday, 9 August 2018 at 14:15:31 UTC, Yuxuan Shui wrote:I think you are correct. And I finally found out what is the culprit: The section is not actually aligned. Bug report: https://issues.dlang.org/show_bug.cgi?id=19148The alignment is specified for the section, and it apparently kept. problem is individual symbols in the section don't have a alignment.If the section is aligned at 16 bytes and the symbol is aligned at 16 bytes in the section, then the symbol will be aligned at 16 bytes, I don't thunk this can go wrong.
Aug 10 2018