Commit 237dfc8f authored by Sean McBride's avatar Sean McBride

Hack HDF5 to build under ASan & UBSan

Parts of HDF are built as part of VTK’s build process.
It crashes and burns under ASan & UBSan thus preventing all
of VTK from being built & tested with these invaluable tools.
Filed as HDF bug HDFFV-8147 in 2012, but the HDF folks don't
seem willing or able to fix it.
parent cd045139
Pipeline #6294 passed with stage
/* This file performs several undefined behaviors, suppress Undefined
* Behavior Sanitizer (UBSan) from warning.
*/
#if defined(__clang__)
#define HDF_NO_UBSAN __attribute__((no_sanitize("undefined")))
#else
#define HDF_NO_UBSAN
#endif
#ifdef H5_FP_TO_INTEGER_OVERFLOW_WORKS_TEST
int main(void)
int main(void) HDF_NO_UBSAN
{
float f = 2147483648.0f;
int i;
......@@ -15,7 +24,7 @@ int main(void)
#ifdef H5_FP_TO_ULLONG_ACCURATE_TEST
int main(void)
int main(void) HDF_NO_UBSAN
{
float f = 111.60f;
double d = 222.55L;
......@@ -35,7 +44,7 @@ int main(void)
#endif
#ifdef H5_FP_TO_ULLONG_RIGHT_MAXIMUM_TEST
int main(void)
int main(void) HDF_NO_UBSAN
{
float f = 9701917572145405952.00f;
double d1 = 9701917572145405952.00L;
......@@ -66,7 +75,7 @@ int main(void)
#include <stdlib.h>
#include <string.h>
int main(void)
int main(void) HDF_NO_UBSAN
{
void *align;
long double ld = 9701917572145405952.00L;
......@@ -90,7 +99,7 @@ int main(void)
#endif
#ifdef H5_LDOUBLE_TO_LLONG_ACCURATE_TEST
int main(void)
int main(void) HDF_NO_UBSAN
{
long double ld = 20041683600089727.779961L;
long long ll;
......@@ -131,7 +140,7 @@ int main(void)
#endif
#ifdef H5_LDOUBLE_TO_UINT_ACCURATE_TEST
int main(void)
int main(void) HDF_NO_UBSAN
{
long double ld = 2733248032.9183987530L;
unsigned int i;
......@@ -147,7 +156,7 @@ int main(void)
#endif
#ifdef H5_LLONG_TO_LDOUBLE_CORRECT_TEST
int main(void)
int main(void) HDF_NO_UBSAN
{
long double ld;
long long ll;
......@@ -213,7 +222,7 @@ int FC_DUMMY_MAIN()
#endif
#endif
int
main ()
main () HDF_NO_UBSAN
{
char *chp = "beefs";
......@@ -255,7 +264,7 @@ main ()
#include <stdlib.h>
#include <string.h>
int main(void)
int main(void) HDF_NO_UBSAN
{
/* General variables */
int endian;
......@@ -331,7 +340,7 @@ int main(void)
#ifdef H5_ULONG_TO_FLOAT_ACCURATE_TEST
int main(void)
int main(void) HDF_NO_UBSAN
{
int ret = 0;
unsigned long l1;
......@@ -366,7 +375,7 @@ done:
#include <string.h>
int main(void)
int main(void) HDF_NO_UBSAN
{
unsigned long l1;
unsigned long l2;
......
......@@ -58,6 +58,16 @@ static const char *FileHeader = "\n\
#include "H5Tpublic.h"
#include "H5Rpublic.h"
/* This file performs several undefined behaviors, suppress Undefined
* Behavior Sanitizer (UBSan) from warning.
*/
#if defined(__clang__)
#define HDF_NO_UBSAN __attribute__((no_sanitize("undefined")))
#else
#define HDF_NO_UBSAN
#endif
#define MAXDETECT 64
/* The ALIGNMENT test code may generate the SIGBUS, SIGSEGV, or SIGILL signals.
......@@ -1351,7 +1361,7 @@ bit.\n";
*-------------------------------------------------------------------------
*/
static void
detect_C89_integers(void)
detect_C89_integers(void) HDF_NO_UBSAN
{
DETECT_BYTE(signed char, SCHAR, d_g[nd_g]); nd_g++;
DETECT_BYTE(unsigned char, UCHAR, d_g[nd_g]); nd_g++;
......@@ -1379,7 +1389,7 @@ detect_C89_integers(void)
*-------------------------------------------------------------------------
*/
static void
detect_C89_floats(void)
detect_C89_floats(void) HDF_NO_UBSAN
{
DETECT_F(float, FLOAT, d_g[nd_g]); nd_g++;
DETECT_F(double, DOUBLE, d_g[nd_g]); nd_g++;
......@@ -1401,7 +1411,7 @@ detect_C89_floats(void)
*-------------------------------------------------------------------------
*/
static void
detect_C99_integers8(void)
detect_C99_integers8(void) HDF_NO_UBSAN
{
#if H5_SIZEOF_INT8_T>0
#if H5_SIZEOF_INT8_T==1
......@@ -1463,7 +1473,7 @@ detect_C99_integers8(void)
*-------------------------------------------------------------------------
*/
static void
detect_C99_integers16(void)
detect_C99_integers16(void) HDF_NO_UBSAN
{
#if H5_SIZEOF_INT16_T>0
DETECT_I(int16_t, INT16, d_g[nd_g]); nd_g++;
......@@ -1501,7 +1511,7 @@ detect_C99_integers16(void)
*-------------------------------------------------------------------------
*/
static void
detect_C99_integers32(void)
detect_C99_integers32(void) HDF_NO_UBSAN
{
#if H5_SIZEOF_INT32_T>0
DETECT_I(int32_t, INT32, d_g[nd_g]); nd_g++;
......@@ -1539,7 +1549,7 @@ detect_C99_integers32(void)
*-------------------------------------------------------------------------
*/
static void
detect_C99_integers64(void)
detect_C99_integers64(void) HDF_NO_UBSAN
{
#if H5_SIZEOF_INT64_T>0
DETECT_I(int64_t, INT64, d_g[nd_g]); nd_g++;
......@@ -1590,7 +1600,7 @@ detect_C99_integers64(void)
*-------------------------------------------------------------------------
*/
static void
detect_C99_integers(void)
detect_C99_integers(void) HDF_NO_UBSAN
{
/* break it down to more subroutines so that each module subroutine */
/* is smaller and takes less time to compile with optimization on. */
......@@ -1616,7 +1626,7 @@ detect_C99_integers(void)
*-------------------------------------------------------------------------
*/
static void
detect_C99_floats(void)
detect_C99_floats(void) HDF_NO_UBSAN
{
#if H5_SIZEOF_DOUBLE == H5_SIZEOF_LONG_DOUBLE
/*
......@@ -1647,7 +1657,7 @@ detect_C99_floats(void)
*-------------------------------------------------------------------------
*/
static void
detect_alignments(void)
detect_alignments(void) HDF_NO_UBSAN
{
/* Detect structure alignment for pointers, hvl_t, hobj_ref_t, hdset_reg_ref_t */
DETECT_M(void *, POINTER, m_g[na_g]); na_g++;
......@@ -1664,7 +1674,14 @@ detect_alignments(void)
* Return 0 for success, -1 for failure.
*/
static int verify_signal_handlers(int signum, void (*handler)(int))
{
{
/* Under Address Sanitizer, don't raise any signals. */
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
return 0;
#endif
#endif
void (*save_handler)(int) = HDsignal(signum, handler);
int i, val;
int ntries=5;
......@@ -1729,7 +1746,7 @@ static int verify_signal_handlers(int signum, void (*handler)(int))
*-------------------------------------------------------------------------
*/
int
main(void)
main(void) HDF_NO_UBSAN
{
#if defined(H5_HAVE_SETSYSINFO) && defined(SSI_NVPAIRS)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment