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-11-29 10:14
Reporternojebar 
Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusnewResolutionopen 
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 crash.ml)

$ ocamlc -ccopt -msse2 -ccopt -O3 -ccopt -malign-double -c daxpy.c
$ ocamlopt daxpy.o crash.ml
$ ./a.out
a=0xb7ce0f34
Segmentation fault (core dumped)
$ ocamlc -ccopt -msse2 -ccopt -O3 -mno-align-double -c daxpy.c
$ ocamlopt daxpy.o crash.ml
$ ./a.out
a=0xb7cbdf34
$
TagsNo tags attached.
Attached Filesc file icon daxpy.c [^] (371 bytes) 2017-11-29 00:17 [Show Content]
? file icon crash.ml [^] (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
(0018713)
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.
(0018714)
nojebar (developer)
2017-11-29 10:14

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

  gcc -Q --help=target

- 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: crash.ml
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


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker