After reallocarray() was added to head, building it on earlier releases
is likely to fail during the bootstrap-tools stage, with something
similar to:
===> usr.bin/m4 (obj,depend,all,install) /usr/obj/home/dim/head/tmp/home/dim/head/usr.bin/m4 created for /home/dim/head/usr.bin/m4 [...] /home/dim/head/usr.bin/m4/misc.c:357:12: warning: implicit declaration of function 'reallocarray' is invalid in C99 [-Wimplicit-function-declaration] void *p = reallocarray(old, s1, s2); ^ /home/dim/head/usr.bin/m4/misc.c:357:8: warning: incompatible integer to pointer conversion initializing 'void *' with an expression of type 'int' [-Wint-conversion] void *p = reallocarray(old, s1, s2); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ 2 warnings generated. [...] clang -O2 -pipe -DEXTENDED -I/home/dim/head/usr.bin/m4 -I/home/dim/head/usr.bin/m4/../../lib/libohash -std=gnu99 -Qunused-arguments -I/usr/obj/home/dim/head/tmp/legacy/usr/include -static -L/usr/obj/home/dim/head/tmp/legacy/usr/lib -o m4 eval.o expr.o look.o main.o misc.o gnum4.o trace.o parser.o tokenizer.o -ly -ll -lm -L/usr/obj/home/dim/head/tmp/home/dim/head/lib/libohash -lohash -legacy misc.o: In function `xreallocarray': /home/dim/head/usr.bin/m4/misc.c:(.text+0xd65): undefined reference to `reallocarray' clang: error: linker command failed with exit code 1 (use -v to see invocation) *** Error code 1
This is because 9.x and 10.x do not have reallocarray() in libc yet.
To work around this:
- Add reallocarray.c to -legacy, and
- Add a wrapper stdlib.h which declares the function.
The latter is needed, because otherwise the compiler would assume an int
return value, which can cause segfaults on 64 bit architectures.