Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Thanks, Coverity.
From f156445e4295392b3bc4ac5714f5f558f1bc26f3 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 18 Oct 2017 12:25:37 -0400
Subject: [PATCH] Work around coverity being a pretty lazy and poor tool.
I mean, come on, at least dynamically import the types you've missed
from the version of GCC that's installed on the system and you're
pretending to emulate.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
src/dbxtool.c | 2 ++
src/esltree.c | 2 ++
src/fix_coverity.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/iter.c | 2 ++
4 files changed, 86 insertions(+)
create mode 100644 src/fix_coverity.h
diff --git a/src/dbxtool.c b/src/dbxtool.c
index 35b5041..5d5efc7 100644
--- a/src/dbxtool.c
+++ b/src/dbxtool.c
@@ -17,6 +17,8 @@
* Author(s): Peter Jones <pjones@redhat.com>
*/
+#include "fix_coverity.h"
+
#include <dirent.h>
#include <efivar.h>
#include <err.h>
diff --git a/src/esltree.c b/src/esltree.c
index 6a4be0c..93852ba 100644
--- a/src/esltree.c
+++ b/src/esltree.c
@@ -17,6 +17,8 @@
* Author(s): Peter Jones <pjones@redhat.com>
*/
+#include "fix_coverity.h"
+
#include <err.h>
#include <search.h>
#include <sys/param.h>
diff --git a/src/fix_coverity.h b/src/fix_coverity.h
new file mode 100644
index 0000000..8660a25
--- /dev/null
+++ b/src/fix_coverity.h
@@ -0,0 +1,80 @@
+/*
+ * fix_coverity.h
+ * Copyright 2017 Peter Jones <pjones@redhat.com>
+ *
+ * Distributed under terms of the GPLv3 license.
+ */
+
+#ifndef FIX_COVERITY_H
+#define FIX_COVERITY_H
+
+#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.
+ *
+ * So if we're in that case, just define the type for the thing.
+ */
+#ifdef __x86_64__
+#if __COVERITY_GCC_VERSION_AT_LEAST(7, 0)
+typedef float _Float128 __attribute__((__vector_size__(128)));
+#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
diff --git a/src/iter.c b/src/iter.c
index 7336365..45ee059 100644
--- a/src/iter.c
+++ b/src/iter.c
@@ -17,6 +17,8 @@
* Author(s): Peter Jones <pjones@redhat.com>
*/
+#include "fix_coverity.h"
+
#include <err.h>
#include <errno.h>
#include <stdlib.h>
--
2.14.2
@chrisbra

This comment has been minimized.

Copy link

chrisbra commented Mar 20, 2018

Hi,
thanks for that patch. That made coverity with gcc 7.3 and vim finally build again (after the service is up again).

@bgoglin

This comment has been minimized.

Copy link

bgoglin commented Mar 20, 2018

Did you report the issue to coverity?

@vathpela

This comment has been minimized.

Copy link
Owner Author

vathpela commented Sep 13, 2018

Did you report the issue to coverity?

Did I report "your closed-source tool hasn't worked in the last couple of years with the free software compiler it claims to be"? No. I'm not on their QA team, and I'm not doing free QA for closed source software.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.