-
Notifications
You must be signed in to change notification settings - Fork 3
/
libiberty-sync.patch
1790 lines (1686 loc) · 55.5 KB
/
libiberty-sync.patch
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
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
From 7b944065aabe7703336180549369db026f1dea52 Mon Sep 17 00:00:00 2001
From: Patrick McCarty <[email protected]>
Date: Mon, 10 Feb 2020 13:06:16 -0800
Subject: [PATCH] Sync libiberty sources from mainline
binutils upgraded their sources, so the gcc-9 stable branch copies
needed the same treatment.
(Note that I excluded ChangeLog updates and files for which only the
copyright year changed, to reduce the diff.)
Signed-off-by: Patrick McCarty <[email protected]>
---
include/ansidecl.h | 36 +-
include/demangle.h | 24 +-
include/hashtab.h | 6 +-
include/libiberty.h | 20 +-
libiberty/Makefile.in | 16 +-
libiberty/argv.c | 8 +
libiberty/cp-demangle.c | 64 +-
libiberty/cp-demint.c | 5 +-
libiberty/cplus-dem.c | 52 +-
libiberty/d-demangle.c | 22 +-
libiberty/filedescriptor.c | 47 ++
libiberty/hashtab.c | 6 +-
libiberty/make-relative-prefix.c | 5 +-
libiberty/rust-demangle.c | 686 +++++++++++++--------
libiberty/simple-object-elf.c | 88 ++-
libiberty/testsuite/d-demangle-expected | 20 +
libiberty/testsuite/demangle-expected | 22 +-
libiberty/testsuite/rust-demangle-expected | 6 +-
18 files changed, 746 insertions(+), 387 deletions(-)
create mode 100644 libiberty/filedescriptor.c
diff --git a/include/ansidecl.h b/include/ansidecl.h
index 0395c4d0e..ec7a13f01 100644
--- a/include/ansidecl.h
+++ b/include/ansidecl.h
@@ -1,5 +1,5 @@
/* ANSI and traditional C compatability macros
- Copyright (C) 1991-2019 Free Software Foundation, Inc.
+ Copyright (C) 1991-2020 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software; you can redistribute it and/or modify
@@ -292,6 +292,40 @@ So instead we use the macro below and test it against specific values. */
# endif
#endif
+/* Attribute `alloc_size' was valid as of gcc 4.3. */
+#ifndef ATTRIBUTE_RESULT_SIZE_1
+# if (GCC_VERSION >= 4003)
+# define ATTRIBUTE_RESULT_SIZE_1 __attribute__ ((alloc_size (1)))
+# else
+# define ATTRIBUTE_RESULT_SIZE_1
+#endif
+#endif
+
+#ifndef ATTRIBUTE_RESULT_SIZE_2
+# if (GCC_VERSION >= 4003)
+# define ATTRIBUTE_RESULT_SIZE_2 __attribute__ ((alloc_size (2)))
+# else
+# define ATTRIBUTE_RESULT_SIZE_2
+#endif
+#endif
+
+#ifndef ATTRIBUTE_RESULT_SIZE_1_2
+# if (GCC_VERSION >= 4003)
+# define ATTRIBUTE_RESULT_SIZE_1_2 __attribute__ ((alloc_size (1, 2)))
+# else
+# define ATTRIBUTE_RESULT_SIZE_1_2
+#endif
+#endif
+
+/* Attribute `warn_unused_result' was valid as of gcc 3.3. */
+#ifndef ATTRIBUTE_WARN_UNUSED_RESULT
+# if GCC_VERSION >= 3003
+# define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
+# else
+# define ATTRIBUTE_WARN_UNUSED_RESULT
+# endif
+#endif
+
/* We use __extension__ in some places to suppress -pedantic warnings
about GCC extensions. This feature didn't work properly before
gcc 2.8. */
diff --git a/include/demangle.h b/include/demangle.h
index f5d9b9e8b..a7f11f592 100644
--- a/include/demangle.h
+++ b/include/demangle.h
@@ -1,5 +1,5 @@
/* Defs for interface to demanglers.
- Copyright (C) 1992-2019 Free Software Foundation, Inc.
+ Copyright (C) 1992-2020 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License
@@ -159,24 +159,11 @@ ada_demangle (const char *mangled, int options);
extern char *
dlang_demangle (const char *mangled, int options);
-/* Returns non-zero iff MANGLED is a rust mangled symbol. MANGLED must
- already have been demangled through cplus_demangle_v3. If this function
- returns non-zero then MANGLED can be demangled (in-place) using
- RUST_DEMANGLE_SYM. */
extern int
-rust_is_mangled (const char *mangled);
-
-/* Demangles SYM (in-place) if RUST_IS_MANGLED returned non-zero for SYM.
- If RUST_IS_MANGLED returned zero for SYM then RUST_DEMANGLE_SYM might
- replace characters that cannot be demangled with '?' and might truncate
- SYM. After calling RUST_DEMANGLE_SYM SYM might be shorter, but never
- larger. */
-extern void
-rust_demangle_sym (char *sym);
-
-/* Demangles MANGLED if it was GNU_V3 and then RUST mangled, otherwise
- returns NULL. Uses CPLUS_DEMANGLE_V3, RUST_IS_MANGLED and
- RUST_DEMANGLE_SYM. Returns a new string that is owned by the caller. */
+rust_demangle_callback (const char *mangled, int options,
+ demangle_callbackref callback, void *opaque);
+
+
extern char *
rust_demangle (const char *mangled, int options);
@@ -481,6 +468,7 @@ struct demangle_component
Initialize to zero. Private to d_print_comp.
All other fields are final after initialization. */
int d_printing;
+ int d_counting;
union
{
diff --git a/include/hashtab.h b/include/hashtab.h
index 9bb0293b6..6cca342b9 100644
--- a/include/hashtab.h
+++ b/include/hashtab.h
@@ -1,5 +1,5 @@
/* An expandable hash tables datatype.
- Copyright (C) 1999-2019 Free Software Foundation, Inc.
+ Copyright (C) 1999-2020 Free Software Foundation, Inc.
Contributed by Vladimir Makarov ([email protected]).
This program is free software; you can redistribute it and/or modify
@@ -173,8 +173,8 @@ extern void * htab_find_with_hash (htab_t, const void *, hashval_t);
extern void ** htab_find_slot_with_hash (htab_t, const void *,
hashval_t, enum insert_option);
extern void htab_clear_slot (htab_t, void **);
-extern void htab_remove_elt (htab_t, void *);
-extern void htab_remove_elt_with_hash (htab_t, void *, hashval_t);
+extern void htab_remove_elt (htab_t, const void *);
+extern void htab_remove_elt_with_hash (htab_t, const void *, hashval_t);
extern void htab_traverse (htab_t, htab_trav, void *);
extern void htab_traverse_noresize (htab_t, htab_trav, void *);
diff --git a/include/libiberty.h b/include/libiberty.h
index 574761350..141cb886a 100644
--- a/include/libiberty.h
+++ b/include/libiberty.h
@@ -1,6 +1,6 @@
/* Function declarations for libiberty.
- Copyright (C) 1997-2019 Free Software Foundation, Inc.
+ Copyright (C) 1997-2020 Free Software Foundation, Inc.
Note - certain prototypes declared in this header file are for
functions whoes implementation copyright does not belong to the
@@ -137,6 +137,10 @@ extern const char *unix_lbasename (const char *) ATTRIBUTE_RETURNS_NONNULL ATTRI
extern char *lrealpath (const char *);
+/* Return true when FD file descriptor exists. */
+
+extern int is_valid_fd (int fd);
+
/* Concatenate an arbitrary number of strings. You must pass NULL as
the last argument of this function, to terminate the list of
strings. Allocates memory using xmalloc. */
@@ -310,30 +314,30 @@ extern void xmalloc_failed (size_t) ATTRIBUTE_NORETURN;
message to stderr (using the name set by xmalloc_set_program_name,
if any) and then call xexit. */
-extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
+extern void *xmalloc (size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1 ATTRIBUTE_WARN_UNUSED_RESULT;
/* Reallocate memory without fail. This works like xmalloc. Note,
realloc type functions are not suitable for attribute malloc since
they may return the same address across multiple calls. */
-extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL;
+extern void *xrealloc (void *, size_t) ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_2 ATTRIBUTE_WARN_UNUSED_RESULT;
/* Allocate memory without fail and set it to zero. This works like
xmalloc. */
-extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
+extern void *xcalloc (size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_RESULT_SIZE_1_2 ATTRIBUTE_WARN_UNUSED_RESULT;
/* Copy a string into a memory buffer without fail. */
-extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
+extern char *xstrdup (const char *) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
/* Copy at most N characters from string into a buffer without fail. */
-extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
+extern char *xstrndup (const char *, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
/* Copy an existing memory buffer to a new memory buffer without fail. */
-extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL;
+extern void *xmemdup (const void *, size_t, size_t) ATTRIBUTE_MALLOC ATTRIBUTE_RETURNS_NONNULL ATTRIBUTE_WARN_UNUSED_RESULT;
/* Physical memory routines. Return values are in BYTES. */
extern double physmem_total (void);
@@ -649,7 +653,7 @@ extern int asprintf (char **, const char *, ...) ATTRIBUTE_PRINTF_2;
extern char *xasprintf (const char *, ...) ATTRIBUTE_MALLOC ATTRIBUTE_PRINTF_1;
-#if !HAVE_DECL_VASPRINTF
+#if defined(HAVE_DECL_VASPRINTF) && !HAVE_DECL_VASPRINTF
/* Like vsprintf but provides a pointer to malloc'd storage, which
must be freed by the caller. */
diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in
index 0be45b4ae..fe738d0db 100644
--- a/libiberty/Makefile.in
+++ b/libiberty/Makefile.in
@@ -1,7 +1,7 @@
# Makefile for the libiberty library.
# Originally written by K. Richard Pixley <[email protected]>.
#
-# Copyright (C) 1990-2019 Free Software Foundation, Inc.
+# Copyright (C) 1990-2020 Free Software Foundation, Inc.
#
# This file is part of the libiberty library.
# Libiberty is free software; you can redistribute it and/or
@@ -127,7 +127,7 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \
calloc.c choose-temp.c clock.c concat.c cp-demangle.c \
cp-demint.c cplus-dem.c crc32.c \
d-demangle.c dwarfnames.c dyn-string.c \
- fdmatch.c ffs.c fibheap.c filename_cmp.c floatformat.c \
+ fdmatch.c ffs.c fibheap.c filedescriptor.c filename_cmp.c floatformat.c \
fnmatch.c fopen_unlocked.c \
getcwd.c getopt.c getopt1.c getpagesize.c getpwd.c getruntime.c \
gettimeofday.c \
@@ -171,6 +171,7 @@ REQUIRED_OFILES = \
./cp-demint.$(objext) ./crc32.$(objext) ./d-demangle.$(objext) \
./dwarfnames.$(objext) ./dyn-string.$(objext) \
./fdmatch.$(objext) ./fibheap.$(objext) \
+ ./filedescriptor.$(objext) \
./filename_cmp.$(objext) ./floatformat.$(objext) \
./fnmatch.$(objext) ./fopen_unlocked.$(objext) \
./getopt.$(objext) ./getopt1.$(objext) ./getpwd.$(objext) \
@@ -756,6 +757,17 @@ $(CONFIGURED_OFILES): stamp-picdir stamp-noasandir
else true; fi
$(COMPILE.c) $(srcdir)/fibheap.c $(OUTPUT_OPTION)
+./filedescriptor.$(objext): $(srcdir)/filedescriptor.c config.h $(INCDIR)/ansidecl.h \
+ $(INCDIR)/libiberty.h
+ if [ x"$(PICFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(srcdir)/filedescriptor.c -o pic/$@; \
+ else true; fi
+ if [ x"$(NOASANFLAG)" != x ]; then \
+ $(COMPILE.c) $(PICFLAG) $(NOASANFLAG) $(srcdir)/filedescriptor.c -o noasan/$@; \
+ else true; fi
+ $(COMPILE.c) $(srcdir)/filedescriptor.c $(OUTPUT_OPTION)
+
+
./filename_cmp.$(objext): $(srcdir)/filename_cmp.c config.h $(INCDIR)/ansidecl.h \
$(INCDIR)/filenames.h $(INCDIR)/hashtab.h \
$(INCDIR)/safe-ctype.h
diff --git a/libiberty/argv.c b/libiberty/argv.c
index 6444896f9..14c1c5115 100644
--- a/libiberty/argv.c
+++ b/libiberty/argv.c
@@ -327,6 +327,14 @@ writeargv (char * const *argv, FILE *f)
arg++;
}
+ /* Write out a pair of quotes for an empty argument. */
+ if (arg == *argv)
+ if (EOF == fputs ("\"\"", f))
+ {
+ status = 1;
+ goto done;
+ }
+
if (EOF == fputc ('\n', f))
{
status = 1;
diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c
index 779b4e763..fc55b7fae 100644
--- a/libiberty/cp-demangle.c
+++ b/libiberty/cp-demangle.c
@@ -1,5 +1,5 @@
/* Demangler for g++ V3 ABI.
- Copyright (C) 2003-2019 Free Software Foundation, Inc.
+ Copyright (C) 2003-2020 Free Software Foundation, Inc.
Written by Ian Lance Taylor <[email protected]>.
This file is part of the libiberty library, which is part of GCC.
@@ -192,9 +192,9 @@ static void d_init_info (const char *, int, size_t, struct d_info *);
#else
#ifdef __STDC__
#ifdef __STDC_VERSION__
-#if __STDC_VERSION__ >= 199901L
+#if __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__
#define CP_DYNAMIC_ARRAYS
-#endif /* __STDC__VERSION >= 199901L */
+#endif /* __STDC_VERSION__ >= 199901L && !__STDC_NO_VLA__ */
#endif /* defined (__STDC_VERSION__) */
#endif /* defined (__STDC__) */
#endif /* ! defined (__GNUC__) */
@@ -517,7 +517,7 @@ d_growable_string_callback_adapter (const char *, size_t, void *);
static void
d_print_init (struct d_print_info *, demangle_callbackref, void *,
- const struct demangle_component *);
+ struct demangle_component *);
static inline void d_print_error (struct d_print_info *);
@@ -864,6 +864,7 @@ cplus_demangle_fill_name (struct demangle_component *p, const char *s, int len)
if (p == NULL || s == NULL || len <= 0)
return 0;
p->d_printing = 0;
+ p->d_counting = 0;
p->type = DEMANGLE_COMPONENT_NAME;
p->u.s_name.s = s;
p->u.s_name.len = len;
@@ -880,6 +881,7 @@ cplus_demangle_fill_extended_operator (struct demangle_component *p, int args,
if (p == NULL || args < 0 || name == NULL)
return 0;
p->d_printing = 0;
+ p->d_counting = 0;
p->type = DEMANGLE_COMPONENT_EXTENDED_OPERATOR;
p->u.s_extended_operator.args = args;
p->u.s_extended_operator.name = name;
@@ -900,6 +902,7 @@ cplus_demangle_fill_ctor (struct demangle_component *p,
|| (int) kind > gnu_v3_object_ctor_group)
return 0;
p->d_printing = 0;
+ p->d_counting = 0;
p->type = DEMANGLE_COMPONENT_CTOR;
p->u.s_ctor.kind = kind;
p->u.s_ctor.name = name;
@@ -920,6 +923,7 @@ cplus_demangle_fill_dtor (struct demangle_component *p,
|| (int) kind > gnu_v3_object_dtor_group)
return 0;
p->d_printing = 0;
+ p->d_counting = 0;
p->type = DEMANGLE_COMPONENT_DTOR;
p->u.s_dtor.kind = kind;
p->u.s_dtor.name = name;
@@ -937,6 +941,7 @@ d_make_empty (struct d_info *di)
return NULL;
p = &di->comps[di->next_comp];
p->d_printing = 0;
+ p->d_counting = 0;
++di->next_comp;
return p;
}
@@ -1330,8 +1335,14 @@ d_encoding (struct d_info *di, int top_level)
really apply here; this happens when parsing a class
which is local to a function. */
if (dc->type == DEMANGLE_COMPONENT_LOCAL_NAME)
- while (is_fnqual_component_type (d_right (dc)->type))
- d_right (dc) = d_left (d_right (dc));
+ {
+ while (d_right (dc) != NULL
+ && is_fnqual_component_type (d_right (dc)->type))
+ d_right (dc) = d_left (d_right (dc));
+
+ if (d_right (dc) == NULL)
+ dc = NULL;
+ }
}
else
{
@@ -1711,7 +1722,7 @@ d_number (struct d_info *di)
}
if (ret > ((INT_MAX - (peek - '0')) / 10))
return -1;
- ret = ret * 10 + peek - '0';
+ ret = ret * 10 + (peek - '0');
d_advance (di, 1);
peek = d_peek_char (di);
}
@@ -1791,6 +1802,7 @@ const struct demangle_operator_info cplus_demangle_operators[] =
{ "ad", NL ("&"), 1 },
{ "an", NL ("&"), 2 },
{ "at", NL ("alignof "), 1 },
+ { "aw", NL ("co_await "), 1 },
{ "az", NL ("alignof "), 1 },
{ "cc", NL ("const_cast"), 2 },
{ "cl", NL ("()"), 2 },
@@ -3359,7 +3371,7 @@ d_expression_1 (struct d_info *di)
d_advance (di, 2);
if (peek == 't')
type = cplus_demangle_type (di);
- if (!d_peek_next_char (di))
+ if (!d_peek_char (di) || !d_peek_next_char (di))
return NULL;
return d_make_comp (di, DEMANGLE_COMPONENT_INITIALIZER_LIST,
type, d_exprlist (di, 'E'));
@@ -3571,6 +3583,17 @@ d_expr_primary (struct d_info *di)
&& type->u.s_builtin.type->print != D_PRINT_DEFAULT)
di->expansion -= type->u.s_builtin.type->len;
+ if (type->type == DEMANGLE_COMPONENT_BUILTIN_TYPE
+ && strcmp (type->u.s_builtin.type->name,
+ cplus_demangle_builtin_types[33].name) == 0)
+ {
+ if (d_peek_char (di) == 'E')
+ {
+ d_advance (di, 1);
+ return type;
+ }
+ }
+
/* Rather than try to interpret the literal value, we just
collect it as a string. Note that it's possible to have a
floating point literal here. The ABI specifies that the
@@ -4062,11 +4085,13 @@ d_growable_string_callback_adapter (const char *s, size_t l, void *opaque)
static void
d_count_templates_scopes (struct d_print_info *dpi,
- const struct demangle_component *dc)
+ struct demangle_component *dc)
{
- if (dc == NULL)
+ if (dc == NULL || dc->d_counting > 1 || dpi->recursion > MAX_RECURSION_COUNT)
return;
+ ++ dc->d_counting;
+
switch (dc->type)
{
case DEMANGLE_COMPONENT_NAME:
@@ -4196,7 +4221,7 @@ d_count_templates_scopes (struct d_print_info *dpi,
static void
d_print_init (struct d_print_info *dpi, demangle_callbackref callback,
- void *opaque, const struct demangle_component *dc)
+ void *opaque, struct demangle_component *dc)
{
dpi->len = 0;
dpi->last_char = '\0';
@@ -4761,12 +4786,8 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
typed_name = d_right (typed_name);
if (typed_name->type == DEMANGLE_COMPONENT_DEFAULT_ARG)
typed_name = typed_name->u.s_unary_num.sub;
- if (typed_name == NULL)
- {
- d_print_error (dpi);
- return;
- }
- while (is_fnqual_component_type (typed_name->type))
+ while (typed_name != NULL
+ && is_fnqual_component_type (typed_name->type))
{
if (i >= sizeof adpm / sizeof adpm[0])
{
@@ -4785,6 +4806,11 @@ d_print_comp_inner (struct d_print_info *dpi, int options,
typed_name = d_left (typed_name);
}
+ if (typed_name == NULL)
+ {
+ d_print_error (dpi);
+ return;
+ }
}
/* If typed_name is a template, then it applies to the
@@ -5970,10 +5996,10 @@ d_print_mod (struct d_print_info *dpi, int options,
d_append_string (dpi, "&&");
return;
case DEMANGLE_COMPONENT_COMPLEX:
- d_append_string (dpi, "complex ");
+ d_append_string (dpi, " _Complex");
return;
case DEMANGLE_COMPONENT_IMAGINARY:
- d_append_string (dpi, "imaginary ");
+ d_append_string (dpi, " _Imaginary");
return;
case DEMANGLE_COMPONENT_PTRMEM_TYPE:
if (d_last_char (dpi) != '(')
diff --git a/libiberty/cp-demint.c b/libiberty/cp-demint.c
index 950e4dc55..6e41bad26 100644
--- a/libiberty/cp-demint.c
+++ b/libiberty/cp-demint.c
@@ -1,5 +1,5 @@
/* Demangler component interface functions.
- Copyright (C) 2004-2019 Free Software Foundation, Inc.
+ Copyright (C) 2004-2020 Free Software Foundation, Inc.
Written by Ian Lance Taylor <[email protected]>.
This file is part of the libiberty library, which is part of GCC.
@@ -125,6 +125,7 @@ cplus_demangle_fill_component (struct demangle_component *p,
p->u.s_binary.left = left;
p->u.s_binary.right = right;
p->d_printing = 0;
+ p->d_counting = 0;
return 1;
}
@@ -149,6 +150,7 @@ cplus_demangle_fill_builtin_type (struct demangle_component *p,
p->type = DEMANGLE_COMPONENT_BUILTIN_TYPE;
p->u.s_builtin.type = &cplus_demangle_builtin_types[i];
p->d_printing = 0;
+ p->d_counting = 0;
return 1;
}
}
@@ -176,6 +178,7 @@ cplus_demangle_fill_operator (struct demangle_component *p,
p->type = DEMANGLE_COMPONENT_OPERATOR;
p->u.s_operator.op = &cplus_demangle_operators[i];
p->d_printing = 0;
+ p->d_counting = 0;
return 1;
}
}
diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c
index afceed2a1..fb0673d18 100644
--- a/libiberty/cplus-dem.c
+++ b/libiberty/cplus-dem.c
@@ -1,5 +1,5 @@
/* Demangler for GNU C++
- Copyright (C) 1989-2019 Free Software Foundation, Inc.
+ Copyright (C) 1989-2020 Free Software Foundation, Inc.
Written by James Clark ([email protected])
Rewritten by Fred Fish ([email protected]) for ARM and Lucid demangling
Modified by Satish Pai ([email protected]) for HP demangling
@@ -159,27 +159,20 @@ cplus_demangle (const char *mangled, int options)
if ((options & DMGL_STYLE_MASK) == 0)
options |= (int) current_demangling_style & DMGL_STYLE_MASK;
+ /* The Rust demangling is implemented elsewhere.
+ Legacy Rust symbols overlap with GNU_V3, so try Rust first. */
+ if (RUST_DEMANGLING || AUTO_DEMANGLING)
+ {
+ ret = rust_demangle (mangled, options);
+ if (ret || RUST_DEMANGLING)
+ return ret;
+ }
+
/* The V3 ABI demangling is implemented elsewhere. */
- if (GNU_V3_DEMANGLING || RUST_DEMANGLING || AUTO_DEMANGLING)
+ if (GNU_V3_DEMANGLING || AUTO_DEMANGLING)
{
ret = cplus_demangle_v3 (mangled, options);
- if (GNU_V3_DEMANGLING)
- return ret;
-
- if (ret)
- {
- /* Rust symbols are GNU_V3 mangled plus some extra subtitutions.
- The subtitutions are always smaller, so do in place changes. */
- if (rust_is_mangled (ret))
- rust_demangle_sym (ret);
- else if (RUST_DEMANGLING)
- {
- free (ret);
- ret = NULL;
- }
- }
-
- if (ret || RUST_DEMANGLING)
+ if (ret || GNU_V3_DEMANGLING)
return ret;
}
@@ -203,27 +196,6 @@ cplus_demangle (const char *mangled, int options)
return (ret);
}
-char *
-rust_demangle (const char *mangled, int options)
-{
- /* Rust symbols are GNU_V3 mangled plus some extra subtitutions. */
- char *ret = cplus_demangle_v3 (mangled, options);
-
- /* The Rust subtitutions are always smaller, so do in place changes. */
- if (ret != NULL)
- {
- if (rust_is_mangled (ret))
- rust_demangle_sym (ret);
- else
- {
- free (ret);
- ret = NULL;
- }
- }
-
- return ret;
-}
-
/* Demangle ada names. The encoding is documented in gcc/ada/exp_dbug.ads. */
char *
diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c
index 8acbf046f..a9702858a 100644
--- a/libiberty/d-demangle.c
+++ b/libiberty/d-demangle.c
@@ -1,5 +1,5 @@
/* Demangler for the D programming language
- Copyright (C) 2014-2019 Free Software Foundation, Inc.
+ Copyright (C) 2014-2020 Free Software Foundation, Inc.
Written by Iain Buclaw ([email protected])
This file is part of the libiberty library.
@@ -939,8 +939,8 @@ dlang_parse_integer (string *decl, const char *mangled, char type)
if (type == 'a' || type == 'u' || type == 'w')
{
/* Parse character value. */
- char value[10];
- int pos = 10;
+ char value[20];
+ int pos = sizeof(value);
int width = 0;
long val;
@@ -991,7 +991,7 @@ dlang_parse_integer (string *decl, const char *mangled, char type)
for (; width > 0; width--)
value[--pos] = '0';
- string_appendn (decl, &(value[pos]), 10 - pos);
+ string_appendn (decl, &(value[pos]), sizeof(value) - pos);
}
string_append (decl, "'");
}
@@ -1191,6 +1191,9 @@ dlang_parse_arrayliteral (string *decl, const char *mangled)
while (elements--)
{
mangled = dlang_value (decl, mangled, NULL, '\0');
+ if (mangled == NULL)
+ return NULL;
+
if (elements != 0)
string_append (decl, ", ");
}
@@ -1214,8 +1217,13 @@ dlang_parse_assocarray (string *decl, const char *mangled)
while (elements--)
{
mangled = dlang_value (decl, mangled, NULL, '\0');
+ if (mangled == NULL)
+ return NULL;
+
string_append (decl, ":");
mangled = dlang_value (decl, mangled, NULL, '\0');
+ if (mangled == NULL)
+ return NULL;
if (elements != 0)
string_append (decl, ", ");
@@ -1243,6 +1251,9 @@ dlang_parse_structlit (string *decl, const char *mangled, const char *name)
while (args--)
{
mangled = dlang_value (decl, mangled, NULL, '\0');
+ if (mangled == NULL)
+ return NULL;
+
if (args != 0)
string_append (decl, ", ");
}
@@ -1497,6 +1508,9 @@ dlang_parse_tuple (string *decl, const char *mangled)
while (elements--)
{
mangled = dlang_type (decl, mangled);
+ if (mangled == NULL)
+ return NULL;
+
if (elements != 0)
string_append (decl, ", ");
}
diff --git a/libiberty/filedescriptor.c b/libiberty/filedescriptor.c
new file mode 100644
index 000000000..ba2e87c24
--- /dev/null
+++ b/libiberty/filedescriptor.c
@@ -0,0 +1,47 @@
+/* File descriptor related functions.
+
+ Copyright (C) 2019-2020 Free Software Foundation, Inc.
+
+ This file is part of the libiberty library.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor,
+ Boston, MA 02110-1301, USA. */
+
+#include "config.h"
+#include "ansidecl.h"
+#include "libiberty.h"
+
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#if defined (_WIN32)
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h> /* for GetFullPathName */
+#endif
+/* Return true when FD file descriptor exists. */
+
+int
+is_valid_fd (int fd)
+{
+#if defined(_WIN32)
+ HANDLE h = (HANDLE) _get_osfhandle (fd);
+ return h != (HANDLE) -1;
+#elif defined(F_GETFD)
+ return fcntl (fd, F_GETFD) >= 0;
+#else
+ return dup2 (fd, fd) < 0;
+#endif
+}
diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
index 9f917c357..225e9e540 100644
--- a/libiberty/hashtab.c
+++ b/libiberty/hashtab.c
@@ -1,5 +1,5 @@
/* An expandable hash tables datatype.
- Copyright (C) 1999-2019 Free Software Foundation, Inc.
+ Copyright (C) 1999-2020 Free Software Foundation, Inc.
Contributed by Vladimir Makarov ([email protected]).
This file is part of the libiberty library.
@@ -709,7 +709,7 @@ htab_find_slot (htab_t htab, const PTR element, enum insert_option insert)
element in the hash table, this function does nothing. */
void
-htab_remove_elt (htab_t htab, PTR element)
+htab_remove_elt (htab_t htab, const PTR element)
{
htab_remove_elt_with_hash (htab, element, (*htab->hash_f) (element));
}
@@ -720,7 +720,7 @@ htab_remove_elt (htab_t htab, PTR element)
function does nothing. */
void
-htab_remove_elt_with_hash (htab_t htab, PTR element, hashval_t hash)
+htab_remove_elt_with_hash (htab_t htab, const PTR element, hashval_t hash)
{
PTR *slot;
diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c
index ec0b0ee74..e3f9f920d 100644
--- a/libiberty/make-relative-prefix.c
+++ b/libiberty/make-relative-prefix.c
@@ -1,5 +1,5 @@
/* Relative (relocatable) prefix support.
- Copyright (C) 1987-2019 Free Software Foundation, Inc.
+ Copyright (C) 1987-2020 Free Software Foundation, Inc.
This file is part of libiberty.
@@ -122,6 +122,9 @@ split_directories (const char *name, int *ptr_num_dirs)
const char *p, *q;
int ch;
+ if (!*name)
+ return NULL;
+
/* Count the number of directories. Special case MSDOS disk names as part
of the initial directory. */
p = name;
diff --git a/libiberty/rust-demangle.c b/libiberty/rust-demangle.c
index 9b2d2dbe6..b87365c85 100644
--- a/libiberty/rust-demangle.c
+++ b/libiberty/rust-demangle.c
@@ -1,5 +1,5 @@
/* Demangler for the Rust programming language
- Copyright (C) 2016-2019 Free Software Foundation, Inc.
+ Copyright (C) 2016-2020 Free Software Foundation, Inc.
Written by David Tolnay ([email protected]).
This file is part of the libiberty library.
@@ -33,9 +33,11 @@ If not, see <http://www.gnu.org/licenses/>. */
#include "safe-ctype.h"
+#include <inttypes.h>
#include <sys/types.h>
#include <string.h>
#include <stdio.h>
+#include <stdlib.h>
#ifdef HAVE_STRING_H
#include <string.h>
@@ -48,301 +50,483 @@ extern void *memset(void *s, int c, size_t n);
#include <demangle.h>
#include "libiberty.h"
+struct rust_demangler
+{
+ const char *sym;
+ size_t sym_len;
-/* Mangled Rust symbols look like this:
- _$LT$std..sys..fd..FileDesc$u20$as$u20$core..ops..Drop$GT$::drop::hc68340e1baa4987a
-
- The original symbol is:
- <std::sys::fd::FileDesc as core::ops::Drop>::drop
-
- The last component of the path is a 64-bit hash in lowercase hex,
- prefixed with "h". Rust does not have a global namespace between
- crates, an illusion which Rust maintains by using the hash to
- distinguish things that would otherwise have the same symbol.
-
- Any path component not starting with a XID_Start character is
- prefixed with "_".
-
- The following escape sequences are used:
+ void *callback_opaque;
+ demangle_callbackref callback;
- "," => $C$
- "@" => $SP$
- "*" => $BP$
- "&" => $RF$
- "<" => $LT$
- ">" => $GT$
- "(" => $LP$
- ")" => $RP$
- " " => $u20$
- "\"" => $u22$
- "'" => $u27$
- "+" => $u2b$
- ";" => $u3b$
- "[" => $u5b$
- "]" => $u5d$
- "{" => $u7b$
- "}" => $u7d$
- "~" => $u7e$
+ /* Position of the next character to read from the symbol. */
+ size_t next;
- A double ".." means "::" and a single "." means "-".
+ /* Non-zero if any error occurred. */
+ int errored;
- The only characters allowed in the mangled symbol are a-zA-Z0-9 and _.:$ */
+ /* Non-zero if printing should be verbose (e.g. include hashes). */
+ int verbose;
-static const char *hash_prefix = "::h";
-static const size_t hash_prefix_len = 3;
-static const size_t hash_len = 16;
+ /* Rust mangling version, with legacy mangling being -1. */
+ int version;
+};
-static int is_prefixed_hash (const char *start);
-static int looks_like_rust (const char *sym, size_t len);
-static int unescape (const char **in, char **out, const char *seq, char value);
+/* Parsing functions. */
-/* INPUT: sym: symbol that has been through C++ (gnu v3) demangling
+static char
+peek (const struct rust_demangler *rdm)
+{
+ if (rdm->next < rdm->sym_len)
+ return rdm->sym[rdm->next];
+ return 0;
+}
- This function looks for the following indicators:
+static char
+next (struct rust_demangler *rdm)
+{
+ char c = peek (rdm);
+ if (!c)
+ rdm->errored = 1;
+ else
+ rdm->next++;
+ return c;
+}
- 1. The hash must consist of "h" followed by 16 lowercase hex digits.
+struct rust_mangled_ident
+{
+ /* ASCII part of the identifier. */
+ const char *ascii;
+ size_t ascii_len;
+};
- 2. As a sanity check, the hash must use between 5 and 15 of the 16
- possible hex digits. This is true of 99.9998% of hashes so once
- in your life you may see a false negative. The point is to
- notice path components that could be Rust hashes but are
- probably not, like "haaaaaaaaaaaaaaaa". In this case a false
- positive (non-Rust symbol has an important path component
- removed because it looks like a Rust hash) is worse than a false
- negative (the rare Rust symbol is not demangled) so this sets
- the balance in favor of false negatives.
+static struct rust_mangled_ident
+parse_ident (struct rust_demangler *rdm)
+{
+ char c;
+ size_t start, len;
+ struct rust_mangled_ident ident;
+
+ ident.ascii = NULL;
+ ident.ascii_len = 0;
+
+ c = next (rdm);
+ if (!ISDIGIT (c))
+ {
+ rdm->errored = 1;
+ return ident;
+ }
+ len = c - '0';
+
+ if (c != '0')
+ while (ISDIGIT (peek (rdm)))
+ len = len * 10 + (next (rdm) - '0');
+
+ start = rdm->next;
+ rdm->next += len;
+ /* Check for overflows. */
+ if ((start > rdm->next) || (rdm->next > rdm->sym_len))
+ {
+ rdm->errored = 1;
+ return ident;
+ }
+
+ ident.ascii = rdm->sym + start;
+ ident.ascii_len = len;
+
+ if (ident.ascii_len == 0)
+ ident.ascii = NULL;
+
+ return ident;
+}
- 3. There must be no characters other than a-zA-Z0-9 and _.:$
+/* Printing functions. */
- 4. There must be no unrecognized $-sign sequences.
+static void
+print_str (struct rust_demangler *rdm, const char *data, size_t len)
+{
+ if (!rdm->errored)
+ rdm->callback (data, len, rdm->callback_opaque);
+}
- 5. There must be no sequence of three or more dots in a row ("..."). */
+#define PRINT(s) print_str (rdm, s, strlen (s))
-int
-rust_is_mangled (const char *sym)
+/* Return a 0x0-0xf value if the char is 0-9a-f, and -1 otherwise. */
+static int
+decode_lower_hex_nibble (char nibble)
{
- size_t len, len_without_hash;
+ if ('0' <= nibble && nibble <= '9')
+ return nibble - '0';
+ if ('a' <= nibble && nibble <= 'f')
+ return 0xa + (nibble - 'a');
+ return -1;
+}
- if (!sym)
- return 0;
+/* Return the unescaped character for a "$...$" escape, or 0 if invalid. */
+static char
+decode_legacy_escape (const char *e, size_t len, size_t *out_len)
+{
+ char c = 0;
+ size_t escape_len = 0;
+ int lo_nibble = -1, hi_nibble = -1;
- len = strlen (sym);
- if (len <= hash_prefix_len + hash_len)
- /* Not long enough to contain "::h" + hash + something else */
+ if (len < 3 || e[0] != '$')
return 0;
- len_without_hash = len - (hash_prefix_len + hash_len);
- if (!is_prefixed_hash (sym + len_without_hash))
+ e++;
+ len--;
+
+ if (e[0] == 'C')