Scan service and "This platform is not supported by Coverity" - xcode

I'm trying to submit a scan under OS X. The procedure I am following works great under 32-bit and 64-bit Linux, and a similar procedure works great under Winows with nmake. On OS X cov-build is failing with:
$ CXXFLAGS="-DNDEBUG -g2 -O3" cov-build --dir cov-int make -j 2
Coverity Build Capture (64-bit) version 8.5.0.3 on Darwin 12.6.0 x86_64
Internal version numbers: db70178643 p-kent-push-26368.949
Platform info:
Sysname = Darwin
Release = 12.6.0
Machine = x86_64
[ERROR] This platform is not supported by Coverity.
[ERROR] See documentation for the list of supported platforms.
A different OS X machine produces the same error:
$ CXXFLAGS="-DNDEBUG -g2 -O3" cov-build --dir cov-int make -j 2
Coverity Build Capture (64-bit) version 8.5.0.3 on Darwin 13.4.0 x86_64
Internal version numbers: db70178643 p-kent-push-26368.949
Platform info:
Sysname = Darwin
Release = 13.4.0
Machine = x86_64
[ERROR] This platform is not supported by Coverity.
[ERROR] See documentation for the list of supported platforms.
I'm having trouble locating the documentation:
$ cov-build --help
Coverity Build Capture (64-bit) version 8.5.0.3 on Darwin 12.6.0 x86_64
Internal version numbers: db70178643 p-kent-push-26368.949
No help found for 'cov-build'
Coverity Data Sheet states OS X is supported, and a press release states OS X 10.8 is supported.
AIX
FreeBSD
HP-UX
Linux
Mac OS X
NetBSD
Solaris
Windows
Why am I receiving [ERROR] This platform is not supported by Coverity, and how do I fix it?

The issue is that Mac OSX 10.8 isn't supported in the Coverity release you're using. It's somewhat common for Apple to break compatibility with Coverity with OS releases, unfortunately.
You can export COVERITY_UNSUPPORTED=1. This will bypass the platform support check, however there's no guarantee things will work as expected. You do have reasonably good odds of success.

This builds on Flash Sheridan and Caleb's suggestions. The problem was less with the platform and more with the compiler. Xcode 5.0 and 5.1 produced the scan build failure:
CXXFLAGS="-DNDEBUG -g2 -O3" cov-build --dir cov-int make -j 2
...
cat cov-int/build-log.txt
...
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../
lib/clang/5.0/include/stddef.h", line 29: error #109:
expression preceding parentheses of apparent call must have
(pointer-to-) function type
#if !defined(_PTRDIFF_T) || __has_feature(modules)
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../
lib/clang/5.0/include/stddef.h", line 31: error #59:
function call is not allowed in a constant expression
#if !__has_feature(modules)
...
The second work-around depends on Flash Sheridan and Caleb's workaround. It adds "use a different compiler". Below, we use MacPorts Clang 3.7 to perform a scan build.
$ CXX=/opt/local/bin/clang++-mp-3.7 COVERITY_UNSUPPORTED=1 CXXFLAGS="-DNDEBUG -g3 -O2" cov-build --dir cov-int make -j 8
Coverity Build Capture (64-bit) version 8.5.0.3 on Darwin 12.6.0 x86_64
Internal version numbers: db70178643 p-kent-push-26368.949
/opt/local/bin/clang++-mp-3.7 -DNDEBUG -g3 -O2 -fPIC -march=native -pipe -c cryptlib.cpp
/opt/local/bin/clang++-mp-3.7 -DNDEBUG -g3 -O2 -fPIC -march=native -pipe -c cpu.cpp
...
Emitted 134 C/C++ compilation units (100%) successfully
134 C/C++ compilation units (100%) are ready for analysis
The cov-build utility completed successfully.
For anyone interested, we are a Free and Open Source Software project, and we take advantage of the Coverity Scan Service at no charge. However, the documentation is kind of light.
If you want prescriptive instructions for performing Scan Builds for Unix, Linux, OS X and Windows, then see Crypto++ wiki | Coverity Scan.

Related

ffmpeg refuses to compile for x86_64 arch on M1 mac

I'm trying to build a universal binary of ffmpeg on MacOS, by compiling it twice (for arm64 and x86_64) and then using the lipo tool to combine the resulting binaries. I'm on an M1 Mac, so uname -m returns arm64 on my machine.
When running the configure script like so:
./configure --arch=x86_64
It outputs:
install prefix /usr/local
source path .
C compiler gcc
C library
ARCH c (generic)
...
And after running make, inspecting the built binaries with lipo -archs reveals that it's building them for arm64.
The result is the same if I add --enable-crosscompile to the configure call.
Based on this post, I also tried --arch=x86, but that had the exact same result, configure script displayed arch as c (generic) and inspecting artefacts with lipo shows they are built for arm64 architecture.
Does anyone have any ideas? Why is the configure script just refusing to build for x86_64?
You can speify -cc to make clang compile x86_64 binary.
Try:
./configure --enable-cross-compile --prefix=./install_x86_64 --arch=x86_64 --cc='clang -arch x86_64'
Note: don't forget to clear the outdated files by
make distclean
By the way, I have successfully built universal binrary of FFmpeg, you can refer to my build scripts. make_compile.py compile both x86_64 and arm64 binraries, and make_universal.py use lipo to generate universal binrary.
Reference
https://ffmpeg.org/platform.html
https://github.com/FFmpeg/gas-preprocessor

How to build an Intel binary on an M1 Mac from the command line with the standard Apple version of clang?

I'm playing with some C code on my M1 MacBook Air and looking at the assembly produced with various optimization levels.
I'm building a single C file from the commandline with the most basic command:
cc foo.c -o foo
What switch do I use to build an Intel binary instead of ARM? Are there different flavours of Intel? 32 vs 64 bit? Maybe even older CPU instruction sets? This is surprisingly hard to Google for, but I'm new to the Apple ecosystem.
What about fat binaries? How would I build a single binary that contained both Intel and ARM code from the commandline?
(For the purposes of this question I'm only interested in what I can do on the commandline. If I need to set up XCode projects or environment variables, then I'll accept an answer that just says "You can't do it with just the commandline".)
Intel 32 bit is not executable on macOS since Catalina. Every Mac since 2006, except the original Intel Mac mini with Core Solo processor, is 64 bit capable.
Intel:
clang -o myTool-x86_64 -mmacosx-version-min=10.15 -arch x86_64 main.c
ARM64:
clang -o myTool-arm64 -mmacosx-version-min=10.15 -arch arm64 main.c
FAT binary:
lipo myTool-x86_64 myTool-arm64 -create -output myTool

How to cross compile solaris 32-bit

We are currently building our Go executables for several platforms including Solaris 64-bit. We have requests for a 32-bit Solaris executable version as well and I am unable to get this to work (the person who setup the Solaris 64-bit cross compiler is gone and unreachable).
I tried just setting -m32 flag on go build using our existing solaris cross compilation, but that didn't work, so I am attempting to build a Solaris 32-bit specific cross compiler.
I googled and found some vague examples, so I am following this process:
Copy headers and libraries from a 32-bit Solaris machine to my Linux build machine.
D/L and build binutils and gcc pointing SYSROOT to the downloaded 32-bit Solaris headers and libraries where:
$TARGET=sparc-sun-solaris2.10
$SYSROOT=/path/to/solaris32/includes
$PREFIX=/path/to/gcc-output
binutils-2.31/configure -target=$TARGET --prefix=$PREFIX -with-sysroot=$SYSROOT -v
gcc-8.2.0/configure --target=$TARGET --with-gnu-as --with-gnu-ld --prefix=$PREFIX -with-sysroot=$SYSROOT --disable-libgcj --enable-languages=c,c++,go -v
Create a symlink to gogcc and put GCC on the path
Compile a trivial test go program like this:
go build --compiler gccgo --gccgoflags "-m32 -O3 -static-libgo -Wl,-dy -lnsl -lsocket -lrt -lsendfile" -o ${GOTOOLS}/${BINARIES}/${PROJECT_NAME}/test/solaris_sparc32 test/main.go
This fails as follows:
go build: when using gccgo toolchain, please pass compiler flags using -gccgoflags, not -gcflags
command-line-arguments
gccgo: error: may not use both -m32 and -m64
Clearly I don't know what I'm doing. Can anyone point me in the right direction?
Solaris 32-bit does not appear to be supported, according to the list of supported OS/arch targets:
The valid combinations of $GOOS and $GOARCH are:
$GOOS $GOARCH
...
solaris amd64
...
That is, Solaris 64-bit is explicitly listed as a supported platform but Solaris 32-bit is not listed.
As such, there is good reason to believe that go programs will not run reliably on Solaris 32-bit systems and you probably should not agree to support that platform (if you do happen to get that cross compilation working) mainly because the go team itself does not support it!

Build Python 2.7.12 on a Mac with Intel compiler

I've been trying to build Python from source on my mac with the Intel compiler suite (Intel Parallel Studio) and link it against Intel's MKL.
The reason for that is that I want to use the exactly the same environment on my mac for developing Python code as on our linux cluster.
As long as I am not telling the configure script to use Intel's parallel studio, Python builds fine (configure and make: ./configure --with(out)-gcc). But as soon as I include --with-icc, or if I set the appropriate environment variables, mentioned in ./configure --help, to the Intel compilers and linkers, make fails with:
icc -c -fno-strict-aliasing -fp-model strict -g -O2 -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -IInclude -I./Include -DPy_BUILD_CORE -o Python/getcompiler.o Python/getcompiler.c
Python/getcompiler.c(27): error: expected a ";"
return COMPILER;
^
compilation aborted for Python/getcompiler.c (code 2)
make: *** [Python/getcompiler.o] Error 2
I've searched everywhere, but nobody seems to be interested in building Python on a mac with intel compilers, or I am the only one who has problems with it. I've also configured my environment according to Intel's instructions: source /opt/intel/bin/compilervars.sh intel64, in ~/.bash_profile.
In any case, my environment is:
OS X 10.11.6
Xcode 8.1 / Build version 8B62
Intel Parallel Studio XE 2017.0.036 (C/C++, Fortran)
Thanks,
François
You could edit the line in getcompiler.c that it is complaining about:
e.g. to
return "[Intel compiler]";
If you wanted to get fancier you could add in the compiler version, using e.g. the __INTEL_COMPILER macro.

How do I make `go get` to build against x86_64 instead of i386

I am trying to use either go-qml or gotk3 to build a very simple desktop app that can run under OS X. However when I try to use go get to install either library, it will try to build for i386 and skip the libraries that were build against x86_64. I could try to get the 32 bit version of those libraries, but I would prefer to build for 64bit. How do I instruct go get to do so?
The warnings that are followed by errors look lie this:
go get gopkg.in/qml.v1
# gopkg.in/qml.v1
ld: warning: ld: warning: ld: warning: ignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtWidgets.framework/QtWidgets, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtWidgets.framework/QtWidgetsignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtGui.framework/QtGui, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtGui.framework/QtGuiignoring file /usr/local/Cellar/qt5/5.3.2/lib/QtQuick.framework/QtQuick, file was built for x86_64 which is not the architecture being linked (i386): /usr/local/Cellar/qt5/5.3.2/lib/QtQuick.framework/QtQuick
Set the environment variable GOARCH to the value amd64. This instructs the go command to generate files for amd64. Other valid values for GOARCH are 386 and arm.
F.Y.I.
The Go compilers support the following instruction sets:
amd64, 386
The x86 instruction set, 64- and 32-bit.
arm64, arm
The ARM instruction set, 64-bit (AArch64) and 32-bit.
mips64, mips64le, mips, mipsle
The MIPS instruction set, big- and little-endian, 64- and 32-bit.
ppc64, ppc64le
The 64-bit PowerPC instruction set, big- and little-endian.
riscv64
The 64-bit RISC-V instruction set.
s390x
The IBM z/Architecture.
wasm
WebAssembly.
(from: Introduction | Installing Go from source | Doc # golang.org)
Also, you can go tool dist list to check the available architectures to build in your machine.
$ go tool dist list
aix/ppc64
android/386
android/amd64
android/arm
android/arm64
darwin/amd64
darwin/arm64
dragonfly/amd64
freebsd/386
(* snip *)
To build a static binary for macOS (Intel/ARM64) would be as below. In this manner, I suppose GOOS="darwin" GOARCH="arm64" combination will be for M1 architecture.
MyVar="foo"
CGO_ENABLED=0 \
GOOS="darwin" \
GOARCH="amd64" \
GOARM="" \
go build \
-ldflags="-s -w -extldflags \"-static\" -X 'main.myVar=${MyVar}'" \
-o="/path/to/export/bin/myApp" \
"/path/to/main.go"
To compile for Linux on ARM v6, such as RaspberryPi Zero W, the combination would be as below.
$ CGO_ENABLED=0 GOOS="linux" GOARCH="arm" GOARM="6" go build .

Resources