1From bcc6816b92ecf409357865589069a82883d589f7 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Tue, 6 Sep 2022 22:53:51 -0700
4Subject: [PATCH] scripts/build: Fix the tests to build with clang15
5
6Upstream-Status: Pending
7Signed-off-by: Khem Raj <raj.khem@gmail.com>
8---
9 scripts/build | 50 +++++++++++++++++++++++++-------------------------
10 1 file changed, 25 insertions(+), 25 deletions(-)
11
12--- a/scripts/build
13+++ b/scripts/build
14@@ -21,7 +21,7 @@ trap 'rm -f ${BASE}$$.s ${BASE}$$.c ${BA
15 LDLIBS="$LDLIBS -lm"
16
17 # check for HP-UX's ANSI compiler
18-echo "main(int ac, char *av[]) { int i; }" > ${BASE}$$.c
19+echo "int main(int ac, char *av[]) { int i; }" > ${BASE}$$.c
20 if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL}
21 then
22 	true;
23@@ -39,7 +39,7 @@ arch=`echo $OS | awk -F- '{print $1;}'`
24 if [ "X$CC" = "Xcc" -a "X$arch" = "Xia64" ]
25 then
26 	echo "#include <stdlib.h>" > ${BASE}$$.c
27-	echo "main(int ac, char *av[])" >> ${BASE}$$.c
28+	echo "int main(int ac, char *av[])" >> ${BASE}$$.c
29 	echo "{ long* p = (long*)malloc(sizeof(long));" >> ${BASE}$$.c
30 	echo "*p = 0; exit((int)*p); }" >> ${BASE}$$.c
31 	${CC} ${CFLAGS} +DD64 -o ${BASE}$$ ${BASE}$$.c 1>${NULL} 2>${NULL} \
32@@ -51,14 +51,14 @@ fi
33
34 # check for bcopy (optionally set the SYS5 flag)
35 echo "#include <string.h>" > ${BASE}$$.c
36-echo "main() { char a[256], b[256]; bcopy(a, b, 256); }" >> ${BASE}$$.c
37+echo "int main() { char a[256], b[256]; bcopy(a, b, 256); }" >> ${BASE}$$.c
38 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
39 	|| CFLAGS="${CFLAGS} -DSYS5"
40 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
41
42 # check for valloc
43 echo "#include <stdlib.h>" > ${BASE}$$.c
44-echo "main() { char* buf = valloc(123); }" >> ${BASE}$$.c
45+echo "int main() { char* buf = valloc(123); }" >> ${BASE}$$.c
46 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
47 	|| CFLAGS="${CFLAGS} -Dvalloc=malloc"
48 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
49@@ -67,7 +67,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
50 echo "#include <stdlib.h>" > ${BASE}$$.c
51 echo "#include <sys/types.h>" >> ${BASE}$$.c
52 echo "#include <unistd.h>" >> ${BASE}$$.c
53-echo "main() { off64_t off; }" >> ${BASE}$$.c
54+echo "int main() { off64_t off; }" >> ${BASE}$$.c
55 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
56 	&& CFLAGS="${CFLAGS} -DHAVE_off64_t"
57 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
58@@ -76,7 +76,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
59 echo "#include <stdlib.h>" > ${BASE}$$.c
60 echo "#include <sys/types.h>" >> ${BASE}$$.c
61 echo "#include <unistd.h>" >> ${BASE}$$.c
62-echo "main() { int fd = 0; off64_t off = 0; off = lseek64(fd, off, SEEK_SET); }" >> ${BASE}$$.c
63+echo "int main() { int fd = 0; off64_t off = 0; off = lseek64(fd, off, SEEK_SET); }" >> ${BASE}$$.c
64 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
65 	&& CFLAGS="${CFLAGS} -DHAVE_lseek64"
66 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
67@@ -88,7 +88,7 @@ echo "#include <sys/resource.h>" >> ${BA
68 echo "#ifndef RUSAGE_SELF" >> ${BASE}$$.c
69 echo "#define RUSAGE_SELF 0" >> ${BASE}$$.c
70 echo "#endif /* RUSAGE_SELF */" >> ${BASE}$$.c
71-echo "main() { struct rusage ru; getrusage(RUSAGE_SELF, &ru); }" >> ${BASE}$$.c
72+echo "int main() { struct rusage ru; getrusage(RUSAGE_SELF, &ru); }" >> ${BASE}$$.c
73 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
74 	&& CFLAGS="${CFLAGS} -DRUSAGE"
75 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
76@@ -125,24 +125,24 @@ fi
77 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
78
79 # check for -lrpc (cygwin/Windows)
80-echo "extern int pmap_set(); main() { pmap_set(); }" >${BASE}$$.c
81+echo "extern int pmap_set(void); int main() { pmap_set(); }" >${BASE}$$.c
82 if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
83        true;
84-else
85-       ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} -lrpc 1>${NULL} 2>${NULL} \
86-               && LDLIBS="${LDLIBS} -lrpc"
87+elif ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} -lrpc 1>${NULL} 2>${NULL}; then
88+      LDLIBS="${LDLIBS} -lrpc"
89+else ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} -ltirpc 1>${NULL} 2>${NULL} && LDLIBS="${LDLIBS} -ltirpc"
90 fi
91 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
92
93 # check for OSs that have S_IFFIFO instead of S_IFIFO
94 echo "#include <sys/stat.h>" > ${BASE}$$.c
95-echo "main() { return (S_IFIFO); }" >> ${BASE}$$.c
96+echo "int main() { return (S_IFIFO); }" >> ${BASE}$$.c
97 if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
98 	true;
99 else
100 	rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
101 	echo "#include <sys/stat.h>" > ${BASE}$$.c
102-	echo "main() { return (S_IFFIFO); }" >> ${BASE}$$.c
103+	echo "int main() { return (S_IFFIFO); }" >> ${BASE}$$.c
104 	${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
105 		|| CFLAGS="${CFLAGS} -DS_IFIFO=S_IFFIFO"
106 fi
107@@ -151,7 +151,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
108 # check that we have uint
109 echo "#include <stdlib.h>" > ${BASE}$$.c
110 echo "#include <sys/types.h>" >> ${BASE}$$.c
111-echo "main() { uint i = 0; return (i); }" >> ${BASE}$$.c
112+echo "int main() { uint i = 0; return (i); }" >> ${BASE}$$.c
113 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
114 	&& CFLAGS="${CFLAGS} -DHAVE_uint=1";
115 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
116@@ -161,7 +161,7 @@ HAVE_uint64=0
117 echo "#include <stdlib.h>" > ${BASE}$$.c
118 echo "#include <sys/types.h>" >> ${BASE}$$.c
119 echo "#include <rpc/types.h>" >> ${BASE}$$.c
120-echo "main() { uint64 i = 0; return (int)(i); }" >> ${BASE}$$.c
121+echo "int main() { uint64 i = 0; return (int)(i); }" >> ${BASE}$$.c
122 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
123 	&& CFLAGS="${CFLAGS} -DHAVE_uint64=1" && HAVE_uint64=1;
124 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
125@@ -170,7 +170,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
126 if [ ${HAVE_uint64} = 0 ]; then
127     echo "#include <stdlib.h>" > ${BASE}$$.c
128     echo "#include <sys/types.h>" >> ${BASE}$$.c
129-    echo "main() { uint64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
130+    echo "int main() { uint64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
131     ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
132 	&& CFLAGS="${CFLAGS} -DHAVE_uint64_t=1";
133     rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
134@@ -181,7 +181,7 @@ HAVE_int64=0
135 echo "#include <stdlib.h>" > ${BASE}$$.c
136 echo "#include <sys/types.h>" >> ${BASE}$$.c
137 echo "#include <rpc/types.h>" >> ${BASE}$$.c
138-echo "main() { int64 i = 0; return (int)(i); }" >> ${BASE}$$.c
139+echo "int main() { int64 i = 0; return (int)(i); }" >> ${BASE}$$.c
140 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
141 	&& CFLAGS="${CFLAGS} -DHAVE_int64=1" && HAVE_int64=1;
142 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
143@@ -190,7 +190,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
144 if [ ${HAVE_int64} = 0 ]; then
145     echo "#include <stdlib.h>" > ${BASE}$$.c
146     echo "#include <sys/types.h>" >> ${BASE}$$.c
147-    echo "main() { int64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
148+    echo "int main() { int64_t i = 0; return (int)(i); }" >> ${BASE}$$.c
149     ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
150 	&& CFLAGS="${CFLAGS} -DHAVE_int64_t=1";
151     rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
152@@ -209,7 +209,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
153 echo "#include <stdlib.h>" > ${BASE}$$.c
154 echo "#include <sys/types.h>" >> ${BASE}$$.c
155 echo "#include <sys/socket.h>" >> ${BASE}$$.c
156-echo "main() { int s; struct sockaddr dest; socklen_t len; getsockname(s, &dest, &len); }" >> ${BASE}$$.c
157+echo "int main() { int s; struct sockaddr dest; socklen_t len; getsockname(s, &dest, &len); }" >> ${BASE}$$.c
158 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
159 	&& CFLAGS="${CFLAGS} -DHAVE_socklen_t"
160 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
161@@ -217,7 +217,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
162 # check that we have drand48 and srand48
163 HAVE_RANDOM=0
164 echo "#include <stdlib.h>" > ${BASE}$$.c
165-echo "main() { srand48(973); return (int)(1.0E9 * drand48()); }" >> ${BASE}$$.c
166+echo "int main() { srand48(973); return (int)(1.0E9 * drand48()); }" >> ${BASE}$$.c
167 if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
168 	CFLAGS="${CFLAGS} -DHAVE_DRAND48"
169 	HAVE_RANDOM=1
170@@ -226,7 +226,7 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
171
172 if [ ${HAVE_RANDOM} -eq 0 ]; then
173     echo "#include <stdlib.h>" > ${BASE}$$.c
174-    echo "main() { srand(973); return (10 * rand()) / RAND_MAX; }" >> ${BASE}$$.c
175+    echo "int main() { srand(973); return (10 * rand()) / RAND_MAX; }" >> ${BASE}$$.c
176     if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
177 	CFLAGS="${CFLAGS} -DHAVE_RAND"
178 	HAVE_RANDOM=1
179@@ -236,7 +236,7 @@ fi
180
181 if [ ${HAVE_RANDOM} -eq 0 ]; then
182     echo "#include <stdlib.h>" > ${BASE}$$.c
183-    echo "main() { srandom(973); return (10 * random()) / RAND_MAX; }" >> ${BASE}$$.c
184+    echo "int main() { srandom(973); return (10 * random()) / RAND_MAX; }" >> ${BASE}$$.c
185     if ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL}; then
186 	CFLAGS="${CFLAGS} -DHAVE_RANDOM"
187 	HAVE_RANDOM=1
188@@ -247,7 +247,7 @@ fi
189 # check that we have sysmp
190 echo "#include <sys/types.h>" > ${BASE}$$.c
191 echo "#include <sys/sysmp.h>" >> ${BASE}$$.c
192-echo "main() { return (int)sysmp(MP_NPROCS); }" >> ${BASE}$$.c
193+echo "int main() { return (int)sysmp(MP_NPROCS); }" >> ${BASE}$$.c
194 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
195 	&& CFLAGS="${CFLAGS} -DHAVE_SYSMP=1";
196 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
197@@ -257,7 +257,7 @@ echo "#include <stdlib.h>" > ${BASE}$$.c
198 echo "#include <unistd.h>" >> ${BASE}$$.c
199 echo "#include <sys/types.h>" >> ${BASE}$$.c
200 echo "#include <sys/processor.h>" >> ${BASE}$$.c
201-echo "main() { return bindprocessor(BINDPROCESS, getpid(), 0); }" >> ${BASE}$$.c
202+echo "int main() { return bindprocessor(BINDPROCESS, getpid(), 0); }" >> ${BASE}$$.c
203 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
204 	&& CFLAGS="${CFLAGS} -DHAVE_BINDPROCESSOR=1";
205 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
206@@ -267,16 +267,17 @@ echo "#include <stdlib.h>" > ${BASE}$$.c
207 echo "#include <sys/types.h>" >> ${BASE}$$.c
208 echo "#include <sys/processor.h>" >> ${BASE}$$.c
209 echo "#include <sys/procset.h>" >> ${BASE}$$.c
210-echo "main() { return processor(P_PID, P_MYPID, 0, NULL); }" >> ${BASE}$$.c
211+echo "int main() { return processor(P_PID, P_MYPID, 0, NULL); }" >> ${BASE}$$.c
212 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
213 	&& CFLAGS="${CFLAGS} -DHAVE_BINDPROCESSOR=1";
214 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
215
216 # check that we have sched_setaffinity
217-echo "#include <stdlib.h>" > ${BASE}$$.c
218+echo "#define _GNU_SOURCE" > ${BASE}$$.c
219+echo "#include <stdlib.h>" >> ${BASE}$$.c
220 echo "#include <unistd.h>" >> ${BASE}$$.c
221 echo "#include <sched.h>" >> ${BASE}$$.c
222-echo "main() { unsigned long mask = 1; return sched_setaffinity(0, sizeof(unsigned long), &mask); }" >> ${BASE}$$.c
223+echo "int main() { unsigned long mask = 1; return sched_setaffinity(0, sizeof(unsigned long), &mask); }" >> ${BASE}$$.c
224 ${CC} ${CFLAGS} -o ${BASE}$$ ${BASE}$$.c ${LDLIBS} 1>${NULL} 2>${NULL} \
225 	&& CFLAGS="${CFLAGS} -DHAVE_SCHED_SETAFFINITY=1";
226 rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
227@@ -285,4 +286,4 @@ rm -f ${BASE}$$ ${BASE}$$.o ${BASE}$$.c
228 if [ ! -d ${BINDIR} ]; then mkdir -p ${BINDIR}; fi
229
230 # now go ahead and build everything!
231-${MAKE} OS="${OS}" CC="${CC}" CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}" O="${BINDIR}" $*
232+${MAKE} OS="${OS}" CC="${CC}" CFLAGS="${CFLAGS}" LDLIBS="${LDLIBS}" O="${BINDIR}" ${EXTRA_OEMAKE} $*
233--- a/src/lib_sched.c
234+++ b/src/lib_sched.c
235@@ -1,3 +1,4 @@
236+#define _GNU_SOURCE
237 #include "bench.h"
238
239 /* #define _DEBUG */
240