Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007681OCamlruntime system and C interfacepublic2017-11-29 00:162017-12-20 17:57
Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0007681: 32-bit gcc potential segfault whith -malign-double
DescriptionWe recently encountered a segfault caused by a 32-bit gcc using -malign-double by default. This option means that all doubles are assumed aligned by gcc, a hypothesis that is typically false for doubles allocated in the OCaml heap.

We saw this problem with i686-w64-mingw32-gcc 6.4.0 under Windows (which activates the -malign-double option by default) with high enough optimisations ("-msse2 -O3").

For correctness it seems it would be best to pass -mno-align-double explicitly to all 32-bit gcc targets (or at the very least for the mingw targets).
Steps To Reproduce(see attached daxpy.c and

$ ocamlc -ccopt -msse2 -ccopt -O3 -ccopt -malign-double -c daxpy.c
$ ocamlopt daxpy.o
$ ./a.out
Segmentation fault (core dumped)
$ ocamlc -ccopt -msse2 -ccopt -O3 -mno-align-double -c daxpy.c
$ ocamlopt daxpy.o
$ ./a.out
TagsNo tags attached.
Attached Filesc file icon daxpy.c [^] (371 bytes) 2017-11-29 00:17 [Show Content]
? file icon [^] (88 bytes) 2017-11-29 00:17 [Show Content]
diff file icon daxpy.s.diff [^] (2,245 bytes) 2017-11-29 10:11 [Show Content]

- Relationships

-  Notes
nojebar (developer)
2017-11-29 10:13

Added file daxpy.s.diff showing the diff between the generated assembly with -malign-double and -mno-align-double. You can see there that "aligned" instructions movaps and movapd are replaced by "unaligned" instructions movups and movupd.
nojebar (developer)
2017-11-29 10:14

Also, you can find out your default -malign-double gcc setting by inspecting

  gcc -Q --help=target
xleroy (administrator)
2017-12-20 17:57

There is a configure-time test to try and see whether doubles need 8-alignment, see config/auto-aux/dblalign.c. However it is easily fooled by clever compilers, hence the many exceptions in the configure script.

- Issue History
Date Modified Username Field Change
2017-11-29 00:16 nojebar New Issue
2017-11-29 00:17 nojebar File Added: daxpy.c
2017-11-29 00:17 nojebar File Added:
2017-11-29 10:11 nojebar File Added: daxpy.s.diff
2017-11-29 10:13 nojebar Note Added: 0018713
2017-11-29 10:14 nojebar Note Added: 0018714
2017-12-20 17:57 xleroy Note Added: 0018758
2017-12-20 17:57 xleroy Status new => acknowledged

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker