Summary: | [regression] llvm18/clang18 produces crashing 32 bit code with -malign-double | ||||||
---|---|---|---|---|---|---|---|
Product: | Base System | Reporter: | Eugene Grosbein <eugen> | ||||
Component: | bin | Assignee: | Dimitry Andric <dim> | ||||
Status: | Open --- | ||||||
Severity: | Affects Some People | CC: | arrowd | ||||
Priority: | --- | Keywords: | regression | ||||
Version: | 15.0-CURRENT | ||||||
Hardware: | i386 | ||||||
OS: | Any | ||||||
Attachments: |
|
Description
Eugene Grosbein
2024-05-09 11:29:03 UTC
# kdump | tail -15 28660 show CALL write(0x1,0x20a09000,0x30) 28660 show GIO fd 1 wrote 48 bytes "To change this login announcement, see motd(5). " 28660 show RET write 48/0x30 28660 show CALL lseek(0x3,0,SEEK_CUR) 28660 show RET lseek 939/0x3ab 28660 show CALL lseek(0x3,0,SEEK_SET) 28660 show RET lseek 0 28660 show CALL lseek(0x3,0x3ab,SEEK_SET) 28660 show RET lseek 939/0x3ab 28660 show CALL close(0x3) 28660 show RET close 0 28660 show PSIG SIGSEGV SIG_DFL code=SEGV_MAPERR 28660 show NAMI "show.core" Yes, that works as advertised. If you want to use -malign-double, you will have to compile the whole system with the same alignment convention. In particular, you need to recompile libc++, at the least. But preferably the whole world. See for example bug 277896, for which I committed https://cgit.freebsd.org/ports/commit/?id=b49518c5c7c16418d7da0a5ce786da139b905bb1, in particular the stern warning: If it is not the architecture default, as it is on amd64, -malign-double should not be used without recompiling basically the entire userspace runtime. Quoting the gcc docs: > Warning: if you use the -malign-double switch, structures containing > the above types are aligned differently than the published application > binary interface specifications for the x86-32 and are not binary > compatible with structures in code compiled without that switch. That's sad: the port databases/xtrabackup80 (formerly xtrabackup8) with previous llvm/clang versions successfully used -malign-double to build and run auxiliary binaries used in build process, as well as its main binary. Now build process fails early because auxiliary binaries work but crash at exit. We have other ports in our tree that use -malign-double, too: audio/penguinsap biology/garlic games/quantumminigolf math/blacs math/fftw3 science/tinker Not to mention databases/xtrabackup8[01]. (In reply to Eugene Grosbein from comment #5) I wonder what the reason for these programs using -malign-double is. Maybe somebody thought that would improve performance? I guess it could, in some cases, but if someone cares about performance, they'd run amd64, not i386. :) The big problem is that with -malign-double, you subtly modify the ABI of every header you include. In lots of cases you can be lucky and not notice anything wrong, but the ABI has been violated anyway: struct members can be at wrong offsets, alignments are off, etc. The only 'safe' way to use it would be to compile *only* the programs themselves using that option, but somehow avoid applying those incompatible settings to all system (and third-party!) includes and libraries that are pulled in. This is also the reason that a global compiler option is a very bad solution for 'improving' the alignment of your own structures: it is much better to selectively add __aligned__ attributes to specific types, of which you *know* (by measuring) that aligning them in a non-default way makes the program go faster... (In reply to Dimitry Andric from comment #6) > I wonder what the reason for these programs using -malign-double is. In case of xtrabackup80, -malign-double helped to deal with mysql80-server codebase braindamage, as xtrabackup contains parts of mysql server code embedded. It cannot be compiled by simply removing -malign-double, as in a commint I just found: https://cgit.freebsd.org/ports/commit/databases/mysql80-server/Makefile?id=b49518c5c7c16418d7da0a5ce786da139b905bb1 |