bind9/lib/irs
Michał Kępień 77dc5be6b4 Include <sched.h> where necessary for musl libc
All unit tests define the UNIT_TESTING macro, which causes <cmocka.h> to
replace malloc(), calloc(), realloc(), and free() with its own functions
tracking memory allocations.  In order for this not to break
compilation, the system header declaring the prototypes for these
standard functions must be included before <cmocka.h>.

Normally, these prototypes are only present in <stdlib.h>, so we make
sure it is included before <cmocka.h>.  However, musl libc also defines
the prototypes for calloc() and free() in <sched.h>, which is included
by <pthread.h>, which is included e.g. by <isc/mutex.h>.  Thus, unit
tests including "dnstest.h" (which includes <isc/mem.h>, which includes
<isc/mutex.h>) after <cmocka.h> will not compile with musl libc as for
these programs, <sched.h> will be included after <cmocka.h>.

Always including <cmocka.h> after all other header files is not a
feasible solution as that causes the mock assertion macros defined in
<isc/util.h> to mangle the contents of <cmocka.h>, thus breaking
compilation.  We cannot really use the __noreturn__ or analyzer_noreturn
attributes with cmocka assertion functions because they do return if the
tested condition is true.  The problem is that what BIND unit tests do
is incompatible with Clang Static Analyzer's assumptions: since we use
cmocka, our custom assertion handlers are present in a shared library
(i.e. it is the cmocka library that checks the assertion condition, not
a macro in unit test code).  Redefining cmocka's assertion macros in
<isc/util.h> is an ugly hack to overcome that problem - unfortunately,
this is the only way we can think of to make Clang Static Analyzer
properly process unit test code.  Giving up on Clang Static Analyzer
being able to properly process unit test code is not a satisfactory
solution.

Undefining _GNU_SOURCE for unit test code could work around the problem
(musl libc's <sched.h> only defines the prototypes for calloc() and
free() when _GNU_SOURCE is defined), but doing that could introduce
discrepancies for unit tests including entire *.c files, so it is also
not a good solution.

All in all, including <sched.h> before <cmocka.h> for all affected unit
tests seems to be the most benign way of working around this musl libc
quirk.  While quite an ugly solution, it achieves our goals here, which
are to keep the benefit of proper static analysis of unit test code and
to fix compilation against musl libc.

(cherry picked from commit 59528d0e9d)
2019-07-30 21:25:30 +02:00
..
include Drop ISC_PLATFORM_USEDECLSPEC and IRS_PLATFORM_USEDECLSPEC as they are platform dependent and only unix vs win32 platform.h header difference is enough 2018-09-07 12:17:30 +02:00
tests Include <sched.h> where necessary for musl libc 2019-07-30 21:25:30 +02:00
win32 look in windows registry for nameservers, domainname and search list 2018-11-09 16:06:49 +11:00
api documentation changes establishing the 9.14 stable branch 2019-02-27 18:06:35 -05:00
context.c isc_mutex_init returns 'void' 2018-11-22 11:51:49 +00:00
dnsconf.c Replace custom isc_u?intNN_t types with C99 u?intNN_t types 2018-08-08 09:37:28 +02:00
gai_strerror.c gai_strerror on Windows is just 'char *' 2018-08-29 22:05:09 +02:00
getaddrinfo.c ensure that WSAStartup is called before getservbyname 2019-01-15 14:19:59 +11:00
getnameinfo.c Hint the compiler with ISC_UNREACHABLE(); that code after INSIST(0); cannot be reached 2018-11-08 12:22:17 +07:00
Kyuafile regen master 2017-12-29 01:44:18 +00:00
Makefile.in Make OpenSSL mandatory 2018-07-19 12:47:03 -04:00
resconf.c look in windows registry for nameservers, domainname and search list 2018-11-09 16:06:49 +11:00
version.c address win32 build issues 2018-05-22 16:32:21 -07:00