Bug 212703 - Clang segmentation fault
Summary: Clang segmentation fault
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: Dimitry Andric
URL: https://llvm.org/bugs/show_bug.cgi?id...
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-15 13:16 UTC by Jason W. Bacon
Modified: 2018-05-28 19:36 UTC (History)
2 users (show)

See Also:


Attachments
Debug files saved by clang crash (205.14 KB, application/x-xz)
2016-09-17 01:43 UTC, Jason W. Bacon
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jason W. Bacon freebsd_committer freebsd_triage 2016-09-15 13:16:25 UTC
Looks like this project is a bit overzealous with the compiler flags, so I can probably work around this.

Same error occurs using CXX=clang++37.

[  3%] Building CXX object third_party/vectorGraphics/CMakeFiles/main_svgSample.dir/main.cpp.o                                                                    
cd /usr/wip/graphics/openmvg/work/.build/third_party/vectorGraphics && /usr/bin/c++   -DHAVE_CXX11_CHRONO -DHAVE_CXX11_THREAD -DOPENMVG_USE_CXX11 -I/usr/local/include/eigen3 -O2 -pipe -fstack-protector -fno-strict-aliasing -mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-sse4a -mno-avx -mno-xop -mno-fma4 -mno-avx2 --std=c++11 -fPIC -O3 -o CMakeFiles/main_svgSample.dir/main.cpp.o -c /usr/wip/graphics/openmvg/work/openmvg-2016.09.06/src/third_party/vectorGraphics/main.cpp
Stack dump:
0.      Program arguments: /usr/bin/c++ -cc1 -triple x86_64-unknown-freebsd10.3 -emit-obj -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -relaxed-aliasing -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature -sse2 -target-feature -sse3 -target-feature -ssse3 -target-feature -sse4.1 -target-feature -sse4.2 -target-feature -sse4a -target-feature -avx -target-feature -xop -target-feature -fma4 -target-feature -avx2 -coverage-file /usr/wip/graphics/openmvg/work/.build/third_party/vectorGraphics/CMakeFiles/main_svgSample.dir/main.cpp.o -resource-dir /usr/bin/../lib/clang/3.4.1 -D HAVE_CXX11_CHRONO -D HAVE_CXX11_THREAD -D OPENMVG_USE_CXX11 -I /usr/local/include/eigen3 -internal-isystem /usr/include/c++/v1 -O3 --std=c++11 -fdeprecated-macro -fdebug-compilation-dir /usr/wip/graphics/openmvg/work/.build/third_party/vectorGraphics -ferror-limit 19 -fmessage-length 81 -stack-protector 1 -mstackrealign -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o CMakeFiles/main_svgSample.dir/main.cpp.o -x c++ /usr/wip/graphics/openmvg/work/openmvg-2016.09.06/src/third_party/vectorGraphics/main.cpp 
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module '/usr/wip/graphics/openmvg/work/openmvg-2016.09.06/src/third_party/vectorGraphics/main.cpp'.
4.      Running pass 'X86 Assembly / Object Emitter' on function '@main'
c++: error: unable to execute command: Segmentation fault (core dumped)
c++: error: clang frontend command failed due to signal (use -v to see invocation)
FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: x86_64-unknown-freebsd10.3
Thread model: posix
c++: note: diagnostic msg: PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
c++: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
c++: note: diagnostic msg: /tmp/main-d0045f.cpp
c++: note: diagnostic msg: /tmp/main-d0045f.sh
c++: note: diagnostic msg: 

********************
*** Error code 254

Stop.
make[3]: stopped in /usr/wip/graphics/openmvg/work/.build
*** Error code 1
Comment 1 Jason W. Bacon freebsd_committer freebsd_triage 2016-09-16 04:33:53 UTC
I worked around the issue by removing their OptimizeForArchitecture CMake module.

post-patch:
        ${REINPLACE_CMD} \
                -e '/OptimizeForArchitecture/d' \
                -e 's|-O3|-O2|g' \
                ${WRKSRC}/src/CMakeLists.txt

The port is building successfully with vanilla compiler flags.

If you want to reproduce the problem, look at graphics/openmvg here:

https://github.com/outpaddling/freebsd-ports-wip

Disable the patch shown above and the issue should appear.  I was able to reproduce it on 10.1 and 10.3 amd64.

   Jason
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2016-09-16 07:01:41 UTC
(In reply to Jason Bacon from comment #0)
> PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
> Preprocessed source(s) and associated run script(s) are located at:
> c++: note: diagnostic msg: /tmp/main-d0045f.cpp
> c++: note: diagnostic msg: /tmp/main-d0045f.sh

Can you please attach these two files?
Comment 3 Jason W. Bacon freebsd_committer freebsd_triage 2016-09-17 01:43:56 UTC
Created attachment 174864 [details]
Debug files saved by clang crash

As requested.  The .cpp file was too big for an attachment, hence the tarball.
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2016-09-17 11:56:41 UTC
I can reproduce this with clang trunk r281149; reported upstream as PR30426 [1].

The problem seems to be caused by the openMVG build system disabling use of SSE, and this confuses llvm, because the target is x86_64.  Any idea why openMVG's build system wants this?

I would try to work around it by getting rid of the "-mno-sse2 -mno-sse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -mno-sse4a -mno-avx -mno-xop -mno-fma4 -mno-avx2" flags.  On x86_64, at least SSE2 is always available, there is no good reason to disable it.

[1] https://llvm.org/bugs/show_bug.cgi?id=30426
Comment 5 Jason W. Bacon freebsd_committer freebsd_triage 2016-09-17 13:43:03 UTC
Thanks.

Their OptimizeForArchitecture.cmake module is 473 lines long and has not been tested on many platforms, so I'm not surprised it has bugs.

I've already worked around it by replacing the module with a simple -O2.  That should be the default for packaging anyway.  If I have time in the future I may try to fix it offer it as a port option.

I mainly wanted to report the problem so the clang seg fault could be isolated.

Regards,

   JB
Comment 6 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:36:26 UTC
Newer clang has since been imported and I don't believe this is an issue anymore.