Skip to content

Instantly share code, notes, and snippets.

@vathpela
Last active April 26, 2022 18:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vathpela/0cede6d6eb5b0ec0791c6afc4282c340 to your computer and use it in GitHub Desktop.
Save vathpela/0cede6d6eb5b0ec0791c6afc4282c340 to your computer and use it in GitHub Desktop.
Fix coverity builds with any gcc in modern history...
From edbb3b49c57f6d33e0b3db1ec87fe93d596f3560 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 9 Nov 2020 15:16:21 -0500
Subject: [PATCH] dammit
---
bin/{cov-emit => cov-emit-real} | Bin
bin/cov-emit | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
rename bin/{cov-emit => cov-emit-real} (100%)
create mode 100755 bin/cov-emit
diff --git a/bin/cov-emit b/bin/cov-emit-real
similarity index 100%
rename from bin/cov-emit
rename to bin/cov-emit-real
diff --git a/bin/cov-emit b/bin/cov-emit
new file mode 100755
index 00000000000..327830e804e
--- /dev/null
+++ b/bin/cov-emit
@@ -0,0 +1,48 @@
+#!/bin/bash
+set -eu
+
+declare -a args
+args=()
+
+if ! [[ -v CC ]] ; then
+ if ! [[ -v COMPILER ]] ; then
+ COMPILER=gcc
+ fi
+ if ! [[ -v CROSS_COMPILER ]] ; then
+ CROSS_COMPILE=""
+ fi
+ CC="${CROSS_COMPILE}${COMPILER}"
+fi
+
+fix-gcc-version() {
+ local gccver
+ gccver="${1}"
+ if [[ ${#1} -lt 4 ]] ; then
+ # shellcheck disable=SC2034
+ gccver="$("${CC}" --version | while read -r ign0 ign1 ver ignN ; do echo "${ver}" ; break ; done)"
+ while [[ $gccver =~ \. ]] ; do
+ gccver="${gccver/./0}"
+ done
+ fi
+ echo "${gccver}"
+}
+
+while [[ $# -gt 0 ]] ; do
+ case " $1 " in
+ " --gnu_version ")
+ args[${#args[@]}]="$1"
+ shift
+ args[${#args[@]}]="$(fix-gcc-version "${1}")"
+ ;;
+ " --gnu_version="*)
+ args[${#args[@]}]="--gnu_version"
+ args[${#args[@]}]="$(fix-gcc-version "${1##--gnu_version=}")"
+ ;;
+ *)
+ args[${#args[@]}]="$1"
+ ;;
+ esac
+ shift
+done
+set -- "${args[@]}"
+exec "${0}-real" "${@}"
--
2.28.0
/*
* fix_coverity.h
* Copyright 2017-2020 Peter Jones <pjones@redhat.com>
*
* We came in peace for all of human kind.
*/
#ifndef FIX_COVERITY_H
#define FIX_COVERITY_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifndef __COVERITY_GCC_VERSION_AT_LEAST
#define __COVERITY_GCC_VERSION_AT_LEAST(x, y) 0
#define FAKE__COVERITY_GCC_VERSION_AT_LEAST__
#endif /* __COVERITY_GCC_VERSION_AT_LEAST */
/* With gcc 7 on x86_64 (at least), coverity pretends to be GCC but
* accidentally doesn't create all of the types GCC would.
*
* In glibc's headers, bits/floatn.h has:
*
* #if (defined __x86_64__ \
* ? __GNUC_PREREQ (4, 3) \
* : (defined __GNU__ ? __GNUC_PREREQ (4, 5) : __GNUC_PREREQ (4, 4)))
* # define __HAVE_FLOAT128 1
* #else
* # define __HAVE_FLOAT128 0
* #endif
*
* and stdlib.h has:
*
* #if __HAVE_FLOAT128 && __GLIBC_USE (IEC_60559_TYPES_EXT)
* slash* Likewise for the '_Float128' format *slash
* extern _Float128 strtof128 (const char *__restrict __nptr,
* char **__restrict __endptr)
* __THROW __nonnull ((1));
* #endif
*
* Which then causes cov-emit to lose its shit:
*
* "/usr/include/stdlib.h", line 133: error #20: identifier "_Float128" is undefined
* extern _Float128 strtof128 (const char *__restrict __nptr,
* ^
* "/usr/include/stdlib.h", line 190: error #20: identifier "_Float128" is undefined
* _Float128 __f)
* ^
* "/usr/include/stdlib.h", line 236: error #20: identifier "_Float128" is undefined
* extern _Float128 strtof128_l (const char *__restrict __nptr,
* ^
*
* And then you'll notice something like this later on:
* [WARNING] Emitted 0 C/C++ compilation units (0%) successfully
*
* 0 C/C++ compilation units (0%) are ready for analysis
* For more details, please look at:
* /home/pjones/devel/github.com/dbxtool/master/cov-int/build-log.txt
*
* You would think that if you're writing something that pretends to be
* gcc, and you've got a "build a configuration by running shit through gcc
* and looking at the output" stage (which they do), you would run "gcc -da
* -fdump-tree-all -c -o foo.o foo.c" on an empty file and snarf up all the
* types defined in the foo.c.001t.tu output. Apparently, they do not.
*
* Anyway, even just defining the type doesn't always work in the face of
* how _Complex is defined, so we cheat a bit here. Be prepared to vomit.
*/
/*
* I'm not actually sure about other arches, so they aren't here. Let me
* know if you see this on other arches and enabling some of it there helps
* there.
*/
#ifdef __x86_64__
# if __COVERITY_GCC_VERSION_AT_LEAST(10, 0)
# define _Float128 _cov_Float128
# define __cfloat128 _cov__cfloat128
# define _Float64 _cov_Float64
# define __cfloat64 _cov__cfloat64
# define _Float32 _cov_Float32
# define __cfloat32 _cov__cfloat32
# define _Float64x _cov_Float64x
# define __cfloat64x _cov__cfloat64x
# define _Float32x _cov_Float32x
# define __cfloat32x _cov__cfloat32x
# include <unistd.h>
# ifdef __cplusplus
# include <bits/floatn.h>
# else
# define __cplusplus 201103L
# include <bits/floatn.h>
# undef __cplusplus
# endif
/*
* I'm not actually sure about 8 or 9, so they aren't here. Let me know if
* one or the other stanza here works for you.
*/
#elif __COVERITY_GCC_VERSION_AT_LEAST(7, 0)
# include <unistd.h>
# define __cplusplus 201103L
# include <bits/floatn.h>
# undef __cplusplus
# endif
#endif
#ifdef FAKE__COVERITY_GCC_VERSION_AT_LEAST__
#undef FAKE__COVERITY_GCC_VERSION_AT_LEAST
#undef __COVERITY_GCC_VERSION_AT_LEAST
#endif
#endif /* !FIX_COVERITY_H */
// vim:fenc=utf-8:tw=75:noet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment