summarylogtreecommitdiffstats
path: root/0001-add-initial-clang-support.patch
blob: 4080911db2e3fdf6c9dc7ba1f7db005f57e45876 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
From 1d39f5599ebeb572ac16c3b2e8ad4691463bf6a1 Mon Sep 17 00:00:00 2001
From: Daniel Kolesa <daniel@octaforge.org>
Date: Wed, 26 Oct 2022 00:30:00 +0200
Subject: [PATCH] add initial clang support

---
 include/fortify-headers.h | 25 ++++++++++++++++++--
 include/poll.h            |  7 +++---
 include/stdio.h           | 38 +++++++++++++++++++++++------
 include/stdlib.h          |  4 +++-
 include/string.h          | 33 ++++++++++++++++----------
 include/strings.h         |  6 +++--
 include/sys/select.h      | 13 ++++++++--
 include/sys/socket.h      | 13 ++++++----
 include/unistd.h          | 30 +++++++++++++----------
 include/wchar.h           | 50 ++++++++++++++++++++++++++-------------
 10 files changed, 158 insertions(+), 61 deletions(-)

diff --git a/include/fortify-headers.h b/include/fortify-headers.h
index 4de5bef..2cf3697 100644
--- a/include/fortify-headers.h
+++ b/include/fortify-headers.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -16,9 +17,29 @@
 #ifndef _FORTIFY_HEADERS_H
 #define _FORTIFY_HEADERS_H
 
+#ifdef __clang__
+
+/* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */
+#define _FORTIFY_POSN(n) const __attribute__((__pass_object_size__(n)))
+/* we can't use extern inline with overloads without making them external */
+#define _FORTIFY_INLINE static __inline__ \
+	__attribute__((__always_inline__,__artificial__,__overloadable__))
+
+#else /* !__clang__ */
+
+#define _FORTIFY_POSN(n)
+#define _FORTIFY_INLINE extern __inline__ \
+	__attribute__((__always_inline__,__gnu_inline__,__artificial__))
+
+#endif /* __clang__ */
+
+#define _FORTIFY_POS0 _FORTIFY_POSN(0)
+#define _FORTIFY_POS1 _FORTIFY_POSN(1)
+#define _FORTIFY_POS2 _FORTIFY_POSN(2)
+
 #define _FORTIFY_STR(s) #s
 #define _FORTIFY_ORIG(p,fn) __typeof__(fn) __orig_##fn __asm__(_FORTIFY_STR(p) #fn)
-#define _FORTIFY_FN(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn); \
-	extern __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
+#define _FORTIFY_FNB(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn)
+#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE
 
 #endif
diff --git a/include/poll.h b/include/poll.h
index 24691f1..60a7623 100644
--- a/include/poll.h
+++ b/include/poll.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -30,7 +31,7 @@ extern "C" {
 
 #undef poll
 
-_FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s)
+_FORTIFY_FN(poll) int poll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n, int __s)
 {
 	__typeof__(sizeof 0) __b = __builtin_object_size(__f, 0);
 
@@ -41,8 +42,8 @@ _FORTIFY_FN(poll) int poll(struct pollfd *__f, nfds_t __n, int __s)
 
 #ifdef _GNU_SOURCE
 #undef ppoll
-_FORTIFY_FN(ppoll) int ppoll(struct pollfd *__f, nfds_t __n, const struct timespec *__s,
-                             const sigset_t *__m)
+_FORTIFY_FN(ppoll) int ppoll(struct pollfd * _FORTIFY_POS0 __f, nfds_t __n,
+                             const struct timespec *__s, const sigset_t *__m)
 {
 	__typeof__(sizeof 0) __b = __builtin_object_size(__f, 0);
 
diff --git a/include/stdio.h b/include/stdio.h
index a965184..e50f65f 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -36,7 +37,7 @@ extern "C" {
 #undef snprintf
 #undef sprintf
 
-_FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f)
+_FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -45,7 +46,8 @@ _FORTIFY_FN(fgets) char *fgets(char *__s, int __n, FILE *__f)
 	return __orig_fgets(__s, __n, __f);
 }
 
-_FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f)
+_FORTIFY_FN(fread) size_t fread(void * _FORTIFY_POS0 __d, size_t __n,
+                                size_t __m, FILE *__f)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -56,7 +58,8 @@ _FORTIFY_FN(fread) size_t fread(void *__d, size_t __n, size_t __m, FILE *__f)
 	return __orig_fread(__d, __n, __m, __f);
 }
 
-_FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE *__f)
+_FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
+                                  size_t __m, FILE *__f)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -67,8 +70,8 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void *__d, size_t __n, size_t __m, FILE
 	return __orig_fwrite(__d, __n, __m, __f);
 }
 
-_FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f,
-                                     __builtin_va_list __v)
+_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
+                                     const char *__f, __builtin_va_list __v)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -77,7 +80,8 @@ _FORTIFY_FN(vsnprintf) int vsnprintf(char *__s, size_t __n, const char *__f,
 	return __orig_vsnprintf(__s, __n, __f, __v);
 }
 
-_FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list __v)
+_FORTIFY_FN(vsprintf) int vsprintf(char * _FORTIFY_POS0 __s, const char *__f,
+                                   __builtin_va_list __v)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 	int __r;
@@ -92,9 +96,26 @@ _FORTIFY_FN(vsprintf) int vsprintf(char *__s, const char *__f, __builtin_va_list
 	return __r;
 }
 
-_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n, const char *__f, ...)
+#if defined(__has_builtin)
+#if __has_builtin(__builtin_va_arg_pack)
+
+/* clang is missing __builtin_va_arg_pack, so we cannot use these impls
+ * outside of gcc; we then have a few options:
+ *
+ * 1) using va_start/end and implementing these functions as static inline,
+ *    with inlining never happening; that means extra symbols with internal
+ *    linkage, which is not ideal
+ * 2) using macros; this is incompatible with c++ and since musl does not
+ *    have the __chk variants, we'd need to implement a body with intermediate
+ *    variables within the macro, which means more non-portable mess
+ * 3) not implementing these under clang, which is what we do for now
+ */
+
+_FORTIFY_FN(snprintf) int snprintf(char *__s, size_t __n,
+                                    const char *__f, ...)
 {
 	size_t __b = __builtin_object_size(__s, 0);
+	int __r;
 
 	if (__n > __b)
 		__builtin_trap();
@@ -116,6 +137,9 @@ _FORTIFY_FN(sprintf) int sprintf(char *__s, const char *__f, ...)
 	return __r;
 }
 
+#endif /* __has_builtin(__builtin_va_arg_pack) */
+#endif /* defined(__has_builtin) */
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/stdlib.h b/include/stdlib.h
index 11155cf..2b854d0 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -35,7 +36,8 @@ __extension__
 extern "C" {
 #endif
 
-#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
+/* FIXME clang */
+#if (defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) && !defined(__clang__)
 #undef realpath
 _FORTIFY_FN(realpath) char *realpath(const char *__p, char *__r)
 {
diff --git a/include/string.h b/include/string.h
index 66c23e1..9d4658c 100644
--- a/include/string.h
+++ b/include/string.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -36,7 +37,8 @@ extern "C" {
 #undef strncat
 #undef strncpy
 
-_FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n)
+_FORTIFY_FN(memcpy) void *memcpy(void * _FORTIFY_POS0 __od,
+                                 const void * _FORTIFY_POS0 __os, size_t __n)
 {
 	size_t __bd = __builtin_object_size(__od, 0);
 	size_t __bs = __builtin_object_size(__os, 0);
@@ -53,7 +55,8 @@ _FORTIFY_FN(memcpy) void *memcpy(void *__od, const void *__os, size_t __n)
 	return __builtin_memcpy(__od, __os, __n);
 }
 
-_FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n)
+_FORTIFY_FN(memmove) void *memmove(void * _FORTIFY_POS0 __d,
+                                   const void * _FORTIFY_POS0 __s, size_t __n)
 {
 	size_t __bd = __builtin_object_size(__d, 0);
 	size_t __bs = __builtin_object_size(__s, 0);
@@ -63,7 +66,7 @@ _FORTIFY_FN(memmove) void *memmove(void *__d, const void *__s, size_t __n)
 	return __orig_memmove(__d, __s, __n);
 }
 
-_FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n)
+_FORTIFY_FN(memset) void *memset(void * _FORTIFY_POS0 __d, int __c, size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -76,7 +79,7 @@ _FORTIFY_FN(memset) void *memset(void *__d, int __c, size_t __n)
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
  || defined(_BSD_SOURCE)
 #undef stpcpy
-_FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s)
+_FORTIFY_FN(stpcpy) char *stpcpy(char * _FORTIFY_POS0 __d, const char *__s)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -86,7 +89,8 @@ _FORTIFY_FN(stpcpy) char *stpcpy(char *__d, const char *__s)
 }
 
 #undef stpncpy
-_FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(stpncpy) char *stpncpy(char * _FORTIFY_POS0 __d, const char *__s,
+                                   size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -96,7 +100,7 @@ _FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n)
 }
 #endif
 
-_FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s)
+_FORTIFY_FN(strcat) char *strcat(char * _FORTIFY_POS0 __d, const char *__s)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -105,7 +109,7 @@ _FORTIFY_FN(strcat) char *strcat(char *__d, const char *__s)
 	return __orig_strcat(__d, __s);
 }
 
-_FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s)
+_FORTIFY_FN(strcpy) char *strcpy(char * _FORTIFY_POS0 __d, const char *__s)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -114,7 +118,8 @@ _FORTIFY_FN(strcpy) char *strcpy(char *__d, const char *__s)
 	return __orig_strcpy(__d, __s);
 }
 
-_FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(strncat) char *strncat(char * _FORTIFY_POS0 __d, const char *__s,
+                                   size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 	size_t __sl, __dl;
@@ -130,7 +135,8 @@ _FORTIFY_FN(strncat) char *strncat(char *__d, const char *__s, size_t __n)
 	return __orig_strncat(__d, __s, __n);
 }
 
-_FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(strncpy) char *strncpy(char * _FORTIFY_POS0 __d,
+                                   const char *__s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -141,7 +147,8 @@ _FORTIFY_FN(strncpy) char *strncpy(char *__d, const char *__s, size_t __n)
 
 #ifdef _GNU_SOURCE
 #undef mempcpy
-_FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n)
+_FORTIFY_FN(mempcpy) void *mempcpy(void * _FORTIFY_POS0 __d,
+                                   const void * _FORTIFY_POS0 __s, size_t __n)
 {
 	size_t __bd = __builtin_object_size(__d, 0);
 	size_t __bs = __builtin_object_size(__s, 0);
@@ -155,7 +162,8 @@ _FORTIFY_FN(mempcpy) void *mempcpy(void *__d, const void *__s, size_t __n)
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #undef strlcat
 #undef strlcpy
-_FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(strlcat) size_t strlcat(char * _FORTIFY_POS0 __d,
+                                    const char *__s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -164,7 +172,8 @@ _FORTIFY_FN(strlcat) size_t strlcat(char *__d, const char *__s, size_t __n)
 	return __orig_strlcat(__d, __s, __n);
 }
 
-_FORTIFY_FN(strlcpy) size_t strlcpy(char *__d, const char *__s, size_t __n)
+_FORTIFY_FN(strlcpy) size_t strlcpy(char * _FORTIFY_POS0 __d,
+                                    const char *__s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
diff --git a/include/strings.h b/include/strings.h
index a16e1ad..4c7e1c7 100644
--- a/include/strings.h
+++ b/include/strings.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -30,7 +31,8 @@ extern "C" {
  || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700)
 #undef bcopy
 #undef bzero
-_FORTIFY_FN(bcopy) void bcopy(const void *__s, void *__d, size_t __n)
+_FORTIFY_FN(bcopy) void bcopy(const void * _FORTIFY_POS0 __s,
+                              void * _FORTIFY_POS0 __d, size_t __n)
 {
 	size_t __bd = __builtin_object_size(__d, 0);
 	size_t __bs = __builtin_object_size(__s, 0);
@@ -40,7 +42,7 @@ _FORTIFY_FN(bcopy) void bcopy(const void *__s, void *__d, size_t __n)
 	return __orig_bcopy(__s, __d, __n);
 }
 
-_FORTIFY_FN(bzero) void bzero(void *__s, size_t __n)
+_FORTIFY_FN(bzero) void bzero(void * _FORTIFY_POS0 __s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
diff --git a/include/sys/select.h b/include/sys/select.h
index bcee8be..527d8e4 100644
--- a/include/sys/select.h
+++ b/include/sys/select.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -27,8 +28,14 @@ __extension__
 extern "C" {
 #endif
 
+#ifdef __clang__
+#define _FORTIFY_FD_POS0 const __attribute__((__pass_object_size__(0)))
+#else
+#define _FORTIFY_FD_POS0
+#endif
+
 static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
-void __fortify_FD_CLR(int __f, fd_set *__s)
+void __fortify_FD_CLR(int __f, fd_set * _FORTIFY_FD_POS0 __s)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -38,7 +45,7 @@ void __fortify_FD_CLR(int __f, fd_set *__s)
 }
 
 static __inline__ __attribute__((__always_inline__,__gnu_inline__,__artificial__))
-void __fortify_FD_SET(int __f, fd_set *__s)
+void __fortify_FD_SET(int __f, fd_set * _FORTIFY_FD_POS0 __s)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -47,6 +54,8 @@ void __fortify_FD_SET(int __f, fd_set *__s)
 	FD_SET(__f, __s);
 }
 
+#undef _FORTIFY_FD_POS0
+
 #undef FD_CLR
 #define FD_CLR(fd, set) __fortify_FD_CLR(fd, set)
 #undef FD_SET
diff --git a/include/sys/socket.h b/include/sys/socket.h
index ad6ab2d..02cad5f 100644
--- a/include/sys/socket.h
+++ b/include/sys/socket.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -33,7 +34,8 @@ extern "C" {
 #undef send
 #undef sendto
 
-_FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl)
+_FORTIFY_FN(recv) ssize_t recv(int __f, void * _FORTIFY_POS0 __s, size_t __n,
+                               int __fl)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -42,7 +44,8 @@ _FORTIFY_FN(recv) ssize_t recv(int __f, void *__s, size_t __n, int __fl)
 	return __orig_recv(__f, __s, __n, __fl);
 }
 
-_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl,
+_FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void * _FORTIFY_POS0 __s,
+                                       size_t __n, int __fl,
                                        struct sockaddr *__a, socklen_t *__l)
 {
 	size_t __b = __builtin_object_size(__s, 0);
@@ -52,7 +55,8 @@ _FORTIFY_FN(recvfrom) ssize_t recvfrom(int __f, void *__s, size_t __n, int __fl,
 	return __orig_recvfrom(__f, __s, __n, __fl, __a, __l);
 }
 
-_FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl)
+_FORTIFY_FN(send) ssize_t send(int __f, const void * _FORTIFY_POS0 __s,
+                               size_t __n, int __fl)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -61,7 +65,8 @@ _FORTIFY_FN(send) ssize_t send(int __f, const void *__s, size_t __n, int __fl)
 	return __orig_send(__f, __s, __n, __fl);
 }
 
-_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void *__s, size_t __n, int __fl,
+_FORTIFY_FN(sendto) ssize_t sendto(int __f, const void * _FORTIFY_POS0 __s,
+                                   size_t __n, int __fl,
                                    const struct sockaddr *__a, socklen_t __l)
 {
 	size_t __b = __builtin_object_size(__s, 0);
diff --git a/include/unistd.h b/include/unistd.h
index 09980ba..9f8a187 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2016 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -40,7 +41,7 @@ extern "C" {
 #undef ttyname_r
 #undef write
 
-_FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l)
+_FORTIFY_FN(confstr) size_t confstr(int __n, char * _FORTIFY_POS0 __s, size_t __l)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 	size_t __r = __orig_confstr(__n, __s, __b > __l ? __l : __b);
@@ -50,7 +51,7 @@ _FORTIFY_FN(confstr) size_t confstr(int __n, char *__s, size_t __l)
 	return __r;
 }
 
-_FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l)
+_FORTIFY_FN(getcwd) char *getcwd(char * _FORTIFY_POS0 __s, size_t __l)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -61,7 +62,7 @@ _FORTIFY_FN(getcwd) char *getcwd(char *__s, size_t __l)
 
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 #undef getdomainname
-_FORTIFY_FN(getdomainname) int getdomainname(char *__s, size_t __l)
+_FORTIFY_FN(getdomainname) int getdomainname(char * _FORTIFY_POS0 __s, size_t __l)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -71,7 +72,7 @@ _FORTIFY_FN(getdomainname) int getdomainname(char *__s, size_t __l)
 }
 #endif
 
-_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t *__s)
+_FORTIFY_FN(getgroups) int getgroups(int __l, gid_t * _FORTIFY_POS0 __s)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -80,7 +81,7 @@ _FORTIFY_FN(getgroups) int getgroups(int __l, gid_t *__s)
 	return __orig_getgroups(__l, __s);
 }
 
-_FORTIFY_FN(gethostname) int gethostname(char *__s, size_t __l)
+_FORTIFY_FN(gethostname) int gethostname(char * _FORTIFY_POS0 __s, size_t __l)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -89,7 +90,7 @@ _FORTIFY_FN(gethostname) int gethostname(char *__s, size_t __l)
 	return __orig_gethostname(__s, __l);
 }
 
-_FORTIFY_FN(getlogin_r) int getlogin_r(char *__s, size_t __l)
+_FORTIFY_FN(getlogin_r) int getlogin_r(char * _FORTIFY_POS0 __s, size_t __l)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -98,7 +99,8 @@ _FORTIFY_FN(getlogin_r) int getlogin_r(char *__s, size_t __l)
 	return __orig_getlogin_r(__s, __l);
 }
 
-_FORTIFY_FN(pread) ssize_t pread(int __f, void *__s, size_t __n, off_t __o)
+_FORTIFY_FN(pread) ssize_t pread(int __f, void * _FORTIFY_POS0 __s,
+                                 size_t __n, off_t __o)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -107,7 +109,7 @@ _FORTIFY_FN(pread) ssize_t pread(int __f, void *__s, size_t __n, off_t __o)
 	return __orig_pread(__f, __s, __n, __o);
 }
 
-_FORTIFY_FN(read) ssize_t read(int __f, void *__s, size_t __n)
+_FORTIFY_FN(read) ssize_t read(int __f, void * _FORTIFY_POS0 __s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -116,7 +118,8 @@ _FORTIFY_FN(read) ssize_t read(int __f, void *__s, size_t __n)
 	return __orig_read(__f, __s, __n);
 }
 
-_FORTIFY_FN(readlink) ssize_t readlink(const char *__p, char *__s, size_t __n)
+_FORTIFY_FN(readlink) ssize_t readlink(const char *__p,
+                                       char * _FORTIFY_POS0 __s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -125,7 +128,8 @@ _FORTIFY_FN(readlink) ssize_t readlink(const char *__p, char *__s, size_t __n)
 	return __orig_readlink(__p, __s, __n);
 }
 
-_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, char *__s, size_t __n)
+_FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p,
+                                           char * _FORTIFY_POS0 __s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -134,7 +138,8 @@ _FORTIFY_FN(readlinkat) ssize_t readlinkat(int __f, const char *__p, char *__s,
 	return __orig_readlinkat(__f, __p, __s, __n);
 }
 
-_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char *__s, size_t __n)
+_FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char * _FORTIFY_POS0 __s,
+                                     size_t __n)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -143,7 +148,8 @@ _FORTIFY_FN(ttyname_r) int ttyname_r(int __f, char *__s, size_t __n)
 	return __orig_ttyname_r(__f, __s, __n);
 }
 
-_FORTIFY_FN(write) ssize_t write(int __f, const void *__s, size_t __n)
+_FORTIFY_FN(write) ssize_t write(int __f, const void * _FORTIFY_POS0 __s,
+                                 size_t __n)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
diff --git a/include/wchar.h b/include/wchar.h
index c5d0e5d..41423a8 100644
--- a/include/wchar.h
+++ b/include/wchar.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2015-2017 Dimitris Papastamos <sin@2f30.org>
+ * Copyright (C) 2022 q66 <q66@chimera-linux.org>
  *
  * Permission to use, copy, modify, and/or distribute this software for any
  * purpose with or without fee is hereby granted.
@@ -55,7 +56,8 @@ extern "C" {
 #undef wmemmove
 #undef wmemset
 
-_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t *__s, int __n, FILE *__f)
+_FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t * _FORTIFY_POS0 __s,
+                                    int __n, FILE *__f)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -67,7 +69,8 @@ _FORTIFY_FN(fgetws) wchar_t *fgetws(wchar_t *__s, int __n, FILE *__f)
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)  || defined(_BSD_SOURCE)
 #undef mbsnrtowcs
-_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *__d, const char **__s, size_t __n,
+_FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t * _FORTIFY_POS0 __d,
+                                          const char **__s, size_t __n,
                                           size_t __wn, mbstate_t *__st)
 {
 	size_t __b = __builtin_object_size(__d, 0);
@@ -87,7 +90,8 @@ _FORTIFY_FN(mbsnrtowcs) size_t mbsnrtowcs(wchar_t *__d, const char **__s, size_t
 }
 #endif
 
-_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t *__d, const char **__s, size_t __wn,
+_FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t * _FORTIFY_POS0 __d,
+                                        const char **__s, size_t __wn,
                                         mbstate_t *__st)
 {
 	size_t __b = __builtin_object_size(__d, 0);
@@ -100,7 +104,8 @@ _FORTIFY_FN(mbsrtowcs) size_t mbsrtowcs(wchar_t *__d, const char **__s, size_t _
 	return __r;
 }
 
-_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t *__ws, const char *__s, size_t __wn)
+_FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t * _FORTIFY_POS0 __ws,
+                                      const char *__s, size_t __wn)
 {
 	size_t __b = __builtin_object_size(__ws, 0);
 
@@ -109,7 +114,9 @@ _FORTIFY_FN(mbstowcs) size_t mbstowcs(wchar_t *__ws, const char *__s, size_t __w
 	return __orig_mbstowcs(__ws, __s, __wn);
 }
 
-_FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st)
+/* FIXME clang */
+#ifndef __clang__
+_FORTIFY_FN(wcrtomb) size_t wcrtomb(char * __s, wchar_t __w, mbstate_t *__st)
 {
 	if (__s && MB_LEN_MAX > __builtin_object_size(__s, 2)) {
 		char __buf[MB_LEN_MAX];
@@ -125,8 +132,10 @@ _FORTIFY_FN(wcrtomb) size_t wcrtomb(char *__s, wchar_t __w, mbstate_t *__st)
 	}
 	return __orig_wcrtomb(__s, __w, __st);
 }
+#endif
 
-_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t *__d, const wchar_t *__s)
+_FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t * _FORTIFY_POS0 __d,
+                                    const wchar_t *__s)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -135,7 +144,8 @@ _FORTIFY_FN(wcscat) wchar_t *wcscat(wchar_t *__d, const wchar_t *__s)
 	return __orig_wcscat(__d, __s);
 }
 
-_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t *__d, const wchar_t *__s)
+_FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t * _FORTIFY_POS0 __d,
+                                    const wchar_t *__s)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -144,7 +154,8 @@ _FORTIFY_FN(wcscpy) wchar_t *wcscpy(wchar_t *__d, const wchar_t *__s)
 	return __orig_wcscpy(__d, __s);
 }
 
-_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t *__d, const wchar_t *__s, size_t __n)
+_FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t * _FORTIFY_POS0 __d,
+                                      const wchar_t *__s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 	size_t __sl, __dl;
@@ -160,7 +171,8 @@ _FORTIFY_FN(wcsncat) wchar_t *wcsncat(wchar_t *__d, const wchar_t *__s, size_t _
 	return __orig_wcsncat(__d, __s, __n);
 }
 
-_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t *__d, const wchar_t *__s, size_t __n)
+_FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t * _FORTIFY_POS0 __d,
+                                      const wchar_t *__s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -172,7 +184,8 @@ _FORTIFY_FN(wcsncpy) wchar_t *wcsncpy(wchar_t *__d, const wchar_t *__s, size_t _
 #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
  || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE)  || defined(_BSD_SOURCE)
 #undef wcsnrtombs
-_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char *__d, const wchar_t **__s, size_t __wn,
+_FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char * _FORTIFY_POS0 __d,
+                                          const wchar_t **__s, size_t __wn,
                                           size_t __n, mbstate_t *__st)
 {
 	size_t __b = __builtin_object_size(__d, 0);
@@ -192,7 +205,8 @@ _FORTIFY_FN(wcsnrtombs) size_t wcsnrtombs(char *__d, const wchar_t **__s, size_t
 }
 #endif
 
-_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char *__d, const wchar_t **__s, size_t __n,
+_FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char * _FORTIFY_POS0 __d,
+                                        const wchar_t **__s, size_t __n,
                                         mbstate_t *__st)
 {
 	size_t __b = __builtin_object_size(__d, 0);
@@ -204,7 +218,8 @@ _FORTIFY_FN(wcsrtombs) size_t wcsrtombs(char *__d, const wchar_t **__s, size_t _
 	return __r;
 }
 
-_FORTIFY_FN(wcstombs) size_t wcstombs(char *__s, const wchar_t *__ws, size_t __n)
+_FORTIFY_FN(wcstombs) size_t wcstombs(char * _FORTIFY_POS0 __s,
+                                      const wchar_t *__ws, size_t __n)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -213,7 +228,7 @@ _FORTIFY_FN(wcstombs) size_t wcstombs(char *__s, const wchar_t *__ws, size_t __n
 	return __orig_wcstombs(__s, __ws, __n);
 }
 
-_FORTIFY_FN(wctomb) int wctomb(char *__s, wchar_t __w)
+_FORTIFY_FN(wctomb) int wctomb(char * _FORTIFY_POS0 __s, wchar_t __w)
 {
 	size_t __b = __builtin_object_size(__s, 0);
 
@@ -222,7 +237,8 @@ _FORTIFY_FN(wctomb) int wctomb(char *__s, wchar_t __w)
 	return __orig_wctomb(__s, __w);
 }
 
-_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t *__d, const wchar_t *__s, size_t __n)
+_FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t * _FORTIFY_POS0 __d,
+                                      const wchar_t *__s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -231,7 +247,8 @@ _FORTIFY_FN(wmemcpy) wchar_t *wmemcpy(wchar_t *__d, const wchar_t *__s, size_t _
 	return __orig_wmemcpy(__d, __s, __n);
 }
 
-_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t *__d, const wchar_t *__s, size_t __n)
+_FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t * _FORTIFY_POS0 __d,
+                                        const wchar_t *__s, size_t __n)
 {
 	size_t __b = __builtin_object_size(__d, 0);
 
@@ -240,7 +257,8 @@ _FORTIFY_FN(wmemmove) wchar_t *wmemmove(wchar_t *__d, const wchar_t *__s, size_t
 	return __orig_wmemmove(__d, __s, __n);
 }
 
-_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t *__s, wchar_t __c, size_t __n)
+_FORTIFY_FN(wmemset) wchar_t *wmemset(wchar_t * _FORTIFY_POS0 __s,
+                                      wchar_t __c, size_t __n)
 {
 	size_t __b = __builtin_object_size(__s, 0);