Issue |
83673
|
Summary |
clang 17 fails to align stack struct with -fstack-protector-strong, building smartmontools
|
Labels |
clang
|
Assignees |
|
Reporter |
citrus-it
|
I searched for any similar issues to this but didn't find anything, so apologies if it's a known issue.
We recently switched the default clang compiler in the OmniOS operating system distribution from 16 to 17, and we had a report that the `smartmontools` package was no longer working correctly.
There is more detail in https://github.com/omniosorg/omnios-extra/issues/1418 but the relevant parts are included below.
The short version is that clang 17 is not aligning `drive` on the stack for some reason in the following code if `-fstack-protector-strong` is in the build flags:
```c
ata_identify_device drive;
memset(&drive, 0, sizeof(drive));
unsigned char raw_drive[sizeof(drive)];
memset(&raw_drive, 0, sizeof(raw_drive));
```
Here's [the context](https://github.com/smartmontools/smartmontools/blob/5feaa21b8989dc32f3dc76d4d7d3b163cef30e41/smartmontools/ataprint.cpp#L3513).
When building with clang 17.0.6, the resulting disassembly shows the misalignment:
```
_Z12ataPrintMainP10ata_deviceRK17ata_print_options+0x3ef: leaq 0xfffffffffffffdc6(%rbp),%rbx
```
which is supported by gdb's interpretation of the DWARF - note that `raw_drive` is aligned as expected.
```
Symbol drive is a variable at frame base reg $rbp offset 0+-570, length 512.
Symbol raw_drive is a variable at frame base reg $rbp offset 0+-1088, length 512.
```
Building with either clang 16 or 18 does not cause this, in both of those cases the variable is properly aligned, as shown below.
```
_Z12ataPrintMainP10ata_deviceRK17ata_print_options+0x3ef: leaq 0xfffffffffffffdc0(%rbp),%rbx
```
Unfortunately I have not been able to come up with a standalone reproducer for this, but I did build the same smartmontools source on Ubuntu 24.04 with clang 17.0.6, and got similar results:
clang17
```
0x000000000000049c <+1068>: lea 0x6ec7(%rsp),%rbx
```
clang18
```
0x0000000000000496 <+1062>: lea 0x6ef0(%rsp),%rbx
```
If there is any more data I can gather on this that would help, please let me know.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs