diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2013-04-11 09:13:11 +0000 |
---|---|---|
committer | <> | 2014-04-23 12:05:38 +0000 |
commit | 6af3fdec2262dd94954acc5e426ef71cbd4521d3 (patch) | |
tree | 9be02de9a80f7935892a2d03741adee44723e65d /libiberty | |
parent | 19be2b4342ac32e9edc78ce6fed8f61b63ae98d1 (diff) | |
download | gcc-tarball-6af3fdec2262dd94954acc5e426ef71cbd4521d3.tar.gz |
Imported from /home/lorry/working-area/delta_gcc-tarball/gcc-4.7.3.tar.bz2.gcc-4.7.3
Diffstat (limited to 'libiberty')
-rw-r--r-- | libiberty/ChangeLog | 325 | ||||
-rw-r--r-- | libiberty/Makefile.in | 33 | ||||
-rw-r--r-- | libiberty/aclocal.m4 | 3 | ||||
-rw-r--r-- | libiberty/argv.c | 23 | ||||
-rw-r--r-- | libiberty/config.in | 6 | ||||
-rwxr-xr-x | libiberty/configure | 126 | ||||
-rw-r--r-- | libiberty/configure.ac | 37 | ||||
-rw-r--r-- | libiberty/cp-demangle.c | 688 | ||||
-rw-r--r-- | libiberty/cp-demint.c | 6 | ||||
-rw-r--r-- | libiberty/cplus-dem.c | 3 | ||||
-rw-r--r-- | libiberty/filename_cmp.c | 28 | ||||
-rw-r--r-- | libiberty/make-relative-prefix.c | 24 | ||||
-rw-r--r-- | libiberty/makefile.vms | 2 | ||||
-rw-r--r-- | libiberty/md5.c | 41 | ||||
-rw-r--r-- | libiberty/pex-common.c | 9 | ||||
-rw-r--r-- | libiberty/pex-msdos.c | 6 | ||||
-rw-r--r-- | libiberty/pex-win32.c | 24 | ||||
-rw-r--r-- | libiberty/regex.c | 19 | ||||
-rw-r--r-- | libiberty/setproctitle.c | 4 | ||||
-rw-r--r-- | libiberty/sha1.c | 3 | ||||
-rw-r--r-- | libiberty/simple-object-mach-o.c | 515 | ||||
-rw-r--r-- | libiberty/spaces.c | 5 | ||||
-rw-r--r-- | libiberty/stack-limit.c | 62 | ||||
-rw-r--r-- | libiberty/testsuite/demangle-expected | 133 | ||||
-rw-r--r-- | libiberty/testsuite/test-demangle.c | 12 | ||||
-rw-r--r-- | libiberty/testsuite/test-expandargv.c | 2 | ||||
-rw-r--r-- | libiberty/timeval-utils.c | 87 |
27 files changed, 1797 insertions, 429 deletions
diff --git a/libiberty/ChangeLog b/libiberty/ChangeLog index e89e4e6730..60265f8e16 100644 --- a/libiberty/ChangeLog +++ b/libiberty/ChangeLog @@ -1,6 +1,181 @@ -2011-10-26 Release Manager +2013-04-11 Release Manager - * GCC 4.6.2 released. + * GCC 4.7.3 released. + +2013-02-19 Jakub Jelinek <jakub@redhat.com> + + Backported from mainline + 2013-02-09 Jakub Jelinek <jakub@redhat.com> + + PR other/56245 + * regex.c (PTR_INT_TYPE): Define. + (EXTEND_BUFFER): Change incr type from int to PTR_INT_TYPE. + +2013-01-31 Kai Tietz <ktietz@redhat.com> + + Merged from trunk + PR other/54620 + * sha1.c (sha1_process_block): Handle case that size_t is + a wider-integer-scalar as a 32-bit unsigned integer. + + Merged from trunk. + PR other/53413 + * md5.c (md5_process_block): Handle case that size_t is + a wider-integer-scalar a 32-bit unsigned integer. + + 2012-07-31 Mike Frysinger <vapier@gentoo.org> + + Merged from trunk. + PR other/53285 + * md5.c (md5_finish_ctx): Declare swap_bytes. Assign SWAP() output + to swap_bytes, and then call memcpy to move it to ctx->buffer. + +2012-09-20 Release Manager + + * GCC 4.7.2 released. + +2012-06-14 Release Manager + + * GCC 4.7.1 released. + +2012-03-24 H.J. Lu <hongjiu.lu@intel.com> + + * testsuite/demangle-expected: Fix a typo. + +2012-03-22 Jason Merrill <jason@redhat.com> + + * cp-demangle.c (cplus_demangle_operators): Add li. + (d_unqualified_name): Handle it specially. + +2012-03-22 Release Manager + + * GCC 4.7.0 released. + +2012-03-20 Jason Merrill <jason@redhat.com> + + * cp-demangle.c (cplus_demangle_type): Handle 'auto'. + +2012-01-26 Jakub Jelinek <jakub@redhat.com> + + * make-relative-prefix.c (make_relative_prefix_1): Avoid warning + about using preprocessor directives inside of macro arguments. + +2012-01-22 Douglas B Rupp <rupp@gnat.com> + + * configure: Regenerate. + +2012-01-10 Jason Merrill <jason@redhat.com> + + * cp-demangle.c (d_print_comp) [DEMANGLE_COMPONENT_OPERATOR]: + Omit a trailing space in the operator name. + +2012-01-06 Jason Merrill <jason@redhat.com> + + PR c++/6057 + PR c++/48051 + PR c++/50855 + PR c++/51322 + * cp-demangle.c (d_dump): Handle DEMANGLE_COMPONENT_NULLARY and + DEMANGLE_COMPONENT_INITIALIZER_LIST. + (d_make_comp): Likewise. Allow null right arg for + DEMANGLE_COMPONENT_TRINARY_ARG2. + (cplus_demangle_operators): Adjust new/delete; add .*, :: and throw. + (d_template_args, d_template_arg): Handle 'J' for argument packs. + (d_exprlist): Add terminator parm. + (d_expression, d_print_comp): Handle initializer lists, nullary + expressions, prefix/suffix operators, and new. + (d_print_subexpr): Avoid parens around DEMANGLE_COMPONENT_QUAL_NAME + and DEMANGLE_COMPONENT_INITIALIZER_LIST. + * testsuite/demangle-expected: Add tests. + + * cp-demangle.c (cplus_demangle_type): decltype, pack expansion + and vector are substitutable. + (cplus_demangle_operators): Sort. + +2012-01-04 Andreas Krebbel <Andreas.Krebbel@de.ibm.com> + + * configure: Regenerate. + +2012-01-02 Jakub Jelinek <jakub@redhat.com> + + * make-relative-prefix.c (make_relative_prefix_1): Avoid + stack overflow if PATH contains just a single entry and + HOST_EXECUTABLE_SUFFIX needs to be used. + + PR driver/48306 + * make-relative-prefix.c: Include sys/stat.h. + (make_relative_prefix_1): If access succeeds, check also stat + if nstore is a regular file. + +2011-12-20 Andreas Schwab <schwab@linux-m68k.org> + + * configure: Regenerate. + +2011-12-20 Tristan Gingold <gingold@adacore.com> + + * aclocal.m4: Assume strncmp works in cross case. + * configure: Regenerate + +2011-12-19 Andreas Schwab <schwab@linux-m68k.org> + + * configure: Regenerate. + +2011-11-07 Richard Henderson <rth@redhat.com> + + Merged from transactional-memory. + + * cp-demangle.c (cplus_demangle_fill_ctor): Accept + gnu_v3_object_ctor_group. + (cplus_demangle_fill_dtor): Accept gnu_v3_object_dtor_group. + (d_ctor_dtor_name): Recognize gnu_v3_object_ctor_group + and gnu_v3_object_dtor_group. + (d_dump): Handle DEMANGLE_COMPONENT_TRANSACTION_CLONE + and DEMANGLE_COMPONENT_NONTRANSACTION_CLONE. + (d_make_comp, d_print_comp): Likewise. + (d_special_name): Generate them. + +2011-11-04 Jason Merrill <jason@redhat.com> + + PR c++/48370 + * cp-demangle.c (d_special_name, d_print_comp): Handle a + discriminator number on DEMANGLE_COMPONENT_REFTEMP. + +2011-11-02 Doug Evans <dje@google.com> + + * Makefile.in (CFILES): Add timeval-utils.c. + (REQUIRED_OFILES): Add timeval-utils.$(objext). + (INSTALLED_HEADERS): Add timeval-utils.h. + (timeval-utils.$(objext)): Add rule. + +2011-10-28 Ian Lance Taylor <iant@google.com> + + * setproctitle.c (setproctitle): Use "GNU/Linux" in comment. + +2011-10-26 Iain Sandoe <iains@gcc.gnu.org> + + PR target/48108 + * simple-object-mach-o.c (GNU_WRAPPER_SECTS, GNU_WRAPPER_INDEX, + GNU_WRAPPER_NAMES): New macros. + (simple_object_mach_o_segment): Handle wrapper scheme. + (simple_object_mach_o_write_section_header): Allow the segment name + to be supplied. + (simple_object_mach_o_write_segment): Handle wrapper scheme. Ensure + that the top-level segment name in the load command is empty. + (simple_object_mach_o_write_to_file): Determine the number of + sections during segment output, use that in writing the header. + +2011-10-10 Ian Lance Taylor <iant@google.com> + + PR c++/48665 + * cp-demangle.c (d_cv_qualifiers): If qualifiers are applied to a + function type, change them to apply to the "this" parameter. + * testsuite/demangle-expected: Add test case. + +2011-09-28 Doug Evans <dje@google.com> + + * timeval-utils.c: New file. + + * argv.c (countargv): New function. 2011-09-23 Cary Coutant <ccoutant@google.com> @@ -12,17 +187,133 @@ (d_print_comp): Print info for clone suffixes. * testsuite/demangle-expected: Add new testcases. +2011-09-23 Ian Lance Taylor <iant@google.com> + Pierre Vittet <piervit@pvittet.com> + + * md5.c (md5_process_bytes): Correct handling of unaligned + buffer. + +2011-08-22 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> + + * aclocal.m4: Include ../config/picflag.m4. + * configure.ac (GCC_PICFLAG): Call it. + (enable_shared): Clear PICFLAG unless shared. + * configure: Regenerate. + +2011-08-12 Steve Ellcey <sje@cup.hp.com> + + * md5.c (md5_read_ctx): Handle mis-aligned resbuf pointer. + 2011-08-06 Uros Bizjak <ubizjak@gmail.com> * testsuite/test-expandargv.c (writeout_test): Check result of fwrite. -2011-06-27 Release Manager +2011-08-01 Jason Merrill <jason@redhat.com> - * GCC 4.6.1 released. + PR c++/49932 + * cp-demangle.c (d_prefix): Handle decltype. + * testsuite/demangle-expected: Test it. -2011-03-25 Release Manager +2011-07-26 H.J. Lu <hongjiu.lu@intel.com> - * GCC 4.6.0 released. + * testsuite/demangle-expected: Remove an extra line. + +2011-07-26 Ian Lance Taylor <iant@google.com> + + * cp-demangle.c (d_print_init): Initialize pack_index field. + (d_print_comp): Check for NULL template argument. + * testsuite/demangle-expected: Add test case. + +2011-07-22 Gerald Pfeifer <gerald@pfeifer.com> + + PR target/49817 + * stack-limit.c: Include <stdint.h>. + +2011-07-22 Jakub Jelinek <jakub@redhat.com> + + PR c++/49756 + * stack-limit.c: New file. + * Makefile.in: Regenerate deps. + (CFILES): Add stack-limit.c. + (REQUIRED_OFILES): Add ./stack-limit.$(objext). + * configure.ac (checkfuncs): Add getrlimit and setrlimit. + (AC_CHECK_FUNCS): Likewise. + * configure: Regenerated. + * config.in: Regenerated. + +2011-07-04 Jason Merrill <jason@redhat.com> + + * cp-demangle.c (d_expression): Handle 'this'. + (d_print_comp) [DEMANGLE_COMPONENT_FUNCTION_PARAM]: Likewise. + +2011-07-01 Joel Brobecker <brobecker@adacore.com> + + * filename_cmp.c (filename_cmp, filename_ncmp): Add handling of + HAVE_CASE_INSENSITIVE_FILE_SYSTEM. + +2011-07-01 Jan Kratochvil <jan.kratochvil@redhat.com> + + PR debug/49408 + * cp-demangle.c (d_print_comp): Suppress argument list for function + references by the '&' unary operator. Keep also already processed + variant without the argument list. Suppress argument list types for + function call used in an expression. + * testsuite/demangle-expected: Fix excessive argument list types in + `test for typed function in decltype'. New testcase for no argument + list types printed. 3 new testcases for function references by the + '&' unary operator.. + +2011-06-20 Jason Merrill <jason@redhat.com> + + PR c++/37089 + * cp-demangle.c (d_print_comp): Handle reference smashing. + * testsuite/demangle-expected: Test it. + +2011-06-13 Jan Kratochvil <jan.kratochvil@redhat.com> + + * cp-demangle.c (d_print_comp) <DEMANGLE_COMPONENT_FUNCTION_TYPE>: + Suppress d_print_mod for DMGL_RET_POSTFIX. + * testsuite/demangle-expected: New testcases for --ret-postfix. + +2011-06-13 Jan Kratochvil <jan.kratochvil@redhat.com> + + * cp-demangle.c (d_print_comp) <DEMANGLE_COMPONENT_FUNCTION_TYPE>: Do + not pass DMGL_RET_POSTFIX or DMGL_RET_DROP. Support DMGL_RET_DROP. + * testsuite/demangle-expected: New testcases for --ret-drop. + * testsuite/test-demangle.c: Document --ret-drop in a comment. + (main): New variable ret_drop, fill it, call cplus_demangle with it. + +2011-06-13 Jan Kratochvil <jan.kratochvil@redhat.com> + + * cp-demangle.c (struct d_print_info): Remove field options. + (d_print_init): Remove parameter options. + (cplus_demangle_print_callback): Update all the callers. + (d_print_comp, d_print_mod_list, d_print_mod, d_print_function_type) + (d_print_array_type, d_print_expr_op, d_print_cast, d_print_subexpr): + Add parameter options, update all the callers. + +2011-04-20 Jim Meyering <meyering@redhat.com> + + * cp-demint.c (cplus_demangle_v3_components): Remove useless + if-before-free. + * cplus-dem.c (squangle_mop_up): Likewise. + (delete_non_B_K_work_stuff): Likewise. + * pex-common.c (pex_free): Likewise. + * pex-msdos.c (pex_msdos_cleanup): Likewise. + * pex-win32.c (mingw_rootify, msys_rootify): Likewise. + (win32_spawn): Likewise. + * regex.c (FREE_VAR, weak_alias): Likewise. + * spaces.c (spaces): Likewise. + +2011-04-10 Jim Meyering <meyering@redhat.com> + + Avoid memory overrun in a test leading to potential double-free. + * testsuite/test-expandargv.c (writeout_test): Fix off-by-one error: + i.e., do copy the trailing NUL byte. + +2011-03-31 Tristan Gingold <gingold@adacore.com> + + * makefile.vms (OBJS): Add filename_cmp.obj 2011-02-28 Kai Tietz <kai.tietz@onevision.com> @@ -501,7 +792,7 @@ 2009-05-29 Kai Tietz <kai.tietz@onevision.com> - * pex-win32.c (pex_win32_fdopenr): Set INHERIT to false. + * pex-win32.c (pex_win32_fdopenr): Set INHERIT to false. 2009-05-29 Michael Matz <matz@suse.de> @@ -553,19 +844,19 @@ 2009-04-13 Ozkan Sezer <sezeroz@gmail.com> - PR target/39397 - * pex-common.h (struct pex_obj): Store pid values as pid_t, - not as long (members *children and (*wait)) - * pex-common.c (pex_run_in_environment): Likewise. - * pex-win32.c (pex_win32_wait): Return pid_t and properly check - returned pid value. - * pex-djgpp.c (pex_djgpp_wait): Return pid_t. - * pex-msdos.c (pex_msdos_wait): Likewise. + PR target/39397 + * pex-common.h (struct pex_obj): Store pid values as pid_t, + not as long (members *children and (*wait)) + * pex-common.c (pex_run_in_environment): Likewise. + * pex-win32.c (pex_win32_wait): Return pid_t and properly check + returned pid value. + * pex-djgpp.c (pex_djgpp_wait): Return pid_t. + * pex-msdos.c (pex_msdos_wait): Likewise. 2009-04-07 Arnaud Patard <apatard@mandriva.com> - * libiberty/configure.ac: Fix Linux/MIPS matching rule. - * libiberty/configure: Regenerate. + * libiberty/configure.ac: Fix Linux/MIPS matching rule. + * libiberty/configure: Regenerate. 2009-03-27 Ian Lance Taylor <iant@google.com> diff --git a/libiberty/Makefile.in b/libiberty/Makefile.in index ef35453c03..5280bc1585 100644 --- a/libiberty/Makefile.in +++ b/libiberty/Makefile.in @@ -2,7 +2,7 @@ # Originally written by K. Richard Pixley <rich@cygnus.com>. # # Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, -# 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 +# 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 # Free Software Foundation # # This file is part of the libiberty library. @@ -148,11 +148,11 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \ simple-object.c simple-object-coff.c simple-object-elf.c \ simple-object-mach-o.c \ snprintf.c sort.c \ - spaces.c splay-tree.c stpcpy.c stpncpy.c strcasecmp.c \ - strchr.c strdup.c strerror.c strncasecmp.c strncmp.c \ - strrchr.c strsignal.c strstr.c strtod.c strtol.c strtoul.c \ - strndup.c strverscmp.c \ - tmpnam.c \ + spaces.c splay-tree.c stack-limit.c stpcpy.c stpncpy.c \ + strcasecmp.c strchr.c strdup.c strerror.c strncasecmp.c \ + strncmp.c strrchr.c strsignal.c strstr.c strtod.c strtol.c \ + strtoul.c strndup.c strverscmp.c \ + timeval-utils.c tmpnam.c \ unlink-if-ordinary.c \ vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c vsprintf.c \ waitpid.c \ @@ -183,8 +183,9 @@ REQUIRED_OFILES = \ ./simple-object.$(objext) ./simple-object-coff.$(objext) \ ./simple-object-elf.$(objext) ./simple-object-mach-o.$(objext) \ ./sort.$(objext) ./spaces.$(objext) \ - ./splay-tree.$(objext) ./strerror.$(objext) \ - ./strsignal.$(objext) ./unlink-if-ordinary.$(objext) \ + ./splay-tree.$(objext) ./stack-limit.$(objext) \ + ./strerror.$(objext) ./strsignal.$(objext) \ + ./timeval-utils.$(objext) ./unlink-if-ordinary.$(objext) \ ./xatexit.$(objext) ./xexit.$(objext) ./xmalloc.$(objext) \ ./xmemdup.$(objext) ./xstrdup.$(objext) ./xstrerror.$(objext) \ ./xstrndup.$(objext) @@ -234,7 +235,8 @@ INSTALLED_HEADERS = \ $(INCDIR)/partition.h \ $(INCDIR)/safe-ctype.h \ $(INCDIR)/sort.h \ - $(INCDIR)/splay-tree.h + $(INCDIR)/splay-tree.h \ + $(INCDIR)/timeval-utils.h $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS) -rm -f $(TARGETLIB) pic/$(TARGETLIB) @@ -1033,6 +1035,12 @@ $(CONFIGURED_OFILES): stamp-picdir else true; fi $(COMPILE.c) $(srcdir)/splay-tree.c $(OUTPUT_OPTION) +./stack-limit.$(objext): $(srcdir)/stack-limit.c config.h + if [ x"$(PICFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/stack-limit.c -o pic/$@; \ + else true; fi + $(COMPILE.c) $(srcdir)/stack-limit.c $(OUTPUT_OPTION) + ./stpcpy.$(objext): $(srcdir)/stpcpy.c $(INCDIR)/ansidecl.h if [ x"$(PICFLAG)" != x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/stpcpy.c -o pic/$@; \ @@ -1134,6 +1142,13 @@ $(CONFIGURED_OFILES): stamp-picdir else true; fi $(COMPILE.c) $(srcdir)/strverscmp.c $(OUTPUT_OPTION) +./timeval-utils.$(objext): $(srcdir)/timeval-utils.c config.h \ + $(INCDIR)/timeval-utils.h + if [ x"$(PICFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $(srcdir)/timeval-utils.c -o pic/$@; \ + else true; fi + $(COMPILE.c) $(srcdir)/timeval-utils.c $(OUTPUT_OPTION) + ./tmpnam.$(objext): $(srcdir)/tmpnam.c if [ x"$(PICFLAG)" != x ]; then \ $(COMPILE.c) $(PICFLAG) $(srcdir)/tmpnam.c -o pic/$@; \ diff --git a/libiberty/aclocal.m4 b/libiberty/aclocal.m4 index f2091c9927..bf8a907100 100644 --- a/libiberty/aclocal.m4 +++ b/libiberty/aclocal.m4 @@ -1,6 +1,7 @@ sinclude(../config/acx.m4) sinclude(../config/no-executables.m4) sinclude(../config/override.m4) +sinclude(../config/picflag.m4) sinclude(../config/warnings.m4) dnl See whether strncmp reads past the end of its string parameters. @@ -71,7 +72,7 @@ main () exit (0); } ], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no, - ac_cv_func_strncmp_works=no) + ac_cv_func_strncmp_works=yes) rm -f core core.* *.core]) if test $ac_cv_func_strncmp_works = no ; then AC_LIBOBJ([strncmp]) diff --git a/libiberty/argv.c b/libiberty/argv.c index 8476c8fda9..ca53f91493 100644 --- a/libiberty/argv.c +++ b/libiberty/argv.c @@ -492,6 +492,29 @@ expandargv (int *argcp, char ***argvp) } } +/* + +@deftypefn Extension int countargv (char **@var{argv}) + +Return the number of elements in @var{argv}. +Returns zero if @var{argv} is NULL. + +@end deftypefn + +*/ + +int +countargv (char **argv) +{ + int argc; + + if (argv == NULL) + return 0; + for (argc = 0; argv[argc] != NULL; argc++) + continue; + return argc; +} + #ifdef MAIN /* Simple little test driver. */ diff --git a/libiberty/config.in b/libiberty/config.in index e4f1f1620e..17c4c2e441 100644 --- a/libiberty/config.in +++ b/libiberty/config.in @@ -109,6 +109,9 @@ /* Define to 1 if you have the `getpagesize' function. */ #undef HAVE_GETPAGESIZE +/* Define to 1 if you have the `getrlimit' function. */ +#undef HAVE_GETRLIMIT + /* Define to 1 if you have the `getrusage' function. */ #undef HAVE_GETRUSAGE @@ -205,6 +208,9 @@ /* Define to 1 if you have the `setproctitle' function. */ #undef HAVE_SETPROCTITLE +/* Define to 1 if you have the `setrlimit' function. */ +#undef HAVE_SETRLIMIT + /* Define to 1 if you have the `sigsetmask' function. */ #undef HAVE_SIGSETMASK diff --git a/libiberty/configure b/libiberty/configure index bdabe8d1a3..6e98352f35 100755 --- a/libiberty/configure +++ b/libiberty/configure @@ -3920,8 +3920,14 @@ ac_c_preproc_warn_flag=yes ac_libiberty_warn_cflags= save_CFLAGS="$CFLAGS" -for option in -W -Wall -Wwrite-strings -Wc++-compat \ +for real_option in -W -Wall -Wwrite-strings -Wc++-compat \ -Wstrict-prototypes; do + # Do the check with the no- prefix removed since gcc silently + # accepts any -Wno-* option on purpose + case $real_option in + -Wno-*) option=-W`expr x$real_option : 'x-Wno-\(.*\)'` ;; + *) option=$real_option ;; + esac as_acx_Woption=`$as_echo "acx_cv_prog_cc_warning_$option" | $as_tr_sh` { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports $option" >&5 @@ -3953,11 +3959,13 @@ eval ac_res=\$$as_acx_Woption { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } if test `eval 'as_val=${'$as_acx_Woption'};$as_echo "$as_val"'` = yes; then : - ac_libiberty_warn_cflags="$ac_libiberty_warn_cflags${ac_libiberty_warn_cflags:+ }$option" + ac_libiberty_warn_cflags="$ac_libiberty_warn_cflags${ac_libiberty_warn_cflags:+ }$real_option" fi done CFLAGS="$save_CFLAGS" +# Do the check with the no- prefix removed from the warning options +# since gcc silently accepts any -Wno-* option on purpose if test "$GCC" = yes; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $CC supports -pedantic " >&5 $as_echo_n "checking whether $CC supports -pedantic ... " >&6; } @@ -4840,6 +4848,83 @@ if [ -n "${frag}" ]; then frag=${libiberty_topdir}/libiberty/config/$frag fi + + + + +case "${host}" in + # PIC is the default on some targets or must not be used. + *-*-darwin*) + # PIC is the default on this platform + # Common symbols not allowed in MH_DYLIB files + PICFLAG=-fno-common + ;; + alpha*-dec-osf5*) + # PIC is the default. + ;; + hppa*64*-*-hpux*) + # PIC is the default for 64-bit PA HP-UX. + ;; + i[34567]86-*-cygwin* | i[34567]86-*-mingw* | x86_64-*-mingw*) + ;; + i[34567]86-*-interix[3-9]*) + # Interix 3.x gcc -fpic/-fPIC options generate broken code. + # Instead, we relocate shared libraries at runtime. + ;; + i[34567]86-*-nto-qnx*) + # QNX uses GNU C++, but need to define -shared option too, otherwise + # it will coredump. + PICFLAG='-fPIC -shared' + ;; + i[34567]86-pc-msdosdjgpp*) + # DJGPP does not support shared libraries at all. + ;; + ia64*-*-hpux*) + # On IA64 HP-UX, PIC is the default but the pic flag + # sets the default TLS model and affects inlining. + PICFLAG=-fPIC + ;; + mips-sgi-irix6*) + # PIC is the default. + ;; + rs6000-ibm-aix* | powerpc-ibm-aix*) + # All AIX code is PIC. + ;; + + # Some targets support both -fPIC and -fpic, but prefer the latter. + # FIXME: Why? + i[34567]86-*-* | x86_64-*-*) + PICFLAG=-fpic + ;; + m68k-*-*) + PICFLAG=-fpic + ;; + # FIXME: Override -fPIC default in libgcc only? + sh-*-linux* | sh[2346lbe]*-*-linux*) + PICFLAG=-fpic + ;; + # FIXME: Simplify to sh*-*-netbsd*? + sh-*-netbsdelf* | shl*-*-netbsdelf* | sh5-*-netbsd* | sh5l*-*-netbsd* | \ + sh64-*-netbsd* | sh64l*-*-netbsd*) + PICFLAG=-fpic + ;; + # Default to -fPIC unless specified otherwise. + *) + PICFLAG=-fPIC + ;; +esac + +# If the user explicitly uses -fpic/-fPIC, keep that. +case "${CFLAGS}" in + *-fpic*) + PICFLAG=-fpic + ;; + *-fPIC*) + PICFLAG=-fPIC + ;; +esac + + # If they didn't specify --enable-shared, don't generate shared libs. case "${enable_shared}" in yes) shared=yes ;; @@ -4847,27 +4932,8 @@ case "${enable_shared}" in "") shared=no ;; *) shared=yes ;; esac -if [ "${shared}" = "yes" ]; then - case "${host}" in - *-*-cygwin*) ;; - alpha*-*-linux*) PICFLAG=-fPIC ;; - arm*-*-*) PICFLAG=-fPIC ;; - hppa*-*-*) PICFLAG=-fPIC ;; - i370-*-*) PICFLAG=-fPIC ;; - ia64-*-*) PICFLAG=-fpic ;; - i[34567]86-*-* | x86_64-*-*) - PICFLAG=-fpic ;; - m68k-*-*) PICFLAG=-fpic ;; - mips*-*-linux*) PICFLAG=-fPIC ;; - powerpc*-*-aix*) ;; - powerpc*-*-*) PICFLAG=-fPIC ;; - sparc*-*-*) case "${CFLAGS}" in - *-fpic* ) PICFLAG=-fpic ;; - * ) PICFLAG=-fPIC ;; - esac ;; - s390*-*-*) PICFLAG=-fpic ;; - sh*-*-*) PICFLAG=-fPIC ;; - esac +if [ "${shared}" != "yes" ]; then + PICFLAG= fi @@ -5293,10 +5359,10 @@ funcs="$funcs setproctitle" vars="sys_errlist sys_nerr sys_siglist" -checkfuncs="__fsetlocking canonicalize_file_name dup3 getrusage getsysinfo \ - gettimeofday on_exit psignal pstat_getdynamic pstat_getstatic realpath \ - sbrk spawnve spawnvpe strerror strsignal sysconf sysctl sysmp table \ - times wait3 wait4" +checkfuncs="__fsetlocking canonicalize_file_name dup3 getrlimit getrusage \ + getsysinfo gettimeofday on_exit psignal pstat_getdynamic pstat_getstatic \ + realpath setrlimit sbrk spawnve spawnvpe strerror strsignal sysconf sysctl \ + sysmp table times wait3 wait4" # These are neither executed nor required, but they help keep # autoheader happy without adding a bunch of text to acconfig.h. @@ -5306,13 +5372,13 @@ if test "x" = "y"; then calloc canonicalize_file_name clock \ dup3 \ ffs __fsetlocking \ - getcwd getpagesize getrusage getsysinfo gettimeofday \ + getcwd getpagesize getrlimit getrusage getsysinfo gettimeofday \ index insque \ memchr memcmp memcpy memmem memmove memset mkstemps \ on_exit \ psignal pstat_getdynamic pstat_getstatic putenv \ random realpath rename rindex \ - sbrk setenv setproctitle sigsetmask snprintf spawnve spawnvpe \ + sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \ stpcpy stpncpy strcasecmp strchr strdup \ strerror strncasecmp strndup strrchr strsignal strstr strtod strtol \ strtoul strverscmp sysconf sysctl sysmp \ @@ -6755,7 +6821,7 @@ if test "${ac_cv_func_strncmp_works+set}" = set; then : $as_echo_n "(cached) " >&6 else if test "$cross_compiling" = yes; then : - ac_cv_func_strncmp_works=no + ac_cv_func_strncmp_works=yes else cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ diff --git a/libiberty/configure.ac b/libiberty/configure.ac index 9f1ff04938..754b66a061 100644 --- a/libiberty/configure.ac +++ b/libiberty/configure.ac @@ -191,6 +191,8 @@ if [[ -n "${frag}" ]]; then frag=${libiberty_topdir}/libiberty/config/$frag fi +GCC_PICFLAG + # If they didn't specify --enable-shared, don't generate shared libs. case "${enable_shared}" in yes) shared=yes ;; @@ -198,27 +200,8 @@ case "${enable_shared}" in "") shared=no ;; *) shared=yes ;; esac -if [[ "${shared}" = "yes" ]]; then - case "${host}" in - *-*-cygwin*) ;; - alpha*-*-linux*) PICFLAG=-fPIC ;; - arm*-*-*) PICFLAG=-fPIC ;; - hppa*-*-*) PICFLAG=-fPIC ;; - i370-*-*) PICFLAG=-fPIC ;; - ia64-*-*) PICFLAG=-fpic ;; - i[[34567]]86-*-* | x86_64-*-*) - PICFLAG=-fpic ;; - m68k-*-*) PICFLAG=-fpic ;; - mips*-*-linux*) PICFLAG=-fPIC ;; - powerpc*-*-aix*) ;; - powerpc*-*-*) PICFLAG=-fPIC ;; - sparc*-*-*) case "${CFLAGS}" in - *-fpic* ) PICFLAG=-fpic ;; - * ) PICFLAG=-fPIC ;; - esac ;; - s390*-*-*) PICFLAG=-fpic ;; - sh*-*-*) PICFLAG=-fPIC ;; - esac +if [[ "${shared}" != "yes" ]]; then + PICFLAG= fi AC_SUBST(PICFLAG) @@ -358,10 +341,10 @@ funcs="$funcs setproctitle" vars="sys_errlist sys_nerr sys_siglist" -checkfuncs="__fsetlocking canonicalize_file_name dup3 getrusage getsysinfo \ - gettimeofday on_exit psignal pstat_getdynamic pstat_getstatic realpath \ - sbrk spawnve spawnvpe strerror strsignal sysconf sysctl sysmp table \ - times wait3 wait4" +checkfuncs="__fsetlocking canonicalize_file_name dup3 getrlimit getrusage \ + getsysinfo gettimeofday on_exit psignal pstat_getdynamic pstat_getstatic \ + realpath setrlimit sbrk spawnve spawnvpe strerror strsignal sysconf sysctl \ + sysmp table times wait3 wait4" # These are neither executed nor required, but they help keep # autoheader happy without adding a bunch of text to acconfig.h. @@ -371,13 +354,13 @@ if test "x" = "y"; then calloc canonicalize_file_name clock \ dup3 \ ffs __fsetlocking \ - getcwd getpagesize getrusage getsysinfo gettimeofday \ + getcwd getpagesize getrlimit getrusage getsysinfo gettimeofday \ index insque \ memchr memcmp memcpy memmem memmove memset mkstemps \ on_exit \ psignal pstat_getdynamic pstat_getstatic putenv \ random realpath rename rindex \ - sbrk setenv setproctitle sigsetmask snprintf spawnve spawnvpe \ + sbrk setenv setproctitle setrlimit sigsetmask snprintf spawnve spawnvpe \ stpcpy stpncpy strcasecmp strchr strdup \ strerror strncasecmp strndup strrchr strsignal strstr strtod strtol \ strtoul strverscmp sysconf sysctl sysmp \ diff --git a/libiberty/cp-demangle.c b/libiberty/cp-demangle.c index 179197cf19..d95b56c71a 100644 --- a/libiberty/cp-demangle.c +++ b/libiberty/cp-demangle.c @@ -1,5 +1,5 @@ /* Demangler for g++ V3 ABI. - Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 + Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. Written by Ian Lance Taylor <ian@wasabisystems.com>. @@ -278,8 +278,6 @@ struct d_growable_string enum { D_PRINT_BUFFER_LENGTH = 256 }; struct d_print_info { - /* The options passed to the demangler. */ - int options; /* Fixed-length allocated buffer for demangled data, flushed to the callback with a NUL termination once full. */ char buf[D_PRINT_BUFFER_LENGTH]; @@ -439,7 +437,7 @@ static void d_growable_string_callback_adapter (const char *, size_t, void *); static void -d_print_init (struct d_print_info *, int, demangle_callbackref, void *); +d_print_init (struct d_print_info *, demangle_callbackref, void *); static inline void d_print_error (struct d_print_info *); @@ -457,32 +455,32 @@ static inline void d_append_string (struct d_print_info *, const char *); static inline char d_last_char (struct d_print_info *); static void -d_print_comp (struct d_print_info *, const struct demangle_component *); +d_print_comp (struct d_print_info *, int, const struct demangle_component *); static void d_print_java_identifier (struct d_print_info *, const char *, int); static void -d_print_mod_list (struct d_print_info *, struct d_print_mod *, int); +d_print_mod_list (struct d_print_info *, int, struct d_print_mod *, int); static void -d_print_mod (struct d_print_info *, const struct demangle_component *); +d_print_mod (struct d_print_info *, int, const struct demangle_component *); static void -d_print_function_type (struct d_print_info *, +d_print_function_type (struct d_print_info *, int, const struct demangle_component *, struct d_print_mod *); static void -d_print_array_type (struct d_print_info *, +d_print_array_type (struct d_print_info *, int, const struct demangle_component *, struct d_print_mod *); static void -d_print_expr_op (struct d_print_info *, const struct demangle_component *); +d_print_expr_op (struct d_print_info *, int, const struct demangle_component *); static void -d_print_cast (struct d_print_info *, const struct demangle_component *); +d_print_cast (struct d_print_info *, int, const struct demangle_component *); static int d_demangle_callback (const char *, int, demangle_callbackref, void *); @@ -587,6 +585,12 @@ d_dump (struct demangle_component *dc, int indent) case DEMANGLE_COMPONENT_HIDDEN_ALIAS: printf ("hidden alias\n"); break; + case DEMANGLE_COMPONENT_TRANSACTION_CLONE: + printf ("transaction clone\n"); + break; + case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE: + printf ("non-transaction clone\n"); + break; case DEMANGLE_COMPONENT_RESTRICT: printf ("restrict\n"); break; @@ -644,9 +648,15 @@ d_dump (struct demangle_component *dc, int indent) case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST: printf ("template argument list\n"); break; + case DEMANGLE_COMPONENT_INITIALIZER_LIST: + printf ("initializer list\n"); + break; case DEMANGLE_COMPONENT_CAST: printf ("cast\n"); break; + case DEMANGLE_COMPONENT_NULLARY: + printf ("nullary operator\n"); + break; case DEMANGLE_COMPONENT_UNARY: printf ("unary operator\n"); break; @@ -734,7 +744,7 @@ cplus_demangle_fill_ctor (struct demangle_component *p, if (p == NULL || name == NULL || (int) kind < gnu_v3_complete_object_ctor - || (int) kind > gnu_v3_complete_object_allocating_ctor) + || (int) kind > gnu_v3_object_ctor_group) return 0; p->type = DEMANGLE_COMPONENT_CTOR; p->u.s_ctor.kind = kind; @@ -753,7 +763,7 @@ cplus_demangle_fill_dtor (struct demangle_component *p, if (p == NULL || name == NULL || (int) kind < gnu_v3_deleting_dtor - || (int) kind > gnu_v3_base_object_dtor) + || (int) kind > gnu_v3_object_dtor_group) return 0; p->type = DEMANGLE_COMPONENT_DTOR; p->u.s_dtor.kind = kind; @@ -802,7 +812,6 @@ d_make_comp (struct d_info *di, enum demangle_component_type type, case DEMANGLE_COMPONENT_BINARY_ARGS: case DEMANGLE_COMPONENT_TRINARY: case DEMANGLE_COMPONENT_TRINARY_ARG1: - case DEMANGLE_COMPONENT_TRINARY_ARG2: case DEMANGLE_COMPONENT_LITERAL: case DEMANGLE_COMPONENT_LITERAL_NEG: case DEMANGLE_COMPONENT_COMPOUND_NAME: @@ -825,6 +834,8 @@ d_make_comp (struct d_info *di, enum demangle_component_type type, case DEMANGLE_COMPONENT_GUARD: case DEMANGLE_COMPONENT_REFTEMP: case DEMANGLE_COMPONENT_HIDDEN_ALIAS: + case DEMANGLE_COMPONENT_TRANSACTION_CLONE: + case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE: case DEMANGLE_COMPONENT_POINTER: case DEMANGLE_COMPONENT_REFERENCE: case DEMANGLE_COMPONENT_RVALUE_REFERENCE: @@ -837,6 +848,8 @@ d_make_comp (struct d_info *di, enum demangle_component_type type, case DEMANGLE_COMPONENT_PACK_EXPANSION: case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS: case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS: + case DEMANGLE_COMPONENT_NULLARY: + case DEMANGLE_COMPONENT_TRINARY_ARG2: if (left == NULL) return NULL; break; @@ -844,6 +857,7 @@ d_make_comp (struct d_info *di, enum demangle_component_type type, /* This needs a right parameter, but the left parameter can be empty. */ case DEMANGLE_COMPONENT_ARRAY_TYPE: + case DEMANGLE_COMPONENT_INITIALIZER_LIST: if (right == NULL) return NULL; break; @@ -1299,6 +1313,7 @@ d_nested_name (struct d_info *di) /* <prefix> ::= <prefix> <unqualified-name> ::= <template-prefix> <template-args> ::= <template-param> + ::= <decltype> ::= ::= <substitution> @@ -1327,10 +1342,19 @@ d_prefix (struct d_info *di) <template-param> here. */ comb_type = DEMANGLE_COMPONENT_QUAL_NAME; - if (IS_DIGIT (peek) + if (peek == 'D') + { + char peek2 = d_peek_next_char (di); + if (peek2 == 'T' || peek2 == 't') + /* Decltype. */ + dc = cplus_demangle_type (di); + else + /* Destructor name. */ + dc = d_unqualified_name (di); + } + else if (IS_DIGIT (peek) || IS_LOWER (peek) || peek == 'C' - || peek == 'D' || peek == 'U' || peek == 'L') dc = d_unqualified_name (di); @@ -1395,7 +1419,12 @@ d_unqualified_name (struct d_info *di) ret = d_operator_name (di); if (ret != NULL && ret->type == DEMANGLE_COMPONENT_OPERATOR) - di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2; + { + di->expansion += sizeof "operator" + ret->u.s_operator.op->len - 2; + if (!strcmp (ret->u.s_operator.op->code, "li")) + ret = d_make_comp (di, DEMANGLE_COMPONENT_UNARY, ret, + d_source_name (di)); + } return ret; } else if (peek == 'C' || peek == 'D') @@ -1538,7 +1567,8 @@ d_identifier (struct d_info *di, int len) /* operator_name ::= many different two character encodings. ::= cv <type> ::= v <digit> <source-name> -*/ + + This list is sorted for binary search. */ #define NL(s) s, (sizeof s) - 1 @@ -1550,23 +1580,28 @@ const struct demangle_operator_info cplus_demangle_operators[] = { "aa", NL ("&&"), 2 }, { "ad", NL ("&"), 1 }, { "an", NL ("&"), 2 }, + { "at", NL ("alignof "), 1 }, + { "az", NL ("alignof "), 1 }, { "cl", NL ("()"), 2 }, { "cm", NL (","), 2 }, { "co", NL ("~"), 1 }, { "dV", NL ("/="), 2 }, - { "da", NL ("delete[]"), 1 }, + { "da", NL ("delete[] "), 1 }, { "de", NL ("*"), 1 }, - { "dl", NL ("delete"), 1 }, + { "dl", NL ("delete "), 1 }, + { "ds", NL (".*"), 2 }, { "dt", NL ("."), 2 }, { "dv", NL ("/"), 2 }, { "eO", NL ("^="), 2 }, { "eo", NL ("^"), 2 }, { "eq", NL ("=="), 2 }, { "ge", NL (">="), 2 }, + { "gs", NL ("::"), 1 }, { "gt", NL (">"), 2 }, { "ix", NL ("[]"), 2 }, { "lS", NL ("<<="), 2 }, { "le", NL ("<="), 2 }, + { "li", NL ("operator\"\" "), 1 }, { "ls", NL ("<<"), 2 }, { "lt", NL ("<"), 2 }, { "mI", NL ("-="), 2 }, @@ -1574,11 +1609,11 @@ const struct demangle_operator_info cplus_demangle_operators[] = { "mi", NL ("-"), 2 }, { "ml", NL ("*"), 2 }, { "mm", NL ("--"), 1 }, - { "na", NL ("new[]"), 1 }, + { "na", NL ("new[]"), 3 }, { "ne", NL ("!="), 2 }, { "ng", NL ("-"), 1 }, { "nt", NL ("!"), 1 }, - { "nw", NL ("new"), 1 }, + { "nw", NL ("new"), 3 }, { "oR", NL ("|="), 2 }, { "oo", NL ("||"), 2 }, { "or", NL ("|"), 2 }, @@ -1595,8 +1630,8 @@ const struct demangle_operator_info cplus_demangle_operators[] = { "rs", NL (">>"), 2 }, { "st", NL ("sizeof "), 1 }, { "sz", NL ("sizeof "), 1 }, - { "at", NL ("alignof "), 1 }, - { "az", NL ("alignof "), 1 }, + { "tr", NL ("throw"), 0 }, + { "tw", NL ("throw "), 1 }, { NULL, NULL, 0, 0 } }; @@ -1754,6 +1789,8 @@ d_java_resource (struct d_info *di) ::= GR <name> ::= GA <encoding> ::= Gr <resource name> + ::= GTt <encoding> + ::= GTn <encoding> */ static struct demangle_component * @@ -1838,13 +1875,33 @@ d_special_name (struct d_info *di) return d_make_comp (di, DEMANGLE_COMPONENT_GUARD, d_name (di), NULL); case 'R': - return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, d_name (di), - NULL); + { + struct demangle_component *name = d_name (di); + return d_make_comp (di, DEMANGLE_COMPONENT_REFTEMP, name, + d_number_component (di)); + } case 'A': return d_make_comp (di, DEMANGLE_COMPONENT_HIDDEN_ALIAS, d_encoding (di, 0), NULL); + case 'T': + switch (d_next_char (di)) + { + case 'n': + return d_make_comp (di, DEMANGLE_COMPONENT_NONTRANSACTION_CLONE, + d_encoding (di, 0), NULL); + default: + /* ??? The proposal is that other letters (such as 'h') stand + for different variants of transaction cloning, such as + compiling directly for hardware transaction support. But + they still should all be transactional clones of some sort + so go ahead and call them that. */ + case 't': + return d_make_comp (di, DEMANGLE_COMPONENT_TRANSACTION_CLONE, + d_encoding (di, 0), NULL); + } + case 'r': return d_java_resource (di); @@ -1928,6 +1985,9 @@ d_ctor_dtor_name (struct d_info *di) case '3': kind = gnu_v3_complete_object_allocating_ctor; break; + case '5': + kind = gnu_v3_object_ctor_group; + break; default: return NULL; } @@ -1950,6 +2010,9 @@ d_ctor_dtor_name (struct d_info *di) case '2': kind = gnu_v3_base_object_dtor; break; + case '5': + kind = gnu_v3_object_dtor_group; + break; default: return NULL; } @@ -2198,12 +2261,19 @@ cplus_demangle_type (struct d_info *di) d_expression (di), NULL); if (ret && d_next_char (di) != 'E') ret = NULL; + can_subst = 1; break; case 'p': /* Pack expansion. */ ret = d_make_comp (di, DEMANGLE_COMPONENT_PACK_EXPANSION, cplus_demangle_type (di), NULL); + can_subst = 1; + break; + + case 'a': + /* auto */ + ret = d_make_name (di, "auto", 4); break; case 'f': @@ -2254,6 +2324,7 @@ cplus_demangle_type (struct d_info *di) case 'v': ret = d_vector_type (di); + can_subst = 1; break; case 'n': @@ -2286,8 +2357,10 @@ static struct demangle_component ** d_cv_qualifiers (struct d_info *di, struct demangle_component **pret, int member_fn) { + struct demangle_component **pstart; char peek; + pstart = pret; peek = d_peek_char (di); while (peek == 'r' || peek == 'V' || peek == 'K') { @@ -2324,6 +2397,28 @@ d_cv_qualifiers (struct d_info *di, peek = d_peek_char (di); } + if (!member_fn && peek == 'F') + { + while (pstart != pret) + { + switch ((*pstart)->type) + { + case DEMANGLE_COMPONENT_RESTRICT: + (*pstart)->type = DEMANGLE_COMPONENT_RESTRICT_THIS; + break; + case DEMANGLE_COMPONENT_VOLATILE: + (*pstart)->type = DEMANGLE_COMPONENT_VOLATILE_THIS; + break; + case DEMANGLE_COMPONENT_CONST: + (*pstart)->type = DEMANGLE_COMPONENT_CONST_THIS; + break; + default: + break; + } + pstart = &d_left (*pstart); + } + } + return pret; } @@ -2607,8 +2702,10 @@ d_template_args (struct d_info *di) constructor or destructor. */ hold_last_name = di->last_name; - if (! d_check_char (di, 'I')) + if (d_peek_char (di) != 'I' + && d_peek_char (di) != 'J') return NULL; + d_advance (di, 1); if (d_peek_char (di) == 'E') { @@ -2667,6 +2764,7 @@ d_template_arg (struct d_info *di) return d_expr_primary (di); case 'I': + case 'J': /* An argument pack. */ return d_template_args (di); @@ -2675,15 +2773,16 @@ d_template_arg (struct d_info *di) } } -/* Subroutine of <expression> ::= cl <expression>+ E */ +/* Parse a sequence of expressions until we hit the terminator + character. */ static struct demangle_component * -d_exprlist (struct d_info *di) +d_exprlist (struct d_info *di, char terminator) { struct demangle_component *list = NULL; struct demangle_component **p = &list; - if (d_peek_char (di) == 'E') + if (d_peek_char (di) == terminator) { d_advance (di, 1); return d_make_comp (di, DEMANGLE_COMPONENT_ARGLIST, NULL, NULL); @@ -2700,7 +2799,7 @@ d_exprlist (struct d_info *di) return NULL; p = &d_right (*p); - if (d_peek_char (di) == 'E') + if (d_peek_char (di) == terminator) { d_advance (di, 1); break; @@ -2757,10 +2856,18 @@ d_expression (struct d_info *di) /* Function parameter used in a late-specified return type. */ int index; d_advance (di, 2); - index = d_compact_number (di); - if (index < 0) - return NULL; - + if (d_peek_char (di) == 'T') + { + /* 'this' parameter. */ + d_advance (di, 1); + index = 0; + } + else + { + index = d_compact_number (di) + 1; + if (index == 0) + return NULL; + } return d_make_function_param (di, index); } else if (IS_DIGIT (peek) @@ -2783,9 +2890,21 @@ d_expression (struct d_info *di) else return name; } + else if ((peek == 'i' || peek == 't') + && d_peek_next_char (di) == 'l') + { + /* Brace-enclosed initializer list, untyped or typed. */ + struct demangle_component *type = NULL; + if (peek == 't') + type = cplus_demangle_type (di); + d_advance (di, 2); + return d_make_comp (di, DEMANGLE_COMPONENT_INITIALIZER_LIST, + type, d_exprlist (di, 'E')); + } else { struct demangle_component *op; + const char *code = NULL; int args; op = d_operator_name (di); @@ -2793,12 +2912,13 @@ d_expression (struct d_info *di) return NULL; if (op->type == DEMANGLE_COMPONENT_OPERATOR) - di->expansion += op->u.s_operator.op->len - 2; - - if (op->type == DEMANGLE_COMPONENT_OPERATOR - && strcmp (op->u.s_operator.op->code, "st") == 0) - return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op, - cplus_demangle_type (di)); + { + code = op->u.s_operator.op->code; + di->expansion += op->u.s_operator.op->len - 2; + if (strcmp (code, "st") == 0) + return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op, + cplus_demangle_type (di)); + } switch (op->type) { @@ -2817,26 +2937,43 @@ d_expression (struct d_info *di) switch (args) { + case 0: + return d_make_comp (di, DEMANGLE_COMPONENT_NULLARY, op, NULL); + case 1: { struct demangle_component *operand; + int suffix = 0; + + if (code && (code[0] == 'p' || code[0] == 'm') + && code[1] == code[0]) + /* pp_ and mm_ are the prefix variants. */ + suffix = !d_check_char (di, '_'); + if (op->type == DEMANGLE_COMPONENT_CAST && d_check_char (di, '_')) - operand = d_exprlist (di); + operand = d_exprlist (di, 'E'); else operand = d_expression (di); - return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op, - operand); + + if (suffix) + /* Indicate the suffix variant for d_print_comp. */ + return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op, + d_make_comp (di, + DEMANGLE_COMPONENT_BINARY_ARGS, + operand, operand)); + else + return d_make_comp (di, DEMANGLE_COMPONENT_UNARY, op, + operand); } case 2: { struct demangle_component *left; struct demangle_component *right; - const char *code = op->u.s_operator.op->code; left = d_expression (di); if (!strcmp (code, "cl")) - right = d_exprlist (di); + right = d_exprlist (di, 'E'); else if (!strcmp (code, "dt") || !strcmp (code, "pt")) { right = d_unqualified_name (di); @@ -2856,17 +2993,50 @@ d_expression (struct d_info *di) { struct demangle_component *first; struct demangle_component *second; + struct demangle_component *third; - first = d_expression (di); - second = d_expression (di); + if (!strcmp (code, "qu")) + { + /* ?: expression. */ + first = d_expression (di); + second = d_expression (di); + third = d_expression (di); + } + else if (code[0] == 'n') + { + /* new-expression. */ + if (code[1] != 'w' && code[1] != 'a') + return NULL; + first = d_exprlist (di, '_'); + second = cplus_demangle_type (di); + if (d_peek_char (di) == 'E') + { + d_advance (di, 1); + third = NULL; + } + else if (d_peek_char (di) == 'p' + && d_peek_next_char (di) == 'i') + { + /* Parenthesized initializer. */ + d_advance (di, 2); + third = d_exprlist (di, 'E'); + } + else if (d_peek_char (di) == 'i' + && d_peek_next_char (di) == 'l') + /* initializer-list. */ + third = d_expression (di); + else + return NULL; + } + else + return NULL; return d_make_comp (di, DEMANGLE_COMPONENT_TRINARY, op, d_make_comp (di, DEMANGLE_COMPONENT_TRINARY_ARG1, first, d_make_comp (di, DEMANGLE_COMPONENT_TRINARY_ARG2, - second, - d_expression (di)))); + second, third))); } default: return NULL; @@ -3337,14 +3507,14 @@ d_growable_string_callback_adapter (const char *s, size_t l, void *opaque) /* Initialize a print information structure. */ static void -d_print_init (struct d_print_info *dpi, int options, - demangle_callbackref callback, void *opaque) +d_print_init (struct d_print_info *dpi, demangle_callbackref callback, + void *opaque) { - dpi->options = options; dpi->len = 0; dpi->last_char = '\0'; dpi->templates = NULL; dpi->modifiers = NULL; + dpi->pack_index = 0; dpi->flush_count = 0; dpi->callback = callback; @@ -3436,9 +3606,9 @@ cplus_demangle_print_callback (int options, { struct d_print_info dpi; - d_print_init (&dpi, options, callback, opaque); + d_print_init (&dpi, callback, opaque); - d_print_comp (&dpi, dc); + d_print_comp (&dpi, options, dc); d_print_flush (&dpi); @@ -3581,16 +3751,18 @@ d_pack_length (const struct demangle_component *dc) if needed. */ static void -d_print_subexpr (struct d_print_info *dpi, +d_print_subexpr (struct d_print_info *dpi, int options, const struct demangle_component *dc) { int simple = 0; if (dc->type == DEMANGLE_COMPONENT_NAME + || dc->type == DEMANGLE_COMPONENT_QUAL_NAME + || dc->type == DEMANGLE_COMPONENT_INITIALIZER_LIST || dc->type == DEMANGLE_COMPONENT_FUNCTION_PARAM) simple = 1; if (!simple) d_append_char (dpi, '('); - d_print_comp (dpi, dc); + d_print_comp (dpi, options, dc); if (!simple) d_append_char (dpi, ')'); } @@ -3598,9 +3770,13 @@ d_print_subexpr (struct d_print_info *dpi, /* Subroutine to handle components. */ static void -d_print_comp (struct d_print_info *dpi, +d_print_comp (struct d_print_info *dpi, int options, const struct demangle_component *dc) { + /* Magic variable to let reference smashing skip over the next modifier + without needing to modify *dc. */ + const struct demangle_component *mod_inner = NULL; + if (dc == NULL) { d_print_error (dpi); @@ -3612,7 +3788,7 @@ d_print_comp (struct d_print_info *dpi, switch (dc->type) { case DEMANGLE_COMPONENT_NAME: - if ((dpi->options & DMGL_JAVA) == 0) + if ((options & DMGL_JAVA) == 0) d_append_buffer (dpi, dc->u.s_name.s, dc->u.s_name.len); else d_print_java_identifier (dpi, dc->u.s_name.s, dc->u.s_name.len); @@ -3620,12 +3796,12 @@ d_print_comp (struct d_print_info *dpi, case DEMANGLE_COMPONENT_QUAL_NAME: case DEMANGLE_COMPONENT_LOCAL_NAME: - d_print_comp (dpi, d_left (dc)); - if ((dpi->options & DMGL_JAVA) == 0) + d_print_comp (dpi, options, d_left (dc)); + if ((options & DMGL_JAVA) == 0) d_append_string (dpi, "::"); else d_append_char (dpi, '.'); - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); return; case DEMANGLE_COMPONENT_TYPED_NAME: @@ -3715,7 +3891,7 @@ d_print_comp (struct d_print_info *dpi, } } - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); if (typed_name->type == DEMANGLE_COMPONENT_TEMPLATE) dpi->templates = dpt.next; @@ -3728,7 +3904,7 @@ d_print_comp (struct d_print_info *dpi, if (! adpm[i].printed) { d_append_char (dpi, ' '); - d_print_mod (dpi, adpm[i].mod); + d_print_mod (dpi, options, adpm[i].mod); } } @@ -3751,7 +3927,7 @@ d_print_comp (struct d_print_info *dpi, dcl = d_left (dc); - if ((dpi->options & DMGL_JAVA) != 0 + if ((options & DMGL_JAVA) != 0 && dcl->type == DEMANGLE_COMPONENT_NAME && dcl->u.s_name.len == 6 && strncmp (dcl->u.s_name.s, "JArray", 6) == 0) @@ -3759,16 +3935,16 @@ d_print_comp (struct d_print_info *dpi, /* Special-case Java arrays, so that JArray<TYPE> appears instead as TYPE[]. */ - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); d_append_string (dpi, "[]"); } else { - d_print_comp (dpi, dcl); + d_print_comp (dpi, options, dcl); if (d_last_char (dpi) == '<') d_append_char (dpi, ' '); d_append_char (dpi, '<'); - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); /* Avoid generating two consecutive '>' characters, to avoid the C++ syntactic ambiguity. */ if (d_last_char (dpi) == '>') @@ -3803,7 +3979,7 @@ d_print_comp (struct d_print_info *dpi, hold_dpt = dpi->templates; dpi->templates = hold_dpt->next; - d_print_comp (dpi, a); + d_print_comp (dpi, options, a); dpi->templates = hold_dpt; @@ -3811,79 +3987,91 @@ d_print_comp (struct d_print_info *dpi, } case DEMANGLE_COMPONENT_CTOR: - d_print_comp (dpi, dc->u.s_ctor.name); + d_print_comp (dpi, options, dc->u.s_ctor.name); return; case DEMANGLE_COMPONENT_DTOR: d_append_char (dpi, '~'); - d_print_comp (dpi, dc->u.s_dtor.name); + d_print_comp (dpi, options, dc->u.s_dtor.name); return; case DEMANGLE_COMPONENT_VTABLE: d_append_string (dpi, "vtable for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_VTT: d_append_string (dpi, "VTT for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_CONSTRUCTION_VTABLE: d_append_string (dpi, "construction vtable for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); d_append_string (dpi, "-in-"); - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); return; case DEMANGLE_COMPONENT_TYPEINFO: d_append_string (dpi, "typeinfo for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_TYPEINFO_NAME: d_append_string (dpi, "typeinfo name for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_TYPEINFO_FN: d_append_string (dpi, "typeinfo fn for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_THUNK: d_append_string (dpi, "non-virtual thunk to "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_VIRTUAL_THUNK: d_append_string (dpi, "virtual thunk to "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_COVARIANT_THUNK: d_append_string (dpi, "covariant return thunk to "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_JAVA_CLASS: d_append_string (dpi, "java Class for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_GUARD: d_append_string (dpi, "guard variable for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_REFTEMP: - d_append_string (dpi, "reference temporary for "); - d_print_comp (dpi, d_left (dc)); + d_append_string (dpi, "reference temporary #"); + d_print_comp (dpi, options, d_right (dc)); + d_append_string (dpi, " for "); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_HIDDEN_ALIAS: d_append_string (dpi, "hidden alias for "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); + return; + + case DEMANGLE_COMPONENT_TRANSACTION_CLONE: + d_append_string (dpi, "transaction clone for "); + d_print_comp (dpi, options, d_left (dc)); + return; + + case DEMANGLE_COMPONENT_NONTRANSACTION_CLONE: + d_append_string (dpi, "non-transaction clone for "); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_SUB_STD: @@ -3910,22 +4098,50 @@ d_print_comp (struct d_print_info *dpi, break; if (pdpm->mod->type == dc->type) { - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; } } } } + goto modifier; + + case DEMANGLE_COMPONENT_REFERENCE: + case DEMANGLE_COMPONENT_RVALUE_REFERENCE: + { + /* Handle reference smashing: & + && = &. */ + const struct demangle_component *sub = d_left (dc); + if (sub->type == DEMANGLE_COMPONENT_TEMPLATE_PARAM) + { + struct demangle_component *a = d_lookup_template_argument (dpi, sub); + if (a && a->type == DEMANGLE_COMPONENT_TEMPLATE_ARGLIST) + a = d_index_template_argument (a, dpi->pack_index); + + if (a == NULL) + { + d_print_error (dpi); + return; + } + + sub = a; + } + + if (sub->type == DEMANGLE_COMPONENT_REFERENCE + || sub->type == dc->type) + dc = sub; + else if (sub->type == DEMANGLE_COMPONENT_RVALUE_REFERENCE) + mod_inner = d_left (sub); + } /* Fall through. */ + case DEMANGLE_COMPONENT_RESTRICT_THIS: case DEMANGLE_COMPONENT_VOLATILE_THIS: case DEMANGLE_COMPONENT_CONST_THIS: case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: case DEMANGLE_COMPONENT_POINTER: - case DEMANGLE_COMPONENT_REFERENCE: - case DEMANGLE_COMPONENT_RVALUE_REFERENCE: case DEMANGLE_COMPONENT_COMPLEX: case DEMANGLE_COMPONENT_IMAGINARY: + modifier: { /* We keep a list of modifiers on the stack. */ struct d_print_mod dpm; @@ -3936,12 +4152,15 @@ d_print_comp (struct d_print_info *dpi, dpm.printed = 0; dpm.templates = dpi->templates; - d_print_comp (dpi, d_left (dc)); + if (!mod_inner) + mod_inner = d_left (dc); + + d_print_comp (dpi, options, mod_inner); /* If the modifier didn't get printed by the type, print it now. */ if (! dpm.printed) - d_print_mod (dpi, dc); + d_print_mod (dpi, options, dc); dpi->modifiers = dpm.next; @@ -3949,7 +4168,7 @@ d_print_comp (struct d_print_info *dpi, } case DEMANGLE_COMPONENT_BUILTIN_TYPE: - if ((dpi->options & DMGL_JAVA) == 0) + if ((options & DMGL_JAVA) == 0) d_append_buffer (dpi, dc->u.s_builtin.type->name, dc->u.s_builtin.type->len); else @@ -3958,16 +4177,21 @@ d_print_comp (struct d_print_info *dpi, return; case DEMANGLE_COMPONENT_VENDOR_TYPE: - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_FUNCTION_TYPE: { - if ((dpi->options & DMGL_RET_POSTFIX) != 0) - d_print_function_type (dpi, dc, dpi->modifiers); + if ((options & DMGL_RET_POSTFIX) != 0) + d_print_function_type (dpi, + options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP), + dc, dpi->modifiers); /* Print return type if present */ - if (d_left (dc) != NULL) + if (d_left (dc) != NULL && (options & DMGL_RET_POSTFIX) != 0) + d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP), + d_left (dc)); + else if (d_left (dc) != NULL && (options & DMGL_RET_DROP) == 0) { struct d_print_mod dpm; @@ -3979,7 +4203,8 @@ d_print_comp (struct d_print_info *dpi, dpm.printed = 0; dpm.templates = dpi->templates; - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP), + d_left (dc)); dpi->modifiers = dpm.next; @@ -3988,12 +4213,14 @@ d_print_comp (struct d_print_info *dpi, /* In standard prefix notation, there is a space between the return type and the function signature. */ - if ((dpi->options & DMGL_RET_POSTFIX) == 0) + if ((options & DMGL_RET_POSTFIX) == 0) d_append_char (dpi, ' '); } - if ((dpi->options & DMGL_RET_POSTFIX) == 0) - d_print_function_type (dpi, dc, dpi->modifiers); + if ((options & DMGL_RET_POSTFIX) == 0) + d_print_function_type (dpi, + options & ~(DMGL_RET_POSTFIX | DMGL_RET_DROP), + dc, dpi->modifiers); return; } @@ -4046,7 +4273,7 @@ d_print_comp (struct d_print_info *dpi, pdpm = pdpm->next; } - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); dpi->modifiers = hold_modifiers; @@ -4056,10 +4283,10 @@ d_print_comp (struct d_print_info *dpi, while (i > 1) { --i; - d_print_mod (dpi, adpm[i].mod); + d_print_mod (dpi, options, adpm[i].mod); } - d_print_array_type (dpi, dc, dpi->modifiers); + d_print_array_type (dpi, options, dc, dpi->modifiers); return; } @@ -4075,12 +4302,12 @@ d_print_comp (struct d_print_info *dpi, dpm.printed = 0; dpm.templates = dpi->templates; - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); /* If the modifier didn't get printed by the type, print it now. */ if (! dpm.printed) - d_print_mod (dpi, dc); + d_print_mod (dpi, options, dc); dpi->modifiers = dpm.next; @@ -4094,7 +4321,7 @@ d_print_comp (struct d_print_info *dpi, if (dc->u.s_fixed.length->u.s_builtin.type != &cplus_demangle_builtin_types['i'-'a']) { - d_print_comp (dpi, dc->u.s_fixed.length); + d_print_comp (dpi, options, dc->u.s_fixed.length); d_append_char (dpi, ' '); } if (dc->u.s_fixed.accum) @@ -4106,7 +4333,7 @@ d_print_comp (struct d_print_info *dpi, case DEMANGLE_COMPONENT_ARGLIST: case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST: if (d_left (dc) != NULL) - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); if (d_right (dc) != NULL) { size_t len; @@ -4118,7 +4345,7 @@ d_print_comp (struct d_print_info *dpi, d_append_string (dpi, ", "); len = dpi->len; flush_count = dpi->flush_count; - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); /* If that didn't print anything (which can happen with empty template argument packs), remove the comma and space. */ if (dpi->flush_count == flush_count && dpi->len == len) @@ -4126,39 +4353,98 @@ d_print_comp (struct d_print_info *dpi, } return; + case DEMANGLE_COMPONENT_INITIALIZER_LIST: + { + struct demangle_component *type = d_left (dc); + struct demangle_component *list = d_right (dc); + + if (type) + d_print_comp (dpi, options, type); + d_append_char (dpi, '{'); + d_print_comp (dpi, options, list); + d_append_char (dpi, '}'); + } + return; + case DEMANGLE_COMPONENT_OPERATOR: { - char c; + const struct demangle_operator_info *op = dc->u.s_operator.op; + int len = op->len; d_append_string (dpi, "operator"); - c = dc->u.s_operator.op->name[0]; - if (IS_LOWER (c)) + /* Add a space before new/delete. */ + if (IS_LOWER (op->name[0])) d_append_char (dpi, ' '); - d_append_buffer (dpi, dc->u.s_operator.op->name, - dc->u.s_operator.op->len); + /* Omit a trailing space. */ + if (op->name[len-1] == ' ') + --len; + d_append_buffer (dpi, op->name, len); return; } case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: d_append_string (dpi, "operator "); - d_print_comp (dpi, dc->u.s_extended_operator.name); + d_print_comp (dpi, options, dc->u.s_extended_operator.name); return; case DEMANGLE_COMPONENT_CAST: d_append_string (dpi, "operator "); - d_print_cast (dpi, dc); + d_print_cast (dpi, options, dc); + return; + + case DEMANGLE_COMPONENT_NULLARY: + d_print_expr_op (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_UNARY: - if (d_left (dc)->type != DEMANGLE_COMPONENT_CAST) - d_print_expr_op (dpi, d_left (dc)); - else - { - d_append_char (dpi, '('); - d_print_cast (dpi, d_left (dc)); - d_append_char (dpi, ')'); - } - d_print_subexpr (dpi, d_right (dc)); + { + struct demangle_component *op = d_left (dc); + struct demangle_component *operand = d_right (dc); + const char *code = NULL; + + if (op->type == DEMANGLE_COMPONENT_OPERATOR) + { + code = op->u.s_operator.op->code; + if (!strcmp (code, "ad")) + { + /* Don't print the argument list for the address of a + function. */ + if (operand->type == DEMANGLE_COMPONENT_TYPED_NAME + && d_left (operand)->type == DEMANGLE_COMPONENT_QUAL_NAME + && d_right (operand)->type == DEMANGLE_COMPONENT_FUNCTION_TYPE) + operand = d_left (operand); + } + if (operand->type == DEMANGLE_COMPONENT_BINARY_ARGS) + { + /* This indicates a suffix operator. */ + operand = d_left (operand); + d_print_subexpr (dpi, options, operand); + d_print_expr_op (dpi, options, op); + return; + } + } + + if (op->type != DEMANGLE_COMPONENT_CAST) + d_print_expr_op (dpi, options, op); + else + { + d_append_char (dpi, '('); + d_print_cast (dpi, options, op); + d_append_char (dpi, ')'); + } + if (code && !strcmp (code, "gs")) + /* Avoid parens after '::'. */ + d_print_comp (dpi, options, operand); + else if (code && !strcmp (code, "st")) + /* Always print parens for sizeof (type). */ + { + d_append_char (dpi, '('); + d_print_comp (dpi, options, operand); + d_append_char (dpi, ')'); + } + else + d_print_subexpr (dpi, options, operand); + } return; case DEMANGLE_COMPONENT_BINARY: @@ -4176,18 +4462,32 @@ d_print_comp (struct d_print_info *dpi, && d_left (dc)->u.s_operator.op->name[0] == '>') d_append_char (dpi, '('); - d_print_subexpr (dpi, d_left (d_right (dc))); + if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") == 0 + && d_left (d_right (dc))->type == DEMANGLE_COMPONENT_TYPED_NAME) + { + /* Function call used in an expression should not have printed types + of the function arguments. Values of the function arguments still + get printed below. */ + + const struct demangle_component *func = d_left (d_right (dc)); + + if (d_right (func)->type != DEMANGLE_COMPONENT_FUNCTION_TYPE) + d_print_error (dpi); + d_print_subexpr (dpi, options, d_left (func)); + } + else + d_print_subexpr (dpi, options, d_left (d_right (dc))); if (strcmp (d_left (dc)->u.s_operator.op->code, "ix") == 0) { d_append_char (dpi, '['); - d_print_comp (dpi, d_right (d_right (dc))); + d_print_comp (dpi, options, d_right (d_right (dc))); d_append_char (dpi, ']'); } else { if (strcmp (d_left (dc)->u.s_operator.op->code, "cl") != 0) - d_print_expr_op (dpi, d_left (dc)); - d_print_subexpr (dpi, d_right (d_right (dc))); + d_print_expr_op (dpi, options, d_left (dc)); + d_print_subexpr (dpi, options, d_right (d_right (dc))); } if (d_left (dc)->type == DEMANGLE_COMPONENT_OPERATOR @@ -4209,11 +4509,33 @@ d_print_comp (struct d_print_info *dpi, d_print_error (dpi); return; } - d_print_subexpr (dpi, d_left (d_right (dc))); - d_print_expr_op (dpi, d_left (dc)); - d_print_subexpr (dpi, d_left (d_right (d_right (dc)))); - d_append_string (dpi, " : "); - d_print_subexpr (dpi, d_right (d_right (d_right (dc)))); + { + struct demangle_component *op = d_left (dc); + struct demangle_component *first = d_left (d_right (dc)); + struct demangle_component *second = d_left (d_right (d_right (dc))); + struct demangle_component *third = d_right (d_right (d_right (dc))); + + if (!strcmp (op->u.s_operator.op->code, "qu")) + { + d_print_subexpr (dpi, options, first); + d_print_expr_op (dpi, options, op); + d_print_subexpr (dpi, options, second); + d_append_string (dpi, " : "); + d_print_subexpr (dpi, options, third); + } + else + { + d_append_string (dpi, "new "); + if (d_left (first) != NULL) + { + d_print_subexpr (dpi, options, first); + d_append_char (dpi, ' '); + } + d_print_comp (dpi, options, second); + if (third) + d_print_subexpr (dpi, options, third); + } + } return; case DEMANGLE_COMPONENT_TRINARY_ARG1: @@ -4244,7 +4566,7 @@ d_print_comp (struct d_print_info *dpi, { if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG) d_append_char (dpi, '-'); - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); switch (tp) { default: @@ -4294,13 +4616,13 @@ d_print_comp (struct d_print_info *dpi, } d_append_char (dpi, '('); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); d_append_char (dpi, ')'); if (dc->type == DEMANGLE_COMPONENT_LITERAL_NEG) d_append_char (dpi, '-'); if (tp == D_PRINT_FLOAT) d_append_char (dpi, '['); - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); if (tp == D_PRINT_FLOAT) d_append_char (dpi, ']'); } @@ -4312,12 +4634,12 @@ d_print_comp (struct d_print_info *dpi, case DEMANGLE_COMPONENT_JAVA_RESOURCE: d_append_string (dpi, "java resource "); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); return; case DEMANGLE_COMPONENT_COMPOUND_NAME: - d_print_comp (dpi, d_left (dc)); - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_left (dc)); + d_print_comp (dpi, options, d_right (dc)); return; case DEMANGLE_COMPONENT_CHARACTER: @@ -4326,7 +4648,7 @@ d_print_comp (struct d_print_info *dpi, case DEMANGLE_COMPONENT_DECLTYPE: d_append_string (dpi, "decltype ("); - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); d_append_char (dpi, ')'); return; @@ -4340,7 +4662,7 @@ d_print_comp (struct d_print_info *dpi, /* d_find_pack won't find anything if the only packs involved in this expansion are function parameter packs; in that case, just print the pattern and "...". */ - d_print_subexpr (dpi, d_left (dc)); + d_print_subexpr (dpi, options, d_left (dc)); d_append_string (dpi, "..."); return; } @@ -4350,7 +4672,7 @@ d_print_comp (struct d_print_info *dpi, for (i = 0; i < len; ++i) { dpi->pack_index = i; - d_print_comp (dpi, dc); + d_print_comp (dpi, options, dc); if (i < len-1) d_append_string (dpi, ", "); } @@ -4358,24 +4680,32 @@ d_print_comp (struct d_print_info *dpi, return; case DEMANGLE_COMPONENT_FUNCTION_PARAM: - d_append_string (dpi, "{parm#"); - d_append_num (dpi, dc->u.s_number.number + 1); - d_append_char (dpi, '}'); + { + long num = dc->u.s_number.number; + if (num == 0) + d_append_string (dpi, "this"); + else + { + d_append_string (dpi, "{parm#"); + d_append_num (dpi, num); + d_append_char (dpi, '}'); + } + } return; case DEMANGLE_COMPONENT_GLOBAL_CONSTRUCTORS: d_append_string (dpi, "global constructors keyed to "); - d_print_comp (dpi, dc->u.s_binary.left); + d_print_comp (dpi, options, dc->u.s_binary.left); return; case DEMANGLE_COMPONENT_GLOBAL_DESTRUCTORS: d_append_string (dpi, "global destructors keyed to "); - d_print_comp (dpi, dc->u.s_binary.left); + d_print_comp (dpi, options, dc->u.s_binary.left); return; case DEMANGLE_COMPONENT_LAMBDA: d_append_string (dpi, "{lambda("); - d_print_comp (dpi, dc->u.s_unary_num.sub); + d_print_comp (dpi, options, dc->u.s_unary_num.sub); d_append_string (dpi, ")#"); d_append_num (dpi, dc->u.s_unary_num.num + 1); d_append_char (dpi, '}'); @@ -4388,9 +4718,9 @@ d_print_comp (struct d_print_info *dpi, return; case DEMANGLE_COMPONENT_CLONE: - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); d_append_string (dpi, " [clone "); - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); d_append_char (dpi, ']'); return; @@ -4456,7 +4786,7 @@ d_print_java_identifier (struct d_print_info *dpi, const char *name, int len) qualifiers on this after printing a function. */ static void -d_print_mod_list (struct d_print_info *dpi, +d_print_mod_list (struct d_print_info *dpi, int options, struct d_print_mod *mods, int suffix) { struct d_print_template *hold_dpt; @@ -4470,7 +4800,7 @@ d_print_mod_list (struct d_print_info *dpi, || mods->mod->type == DEMANGLE_COMPONENT_VOLATILE_THIS || mods->mod->type == DEMANGLE_COMPONENT_CONST_THIS))) { - d_print_mod_list (dpi, mods->next, suffix); + d_print_mod_list (dpi, options, mods->next, suffix); return; } @@ -4481,13 +4811,13 @@ d_print_mod_list (struct d_print_info *dpi, if (mods->mod->type == DEMANGLE_COMPONENT_FUNCTION_TYPE) { - d_print_function_type (dpi, mods->mod, mods->next); + d_print_function_type (dpi, options, mods->mod, mods->next); dpi->templates = hold_dpt; return; } else if (mods->mod->type == DEMANGLE_COMPONENT_ARRAY_TYPE) { - d_print_array_type (dpi, mods->mod, mods->next); + d_print_array_type (dpi, options, mods->mod, mods->next); dpi->templates = hold_dpt; return; } @@ -4503,10 +4833,10 @@ d_print_mod_list (struct d_print_info *dpi, hold_modifiers = dpi->modifiers; dpi->modifiers = NULL; - d_print_comp (dpi, d_left (mods->mod)); + d_print_comp (dpi, options, d_left (mods->mod)); dpi->modifiers = hold_modifiers; - if ((dpi->options & DMGL_JAVA) == 0) + if ((options & DMGL_JAVA) == 0) d_append_string (dpi, "::"); else d_append_char (dpi, '.'); @@ -4526,23 +4856,23 @@ d_print_mod_list (struct d_print_info *dpi, || dc->type == DEMANGLE_COMPONENT_CONST_THIS) dc = d_left (dc); - d_print_comp (dpi, dc); + d_print_comp (dpi, options, dc); dpi->templates = hold_dpt; return; } - d_print_mod (dpi, mods->mod); + d_print_mod (dpi, options, mods->mod); dpi->templates = hold_dpt; - d_print_mod_list (dpi, mods->next, suffix); + d_print_mod_list (dpi, options, mods->next, suffix); } /* Print a modifier. */ static void -d_print_mod (struct d_print_info *dpi, +d_print_mod (struct d_print_info *dpi, int options, const struct demangle_component *mod) { switch (mod->type) @@ -4561,11 +4891,11 @@ d_print_mod (struct d_print_info *dpi, return; case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: d_append_char (dpi, ' '); - d_print_comp (dpi, d_right (mod)); + d_print_comp (dpi, options, d_right (mod)); return; case DEMANGLE_COMPONENT_POINTER: /* There is no pointer symbol in Java. */ - if ((dpi->options & DMGL_JAVA) == 0) + if ((options & DMGL_JAVA) == 0) d_append_char (dpi, '*'); return; case DEMANGLE_COMPONENT_REFERENCE: @@ -4583,22 +4913,22 @@ d_print_mod (struct d_print_info *dpi, case DEMANGLE_COMPONENT_PTRMEM_TYPE: if (d_last_char (dpi) != '(') d_append_char (dpi, ' '); - d_print_comp (dpi, d_left (mod)); + d_print_comp (dpi, options, d_left (mod)); d_append_string (dpi, "::*"); return; case DEMANGLE_COMPONENT_TYPED_NAME: - d_print_comp (dpi, d_left (mod)); + d_print_comp (dpi, options, d_left (mod)); return; case DEMANGLE_COMPONENT_VECTOR_TYPE: d_append_string (dpi, " __vector("); - d_print_comp (dpi, d_left (mod)); + d_print_comp (dpi, options, d_left (mod)); d_append_char (dpi, ')'); return; default: /* Otherwise, we have something that won't go back on the modifier stack, so we can just print it. */ - d_print_comp (dpi, mod); + d_print_comp (dpi, options, mod); return; } } @@ -4606,7 +4936,7 @@ d_print_mod (struct d_print_info *dpi, /* Print a function type, except for the return type. */ static void -d_print_function_type (struct d_print_info *dpi, +d_print_function_type (struct d_print_info *dpi, int options, const struct demangle_component *dc, struct d_print_mod *mods) { @@ -4666,7 +4996,7 @@ d_print_function_type (struct d_print_info *dpi, hold_modifiers = dpi->modifiers; dpi->modifiers = NULL; - d_print_mod_list (dpi, mods, 0); + d_print_mod_list (dpi, options, mods, 0); if (need_paren) d_append_char (dpi, ')'); @@ -4674,11 +5004,11 @@ d_print_function_type (struct d_print_info *dpi, d_append_char (dpi, '('); if (d_right (dc) != NULL) - d_print_comp (dpi, d_right (dc)); + d_print_comp (dpi, options, d_right (dc)); d_append_char (dpi, ')'); - d_print_mod_list (dpi, mods, 1); + d_print_mod_list (dpi, options, mods, 1); dpi->modifiers = hold_modifiers; } @@ -4686,7 +5016,7 @@ d_print_function_type (struct d_print_info *dpi, /* Print an array type, except for the element type. */ static void -d_print_array_type (struct d_print_info *dpi, +d_print_array_type (struct d_print_info *dpi, int options, const struct demangle_component *dc, struct d_print_mod *mods) { @@ -4720,7 +5050,7 @@ d_print_array_type (struct d_print_info *dpi, if (need_paren) d_append_string (dpi, " ("); - d_print_mod_list (dpi, mods, 0); + d_print_mod_list (dpi, options, mods, 0); if (need_paren) d_append_char (dpi, ')'); @@ -4732,7 +5062,7 @@ d_print_array_type (struct d_print_info *dpi, d_append_char (dpi, '['); if (d_left (dc) != NULL) - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); d_append_char (dpi, ']'); } @@ -4740,24 +5070,24 @@ d_print_array_type (struct d_print_info *dpi, /* Print an operator in an expression. */ static void -d_print_expr_op (struct d_print_info *dpi, +d_print_expr_op (struct d_print_info *dpi, int options, const struct demangle_component *dc) { if (dc->type == DEMANGLE_COMPONENT_OPERATOR) d_append_buffer (dpi, dc->u.s_operator.op->name, dc->u.s_operator.op->len); else - d_print_comp (dpi, dc); + d_print_comp (dpi, options, dc); } /* Print a cast. */ static void -d_print_cast (struct d_print_info *dpi, +d_print_cast (struct d_print_info *dpi, int options, const struct demangle_component *dc) { if (d_left (dc)->type != DEMANGLE_COMPONENT_TEMPLATE) - d_print_comp (dpi, d_left (dc)); + d_print_comp (dpi, options, d_left (dc)); else { struct d_print_mod *hold_dpm; @@ -4775,14 +5105,14 @@ d_print_cast (struct d_print_info *dpi, dpi->templates = &dpt; dpt.template_decl = d_left (dc); - d_print_comp (dpi, d_left (d_left (dc))); + d_print_comp (dpi, options, d_left (d_left (dc))); dpi->templates = dpt.next; if (d_last_char (dpi) == '<') d_append_char (dpi, ' '); d_append_char (dpi, '<'); - d_print_comp (dpi, d_right (d_left (dc))); + d_print_comp (dpi, options, d_right (d_left (dc))); /* Avoid generating two consecutive '>' characters, to avoid the C++ syntactic ambiguity. */ if (d_last_char (dpi) == '>') diff --git a/libiberty/cp-demint.c b/libiberty/cp-demint.c index 2e8f8d2d05..1d1a77af74 100644 --- a/libiberty/cp-demint.c +++ b/libiberty/cp-demint.c @@ -206,10 +206,8 @@ cplus_demangle_v3_components (const char *mangled, int options, void **mem) malloc (di.num_subs * sizeof (struct demangle_component *))); if (di.comps == NULL || di.subs == NULL) { - if (di.comps != NULL) - free (di.comps); - if (di.subs != NULL) - free (di.subs); + free (di.comps); + free (di.subs); return NULL; } diff --git a/libiberty/cplus-dem.c b/libiberty/cplus-dem.c index 84f94b6a8d..e94848767e 100644 --- a/libiberty/cplus-dem.c +++ b/libiberty/cplus-dem.c @@ -1311,8 +1311,7 @@ delete_non_B_K_work_stuff (struct work_stuff *work) int i; for (i = 0; i < work->ntmpl_args; i++) - if (work->tmpl_argvec[i]) - free ((char*) work->tmpl_argvec[i]); + free ((char*) work->tmpl_argvec[i]); free ((char*) work->tmpl_argvec); work->tmpl_argvec = NULL; diff --git a/libiberty/filename_cmp.c b/libiberty/filename_cmp.c index 0eed12086b..5179f8dd14 100644 --- a/libiberty/filename_cmp.c +++ b/libiberty/filename_cmp.c @@ -50,19 +50,27 @@ and backward slashes are equal. int filename_cmp (const char *s1, const char *s2) { -#ifndef HAVE_DOS_BASED_FILE_SYSTEM +#if !defined(HAVE_DOS_BASED_FILE_SYSTEM) \ + && !defined(HAVE_CASE_INSENSITIVE_FILE_SYSTEM) return strcmp(s1, s2); #else for (;;) { - int c1 = TOLOWER (*s1); - int c2 = TOLOWER (*s2); + int c1 = *s1; + int c2 = *s2; +#if defined (HAVE_CASE_INSENSITIVE_FILE_SYSTEM) + c1 = TOLOWER (c1); + c2 = TOLOWER (c2); +#endif + +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) /* On DOS-based file systems, the '/' and the '\' are equivalent. */ if (c1 == '/') c1 = '\\'; if (c2 == '/') c2 = '\\'; +#endif if (c1 != c2) return (c1 - c2); @@ -100,21 +108,29 @@ and backward slashes are equal. int filename_ncmp (const char *s1, const char *s2, size_t n) { -#ifndef HAVE_DOS_BASED_FILE_SYSTEM +#if !defined(HAVE_DOS_BASED_FILE_SYSTEM) \ + && !defined(HAVE_CASE_INSENSITIVE_FILE_SYSTEM) return strncmp(s1, s2, n); #else if (!n) return 0; for (; n > 0; --n) { - int c1 = TOLOWER (*s1); - int c2 = TOLOWER (*s2); + int c1 = *s1; + int c2 = *s2; +#if defined (HAVE_CASE_INSENSITIVE_FILE_SYSTEM) + c1 = TOLOWER (c1); + c2 = TOLOWER (c2); +#endif + +#if defined (HAVE_DOS_BASED_FILE_SYSTEM) /* On DOS-based file systems, the '/' and the '\' are equivalent. */ if (c1 == '/') c1 = '\\'; if (c2 == '/') c2 = '\\'; +#endif if (c1 == '\0' || c1 != c2) return (c1 - c2); diff --git a/libiberty/make-relative-prefix.c b/libiberty/make-relative-prefix.c index 4553a7109d..fe639d18bd 100644 --- a/libiberty/make-relative-prefix.c +++ b/libiberty/make-relative-prefix.c @@ -1,6 +1,6 @@ /* Relative (relocatable) prefix support. Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, - 1999, 2000, 2001, 2002, 2006 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2006, 2012 Free Software Foundation, Inc. This file is part of libiberty. @@ -58,6 +58,9 @@ relative prefix can be found, return @code{NULL}. #ifdef HAVE_UNISTD_H #include <unistd.h> #endif +#ifdef HAVE_SYS_STAT_H +#include <sys/stat.h> +#endif #include <string.h> @@ -245,10 +248,15 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, { char *startp, *endp, *nstore; size_t prefixlen = strlen (temp) + 1; + size_t len; if (prefixlen < 2) prefixlen = 2; - nstore = (char *) alloca (prefixlen + strlen (progname) + 1); + len = prefixlen + strlen (progname) + 1; +#ifdef HAVE_HOST_EXECUTABLE_SUFFIX + len += strlen (HOST_EXECUTABLE_SUFFIX); +#endif + nstore = (char *) alloca (len); startp = endp = temp; while (1) @@ -263,7 +271,7 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, } else { - strncpy (nstore, startp, endp - startp); + memcpy (nstore, startp, endp - startp); if (! IS_DIR_SEPARATOR (endp[-1])) { nstore[endp - startp] = DIR_SEPARATOR; @@ -279,8 +287,14 @@ make_relative_prefix_1 (const char *progname, const char *bin_prefix, #endif ) { - progname = nstore; - break; +#if defined (HAVE_SYS_STAT_H) && defined (S_ISREG) + struct stat st; + if (stat (nstore, &st) >= 0 && S_ISREG (st.st_mode)) +#endif + { + progname = nstore; + break; + } } if (*endp == 0) diff --git a/libiberty/makefile.vms b/libiberty/makefile.vms index d69d7d9efa..606adac096 100644 --- a/libiberty/makefile.vms +++ b/libiberty/makefile.vms @@ -9,7 +9,7 @@ OBJS=getopt.obj,obstack.obj,xexit.obj,xmalloc.obj,hex.obj,\ getopt1.obj,cplus-dem.obj,cp-demangle.obj,cp-demint.obj,\ - asprintf.obj vasprintf.obj,mkstemps.obj,\ + asprintf.obj vasprintf.obj,mkstemps.obj,filename_cmp.obj,\ concat.obj,getruntime.obj,getpagesize.obj,getpwd.obj,xstrerror.obj,\ xmemdup.obj,xstrdup.obj,xatexit.obj,choose-temp.obj,fnmatch.obj,\ objalloc.obj,safe-ctype.obj,hashtab.obj,lbasename.obj,argv.obj,\ diff --git a/libiberty/md5.c b/libiberty/md5.c index 9de9d88c22..b30a6b7bfc 100644 --- a/libiberty/md5.c +++ b/libiberty/md5.c @@ -1,6 +1,6 @@ /* md5.c - Functions to compute MD5 message digest of files or memory blocks according to the definition of MD5 in RFC 1321 from April 1992. - Copyright (C) 1995, 1996 Free Software Foundation, Inc. + Copyright (C) 1995, 1996, 2011 Free Software Foundation, Inc. NOTE: This source is derived from an old version taken from the GNU C Library (glibc). @@ -76,15 +76,19 @@ md5_init_ctx (struct md5_ctx *ctx) /* Put result from CTX in first 16 bytes following RESBUF. The result must be in little endian byte order. - IMPORTANT: On some systems it is required that RESBUF is correctly - aligned for a 32 bits value. */ + IMPORTANT: RESBUF may not be aligned as strongly as MD5_UNIT32 so we + put things in a local (aligned) buffer first, then memcpy into RESBUF. */ void * md5_read_ctx (const struct md5_ctx *ctx, void *resbuf) { - ((md5_uint32 *) resbuf)[0] = SWAP (ctx->A); - ((md5_uint32 *) resbuf)[1] = SWAP (ctx->B); - ((md5_uint32 *) resbuf)[2] = SWAP (ctx->C); - ((md5_uint32 *) resbuf)[3] = SWAP (ctx->D); + md5_uint32 buffer[4]; + + buffer[0] = SWAP (ctx->A); + buffer[1] = SWAP (ctx->B); + buffer[2] = SWAP (ctx->C); + buffer[3] = SWAP (ctx->D); + + memcpy (resbuf, buffer, 16); return resbuf; } @@ -99,6 +103,7 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) { /* Take yet unprocessed bytes into account. */ md5_uint32 bytes = ctx->buflen; + md5_uint32 swap_bytes; size_t pad; /* Now count remaining bytes. */ @@ -109,10 +114,13 @@ md5_finish_ctx (struct md5_ctx *ctx, void *resbuf) pad = bytes >= 56 ? 64 + 56 - bytes : 56 - bytes; memcpy (&ctx->buffer[bytes], fillbuf, pad); - /* Put the 64-bit file length in *bits* at the end of the buffer. */ - *(md5_uint32 *) &ctx->buffer[bytes + pad] = SWAP (ctx->total[0] << 3); - *(md5_uint32 *) &ctx->buffer[bytes + pad + 4] = SWAP ((ctx->total[1] << 3) | - (ctx->total[0] >> 29)); + /* Put the 64-bit file length in *bits* at the end of the buffer. + Use memcpy to avoid aliasing problems. On most systems, this + will be optimized away to the same code. */ + swap_bytes = SWAP (ctx->total[0] << 3); + memcpy (&ctx->buffer[bytes + pad], &swap_bytes, sizeof (swap_bytes)); + swap_bytes = SWAP ((ctx->total[1] << 3) | (ctx->total[0] >> 29)); + memcpy (&ctx->buffer[bytes + pad + 4], &swap_bytes, sizeof (swap_bytes)); /* Process last bytes. */ md5_process_block (ctx->buffer, bytes + pad + 8, ctx); @@ -241,9 +249,11 @@ md5_process_bytes (const void *buffer, size_t len, struct md5_ctx *ctx) } else #endif - md5_process_block (buffer, len & ~63, ctx); - buffer = (const void *) ((const char *) buffer + (len & ~63)); - len &= 63; + { + md5_process_block (buffer, len & ~63, ctx); + buffer = (const void *) ((const char *) buffer + (len & ~63)); + len &= 63; + } } /* Move remaining bytes in internal buffer. */ @@ -283,8 +293,7 @@ md5_process_block (const void *buffer, size_t len, struct md5_ctx *ctx) length of the file up to 2^64 bits. Here we only compute the number of bytes. Do a double word increment. */ ctx->total[0] += len; - if (ctx->total[0] < len) - ++ctx->total[1]; + ctx->total[1] += ((len >> 31) >> 1) + (ctx->total[0] < len); /* Process all bytes in the buffer with 64 bytes in each round of the loop. */ diff --git a/libiberty/pex-common.c b/libiberty/pex-common.c index 55b63ae33f..6fd3fdecd8 100644 --- a/libiberty/pex-common.c +++ b/libiberty/pex-common.c @@ -623,12 +623,9 @@ pex_free (struct pex_obj *obj) if (obj->next_input_name_allocated) free (obj->next_input_name); - if (obj->children != NULL) - free (obj->children); - if (obj->status != NULL) - free (obj->status); - if (obj->time != NULL) - free (obj->time); + free (obj->children); + free (obj->status); + free (obj->time); if (obj->remove_count > 0) { diff --git a/libiberty/pex-msdos.c b/libiberty/pex-msdos.c index 4b77bf655f..fa0f40ac9e 100644 --- a/libiberty/pex-msdos.c +++ b/libiberty/pex-msdos.c @@ -310,10 +310,8 @@ pex_msdos_cleanup (struct pex_obj *obj) ms = (struct pex_msdos *) obj->sysdep; for (i = 0; i < PEX_MSDOS_FILE_COUNT; ++i) - if (msdos->files[i] != NULL) - free (msdos->files[i]); - if (msdos->statuses != NULL) - free (msdos->statuses); + free (msdos->files[i]); + free (msdos->statuses); free (msdos); obj->sysdep = NULL; } diff --git a/libiberty/pex-win32.c b/libiberty/pex-win32.c index 4427406748..107ac6fdcc 100644 --- a/libiberty/pex-win32.c +++ b/libiberty/pex-win32.c @@ -210,10 +210,8 @@ mingw_rootify (const char *executable) if (!namebuf || !foundbuf) { RegCloseKey (hKey); - if (namebuf) - free (namebuf); - if (foundbuf) - free (foundbuf); + free (namebuf); + free (foundbuf); return executable; } @@ -315,8 +313,7 @@ msys_rootify (const char *executable) return tack_on_executable (buf, executable); /* failed */ - if (buf) - free (buf); + free (buf); return executable; } #endif @@ -607,8 +604,7 @@ win32_spawn (const char *executable, si, pi)) { - if (env_block) - free (env_block); + free (env_block); free (full_executable); @@ -618,18 +614,14 @@ win32_spawn (const char *executable, /* Clean up. */ CloseHandle (pi->hThread); free (full_executable); - if (env_block) - free (env_block); + free (env_block); return (pid_t) pi->hProcess; error: - if (env_block) - free (env_block); - if (cmdline) - free (cmdline); - if (full_executable) - free (full_executable); + free (env_block); + free (cmdline); + free (full_executable); return (pid_t) -1; } diff --git a/libiberty/regex.c b/libiberty/regex.c index 420c7f4a47..e5ad222bac 100644 --- a/libiberty/regex.c +++ b/libiberty/regex.c @@ -46,9 +46,11 @@ # if defined STDC_HEADERS && !defined emacs # include <stddef.h> +# define PTR_INT_TYPE ptrdiff_t # else /* We need this for `regex.h', and perhaps for the Emacs include files. */ # include <sys/types.h> +# define PTR_INT_TYPE long # endif # define WIDE_CHAR_SUPPORT (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC) @@ -2045,7 +2047,7 @@ static reg_errcode_t byte_compile_range (unsigned int range_start, /* How many characters the new buffer can have? */ \ wchar_count = bufp->allocated / sizeof(UCHAR_T); \ if (wchar_count == 0) wchar_count = 1; \ - /* Truncate the buffer to CHAR_T align. */ \ + /* Truncate the buffer to CHAR_T align. */ \ bufp->allocated = wchar_count * sizeof(UCHAR_T); \ RETALLOC (COMPILED_BUFFER_VAR, wchar_count, UCHAR_T); \ bufp->buffer = (char*)COMPILED_BUFFER_VAR; \ @@ -2054,7 +2056,7 @@ static reg_errcode_t byte_compile_range (unsigned int range_start, /* If the buffer moved, move all the pointers into it. */ \ if (old_buffer != COMPILED_BUFFER_VAR) \ { \ - int incr = COMPILED_BUFFER_VAR - old_buffer; \ + PTR_INT_TYPE incr = COMPILED_BUFFER_VAR - old_buffer; \ MOVE_BUFFER_POINTER (b); \ MOVE_BUFFER_POINTER (begalt); \ if (fixup_alt_jump) \ @@ -2082,7 +2084,7 @@ static reg_errcode_t byte_compile_range (unsigned int range_start, /* If the buffer moved, move all the pointers into it. */ \ if (old_buffer != COMPILED_BUFFER_VAR) \ { \ - int incr = COMPILED_BUFFER_VAR - old_buffer; \ + PTR_INT_TYPE incr = COMPILED_BUFFER_VAR - old_buffer; \ MOVE_BUFFER_POINTER (b); \ MOVE_BUFFER_POINTER (begalt); \ if (fixup_alt_jump) \ @@ -4970,7 +4972,7 @@ weak_alias (__re_search_2, re_search_2) #ifdef MATCH_MAY_ALLOCATE # define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL #else -# define FREE_VAR(var) if (var) free (var); var = NULL +# define FREE_VAR(var) free (var); var = NULL #endif #ifdef WCHAR @@ -8111,20 +8113,17 @@ weak_alias (__regerror, regerror) void regfree (regex_t *preg) { - if (preg->buffer != NULL) - free (preg->buffer); + free (preg->buffer); preg->buffer = NULL; preg->allocated = 0; preg->used = 0; - if (preg->fastmap != NULL) - free (preg->fastmap); + free (preg->fastmap); preg->fastmap = NULL; preg->fastmap_accurate = 0; - if (preg->translate != NULL) - free (preg->translate); + free (preg->translate); preg->translate = NULL; } #ifdef _LIBC diff --git a/libiberty/setproctitle.c b/libiberty/setproctitle.c index 3b3f377b67..6a2fe8ce3a 100644 --- a/libiberty/setproctitle.c +++ b/libiberty/setproctitle.c @@ -41,8 +41,8 @@ void setproctitle (const char *name ATTRIBUTE_UNUSED, ...) { #ifdef PR_SET_NAME - /* On Linux this sets the top visible "comm", but not necessarily - the name visible in ps. */ + /* On GNU/Linux this sets the top visible "comm", but not + necessarily the name visible in ps. */ prctl (PR_SET_NAME, name); #endif } diff --git a/libiberty/sha1.c b/libiberty/sha1.c index 6a25ab2399..617e743a15 100644 --- a/libiberty/sha1.c +++ b/libiberty/sha1.c @@ -300,8 +300,7 @@ sha1_process_block (const void *buffer, size_t len, struct sha1_ctx *ctx) length of the file up to 2^64 bits. Here we only compute the number of bytes. Do a double word increment. */ ctx->total[0] += len; - if (ctx->total[0] < len) - ++ctx->total[1]; + ctx->total[1] += ((len >> 31) >> 1) + (ctx->total[0] < len); #define rol(x, n) (((x) << (n)) | ((sha1_uint32) (x) >> (32 - (n)))) diff --git a/libiberty/simple-object-mach-o.c b/libiberty/simple-object-mach-o.c index bbbbd09de5..af5e4f9ca8 100644 --- a/libiberty/simple-object-mach-o.c +++ b/libiberty/simple-object-mach-o.c @@ -1,5 +1,5 @@ /* simple-object-mach-o.c -- routines to manipulate Mach-O object files. - Copyright 2010 Free Software Foundation, Inc. + Copyright 2010, 2011 Free Software Foundation, Inc. Written by Ian Lance Taylor, Google. This program is free software; you can redistribute it and/or modify it @@ -174,6 +174,15 @@ struct mach_o_section_64 #define GNU_SECTION_NAMES "__section_names" +/* A GNU-specific extension to wrap multiple sections using three + mach-o sections within a given segment. The section '__wrapper_sects' + is subdivided according to the index '__wrapper_index' and each sub + sect is named according to the names supplied in '__wrapper_names'. */ + +#define GNU_WRAPPER_SECTS "__wrapper_sects" +#define GNU_WRAPPER_INDEX "__wrapper_index" +#define GNU_WRAPPER_NAMES "__wrapper_names" + /* Private data for an simple_object_read. */ struct simple_object_mach_o_read @@ -214,7 +223,18 @@ struct simple_object_mach_o_attributes unsigned int reserved; }; -/* See if we have a Mach-O file. */ +/* See if we have a Mach-O MH_OBJECT file: + + A standard MH_OBJECT (from as) will have three load commands: + 0 - LC_SEGMENT/LC_SEGMENT64 + 1 - LC_SYMTAB + 2 - LC_DYSYMTAB + + The LC_SEGMENT/LC_SEGMENT64 will introduce a single anonymous segment + containing all the sections. + + Files written by simple-object will have only the segment command + (no symbol tables). */ static void * simple_object_mach_o_match ( @@ -356,8 +376,29 @@ simple_object_mach_o_section_info (int is_big_endian, int is_32, } } -/* Handle a segment in a Mach-O file. Return 1 if we should continue, - 0 if the caller should return. */ +/* Handle a segment in a Mach-O Object file. + + This will callback to the function pfn for each "section found" the meaning + of which depends on gnu extensions to mach-o: + + If we find mach-o sections (with the segment name as specified) which also + contain: a 'sects' wrapper, an index, and a name table, we expand this into + as many sections as are specified in the index. In this case, there will + be a callback for each of these. + + We will also allow an extension that permits long names (more than 16 + characters) to be used with mach-o. In this case, the section name has + a specific format embedding an index into a name table, and the file must + contain such name table. + + Return 1 if we should continue, 0 if the caller should return. */ + +#define SOMO_SECTS_PRESENT 0x01 +#define SOMO_INDEX_PRESENT 0x02 +#define SOMO_NAMES_PRESENT 0x04 +#define SOMO_LONGN_PRESENT 0x08 +#define SOMO_WRAPPING (SOMO_SECTS_PRESENT | SOMO_INDEX_PRESENT \ + | SOMO_NAMES_PRESENT) static int simple_object_mach_o_segment (simple_object_read *sobj, off_t offset, @@ -378,9 +419,20 @@ simple_object_mach_o_segment (simple_object_read *sobj, off_t offset, unsigned int nsects; unsigned char *secdata; unsigned int i; + unsigned int gnu_sections_found; unsigned int strtab_index; + unsigned int index_index; + unsigned int nametab_index; + unsigned int sections_index; char *strtab; + char *nametab; + unsigned char *index; size_t strtab_size; + size_t nametab_size; + size_t index_size; + unsigned int n_wrapped_sects; + size_t wrapper_sect_size; + off_t wrapper_sect_offset; fetch_32 = (omr->is_big_endian ? simple_object_fetch_big_32 @@ -409,6 +461,8 @@ simple_object_mach_o_segment (simple_object_read *sobj, off_t offset, nsects)); } + /* Fetch the section headers from the segment command. */ + secdata = XNEWVEC (unsigned char, nsects * sechdrsize); if (!simple_object_internal_read (sobj->descriptor, offset + seghdrsize, secdata, nsects * sechdrsize, errmsg, err)) @@ -417,9 +471,13 @@ simple_object_mach_o_segment (simple_object_read *sobj, off_t offset, return 0; } - /* Scan for a __section_names section. This is in effect a GNU - extension that permits section names longer than 16 chars. */ + /* Scan for special sections that signal GNU extensions to the format. */ + gnu_sections_found = 0; + index_index = nsects; + sections_index = nsects; + strtab_index = nsects; + nametab_index = nsects; for (i = 0; i < nsects; ++i) { size_t nameoff; @@ -427,19 +485,104 @@ simple_object_mach_o_segment (simple_object_read *sobj, off_t offset, nameoff = i * sechdrsize + segname_offset; if (strcmp ((char *) secdata + nameoff, omr->segment_name) != 0) continue; + nameoff = i * sechdrsize + sectname_offset; - if (strcmp ((char *) secdata + nameoff, GNU_SECTION_NAMES) == 0) - break; + if (strcmp ((char *) secdata + nameoff, GNU_WRAPPER_NAMES) == 0) + { + nametab_index = i; + gnu_sections_found |= SOMO_NAMES_PRESENT; + } + else if (strcmp ((char *) secdata + nameoff, GNU_WRAPPER_INDEX) == 0) + { + index_index = i; + gnu_sections_found |= SOMO_INDEX_PRESENT; + } + else if (strcmp ((char *) secdata + nameoff, GNU_WRAPPER_SECTS) == 0) + { + sections_index = i; + gnu_sections_found |= SOMO_SECTS_PRESENT; + } + else if (strcmp ((char *) secdata + nameoff, GNU_SECTION_NAMES) == 0) + { + strtab_index = i; + gnu_sections_found |= SOMO_LONGN_PRESENT; + } } - strtab_index = i; - if (strtab_index >= nsects) + /* If any of the special wrapper section components is present, then + they all should be. */ + + if ((gnu_sections_found & SOMO_WRAPPING) != 0) { - strtab = NULL; - strtab_size = 0; + off_t nametab_offset; + off_t index_offset; + + if ((gnu_sections_found & SOMO_WRAPPING) != SOMO_WRAPPING) + { + *errmsg = "GNU Mach-o section wrapper: required section missing"; + *err = 0; /* No useful errno. */ + XDELETEVEC (secdata); + return 0; + } + + /* Fetch the name table. */ + + simple_object_mach_o_section_info (omr->is_big_endian, is_32, + secdata + nametab_index * sechdrsize, + &nametab_offset, &nametab_size); + nametab = XNEWVEC (char, nametab_size); + if (!simple_object_internal_read (sobj->descriptor, + sobj->offset + nametab_offset, + (unsigned char *) nametab, nametab_size, + errmsg, err)) + { + XDELETEVEC (nametab); + XDELETEVEC (secdata); + return 0; + } + + /* Fetch the index. */ + + simple_object_mach_o_section_info (omr->is_big_endian, is_32, + secdata + index_index * sechdrsize, + &index_offset, &index_size); + index = XNEWVEC (unsigned char, index_size); + if (!simple_object_internal_read (sobj->descriptor, + sobj->offset + index_offset, + index, index_size, + errmsg, err)) + { + XDELETEVEC (index); + XDELETEVEC (nametab); + XDELETEVEC (secdata); + return 0; + } + + /* The index contains 4 unsigned ints per sub-section: + sub-section offset/length, sub-section name/length. + We fix this for both 32 and 64 bit mach-o for now, since + other fields limit the maximum size of an object to 4G. */ + n_wrapped_sects = index_size / 16; + + /* Get the parameters for the wrapper too. */ + simple_object_mach_o_section_info (omr->is_big_endian, is_32, + secdata + sections_index * sechdrsize, + &wrapper_sect_offset, + &wrapper_sect_size); } else { + index = NULL; + index_size = 0; + nametab = NULL; + nametab_size = 0; + n_wrapped_sects = 0; + } + + /* If we have a long names section, fetch it. */ + + if ((gnu_sections_found & SOMO_LONGN_PRESENT) != 0) + { off_t strtab_offset; simple_object_mach_o_section_info (omr->is_big_endian, is_32, @@ -452,52 +595,120 @@ simple_object_mach_o_segment (simple_object_read *sobj, off_t offset, errmsg, err)) { XDELETEVEC (strtab); + XDELETEVEC (index); + XDELETEVEC (nametab); XDELETEVEC (secdata); return 0; } } + else + { + strtab = NULL; + strtab_size = 0; + strtab_index = nsects; + } /* Process the sections. */ for (i = 0; i < nsects; ++i) { const unsigned char *sechdr; - char namebuf[MACH_O_NAME_LEN + 1]; + char namebuf[MACH_O_NAME_LEN * 2 + 2]; char *name; off_t secoffset; size_t secsize; + int l; - if (i == strtab_index) + sechdr = secdata + i * sechdrsize; + + /* We've already processed the long section names. */ + + if ((gnu_sections_found & SOMO_LONGN_PRESENT) != 0 + && i == strtab_index) continue; - sechdr = secdata + i * sechdrsize; + /* We only act on the segment named. */ if (strcmp ((char *) sechdr + segname_offset, omr->segment_name) != 0) continue; - memcpy (namebuf, sechdr + sectname_offset, MACH_O_NAME_LEN); - namebuf[MACH_O_NAME_LEN] = '\0'; + /* Process sections associated with the wrapper. */ - name = &namebuf[0]; - if (strtab != NULL && name[0] == '_' && name[1] == '_') + if ((gnu_sections_found & SOMO_WRAPPING) != 0) { - unsigned long stringoffset; + if (i == nametab_index || i == index_index) + continue; - if (sscanf (name + 2, "%08lX", &stringoffset) == 1) + if (i == sections_index) { - if (stringoffset >= strtab_size) + unsigned int j; + for (j = 0; j < n_wrapped_sects; ++j) { - *errmsg = "section name offset out of range"; - *err = 0; - XDELETEVEC (strtab); - XDELETEVEC (secdata); - return 0; + unsigned int subsect_offset, subsect_length, name_offset; + subsect_offset = (*fetch_32) (index + 16 * j); + subsect_length = (*fetch_32) (index + 16 * j + 4); + name_offset = (*fetch_32) (index + 16 * j + 8); + /* We don't need the name_length yet. */ + + secoffset = wrapper_sect_offset + subsect_offset; + secsize = subsect_length; + name = nametab + name_offset; + + if (!(*pfn) (data, name, secoffset, secsize)) + { + *errmsg = NULL; + *err = 0; + XDELETEVEC (index); + XDELETEVEC (nametab); + XDELETEVEC (strtab); + XDELETEVEC (secdata); + return 0; + } } - - name = strtab + stringoffset; + continue; } } + if ((gnu_sections_found & SOMO_LONGN_PRESENT) != 0) + { + memcpy (namebuf, sechdr + sectname_offset, MACH_O_NAME_LEN); + namebuf[MACH_O_NAME_LEN] = '\0'; + + name = &namebuf[0]; + if (strtab != NULL && name[0] == '_' && name[1] == '_') + { + unsigned long stringoffset; + + if (sscanf (name + 2, "%08lX", &stringoffset) == 1) + { + if (stringoffset >= strtab_size) + { + *errmsg = "section name offset out of range"; + *err = 0; + XDELETEVEC (index); + XDELETEVEC (nametab); + XDELETEVEC (strtab); + XDELETEVEC (secdata); + return 0; + } + + name = strtab + stringoffset; + } + } + } + else + { + /* Otherwise, make a name like __segment,__section as per the + convention in mach-o asm. */ + name = &namebuf[0]; + memset (namebuf, 0, MACH_O_NAME_LEN * 2 + 2); + memcpy (namebuf, (char *) sechdr + segname_offset, MACH_O_NAME_LEN); + l = strlen (namebuf); + namebuf[l] = ','; + memcpy (namebuf + l + 1, (char *) sechdr + sectname_offset, + MACH_O_NAME_LEN); + } + simple_object_mach_o_section_info (omr->is_big_endian, is_32, sechdr, &secoffset, &secsize); @@ -505,12 +716,16 @@ simple_object_mach_o_segment (simple_object_read *sobj, off_t offset, { *errmsg = NULL; *err = 0; + XDELETEVEC (index); + XDELETEVEC (nametab); XDELETEVEC (strtab); XDELETEVEC (secdata); return 0; } } + XDELETEVEC (index); + XDELETEVEC (nametab); XDELETEVEC (strtab); XDELETEVEC (secdata); @@ -724,9 +939,9 @@ static int simple_object_mach_o_write_section_header (simple_object_write *sobj, int descriptor, size_t sechdr_offset, - const char *name, size_t secaddr, - size_t secsize, size_t offset, - unsigned int align, + const char *name, const char *segn, + size_t secaddr, size_t secsize, + size_t offset, unsigned int align, const char **errmsg, int *err) { struct simple_object_mach_o_attributes *attrs = @@ -748,7 +963,7 @@ simple_object_mach_o_write_section_header (simple_object_write *sobj, strncpy ((char *) hdr + offsetof (struct mach_o_section_32, sectname), name, MACH_O_NAME_LEN); strncpy ((char *) hdr + offsetof (struct mach_o_section_32, segname), - sobj->segment_name, MACH_O_NAME_LEN); + segn, MACH_O_NAME_LEN); set_32 (hdr + offsetof (struct mach_o_section_32, addr), secaddr); set_32 (hdr + offsetof (struct mach_o_section_32, size), secsize); set_32 (hdr + offsetof (struct mach_o_section_32, offset), offset); @@ -773,7 +988,7 @@ simple_object_mach_o_write_section_header (simple_object_write *sobj, strncpy ((char *) hdr + offsetof (struct mach_o_section_64, sectname), name, MACH_O_NAME_LEN); strncpy ((char *) hdr + offsetof (struct mach_o_section_64, segname), - sobj->segment_name, MACH_O_NAME_LEN); + segn, MACH_O_NAME_LEN); set_64 (hdr + offsetof (struct mach_o_section_64, addr), secaddr); set_64 (hdr + offsetof (struct mach_o_section_64, size), secsize); set_32 (hdr + offsetof (struct mach_o_section_64, offset), offset); @@ -793,11 +1008,25 @@ simple_object_mach_o_write_section_header (simple_object_write *sobj, sechdrsize, errmsg, err); } -/* Write out the single segment and the sections of a Mach-O file. */ +/* Write out the single (anonymous) segment containing the sections of a Mach-O + Object file. + + As a GNU extension to mach-o, when the caller specifies a segment name in + sobj->segment_name, all the sections passed will be output under a single + mach-o section header. The caller's sections are indexed within this + 'wrapper' section by a table stored in a second mach-o section. Finally, + arbitrary length section names are permitted by the extension and these are + stored in a table in a third mach-o section. + + Note that this is only likely to make any sense for the __GNU_LTO segment + at present. + + If the wrapper extension is not in force, we assume that the section name + is in the form __SEGMENT_NAME,__section_name as per Mach-O asm. */ static int simple_object_mach_o_write_segment (simple_object_write *sobj, int descriptor, - size_t nsects, const char **errmsg, + size_t *nsects, const char **errmsg, int *err) { struct simple_object_mach_o_attributes *attrs = @@ -814,6 +1043,10 @@ simple_object_mach_o_write_segment (simple_object_write *sobj, int descriptor, simple_object_write_section *section; unsigned char hdrbuf[sizeof (struct mach_o_segment_command_64)]; unsigned char *hdr; + size_t nsects_in; + unsigned int *index; + char *snames; + unsigned int sect; set_32 = (attrs->is_big_endian ? simple_object_set_big_32 @@ -834,19 +1067,62 @@ simple_object_mach_o_write_segment (simple_object_write *sobj, int descriptor, sechdrsize = sizeof (struct mach_o_section_64); } + name_offset = 0; + *nsects = nsects_in = 0; + + /* Count the number of sections we start with. */ + + for (section = sobj->sections; section != NULL; section = section->next) + nsects_in++; + + if (sobj->segment_name != NULL) + { + /* We will only write 3 sections: wrapped data, index and names. */ + + *nsects = 3; + + /* The index has four entries per wrapped section: + Section Offset, length, Name offset, length. + Where the offsets are based at the start of the wrapper and name + sections respectively. + The values are stored as 32 bit int for both 32 and 64 bit mach-o + since the size of a mach-o MH_OBJECT cannot exceed 4G owing to + other constraints. */ + + index = XNEWVEC (unsigned int, nsects_in * 4); + + /* We now need to figure out the size of the names section. This just + stores the names as null-terminated c strings, packed without any + alignment padding. */ + + for (section = sobj->sections, sect = 0; section != NULL; + section = section->next, sect++) + { + index[sect*4+2] = name_offset; + index[sect*4+3] = strlen (section->name) + 1; + name_offset += strlen (section->name) + 1; + } + snames = XNEWVEC (char, name_offset); + } + else + { + *nsects = nsects_in; + index = NULL; + snames = NULL; + } + sechdr_offset = hdrsize + seghdrsize; - cmdsize = seghdrsize + nsects * sechdrsize; + cmdsize = seghdrsize + *nsects * sechdrsize; offset = hdrsize + cmdsize; - name_offset = 0; secaddr = 0; - for (section = sobj->sections; section != NULL; section = section->next) + for (section = sobj->sections, sect = 0; + section != NULL; section = section->next, sect++) { size_t mask; size_t new_offset; size_t secsize; struct simple_object_write_section_buffer *buffer; - char namebuf[MACH_O_NAME_LEN + 1]; mask = (1U << section->align) - 1; new_offset = offset + mask; @@ -877,39 +1153,126 @@ simple_object_mach_o_write_segment (simple_object_write *sobj, int descriptor, secsize += buffer->size; } - snprintf (namebuf, sizeof namebuf, "__%08X", name_offset); + if (sobj->segment_name != NULL) + { + index[sect*4+0] = (unsigned int) offset; + index[sect*4+1] = secsize; + /* Stash the section name in our table. */ + memcpy (snames + index[sect * 4 + 2], section->name, + index[sect * 4 + 3]); + } + else + { + char namebuf[MACH_O_NAME_LEN + 1]; + char segnbuf[MACH_O_NAME_LEN + 1]; + char *comma; + + /* Try to extract segment,section from the input name. */ + + memset (namebuf, 0, sizeof namebuf); + memset (segnbuf, 0, sizeof segnbuf); + comma = strchr (section->name, ','); + if (comma != NULL) + { + int len = comma - section->name; + len = len > MACH_O_NAME_LEN ? MACH_O_NAME_LEN : len; + strncpy (namebuf, section->name, len); + strncpy (segnbuf, comma + 1, MACH_O_NAME_LEN); + } + else /* just try to copy the name, leave segment blank. */ + strncpy (namebuf, section->name, MACH_O_NAME_LEN); + + if (!simple_object_mach_o_write_section_header (sobj, descriptor, + sechdr_offset, + namebuf, segnbuf, + secaddr, secsize, + offset, + section->align, + errmsg, err)) + return 0; + sechdr_offset += sechdrsize; + } + + offset += secsize; + secaddr += secsize; + } + + if (sobj->segment_name != NULL) + { + size_t secsize; + unsigned int i; + + /* Write the section header for the wrapper. */ + /* Account for any initial aligment - which becomes the alignment for this + created section. */ + + secsize = (offset - index[0]); if (!simple_object_mach_o_write_section_header (sobj, descriptor, - sechdr_offset, namebuf, - secaddr, secsize, offset, - section->align, + sechdr_offset, + GNU_WRAPPER_SECTS, + sobj->segment_name, + 0 /*secaddr*/, + secsize, index[0], + sobj->sections->align, errmsg, err)) return 0; + /* Subtract the wrapper section start from the begining of each sub + section. */ + + for (i = 1; i < nsects_in; ++i) + index[4 * i] -= index[0]; + index[0] = 0; + sechdr_offset += sechdrsize; - offset += secsize; - name_offset += strlen (section->name) + 1; - secaddr += secsize; - } - /* Write out the section names. */ + /* Write out the section names. + ... the header ... + name_offset contains the length of the section. It is not aligned. */ - if (!simple_object_mach_o_write_section_header (sobj, descriptor, - sechdr_offset, - GNU_SECTION_NAMES, secaddr, - name_offset, offset, 0, - errmsg, err)) - return 0; + if (!simple_object_mach_o_write_section_header (sobj, descriptor, + sechdr_offset, + GNU_WRAPPER_NAMES, + sobj->segment_name, + 0 /*secaddr*/, + name_offset, + offset, + 0, errmsg, err)) + return 0; - for (section = sobj->sections; section != NULL; section = section->next) - { - size_t namelen; + /* ... and the content.. */ + if (!simple_object_internal_write (descriptor, offset, + (const unsigned char *) snames, + name_offset, errmsg, err)) + return 0; + + sechdr_offset += sechdrsize; + secaddr += name_offset; + offset += name_offset; + + /* Now do the index, we'll align this to 4 bytes although the read code + will handle unaligned. */ + + offset += 3; + offset &= ~0x03; + if (!simple_object_mach_o_write_section_header (sobj, descriptor, + sechdr_offset, + GNU_WRAPPER_INDEX, + sobj->segment_name, + 0 /*secaddr*/, + nsects_in * 16, + offset, + 2, errmsg, err)) + return 0; - namelen = strlen (section->name) + 1; + /* ... and the content.. */ if (!simple_object_internal_write (descriptor, offset, - (const unsigned char *) section->name, - namelen, errmsg, err)) + (const unsigned char *) index, + nsects_in*16, errmsg, err)) return 0; - offset += namelen; + + XDELETEVEC (index); + XDELETEVEC (snames); } /* Write out the segment header. */ @@ -923,9 +1286,8 @@ simple_object_mach_o_write_segment (simple_object_write *sobj, int descriptor, MACH_O_LC_SEGMENT); set_32 (hdr + offsetof (struct mach_o_segment_command_32, cmdsize), cmdsize); - strncpy (((char *) hdr - + offsetof (struct mach_o_segment_command_32, segname)), - sobj->segment_name, MACH_O_NAME_LEN); + /* MH_OBJECTS have a single, anonymous, segment - so the segment name + is left empty. */ /* vmaddr left as zero. */ /* vmsize left as zero. */ set_32 (hdr + offsetof (struct mach_o_segment_command_32, fileoff), @@ -935,7 +1297,7 @@ simple_object_mach_o_write_segment (simple_object_write *sobj, int descriptor, /* maxprot left as zero. */ /* initprot left as zero. */ set_32 (hdr + offsetof (struct mach_o_segment_command_32, nsects), - nsects); + *nsects); /* flags left as zero. */ } else @@ -951,9 +1313,8 @@ simple_object_mach_o_write_segment (simple_object_write *sobj, int descriptor, MACH_O_LC_SEGMENT); set_32 (hdr + offsetof (struct mach_o_segment_command_64, cmdsize), cmdsize); - strncpy (((char *) hdr - + offsetof (struct mach_o_segment_command_64, segname)), - sobj->segment_name, MACH_O_NAME_LEN); + /* MH_OBJECTS have a single, anonymous, segment - so the segment name + is left empty. */ /* vmaddr left as zero. */ /* vmsize left as zero. */ set_64 (hdr + offsetof (struct mach_o_segment_command_64, fileoff), @@ -963,7 +1324,7 @@ simple_object_mach_o_write_segment (simple_object_write *sobj, int descriptor, /* maxprot left as zero. */ /* initprot left as zero. */ set_32 (hdr + offsetof (struct mach_o_segment_command_64, nsects), - nsects); + *nsects); /* flags left as zero. */ #endif } @@ -978,23 +1339,17 @@ static const char * simple_object_mach_o_write_to_file (simple_object_write *sobj, int descriptor, int *err) { - size_t nsects; - simple_object_write_section *section; + size_t nsects = 0; const char *errmsg; - /* Start at 1 for symbol_names section. */ - nsects = 1; - for (section = sobj->sections; section != NULL; section = section->next) - ++nsects; + if (!simple_object_mach_o_write_segment (sobj, descriptor, &nsects, + &errmsg, err)) + return errmsg; if (!simple_object_mach_o_write_header (sobj, descriptor, nsects, &errmsg, err)) return errmsg; - if (!simple_object_mach_o_write_segment (sobj, descriptor, nsects, - &errmsg, err)) - return errmsg; - return NULL; } diff --git a/libiberty/spaces.c b/libiberty/spaces.c index 67481c9bcd..69d7a2d3f8 100644 --- a/libiberty/spaces.c +++ b/libiberty/spaces.c @@ -53,10 +53,7 @@ spaces (int count) if (count > maxsize) { - if (buf) - { - free (buf); - } + free (buf); buf = (char *) malloc (count + 1); if (buf == (char *) 0) return 0; diff --git a/libiberty/stack-limit.c b/libiberty/stack-limit.c new file mode 100644 index 0000000000..e64cac28d1 --- /dev/null +++ b/libiberty/stack-limit.c @@ -0,0 +1,62 @@ +/* Increase stack size limit if possible. + Copyright (C) 2011 Free Software Foundation, Inc. + +This file is part of the libiberty library. This library 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, or (at your option) +any later version. + +This library 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 GNU CC; see the file COPYING. If not, write to +the Free Software Foundation, 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. + +As a special exception, if you link this library with files +compiled with a GNU compiler to produce an executable, this does not cause +the resulting executable to be covered by the GNU General Public License. +This exception does not however invalidate any other reasons why +the executable file might be covered by the GNU General Public License. */ + +/* + +@deftypefn Extension void stack_limit_increase (unsigned long @var{pref}) + +Attempt to increase stack size limit to @var{pref} bytes if possible. + +@end deftypefn + +*/ + +#include "config.h" + +#ifdef HAVE_STDINT_H +#include <stdint.h> +#endif +#ifdef HAVE_SYS_RESOURCE_H +#include <sys/resource.h> +#endif + +void +stack_limit_increase (unsigned long pref) +{ +#if defined(HAVE_SETRLIMIT) && defined(HAVE_GETRLIMIT) \ + && defined(RLIMIT_STACK) && defined(RLIM_INFINITY) + struct rlimit rlim; + if (getrlimit (RLIMIT_STACK, &rlim) == 0 + && rlim.rlim_cur != RLIM_INFINITY + && rlim.rlim_cur < pref + && (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_cur < rlim.rlim_max)) + { + rlim.rlim_cur = pref; + if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_cur > rlim.rlim_max) + rlim.rlim_cur = rlim.rlim_max; + setrlimit (RLIMIT_STACK, &rlim); + } +#endif +} diff --git a/libiberty/testsuite/demangle-expected b/libiberty/testsuite/demangle-expected index 74dbe8fdab..d489692f0b 100644 --- a/libiberty/testsuite/demangle-expected +++ b/libiberty/testsuite/demangle-expected @@ -3901,10 +3901,18 @@ java resource java/util/iso4217.properties --format=gnu-v3 _Z3addIidEDTplfp_fp0_ET_T0_ decltype ({parm#1}+{parm#2}) add<int, double>(int, double) +# decltype scope test +--format=gnu-v3 +_Z1fI1SENDtfp_E4typeET_ +decltype ({parm#1})::type f<S>(S) # decltype/fn call test --format=gnu-v3 _Z4add3IidEDTclL_Z1gEfp_fp0_EET_T0_ decltype (g({parm#1}, {parm#2})) add3<int, double>(int, double) +# 'this' test +--format=gnu-v3 +_ZN1A1fIiEEDTcldtdtdefpT1b1fIT_EEEv +decltype ((((*this).b).(f<int>))()) A::f<int>() # new (2008) built in types test --format=gnu-v3 _Z1fDfDdDeDhDsDi @@ -3920,10 +3928,14 @@ decltype (({parm#1}.(g<double>))()) h<A<int>, double>(A<int>, double) # test for typed function in decltype --format=gnu-v3 _ZN1AIiE1jIiEEDTplfp_clL_Z1xvEEET_ -decltype ({parm#1}+((x())())) A<int>::j<int>(int) +decltype ({parm#1}+(x())) A<int>::j<int>(int) +# typed function in decltype with an argument list +--format=gnu-v3 +_Z1tIlEDTplcvT_Li5EclL_Z1qsELi6EEEv +decltype (((long)(5))+(q(6))) t<long>() # test for expansion of function parameter pack --format=gnu-v3 -_Z1gIIidEEDTclL_Z1fEspplfp_Li1EEEDpT_ +_Z1gIJidEEDTclL_Z1fEspplfp_Li1EEEDpT_ decltype (f(({parm#1}+(1))...)) g<int, double>(int, double) # lambda tests --format=gnu-v3 @@ -3957,8 +3969,118 @@ decltype (({parm#1}.(operator-))()) h<A>(A) _Z1fDn f(decltype(nullptr)) --format=gnu-v3 +_Z1fIRiEvOT_b +void f<int&>(int&, bool) +--format=gnu-v3 _ZN5aaaaa6bbbbbb5cccccIN23ddddddddddddddddddddddd3eeeENS2_4ffff16ggggggggggggggggENS0_9hhhhhhhhhES6_S6_S6_S6_S6_S6_S6_EE aaaaa::bbbbbb::ccccc<ddddddddddddddddddddddd::eee, ddddddddddddddddddddddd::ffff::gggggggggggggggg, aaaaa::bbbbbb::hhhhhhhhh, aaaaa::bbbbbb::hhhhhhhhh, aaaaa::bbbbbb::hhhhhhhhh, aaaaa::bbbbbb::hhhhhhhhh, aaaaa::bbbbbb::hhhhhhhhh, aaaaa::bbbbbb::hhhhhhhhh, aaaaa::bbbbbb::hhhhhhhhh, aaaaa::bbbbbb::hhhhhhhhh> +--format=gnu-v3 +_Z5outerIsEcPFilE +char outer<short>(int (*)(long)) +--format=gnu-v3 +_Z5outerPFsiEl +outer(short (*)(int), long) +--format=gnu-v3 +_Z6outer2IsEPFilES1_ +int (*outer2<short>(int (*)(long)))(long) +--format=gnu-v3 --ret-postfix +_Z5outerIsEcPFilE +outer<short>(int (*)(long))char +--format=gnu-v3 --ret-postfix +_Z5outerPFsiEl +outer(short (*)(int), long) +--format=gnu-v3 --ret-postfix +_Z6outer2IsEPFilES1_ +outer2<short>(int (*)(long))int (*)(long) +--format=gnu-v3 --ret-drop +_Z5outerIsEcPFilE +outer<short>(int (*)(long)) +--format=gnu-v3 --ret-drop +_Z5outerPFsiEl +outer(short (*)(int), long) +--format=gnu-v3 --ret-drop +_Z6outer2IsEPFilES1_ +outer2<short>(int (*)(long)) +# +--format=gnu-v3 --no-params +_ZN1KIXadL_ZN1S1mEiEEE1fEv +K<&S::m>::f() +K<&S::m>::f +--format=gnu-v3 +_ZN1KILi1EXadL_ZN1S1mEiEEE1fEv +K<1, &S::m>::f() +# Here the `(int)' argument list of `S::m' is already removed. +--format=gnu-v3 +_ZN1KILi1EXadL_ZN1S1mEEEE1fEv +K<1, &S::m>::f() +# +# Used to crash -- binutils PR 13030. +--format=gnu-v3 +_ZSt10_ConstructI10CellBorderIS0_EEvPT_DpOT0_ +_ZSt10_ConstructI10CellBorderIS0_EEvPT_DpOT0_ +# A pack expansion is substitutable. +--format=gnu-v3 +_Z1fIJiEiEv1AIJDpT_EET0_S4_ +void f<int, int>(A<int>, int, int) +# So is decltype. +--format=gnu-v3 +_Z1fIiiEDTcvT__EET0_S2_ +decltype ((int)()) f<int, int>(int, int) +# And vector. +--format=gnu-v3 +_Z1fDv4_iS_ +f(int __vector(4), int __vector(4)) +--format=gnu-v3 +_Z2f1Ii1AEDTdsfp_fp0_ET0_MS2_T_ +decltype ({parm#1}.*{parm#2}) f1<int, A>(A, int A::*) +--format=gnu-v3 +_Z2f2IiEDTquL_Z1bEfp_trET_ +decltype (b?{parm#1} : (throw)) f2<int>(int) +--format=gnu-v3 +_Z6check1IiEvP6helperIXsznw_T_EEE +void check1<int>(helper<sizeof (new int)>*) +--format=gnu-v3 +_Z6check2IiEvP6helperIXszgsnw_T_piEEE +void check2<int>(helper<sizeof (::new int())>*) +--format=gnu-v3 +_Z6check3IiEvP6helperIXsznwadL_Z1iE_T_piLi1EEEE +void check3<int>(helper<sizeof (new (&i) int(1))>*) +--format=gnu-v3 +_Z6check4IiEvP6helperIXszna_A1_T_EEE +void check4<int>(helper<sizeof (new int [1])>*) +--format=gnu-v3 +_Z6check5IiEvP6helperIXszna_A1_T_piEEE +void check5<int>(helper<sizeof (new int [1]())>*) +--format=gnu-v3 +_Z1fIiEDTcmgsdlfp_psfp_EPT_ +decltype ((::delete {parm#1}),(+{parm#1})) f<int>(int*) +--format=gnu-v3 +_Z1fIiEDTcmdafp_psfp_EPT_ +decltype ((delete[] {parm#1}),(+{parm#1})) f<int>(int*) +--format=gnu-v3 +_ZN1AdlEPv +A::operator delete(void*) +--format=gnu-v3 +_Z2f1IiEDTppfp_ET_ +decltype ({parm#1}++) f1<int>(int) +--format=gnu-v3 +_Z2f1IiEDTpp_fp_ET_ +decltype (++{parm#1}) f1<int>(int) +--format=gnu-v3 +_Z2f1IiEDTcl1gfp_ilEEET_ +decltype (g({parm#1}, {})) f1<int>(int) +--format=gnu-v3 +_Z2f1IiEDTnw_T_ilEES0_ +decltype (new int{}) f1<int>(int) +--format=gnu-v3 +_Zli2_wPKc +operator"" _w(char const*) +--format=gnu-v3 +_Z1fIiEDTnw_Dapifp_EET_ +decltype (new auto({parm#1})) f<int>(int) +--format=gnu-v3 +_Z1fIiERDaRKT_S1_ +auto& f<int>(int const&, int) # # Ada (GNAT) tests. # @@ -4091,7 +4213,7 @@ DFA # http://sourceware.org/bugzilla/show_bug.cgi?id=11572 --format=auto _ZN3Psi7VariantIIcPKcEE5visitIIRZN11VariantTest9TestVisit11test_methodEvEUlS2_E0_RZNS6_11test_methodEvEUlcE1_RZNS6_11test_methodEvEUlNS_4NoneEE_EEENS_13VariantDetail19SelectVisitorResultIIDpT_EE4typeEDpOSG_ -Psi::VariantDetail::SelectVisitorResult<VariantTest::TestVisit::test_method()::{lambda(char const*)#2}&, VariantTest::TestVisit::test_method()::{lambda(char)#3}&, VariantTest::TestVisit::test_method()::{lambda(Psi::None)#1}&>::type Psi::Variant<char, char const*>::visit<VariantTest::TestVisit::test_method()::{lambda(char const*)#2}&, VariantTest::TestVisit::test_method()::{lambda(char)#3}&, VariantTest::TestVisit::test_method()::{lambda(Psi::None)#1}&>((VariantTest::TestVisit::test_method()::{lambda(Psi::None)#1}&&&)...) +Psi::VariantDetail::SelectVisitorResult<VariantTest::TestVisit::test_method()::{lambda(char const*)#2}&, VariantTest::TestVisit::test_method()::{lambda(char)#3}&, VariantTest::TestVisit::test_method()::{lambda(Psi::None)#1}&>::type Psi::Variant<char, char const*>::visit<VariantTest::TestVisit::test_method()::{lambda(char const*)#2}&, VariantTest::TestVisit::test_method()::{lambda(char)#3}&, VariantTest::TestVisit::test_method()::{lambda(Psi::None)#1}&>((VariantTest::TestVisit::test_method()::{lambda(Psi::None)#1}&)...) # # Clone suffix tests # @@ -4139,3 +4261,8 @@ f1<int> _Z3fooi._omp_cpyfn.6 foo(int) [clone ._omp_cpyfn.6] foo +# +--format=gnu-v3 --no-params +_Z1fIKFvvES0_Evv +void f<void () const, void ()>() +f<void () const, void ()> diff --git a/libiberty/testsuite/test-demangle.c b/libiberty/testsuite/test-demangle.c index 1c982d6ef2..11d9729999 100644 --- a/libiberty/testsuite/test-demangle.c +++ b/libiberty/testsuite/test-demangle.c @@ -159,6 +159,7 @@ exp: %s\n", output is an integer representing ctor_kind. --is-v3-dtor Likewise, but for dtors. --ret-postfix Passes the DMGL_RET_POSTFIX option + --ret-drop Passes the DMGL_RET_DROP option For compatibility, just in case it matters, the options line may be empty, to mean --format=auto. If it doesn't start with --, then it @@ -174,7 +175,7 @@ main(argc, argv) int no_params; int is_v3_ctor; int is_v3_dtor; - int ret_postfix; + int ret_postfix, ret_drop; struct line format; struct line input; struct line expect; @@ -209,6 +210,7 @@ main(argc, argv) no_params = 0; ret_postfix = 0; + ret_drop = 0; is_v3_ctor = 0; is_v3_dtor = 0; if (format.data[0] == '\0') @@ -265,6 +267,8 @@ main(argc, argv) is_v3_dtor = 1; else if (strcmp (opt, "--ret-postfix") == 0) ret_postfix = 1; + else if (strcmp (opt, "--ret-drop") == 0) + ret_drop = 1; else { printf ("FAIL at line %d: unrecognized option %s\n", @@ -307,9 +311,9 @@ main(argc, argv) cplus_demangle_set_style (style); - result = cplus_demangle (inp, - DMGL_PARAMS|DMGL_ANSI|DMGL_TYPES - |(ret_postfix ? DMGL_RET_POSTFIX : 0)); + result = cplus_demangle (inp, (DMGL_PARAMS | DMGL_ANSI | DMGL_TYPES + | (ret_postfix ? DMGL_RET_POSTFIX : 0) + | (ret_drop ? DMGL_RET_DROP : 0))); if (result ? strcmp (result, expect.data) diff --git a/libiberty/testsuite/test-expandargv.c b/libiberty/testsuite/test-expandargv.c index dc44a1750e..dff20d41da 100644 --- a/libiberty/testsuite/test-expandargv.c +++ b/libiberty/testsuite/test-expandargv.c @@ -204,7 +204,7 @@ writeout_test (int test, const char * test_data) if (parse == NULL) fatal_error (__LINE__, "Failed to malloc parse.", errno); - memcpy (parse, test_data, sizeof (char) * len); + memcpy (parse, test_data, sizeof (char) * (len + 1)); /* Run all possible replaces */ run_replaces (parse); diff --git a/libiberty/timeval-utils.c b/libiberty/timeval-utils.c new file mode 100644 index 0000000000..4c9f6a85ee --- /dev/null +++ b/libiberty/timeval-utils.c @@ -0,0 +1,87 @@ +/* Basic struct timeval utilities. + Copyright (C) 2011 Free Software Foundation, Inc. + +This file is part of the libiberty library. +Libiberty is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public +License as published by the Free Software Foundation; either +version 2 of the License, or (at your option) any later version. + +Libiberty 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 +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with libiberty; see the file COPYING.LIB. If not, +write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, +Boston, MA 02110-1301, USA. */ + +#include "config.h" + +/* On some systems (such as WindISS), you must include <sys/types.h> + to get the definition of "time_t" before you include <time.h>. */ +#include <sys/types.h> + +#ifdef TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# else +# ifdef HAVE_TIME_H +# include <time.h> +# endif +# endif +#endif + +#include "timeval-utils.h" + +/* + +@deftypefn Extension void timeval_add (struct timeval *@var{a}, @ + struct timeval *@var{b}, struct timeval *@var{result}) + +Adds @var{a} to @var{b} and stores the result in @var{result}. + +@end deftypefn + +*/ + +void +timeval_add (struct timeval *result, + const struct timeval *a, const struct timeval *b) +{ + result->tv_sec = a->tv_sec + b->tv_sec; + result->tv_usec = a->tv_usec + b->tv_usec; + if (result->tv_usec >= 1000000) + { + ++result->tv_sec; + result->tv_usec -= 1000000; + } +} + +/* + +@deftypefn Extension void timeval_sub (struct timeval *@var{a}, @ + struct timeval *@var{b}, struct timeval *@var{result}) + +Subtracts @var{b} from @var{a} and stores the result in @var{result}. + +@end deftypefn + +*/ + +void +timeval_sub (struct timeval *result, + const struct timeval *a, const struct timeval *b) +{ + result->tv_sec = a->tv_sec - b->tv_sec; + result->tv_usec = a->tv_usec - b->tv_usec; + if (result->tv_usec < 0) + { + --result->tv_sec; + result->tv_usec += 1000000; + } +} |