Description
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 omniosorg/omnios-extra#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:
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.
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:
The build line for these was:
clang-17 -DHAVE_CONFIG_H -I. -DBUILD_INFO='"(local build)"' -DSMARTMONTOOLS_SYSCONFDIR='"/usr/local/etc"' -DSMARTMONTOOLS_SMARTDSCRIPTDIR='"/usr/local/etc"' -DSMARTMONTOOLS_DRIVEDBDIR='"/usr/local/share/smartmontools"' -D_FORTIFY_SOURCE=3 -g -O2 -std=gnu++11 -Wall -W -Wformat=2 -Werror=return-type -fstack-protector-strong -MT ataprint.o -MD -MP -MF .deps/ataprint.Tpo -c -o ataprint.o ataprint.cpp
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.