include/linux/string.h:209: error: '______f' is static but declared in inline function 'strcpy' which is not static

From: kbuild test robot
Date: Mon Sep 18 2017 - 13:52:24 EST


Hi Daniel,

FYI, the error/warning still remains.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: ebb2c2437d8008d46796902ff390653822af6cc4
commit: 6974f0c4555e285ab217cee58b6e874f776ff409 include/linux/string.h: add the option of fortified string.h functions
date: 10 weeks ago
config: x86_64-randconfig-v0-09182355 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7
reproduce:
git checkout 6974f0c4555e285ab217cee58b6e874f776ff409
# save the attached .config to linux build tree
make ARCH=x86_64

All errors (new ones prefixed by >>):

cc1: warnings being treated as errors
In file included from include/linux/bitmap.h:8,
from include/linux/cpumask.h:11,
from arch/x86/include/asm/cpumask.h:4,
from arch/x86/include/asm/msr.h:10,
from arch/x86/include/asm/processor.h:20,
from arch/x86/include/asm/cpufeature.h:4,
from arch/x86/include/asm/thread_info.h:52,
from include/linux/thread_info.h:37,
from arch/x86/include/asm/preempt.h:6,
from include/linux/preempt.h:80,
from include/linux/spinlock.h:50,
from include/linux/mmzone.h:7,
from include/linux/gfp.h:5,
from include/linux/slab.h:14,
from include/linux/resource_ext.h:19,
from include/linux/acpi.h:26,
from drivers/gpu/drm/i915/i915_drv.c:30:
include/linux/string.h: In function 'strcpy':
>> include/linux/string.h:209: error: '______f' is static but declared in inline function 'strcpy' which is not static
include/linux/string.h:211: error: '______f' is static but declared in inline function 'strcpy' which is not static
include/linux/string.h: In function 'strncpy':
>> include/linux/string.h:219: error: '______f' is static but declared in inline function 'strncpy' which is not static
include/linux/string.h:221: error: '______f' is static but declared in inline function 'strncpy' which is not static
include/linux/string.h: In function 'strcat':
>> include/linux/string.h:229: error: '______f' is static but declared in inline function 'strcat' which is not static
include/linux/string.h:231: error: '______f' is static but declared in inline function 'strcat' which is not static
include/linux/string.h: In function 'strlen':
>> include/linux/string.h:240: error: '______f' is static but declared in inline function 'strlen' which is not static
include/linux/string.h:243: error: '______f' is static but declared in inline function 'strlen' which is not static
include/linux/string.h: In function 'strnlen':
>> include/linux/string.h:253: error: '______f' is static but declared in inline function 'strnlen' which is not static
include/linux/string.h: In function 'strlcpy':
>> include/linux/string.h:265: error: '______f' is static but declared in inline function 'strlcpy' which is not static
include/linux/string.h:268: error: '______f' is static but declared in inline function 'strlcpy' which is not static
include/linux/string.h:270: error: '______f' is static but declared in inline function 'strlcpy' which is not static
include/linux/string.h:272: error: '______f' is static but declared in inline function 'strlcpy' which is not static
include/linux/string.h: In function 'strncat':
>> include/linux/string.h:286: error: '______f' is static but declared in inline function 'strncat' which is not static
include/linux/string.h:290: error: '______f' is static but declared in inline function 'strncat' which is not static
include/linux/string.h: In function 'memset':
>> include/linux/string.h:300: error: '______f' is static but declared in inline function 'memset' which is not static
include/linux/string.h:302: error: '______f' is static but declared in inline function 'memset' which is not static
include/linux/string.h: In function 'memcpy':
>> include/linux/string.h:311: error: '______f' is static but declared in inline function 'memcpy' which is not static
include/linux/string.h:312: error: '______f' is static but declared in inline function 'memcpy' which is not static
include/linux/string.h:314: error: '______f' is static but declared in inline function 'memcpy' which is not static
include/linux/string.h:317: error: '______f' is static but declared in inline function 'memcpy' which is not static
include/linux/string.h: In function 'memmove':
>> include/linux/string.h:326: error: '______f' is static but declared in inline function 'memmove' which is not static
include/linux/string.h:327: error: '______f' is static but declared in inline function 'memmove' which is not static
include/linux/string.h:329: error: '______f' is static but declared in inline function 'memmove' which is not static
include/linux/string.h:332: error: '______f' is static but declared in inline function 'memmove' which is not static
include/linux/string.h: In function 'memscan':
>> include/linux/string.h:341: error: '______f' is static but declared in inline function 'memscan' which is not static
include/linux/string.h:343: error: '______f' is static but declared in inline function 'memscan' which is not static
include/linux/string.h: In function 'memcmp':
>> include/linux/string.h:352: error: '______f' is static but declared in inline function 'memcmp' which is not static
include/linux/string.h:353: error: '______f' is static but declared in inline function 'memcmp' which is not static
include/linux/string.h:355: error: '______f' is static but declared in inline function 'memcmp' which is not static
include/linux/string.h:358: error: '______f' is static but declared in inline function 'memcmp' which is not static
include/linux/string.h: In function 'memchr':
>> include/linux/string.h:366: error: '______f' is static but declared in inline function 'memchr' which is not static
include/linux/string.h:368: error: '______f' is static but declared in inline function 'memchr' which is not static
include/linux/string.h: In function 'memchr_inv':
>> include/linux/string.h:377: error: '______f' is static but declared in inline function 'memchr_inv' which is not static
include/linux/string.h:379: error: '______f' is static but declared in inline function 'memchr_inv' which is not static
include/linux/string.h: In function 'kmemdup':
>> include/linux/string.h:388: error: '______f' is static but declared in inline function 'kmemdup' which is not static
include/linux/string.h:390: error: '______f' is static but declared in inline function 'kmemdup' which is not static

vim +209 include/linux/string.h

203
204 #if !defined(__NO_FORTIFY) && defined(__OPTIMIZE__) && defined(CONFIG_FORTIFY_SOURCE)
205 __FORTIFY_INLINE char *strcpy(char *p, const char *q)
206 {
207 size_t p_size = __builtin_object_size(p, 0);
208 size_t q_size = __builtin_object_size(q, 0);
> 209 if (p_size == (size_t)-1 && q_size == (size_t)-1)
210 return __builtin_strcpy(p, q);
211 if (strscpy(p, q, p_size < q_size ? p_size : q_size) < 0)
212 fortify_panic(__func__);
213 return p;
214 }
215
216 __FORTIFY_INLINE char *strncpy(char *p, const char *q, __kernel_size_t size)
217 {
218 size_t p_size = __builtin_object_size(p, 0);
> 219 if (__builtin_constant_p(size) && p_size < size)
220 __write_overflow();
221 if (p_size < size)
222 fortify_panic(__func__);
223 return __builtin_strncpy(p, q, size);
224 }
225
226 __FORTIFY_INLINE char *strcat(char *p, const char *q)
227 {
228 size_t p_size = __builtin_object_size(p, 0);
> 229 if (p_size == (size_t)-1)
230 return __builtin_strcat(p, q);
231 if (strlcat(p, q, p_size) >= p_size)
232 fortify_panic(__func__);
233 return p;
234 }
235
236 __FORTIFY_INLINE __kernel_size_t strlen(const char *p)
237 {
238 __kernel_size_t ret;
239 size_t p_size = __builtin_object_size(p, 0);
> 240 if (p_size == (size_t)-1)
241 return __builtin_strlen(p);
242 ret = strnlen(p, p_size);
> 243 if (p_size <= ret)
244 fortify_panic(__func__);
245 return ret;
246 }
247
248 extern __kernel_size_t __real_strnlen(const char *, __kernel_size_t) __RENAME(strnlen);
249 __FORTIFY_INLINE __kernel_size_t strnlen(const char *p, __kernel_size_t maxlen)
250 {
251 size_t p_size = __builtin_object_size(p, 0);
252 __kernel_size_t ret = __real_strnlen(p, maxlen < p_size ? maxlen : p_size);
> 253 if (p_size <= ret && maxlen != ret)
254 fortify_panic(__func__);
255 return ret;
256 }
257
258 /* defined after fortified strlen to reuse it */
259 extern size_t __real_strlcpy(char *, const char *, size_t) __RENAME(strlcpy);
260 __FORTIFY_INLINE size_t strlcpy(char *p, const char *q, size_t size)
261 {
262 size_t ret;
263 size_t p_size = __builtin_object_size(p, 0);
264 size_t q_size = __builtin_object_size(q, 0);
> 265 if (p_size == (size_t)-1 && q_size == (size_t)-1)
266 return __real_strlcpy(p, q, size);
267 ret = strlen(q);
268 if (size) {
269 size_t len = (ret >= size) ? size - 1 : ret;
> 270 if (__builtin_constant_p(len) && len >= p_size)
271 __write_overflow();
272 if (len >= p_size)
273 fortify_panic(__func__);
274 __builtin_memcpy(p, q, len);
275 p[len] = '\0';
276 }
277 return ret;
278 }
279
280 /* defined after fortified strlen and strnlen to reuse them */
281 __FORTIFY_INLINE char *strncat(char *p, const char *q, __kernel_size_t count)
282 {
283 size_t p_len, copy_len;
284 size_t p_size = __builtin_object_size(p, 0);
285 size_t q_size = __builtin_object_size(q, 0);
> 286 if (p_size == (size_t)-1 && q_size == (size_t)-1)
287 return __builtin_strncat(p, q, count);
288 p_len = strlen(p);
289 copy_len = strnlen(q, count);
290 if (p_size < p_len + copy_len + 1)
291 fortify_panic(__func__);
292 __builtin_memcpy(p + p_len, q, copy_len);
293 p[p_len + copy_len] = '\0';
294 return p;
295 }
296
297 __FORTIFY_INLINE void *memset(void *p, int c, __kernel_size_t size)
298 {
299 size_t p_size = __builtin_object_size(p, 0);
> 300 if (__builtin_constant_p(size) && p_size < size)
301 __write_overflow();
302 if (p_size < size)
303 fortify_panic(__func__);
304 return __builtin_memset(p, c, size);
305 }
306
307 __FORTIFY_INLINE void *memcpy(void *p, const void *q, __kernel_size_t size)
308 {
309 size_t p_size = __builtin_object_size(p, 0);
310 size_t q_size = __builtin_object_size(q, 0);
> 311 if (__builtin_constant_p(size)) {
> 312 if (p_size < size)
313 __write_overflow();
314 if (q_size < size)
315 __read_overflow2();
316 }
317 if (p_size < size || q_size < size)
318 fortify_panic(__func__);
319 return __builtin_memcpy(p, q, size);
320 }
321
322 __FORTIFY_INLINE void *memmove(void *p, const void *q, __kernel_size_t size)
323 {
324 size_t p_size = __builtin_object_size(p, 0);
325 size_t q_size = __builtin_object_size(q, 0);
> 326 if (__builtin_constant_p(size)) {
327 if (p_size < size)
328 __write_overflow();
329 if (q_size < size)
330 __read_overflow2();
331 }
332 if (p_size < size || q_size < size)
333 fortify_panic(__func__);
334 return __builtin_memmove(p, q, size);
335 }
336
337 extern void *__real_memscan(void *, int, __kernel_size_t) __RENAME(memscan);
338 __FORTIFY_INLINE void *memscan(void *p, int c, __kernel_size_t size)
339 {
340 size_t p_size = __builtin_object_size(p, 0);
> 341 if (__builtin_constant_p(size) && p_size < size)
342 __read_overflow();
343 if (p_size < size)
344 fortify_panic(__func__);
345 return __real_memscan(p, c, size);
346 }
347
348 __FORTIFY_INLINE int memcmp(const void *p, const void *q, __kernel_size_t size)
349 {
350 size_t p_size = __builtin_object_size(p, 0);
351 size_t q_size = __builtin_object_size(q, 0);
> 352 if (__builtin_constant_p(size)) {
353 if (p_size < size)
354 __read_overflow();
> 355 if (q_size < size)
356 __read_overflow2();
357 }
358 if (p_size < size || q_size < size)
359 fortify_panic(__func__);
360 return __builtin_memcmp(p, q, size);
361 }
362
363 __FORTIFY_INLINE void *memchr(const void *p, int c, __kernel_size_t size)
364 {
365 size_t p_size = __builtin_object_size(p, 0);
> 366 if (__builtin_constant_p(size) && p_size < size)
367 __read_overflow();
368 if (p_size < size)
369 fortify_panic(__func__);
370 return __builtin_memchr(p, c, size);
371 }
372
373 void *__real_memchr_inv(const void *s, int c, size_t n) __RENAME(memchr_inv);
374 __FORTIFY_INLINE void *memchr_inv(const void *p, int c, size_t size)
375 {
376 size_t p_size = __builtin_object_size(p, 0);
> 377 if (__builtin_constant_p(size) && p_size < size)
378 __read_overflow();
379 if (p_size < size)
380 fortify_panic(__func__);
381 return __real_memchr_inv(p, c, size);
382 }
383
384 extern void *__real_kmemdup(const void *src, size_t len, gfp_t gfp) __RENAME(kmemdup);
385 __FORTIFY_INLINE void *kmemdup(const void *p, size_t size, gfp_t gfp)
386 {
387 size_t p_size = __builtin_object_size(p, 0);
> 388 if (__builtin_constant_p(size) && p_size < size)
389 __read_overflow();
390 if (p_size < size)
391 fortify_panic(__func__);
392 return __real_kmemdup(p, size, gfp);
393 }
394 #endif
395

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

Attachment: .config.gz
Description: application/gzip