elfutils: bump to 0.167
[librecmc/librecmc.git] / package / libs / elfutils / patches / 100-musl-compat.patch
1 --- a/lib/system.h
2 +++ b/lib/system.h
3 @@ -68,6 +68,16 @@ extern int crc32_file (int fd, uint32_t
4  
5  #define gettext_noop(Str) Str
6  
7 +#ifndef TEMP_FAILURE_RETRY
8 +#define TEMP_FAILURE_RETRY(expression) \
9 +  (__extension__                                                             \
10 +    ({ long int __result;                                                    \
11 +       do __result = (long int) (expression);                                \
12 +       while (__result == -1L && errno == EINTR);                            \
13 +       __result; }))
14 +#endif
15 +
16 +#define error(status, errno, ...) err(status, __VA_ARGS__)
17  
18  static inline ssize_t __attribute__ ((unused))
19  pwrite_retry (int fd, const void *buf, size_t len, off_t off)
20 --- a/lib/color.c
21 +++ b/lib/color.c
22 @@ -32,7 +32,7 @@
23  #endif
24  
25  #include <argp.h>
26 -#include <error.h>
27 +#include <err.h>
28  #include <libintl.h>
29  #include <stdlib.h>
30  #include <string.h>
31 --- a/lib/xmalloc.c
32 +++ b/lib/xmalloc.c
33 @@ -30,7 +30,7 @@
34  # include <config.h>
35  #endif
36  
37 -#include <error.h>
38 +#include <err.h>
39  #include <libintl.h>
40  #include <stddef.h>
41  #include <stdlib.h>
42 --- a/src/addr2line.c
43 +++ b/src/addr2line.c
44 @@ -23,7 +23,7 @@
45  #include <argp.h>
46  #include <assert.h>
47  #include <errno.h>
48 -#include <error.h>
49 +#include <err.h>
50  #include <fcntl.h>
51  #include <inttypes.h>
52  #include <libdwfl.h>
53 --- a/src/ar.c
54 +++ b/src/ar.c
55 @@ -22,7 +22,7 @@
56  
57  #include <argp.h>
58  #include <assert.h>
59 -#include <error.h>
60 +#include <err.h>
61  #include <fcntl.h>
62  #include <gelf.h>
63  #include <libintl.h>
64 --- a/src/arlib2.c
65 +++ b/src/arlib2.c
66 @@ -20,7 +20,7 @@
67  # include <config.h>
68  #endif
69  
70 -#include <error.h>
71 +#include <err.h>
72  #include <libintl.h>
73  #include <limits.h>
74  #include <string.h>
75 --- a/src/arlib.c
76 +++ b/src/arlib.c
77 @@ -21,7 +21,7 @@
78  #endif
79  
80  #include <assert.h>
81 -#include <error.h>
82 +#include <err.h>
83  #include <gelf.h>
84  #include <libintl.h>
85  #include <stdio.h>
86 --- a/src/elfcmp.c
87 +++ b/src/elfcmp.c
88 @@ -23,7 +23,7 @@
89  #include <argp.h>
90  #include <assert.h>
91  #include <errno.h>
92 -#include <error.h>
93 +#include <err.h>
94  #include <fcntl.h>
95  #include <locale.h>
96  #include <libintl.h>
97 --- a/src/elflint.c
98 +++ b/src/elflint.c
99 @@ -24,7 +24,7 @@
100  #include <assert.h>
101  #include <byteswap.h>
102  #include <endian.h>
103 -#include <error.h>
104 +#include <err.h>
105  #include <fcntl.h>
106  #include <gelf.h>
107  #include <inttypes.h>
108 --- a/src/findtextrel.c
109 +++ b/src/findtextrel.c
110 @@ -23,7 +23,7 @@
111  #include <argp.h>
112  #include <assert.h>
113  #include <errno.h>
114 -#include <error.h>
115 +#include <err.h>
116  #include <fcntl.h>
117  #include <gelf.h>
118  #include <libdw.h>
119 --- a/src/nm.c
120 +++ b/src/nm.c
121 @@ -26,7 +26,7 @@
122  #include <ctype.h>
123  #include <dwarf.h>
124  #include <errno.h>
125 -#include <error.h>
126 +#include <err.h>
127  #include <fcntl.h>
128  #include <gelf.h>
129  #include <inttypes.h>
130 --- a/src/objdump.c
131 +++ b/src/objdump.c
132 @@ -21,7 +21,7 @@
133  #endif
134  
135  #include <argp.h>
136 -#include <error.h>
137 +#include <err.h>
138  #include <fcntl.h>
139  #include <inttypes.h>
140  #include <libintl.h>
141 --- a/src/ranlib.c
142 +++ b/src/ranlib.c
143 @@ -24,7 +24,7 @@
144  #include <argp.h>
145  #include <assert.h>
146  #include <errno.h>
147 -#include <error.h>
148 +#include <err.h>
149  #include <fcntl.h>
150  #include <gelf.h>
151  #include <libintl.h>
152 --- a/src/readelf.c
153 +++ b/src/readelf.c
154 @@ -25,7 +25,7 @@
155  #include <ctype.h>
156  #include <dwarf.h>
157  #include <errno.h>
158 -#include <error.h>
159 +#include <err.h>
160  #include <fcntl.h>
161  #include <gelf.h>
162  #include <inttypes.h>
163 --- a/src/size.c
164 +++ b/src/size.c
165 @@ -21,7 +21,7 @@
166  #endif
167  
168  #include <argp.h>
169 -#include <error.h>
170 +#include <err.h>
171  #include <fcntl.h>
172  #include <gelf.h>
173  #include <inttypes.h>
174 --- a/src/stack.c
175 +++ b/src/stack.c
176 @@ -18,7 +18,7 @@
177  #include <config.h>
178  #include <assert.h>
179  #include <argp.h>
180 -#include <error.h>
181 +#include <err.h>
182  #include <stdlib.h>
183  #include <inttypes.h>
184  #include <stdio.h>
185 --- a/src/strings.c
186 +++ b/src/strings.c
187 @@ -25,7 +25,7 @@
188  #include <ctype.h>
189  #include <endian.h>
190  #include <errno.h>
191 -#include <error.h>
192 +#include <err.h>
193  #include <fcntl.h>
194  #include <gelf.h>
195  #include <inttypes.h>
196 --- a/src/strip.c
197 +++ b/src/strip.c
198 @@ -24,7 +24,7 @@
199  #include <assert.h>
200  #include <byteswap.h>
201  #include <endian.h>
202 -#include <error.h>
203 +#include <err.h>
204  #include <fcntl.h>
205  #include <gelf.h>
206  #include <libelf.h>
207 --- a/src/unstrip.c
208 +++ b/src/unstrip.c
209 @@ -31,7 +31,7 @@
210  #include <argp.h>
211  #include <assert.h>
212  #include <errno.h>
213 -#include <error.h>
214 +#include <err.h>
215  #include <fcntl.h>
216  #include <fnmatch.h>
217  #include <libintl.h>
218 --- a/tests/addrscopes.c
219 +++ b/tests/addrscopes.c
220 @@ -25,7 +25,7 @@
221  #include <stdio_ext.h>
222  #include <locale.h>
223  #include <stdlib.h>
224 -#include <error.h>
225 +#include <err.h>
226  #include <string.h>
227  
228  
229 --- a/tests/allregs.c
230 +++ b/tests/allregs.c
231 @@ -21,7 +21,7 @@
232  #include <stdio.h>
233  #include <stdlib.h>
234  #include <string.h>
235 -#include <error.h>
236 +#include <err.h>
237  #include <locale.h>
238  #include <argp.h>
239  #include <assert.h>
240 --- a/tests/backtrace.c
241 +++ b/tests/backtrace.c
242 @@ -24,7 +24,7 @@
243  #include <dirent.h>
244  #include <stdlib.h>
245  #include <errno.h>
246 -#include <error.h>
247 +#include <err.h>
248  #include <unistd.h>
249  #include <dwarf.h>
250  #ifdef __linux__
251 --- a/tests/backtrace-data.c
252 +++ b/tests/backtrace-data.c
253 @@ -27,7 +27,7 @@
254  #include <dirent.h>
255  #include <stdlib.h>
256  #include <errno.h>
257 -#include <error.h>
258 +#include <err.h>
259  #include <unistd.h>
260  #include <dwarf.h>
261  #if defined(__x86_64__) && defined(__linux__)
262 --- a/tests/buildid.c
263 +++ b/tests/buildid.c
264 @@ -23,7 +23,7 @@
265  #include ELFUTILS_HEADER(elf)
266  #include ELFUTILS_HEADER(dwelf)
267  #include <stdio.h>
268 -#include <error.h>
269 +#include <err.h>
270  #include <string.h>
271  #include <stdlib.h>
272  #include <sys/types.h>
273 --- a/tests/debugaltlink.c
274 +++ b/tests/debugaltlink.c
275 @@ -23,7 +23,7 @@
276  #include ELFUTILS_HEADER(dw)
277  #include ELFUTILS_HEADER(dwelf)
278  #include <stdio.h>
279 -#include <error.h>
280 +#include <err.h>
281  #include <string.h>
282  #include <stdlib.h>
283  #include <sys/types.h>
284 --- a/tests/debuglink.c
285 +++ b/tests/debuglink.c
286 @@ -21,7 +21,7 @@
287  #include <errno.h>
288  #include ELFUTILS_HEADER(dwelf)
289  #include <stdio.h>
290 -#include <error.h>
291 +#include <err.h>
292  #include <string.h>
293  #include <stdlib.h>
294  #include <sys/types.h>
295 --- a/tests/dwfl-addr-sect.c
296 +++ b/tests/dwfl-addr-sect.c
297 @@ -23,7 +23,7 @@
298  #include <stdio_ext.h>
299  #include <stdlib.h>
300  #include <string.h>
301 -#include <error.h>
302 +#include <err.h>
303  #include <locale.h>
304  #include <argp.h>
305  #include ELFUTILS_HEADER(dwfl)
306 --- a/tests/dwfl-bug-addr-overflow.c
307 +++ b/tests/dwfl-bug-addr-overflow.c
308 @@ -20,7 +20,7 @@
309  #include <inttypes.h>
310  #include <stdio.h>
311  #include <stdio_ext.h>
312 -#include <error.h>
313 +#include <err.h>
314  #include <locale.h>
315  #include ELFUTILS_HEADER(dwfl)
316  
317 --- a/tests/dwfl-bug-fd-leak.c
318 +++ b/tests/dwfl-bug-fd-leak.c
319 @@ -24,7 +24,7 @@
320  #include <dirent.h>
321  #include <stdlib.h>
322  #include <errno.h>
323 -#include <error.h>
324 +#include <err.h>
325  #include <unistd.h>
326  #include <dwarf.h>
327  
328 --- a/tests/dwfl-bug-getmodules.c
329 +++ b/tests/dwfl-bug-getmodules.c
330 @@ -18,7 +18,7 @@
331  #include <config.h>
332  #include ELFUTILS_HEADER(dwfl)
333  
334 -#include <error.h>
335 +#include <err.h>
336  
337  static const Dwfl_Callbacks callbacks =
338    {
339 --- a/tests/dwfllines.c
340 +++ b/tests/dwfllines.c
341 @@ -27,7 +27,7 @@
342  #include <stdio.h>
343  #include <stdlib.h>
344  #include <string.h>
345 -#include <error.h>
346 +#include <err.h>
347  
348  int
349  main (int argc, char *argv[])
350 --- a/tests/dwflmodtest.c
351 +++ b/tests/dwflmodtest.c
352 @@ -23,7 +23,7 @@
353  #include <stdio_ext.h>
354  #include <stdlib.h>
355  #include <string.h>
356 -#include <error.h>
357 +#include <err.h>
358  #include <locale.h>
359  #include <argp.h>
360  #include ELFUTILS_HEADER(dwfl)
361 --- a/tests/dwfl-report-elf-align.c
362 +++ b/tests/dwfl-report-elf-align.c
363 @@ -20,7 +20,7 @@
364  #include <inttypes.h>
365  #include <stdio.h>
366  #include <stdio_ext.h>
367 -#include <error.h>
368 +#include <err.h>
369  #include <locale.h>
370  #include <string.h>
371  #include <stdlib.h>
372 --- a/tests/dwflsyms.c
373 +++ b/tests/dwflsyms.c
374 @@ -25,7 +25,7 @@
375  #include <stdio.h>
376  #include <stdio_ext.h>
377  #include <stdlib.h>
378 -#include <error.h>
379 +#include <err.h>
380  #include <string.h>
381  
382  static const char *
383 --- a/tests/early-offscn.c
384 +++ b/tests/early-offscn.c
385 @@ -19,7 +19,7 @@
386  #endif
387  
388  #include <errno.h>
389 -#include <error.h>
390 +#include <err.h>
391  #include <fcntl.h>
392  #include <gelf.h>
393  #include <stdio.h>
394 --- a/tests/ecp.c
395 +++ b/tests/ecp.c
396 @@ -20,7 +20,7 @@
397  #endif
398  
399  #include <errno.h>
400 -#include <error.h>
401 +#include <err.h>
402  #include <fcntl.h>
403  #include <gelf.h>
404  #include <stdlib.h>
405 --- a/tests/find-prologues.c
406 +++ b/tests/find-prologues.c
407 @@ -25,7 +25,7 @@
408  #include <stdio_ext.h>
409  #include <locale.h>
410  #include <stdlib.h>
411 -#include <error.h>
412 +#include <err.h>
413  #include <string.h>
414  #include <fnmatch.h>
415  
416 --- a/tests/funcretval.c
417 +++ b/tests/funcretval.c
418 @@ -25,7 +25,7 @@
419  #include <stdio_ext.h>
420  #include <locale.h>
421  #include <stdlib.h>
422 -#include <error.h>
423 +#include <err.h>
424  #include <string.h>
425  #include <fnmatch.h>
426  
427 --- a/tests/funcscopes.c
428 +++ b/tests/funcscopes.c
429 @@ -25,7 +25,7 @@
430  #include <stdio_ext.h>
431  #include <locale.h>
432  #include <stdlib.h>
433 -#include <error.h>
434 +#include <err.h>
435  #include <string.h>
436  #include <fnmatch.h>
437  
438 --- a/tests/line2addr.c
439 +++ b/tests/line2addr.c
440 @@ -26,7 +26,7 @@
441  #include <locale.h>
442  #include <stdlib.h>
443  #include <string.h>
444 -#include <error.h>
445 +#include <err.h>
446  
447  
448  static void
449 --- a/tests/low_high_pc.c
450 +++ b/tests/low_high_pc.c
451 @@ -25,7 +25,7 @@
452  #include <stdio_ext.h>
453  #include <locale.h>
454  #include <stdlib.h>
455 -#include <error.h>
456 +#include <err.h>
457  #include <string.h>
458  #include <fnmatch.h>
459  
460 --- a/tests/md5-sha1-test.c
461 +++ b/tests/md5-sha1-test.c
462 @@ -19,7 +19,7 @@
463  #endif
464  
465  #include <string.h>
466 -#include <error.h>
467 +#include <err.h>
468  
469  #include "md5.h"
470  #include "sha1.h"
471 --- a/tests/rdwrmmap.c
472 +++ b/tests/rdwrmmap.c
473 @@ -19,7 +19,7 @@
474  #endif
475  
476  #include <errno.h>
477 -#include <error.h>
478 +#include <err.h>
479  #include <stdio.h>
480  #include <fcntl.h>
481  #include <unistd.h>
482 --- a/tests/saridx.c
483 +++ b/tests/saridx.c
484 @@ -17,7 +17,7 @@
485  
486  #include <config.h>
487  
488 -#include <error.h>
489 +#include <err.h>
490  #include <fcntl.h>
491  #include <gelf.h>
492  #include <stdio.h>
493 --- a/tests/sectiondump.c
494 +++ b/tests/sectiondump.c
495 @@ -18,7 +18,7 @@
496  #include <config.h>
497  
498  #include <errno.h>
499 -#include <error.h>
500 +#include <err.h>
501  #include <fcntl.h>
502  #include <gelf.h>
503  #include <inttypes.h>
504 --- a/tests/varlocs.c
505 +++ b/tests/varlocs.c
506 @@ -25,7 +25,7 @@
507  #include <dwarf.h>
508  #include <stdio.h>
509  #include <stdlib.h>
510 -#include <error.h>
511 +#include <err.h>
512  #include <string.h>
513  #include <sys/types.h>
514  #include <sys/stat.h>
515 --- a/libelf/libelf.h
516 +++ b/libelf/libelf.h
517 @@ -29,6 +29,7 @@
518  #ifndef _LIBELF_H
519  #define _LIBELF_H 1
520  
521 +#include <fcntl.h>
522  #include <stdint.h>
523  #include <sys/types.h>
524  
525 --- a/libasm/asm_end.c
526 +++ b/libasm/asm_end.c
527 @@ -32,7 +32,7 @@
528  #endif
529  
530  #include <assert.h>
531 -#include <error.h>
532 +#include <err.h>
533  #include <libintl.h>
534  #include <stdio.h>
535  #include <stdlib.h>
536 --- a/libasm/asm_newscn.c
537 +++ b/libasm/asm_newscn.c
538 @@ -32,7 +32,7 @@
539  #endif
540  
541  #include <assert.h>
542 -#include <error.h>
543 +#include <err.h>
544  #include <libintl.h>
545  #include <stdlib.h>
546  #include <string.h>
547 --- a/libcpu/i386_gendis.c
548 +++ b/libcpu/i386_gendis.c
549 @@ -31,7 +31,7 @@
550  # include <config.h>
551  #endif
552  
553 -#include <error.h>
554 +#include <err.h>
555  #include <errno.h>
556  #include <stdio.h>
557  #include <stdlib.h>
558 --- a/libcpu/i386_lex.c
559 +++ b/libcpu/i386_lex.c
560 @@ -578,7 +578,7 @@ char *i386_text;
561  #endif
562  
563  #include <ctype.h>
564 -#include <error.h>
565 +#include <err.h>
566  #include <libintl.h>
567  
568  #include <system.h>
569 --- a/libcpu/i386_lex.l
570 +++ b/libcpu/i386_lex.l
571 @@ -31,7 +31,7 @@
572  #endif
573  
574  #include <ctype.h>
575 -#include <error.h>
576 +#include <err.h>
577  #include <libintl.h>
578  
579  #include <system.h>
580 --- a/libcpu/i386_parse.c
581 +++ b/libcpu/i386_parse.c
582 @@ -107,7 +107,7 @@
583  #include <assert.h>
584  #include <ctype.h>
585  #include <errno.h>
586 -#include <error.h>
587 +#include <err.h>
588  #include <inttypes.h>
589  #include <libintl.h>
590  #include <math.h>
591 --- a/libdw/libdw_alloc.c
592 +++ b/libdw/libdw_alloc.c
593 @@ -31,7 +31,7 @@
594  # include <config.h>
595  #endif
596  
597 -#include <error.h>
598 +#include <err.h>
599  #include <errno.h>
600  #include <stdlib.h>
601  #include <sys/param.h>
602 @@ -74,5 +74,5 @@ __attribute ((noreturn, visibility ("hid
603  __libdw_oom (void)
604  {
605    while (1)
606 -    error (EXIT_FAILURE, ENOMEM, "libdw");
607 +    err (EXIT_FAILURE, "libdw: out of memory");
608  }
609 --- a/libebl/eblopenbackend.c
610 +++ b/libebl/eblopenbackend.c
611 @@ -32,7 +32,7 @@
612  
613  #include <assert.h>
614  #include <dlfcn.h>
615 -#include <error.h>
616 +#include <err.h>
617  #include <libelfP.h>
618  #include <dwarf.h>
619  #include <stdlib.h>
620 --- a/libdwfl/dwfl_error.c
621 +++ b/libdwfl/dwfl_error.c
622 @@ -140,6 +140,7 @@ __libdwfl_seterrno (Dwfl_Error error)
623  const char *
624  dwfl_errmsg (int error)
625  {
626 +  static __thread char s[64] = "";
627    if (error == 0 || error == -1)
628      {
629        int last_error = global_error;
630 @@ -154,7 +155,8 @@ dwfl_errmsg (int error)
631    switch (error &~ 0xffff)
632      {
633      case OTHER_ERROR (ERRNO):
634 -      return strerror_r (error & 0xffff, "bad", 0);
635 +      strerror_r (error & 0xffff, s, sizeof(s));
636 +      return s;
637      case OTHER_ERROR (LIBELF):
638        return elf_errmsg (error & 0xffff);
639      case OTHER_ERROR (LIBDW):
640 --- a/libdwfl/libdwfl.h
641 +++ b/libdwfl/libdwfl.h
642 @@ -31,6 +31,27 @@
643  
644  #include "libdw.h"
645  #include <stdio.h>
646 +#include <unistd.h>
647 +#include <alloca.h>
648 +#include <string.h>
649 +
650 +#ifndef TEMP_FAILURE_RETRY
651 +#define TEMP_FAILURE_RETRY(expression) \
652 +  (__extension__                                                              \
653 +    ({ long int __result;                                                     \
654 +       do __result = (long int) (expression);                                 \
655 +       while (__result == -1L && errno == EINTR);                             \
656 +       __result; }))
657 +#endif
658 +
659 +#ifndef strndupa
660 +#define strndupa(s, n) \
661 +       (__extension__ ({const char *__in = (s); \
662 +                        size_t __len = strnlen (__in, (n)) + 1; \
663 +                        char *__out = (char *) alloca (__len); \
664 +                        __out[__len-1] = '\0'; \
665 +                        (char *) memcpy (__out, __in, __len-1);}))
666 +#endif
667  
668  /* Handle for a session using the library.  */
669  typedef struct Dwfl Dwfl;
670 --- a/libdwfl/find-debuginfo.c
671 +++ b/libdwfl/find-debuginfo.c
672 @@ -385,7 +385,7 @@ dwfl_standard_find_debuginfo (Dwfl_Modul
673        /* If FILE_NAME is a symlink, the debug file might be associated
674          with the symlink target name instead.  */
675  
676 -      char *canon = canonicalize_file_name (file_name);
677 +      char *canon = realpath (file_name, NULL);
678        if (canon != NULL && strcmp (file_name, canon))
679         fd = find_debuginfo_in_path (mod, canon,
680                                      debuglink_file, debuglink_crc,
681 --- a/libdwfl/dwfl_build_id_find_elf.c
682 +++ b/libdwfl/dwfl_build_id_find_elf.c
683 @@ -94,7 +94,7 @@ __libdwfl_open_by_build_id (Dwfl_Module
684         {
685           if (*file_name != NULL)
686             free (*file_name);
687 -         *file_name = canonicalize_file_name (name);
688 +         *file_name = realpath (name, NULL);
689           if (*file_name == NULL)
690             {
691               *file_name = name;
692 --- a/libelf/elf_getarsym.c
693 +++ b/libelf/elf_getarsym.c
694 @@ -297,7 +297,7 @@ elf_getarsym (Elf *elf, size_t *ptr)
695                 arsym[cnt].as_off = (*u32)[cnt];
696  
697               arsym[cnt].as_hash = _dl_elf_hash (str_data);
698 -             str_data = rawmemchr (str_data, '\0') + 1;
699 +             str_data = memchr (str_data, '\0', SIZE_MAX) + 1;
700             }
701  
702           /* At the end a special entry.  */