Page MenuHomeFreeBSD

Provide reallocarray() stub in -legacy to allow building head on 9.x and 10.x
ClosedPublic

Authored by dim on May 15 2015, 8:32 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Feb 9, 5:48 AM
Unknown Object (File)
Sat, Feb 8, 7:15 AM
Unknown Object (File)
Fri, Jan 31, 11:28 AM
Unknown Object (File)
Fri, Jan 31, 10:25 AM
Unknown Object (File)
Jan 9 2025, 3:47 AM
Unknown Object (File)
Dec 1 2024, 12:08 AM
Unknown Object (File)
Nov 19 2024, 7:27 AM
Unknown Object (File)
Nov 18 2024, 4:45 PM
Subscribers

Details

Summary

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.

Test Plan

Build world from various older releases. I verified that this builds
from 9.3-RELEASE, at least to the cross-tools stage.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

dim retitled this revision from to Provide reallocarray() stub in -legacy to allow building head on 9.x and 10.x.
dim updated this object.
dim edited the test plan for this revision. (Show Details)
dim added reviewers: bapt, emaste, imp.
bapt edited edge metadata.
This revision is now accepted and ready to land.May 15 2015, 8:48 PM
This revision was automatically updated to reflect the committed changes.