diff options
author | obrien <obrien@FreeBSD.org> | 2001-05-28 05:21:37 +0000 |
---|---|---|
committer | obrien <obrien@FreeBSD.org> | 2001-05-28 05:21:37 +0000 |
commit | 328e45595b12375b6d16a846069507d25086abdb (patch) | |
tree | ae2a6f4f4987889b7bd2af7bdf0b86fa580df011 /contrib/binutils/libiberty | |
parent | 7fbb72605a1c3bcb81f8b6bb6297ffef30f84335 (diff) | |
download | FreeBSD-src-328e45595b12375b6d16a846069507d25086abdb.zip FreeBSD-src-328e45595b12375b6d16a846069507d25086abdb.tar.gz |
Import of GNU Binutils version 2.11.0.
Believe it or not, this is heavily stripped down.
Diffstat (limited to 'contrib/binutils/libiberty')
47 files changed, 4293 insertions, 1086 deletions
diff --git a/contrib/binutils/libiberty/ChangeLog b/contrib/binutils/libiberty/ChangeLog index dbd616b..dc1ef09 100644 --- a/contrib/binutils/libiberty/ChangeLog +++ b/contrib/binutils/libiberty/ChangeLog @@ -1,16 +1,740 @@ -2000-10-17 Philip Blundell <pb@futuretv.com> - - * cp-demangle.c, dyn-string.c, cplus-dem.c: Update from trunk - version. - * testsuite/demangle-expected, testsuite/regress-demangle: - Likewise. +2000-12-29 DJ Delorie <dj@redhat.com> + + * fnmatch.c: Make the note about the origins of this file more + accurate, at least until we can sync with glibc. + * getopt.c: Ditto. + * getopt1.c: Ditto. + * md5.c: Ditto. + * obstack.c: Ditto. - From 2000-06-04 Alex Samuel <samuel@codesourcery.com> +2000-12-26 Michael Sokolov <msokolov@ivan.Harhan.ORG> + + * bsearch.c: New file. + * configure.in (funcs): Add bsearch. + (AC_CHECK_FUNCS): Likewise. + * configure, config.in: Regenerate. + +2000-12-13 Michael Sokolov <msokolov@ivan.Harhan.ORG> + + * safe-ctype.c: #include "ansidecl.h". + * strtod.c: Likewise. + +2000-12-13 Michael Sokolov <msokolov@ivan.Harhan.ORG> + + * strtoul.c: Include safe-ctype.h, not ctype.h. + +2000-12-07 Zack Weinberg <zack@wolery.stanford.edu> + + * safe-ctype.c: New file. + * Makefile.in (CFILES): Add safe-ctype.c. + (REQUIRED_OFILES): Add safe-ctype.o. + + * argv.c: Define ISBLANK and use it, not isspace. + * basename.c, cplus-dem.c, fnmatch.c, pexecute.c, strtod.c, + strtol.c, strtoul.c: Include safe-ctype.h, not ctype.h. Use + uppercase ctype macros. Don't test ISUPPER(c)/ISLOWER(c) + before calling TOLOWER(c)/TOUPPER(c). + +2000-12-07 Mike Stump <mrs@wrs.com> + + * Makefile.in (distclean): When cleaning, remove testsuite. + +2000-12-05 Jason Merrill <jason@redhat.com> + + * cp-demangle.c (cplus_demangle_v3): Check that it's a v3 mangled + name before allocating the dyn_string. + +2000-12-04 Jason Merrill <jason@redhat.com> + + * cp-demangle.c: s/new_abi/v3/. + * cplus-dem.c: Likewise. + (current_demangling_style): Now auto_demangling. + (cplus_demangle): Try v3 demangling if AUTO_DEMANGLING. + (main): Use standard symbol chars for auto_demangling. + +2000-11-26 Mark Mitchell <mark@codesourcery.com> + + * hashtab.c (higher_prime_number): Use a table, rather than a + seive, to find the next prime. + +2000-11-22 H.J. Lu <hjl@gnu.org> + + * cplus-dem.c (main): Handle gnat_demangling. + +2000-11-22 Zack Weinberg <zack@wolery.stanford.edu> + + * aclocal.m4 (LIB_AC_PROG_CC): Moved here from configure.in. + (AC_DEFINE_NOAUTOHEADER): New - work around bug in autoheader. + * configure.in: Call AC_C_INLINE and AC_C_CONST. Use three + argument form of AC_DEFINE in dummy definitions block. Use + AC_DEFINE_NOAUTOHEADER for real definitions of things defined + in dummy block. Preload cache variables instead of bypassing + tests, where possible. + * acconfig.h: Removed. + + * xmalloc.c (xmalloc_failed): New function, does error + reporting on failed allocation. + (xmalloc, xcalloc, xrealloc): Use it. + +2000-11-21 Hans-Peter Nilsson <hp@bitrange.com> + + * cplus-dem.c (cplus_demangle): Fix formatting. + (grow_vect): Ditto. + (ada_demangle): Ditto. + (internal_cplus_demangle): Ditto. + (mop_up): Ditto. + +2000-11-21 H.J. Lu <hjl@gnu.org> + + * cplus-dem.c (main): Handle java_demangling. + +2000-11-19 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * cplus-dem.c (grow_vect): Prototype. + (ada_demangle): Cast the arg of ctype macros to unsigned char. + +2000-11-15 Hans-Peter Nilsson <hp@bitrange.com> + + * cplus-dem.c (ada_demangle): Add back ATTRIBUTE_UNUSED for + parameter `option'. + +2000-11-15 Kenneth Block <kenneth.block@compaq.com> + + * cplus-dem.c: Eliminate use of DEFUN, it is obsolete and cannot + be used in GCC. + +2000-11-15 Kenneth Block <kenneth.block@compaq.com> + + * cplus-dem.c: Add gnat demangler. Add java to demangle style + list. + +2000-11-04 Hans-Peter Nilsson <hp@bitrange.com> + + * hashtab.c (htab_expand): Change to return int. Use calloc or + xcalloc depending on htab->return_allocation_failure. Return zero + if calloc fails. + (htab_create): Update comment to cover memory allocation. + (htab_try_create): New. + (htab_find_slot_with_hash): Return NULL if htab_expand fails. + Update comment to cover this. + +2000-11-03 Hans-Peter Nilsson <hp@bitrange.com> + + * hashtab.c: Change void * to PTR where necessary. + (htab_create, htab_expand): Correct formatting of comment before + function. + +2000-10-22 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (string_list_def): Add caret_position and comments. + (result_caret_pos): New macro. + (result_append_string): Rename to... + (result_add_string): ... this, and insert at caret position. + Rename throughout. + (result_append): Rename to... + (result_add): ... this, and insert at caret position. Rename + throughout. + (result_append_char): Rename to... + (result_add_char): ... this, and insert at caret position. Rename + throughout. + (result_append_space): Remove. + (string_list_new): Initialize caret position. + (result_add_separated_char): Use caret position. + (result_get_caret): New funtion. + (result_set_caret): Likewise. + (result_shift_caret): Likewise. + (result_previous_char_is_space): Likewise. + (substitution_start): Use caret position. + (substitution_add): Likewise. + (demangling_new): Initialize caret position. + (demangle_encoding): Use caret position. + (demanglin_nested_name): Put CV qualifiers after name. + (demangle_type_ptr): Use switch statement. Handle pointers to + arrays. Don't use result_append_space. Use caret position. + (demangle_type): Emit CV qualifiers after underlying type. Adjust + call to demangle_array_type. + (demangle_array_type): Add parameter to handle pointers to arrays. + +2000-10-01 Mark Mitchell <mark@codesourcery.com> + + * splay-tree.c (splay_tree_insert): Fix formatting. + +2000-09-16 Mark Mitchell <mark@codesourcery.com> + + * splay-tree.c (splay_tree_predecessor): Fix typo in comment. + +2000-09-14 Michael Sokolov <msokolov@ivan.Harhan.ORG> + + * splay-tree.c: #include <stdio.h>. + +2000-09-14 Hans-Peter Nilsson <hp@axis.com> + + * testsuite/demangle-expected: Add two tests for anonymous + namespaces. + * cplus-dem.c (gnu_special): Handle anonymous namespaces. + +2000-09-10 Mark Mitchell <mark@codesourcery.com> + + * splay-tree.c (splay_tree_predecessor): New function. + (splay_tree_successor): Likewise. + +2000-09-10 Hans-Peter Nilsson <hp@axis.com> + + * testsuite/demangle-expected: Add four tests for type_info + mangling. + * cplus-dem.c (gnu_special): Use do_type, not demangle_fund_type, + for a non-template non-qualified type_info function or node. + +2000-09-08 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c: Fix copyright banner. + +2000-09-07 Michael Sokolov <msokolov@ivan.Harhan.ORG> + + * md5.c: #include "ansidecl.h". + +2000-09-06 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (status_allocation_failed): Rearrange whitespace. + (demangle_type): Handle substitution candidates correctly in the + face of special substitutions. + +2000-09-05 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_encoding): Rename variable. + (demangle_name): Rename parameter. Handle return type + suppression. + (demangle_nested_name): Rename parameter. + (demangle_prefix): Likewise. Change return type suppression. + (demangle_unqualified_name): Add parameter. Flag constructors and + conversion operators. + (demangle_special_name): Fix comment. + (demangle_type): Rename variable. + (demangle_bare_function_type): Check for missing return type and + parameter. + (demangle_class_enum_type): Rename parameter. + (demangle_discriminator): Fix misspelling in comment. + +2000-08-31 DJ Delorie <dj@redhat.com> + + * configure.in (Cygwin): special case cygwin only when we're + building cygwin, not when we're hosting cygwin. + +2000-09-04 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_template_arg): Eat an `E' after an + <expression>. + +2000-09-04 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_type_ptr): Increment position past + pointer and reference characters. + +2000-09-04 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_nv_offset): New function. + (demangle_v_offset): Likewise. + (demangle_call_offset): Likewise. + (demangle_special_name): Update thunk demangling to comply with + ABI changes. + +2000-09-03 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (ANONYMOUS_NAMESPACE_PREFIX): New macro. + (substitution_def): Remove template_parm_number. + (NOT_TEMPLATE_PARM): Remove. + (result_insert_string): New macro. + (result_insert): Likewise. + (result_insert_char): Likewise. + (substitution_add): Remove last parameter. Don't store template + parm number. + (BFT_NO_RETURN_TYPE): Define as NULL. + (demangle_encoding): Adjust call to demangle_bare_function_type. + (demangle_name): Adjust substitution. Adjust call to + substitution_add. + (demangle_prefix): Adjust call to substitution_add. + (demangle_identifier): Handle anonymous namespaces. + (demangle_operator_name): Change demangling of vendor-extended + operator to match ABI changes. + (demangle_type_ptr): Change parameters. Make recursive. Handle + substitutions here. + (demangle_type): Adjust calls to demangle_template_param, + substitution_add, and demangle_type_ptr. Fix substitution of + templated types. + (demangle_function_type): Change parameter to a pointer. + (demangle_bare_function_type): Likewise. Adjust insertion point. + (demangle_template_param): Remove last parameter. + (demangle_expr_primary): Remove unused variable. Adjust call to + demangle_template_param. + (is_mangled_char): Accept `$' and `.'. + * cplus-dem.c (gnu_new_abi_symbol_characters): Add '$' and '.'. + * dyn-string.c (dyn_string_insert_char): New function. + +2000-08-31 Hans-Peter Nilsson <hp@axis.com> + + * testsuite/demangle-expected: Add nine tests for + underscore-after-number followed by five tests for name-signature + delimiter. + +2000-08-28 Richard Henderson <rth@cygnus.com> + + * Makefile.in (md5.o): Depend on config.h. + +2000-08-28 Jason Merrill <jason@redhat.com> + + * Makefile.in (REQUIRED_OFILES): Add md5.o. + (CFILES): Add md5.c. + * md5.c: New file. + +2000-08-27 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_name): Initialize template_p in local + name case. Don't re-add substitutions as candidates. + (demangle_nested_name): Use <unqualified-name>. + (demangle_prefix): Likewise. Don't add template names as + substitution candidates twice, or re-add a substitution or the + last prefix component. + (demangle_local_name): Adjust output format. + +2000-08-25 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (result_add_separated_char): Change parameter to + int. + (substitution_add): Don't check for duplicates. Check if + previously allocated size is zero. + (demangle_name): Remove duplicate check for std substitution. + Clear template flag appropriately. + (demangle_prefix): Remove argument to demangle_substitution. + Don't check that template flag is already set. + (demangle_operator_name): Add pt operator. + (demangle_type): Don't treat r as built-in type. Remove argument + to demangle_substitution. Fix substitution candidate mechanics. + Handle <template-template-parm>s. Improve comments. + (demangle_template_param): Don't handle template arg lists here. + (demangle_substitution): Remove parameter. + (print_usage): Remove extra fprintf option. + +2000-08-24 Greg McGary <greg@mcgary.org> + + * libiberty/random.c (end_ptr): Revert previous change. + +2000-08-24 Greg McGary <greg@mcgary.org> + + * libiberty/cplus-dem.c (cplus_demangle_opname, cplus_mangle_opname, + demangle_expression, demangle_function_name): Use ARRAY_SIZE. + * libiberty/random.c (end_ptr): Likewise. + +2000-08-23 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (result_close_template_list): Remove function. + (result_add_separated_char): New function. + (result_open_template_list): New macro. + (result_close_template_list): Likewise. + (demangle_prefix): Don't set template_p if the + prefix ends with a ctor name. + (demangle_type_ptr): Remove duplicate RETURN_IF_ERROR. + (demangle_type): Check for template args after substitution. + (demangle_template_args): Use result_open_template_list. + +2000-08-02 Zack Weinberg <zack@wolery.cumb.org> + + * pexecute.c: Don't use vfork. Initialize 'pid' before retry loop. + +2000-07-26 Dave Pitts <dpitts@cozx.com> + + * config/mh-openedition.h: Added -DLE370 definition. + +2000-07-26 Mark Elbrecht <snowball3@bigfoot.com> + + * pexecute.c (pexecute) [__MSDOS__]: Change __GO32__ to + __DJGPP__. Use P_WAIT instead of constant in the spawnv* call. + Cast program to 'char *' in errmsg_arg assignment. + (PWAIT_ERROR): Define. + (pwait): Use PWAIT_ERROR. Adjust DJGPP's status code to conform + to DJGPP's WIF* macros. + +2000-07-27 RodneyBrown <RodneyBrown@pmsc.com> + Jeff Law <law@cygnus.com> + + * getcwd.c: Include string.h, stdlib.h for prototypes + + * Makefile.in (rename.o, waitpid.o): Depend on config.h + * rename.c: Include config.h, unistd.h + * waitpid.c: Include config.h, sys/wait.h + +2000-07-24 Hans-Peter Nilsson <hp@axis.com> + + * cplus-dem.c (work_stuff_copy_to_from): New. + (delete_non_B_K_work_stuff): New. + (delete_work_stuff): New. + (mop_up): Break out work_stuff partly destruction to + delete_non_B_K_work_stuff. + (iterate_demangle_function): New. + (demangle_prefix): Call iterate_demangle_function instead of + demangle_function_name. Leave handling of name-signature + __-delimiters to iterate_demangle_function. + (demangle_integral_value): Strip an optional + following underscore cautiously. Handle negative numbers. + +2000-07-24 Daniel Berlin <dberlin@redhat.com> + + * cplus-dem.c (demangle_signature): Change if (GNU_DEMANGLING) to + if (AUTO_DEMANGLING || GNU_DEMANGLING) + +2000-07-21 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_ctor_dtor_name): Remove not-in-charge + allocating ctor mangling. + (demangle_array_type): Handle empty and non-constant array length. + +2000-07-23 Michael Sokolov <msokolov@ivan.Harhan.ORG> + Jeff Law <law@cygnus.com> + + * configure.in (AC_CHECK_HEADERS): Add time.h. + (AC_HEADER_TIME): Add check. + * configure, config.in: Regenerate. + * getruntime.c: Portably #include <sys/time.h> and/or <time.h>. + + * configure.in (AC_CHECK_HEADERS): Add limits.h. + * configure, config.in: Regenerate. + * sort.c: Portably #include <limits.h> and/or <sys/param.h>. + * strtol.c, strtoul.c: #include "config.h". Portably #include + <limits.h> and/or <sys/param.h>. + * Makefile.in (strtol.o, strtoul.o): Update dependencies. + + * aclocal.m4 (libiberty_AC_DECLARE_ERRNO): New macro. + * configure.in (libiberty_AC_DECLARE_ERRNO): Add check. + * configure, config.in: Regenerate. + * pexecute.c, strtol.c, strtoul.c: Declare errno if necessary. + + * cp-demangle.c, mkstemps.c: #include <sys/types.h>. + +2000-07-21 Mike Stump <mrs@wrs.com> + + * Makefile.in (xexit.o): Add dependency for config.h in xexit.c. + * (vasprintf.o): Add dependency for config.h in vasprintf.c. + +2000-07-21 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * cp-demangle.c (cp_demangle_type): Wrap in IN_LIBGCC2. + + * setenv.c (setenv): Initialize variable `ep'. + + * sigsetmask.c (abort): Prototype. + + * vasprintf.c: Include config.h. Check ANSI_PROTOTYPES, not + __STDC__ for stdarg.h include. + (int_vasprintf): Prototype. + (checkit): Prototype. Use VPARAMS/ANSI_PROTOTYPES/VA_START in + definition. Cast `global_total_width' in comparison. + (main): Prototype. Return a value. + + * vfork.c (fork): Prototype. + + * xexit.c: Include config.h. + +2000-07-20 Joseph S. Myers <jsm28@cam.ac.uk> + + * cplus-dem.c (demangle_fund_type): Make 'dec' an unsigned int, + and print it with %u. + +2000-07-17 Hans-Peter Nilsson <hp@axis.com> + + * testsuite/regress-demangle (failed test): Show result and + expected output. + +2000-07-07 Andrew Haley <aph@cygnus.com> + + * cplus-dem.c (main): fflush() after emitting last char before + waiting for input. + +2000-06-28 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_encoding): Accept no substitutions. + (demangle_name): Handle <substitution> followed by + <unqualified-template-name>. + (demangle_type): Follow special substitutions with + <class-enum-type> + (demangle_subtitution): Set template_p for special substitutions. + (main): Fix typos. + +2000-06-27 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_special_name): Swap base and derived + class when demangling construction vtables. + +2000-06-21 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c: Don't include ctype.h. + (IS_DIGIT): New macro. + (IS_ALPHA): Likewise. Use IS_DIGIT and IS_ALPHA throughout + instead of isdigit and isalpanum. + (demangling_def): Make name and next const pointers. + (STATUS_ALLOCATION_FAILED): New status code. + (dyn_string_append_space): Handle failure in + dyn_string_append_char. + (int_to_dyn_string): Likewise. Change return value to status_t. + (string_list_new): Handle failure of dyn_string_init. + (result_close_template_list): Change return type to status_t. + Handle failure in dyn_string_append. + (result_push): Change return value to status_t. Handle failure in + string_list_new. Handle failure of result_push throughout. + (substitution_add): Change return value to status_t. Handle + dyn_string failures. Handle failure of substitution_add + throughout. + (template_arg_list_new): Return NULL on allocation failure. + (result_append_string): Return STATUS_ALLOCATION_FAILED on error. + Handle error result throughout. + (result_append): Likewise. + (result_append_char): Likewise. + (result_append_space): Likewise. + (demangling_new): Make argument a const pointer. Handle + allocation failures. + (demangle_template_args): Handle failure in template_arg_list_new + and result_close_template_list. + (demangle_discriminator): Return if int_to_dyn_string fails. + (cp_demangle): Likewise. + (cp_demangle_type): New function. + (cplus_demangle_new_abi): Don't call dyn_string_delete. Abort on + memory allocation failure. + (main): Likewise. + * dyn-string.c (RETURN_ON_ALLOCATION_FAILURE): Define if + IN_LIBGCC2. + (dyn_string_init): Change return value to int. Handle + RETURN_ON_ALLOCATION_FAILURE case. + (dyn_string_new): Handle RETURN_ON_ALLOCATION_FAILURE case. + (dyn_string_release): Delete the dyn_string. + (dyn_string_resize): Handle RETURN_ON_ALLOCATION_FAILURE case. + (dyn_string_copy): Change return type to int. + (dyn_string_copy_cstr): Likewise. + (dyn_string_prepend): Likewise. + (dyn_string_prepend_cstr): Likewise. + (dyn_string_insert): Likewise. + (dyn_string_insert_cstr): Likewise. + (dyn_string_append): Likewise. + (dyn_string_append_cstr): Likewise. + (dyn_string_append_char): Likewise. + (dyn_string_substring): Likewise. + +2000-06-09 Zack Weinberg <zack@wolery.cumb.org> + + * cp-demangle.c (demangle_operator_name): Add spaces before + names beginning with a letter: delete, delete[], new, new[], + sizeof. + (demangle_special_name): Handle TF <type> and TJ <type>. + +Thu Jun 8 18:52:24 2000 Philippe De Muyter <phdm@macqel.be> + + * cp-demangle.c (template_arg_list_new): Revert previous PARAMS patch. + +Thu Jun 8 09:25:54 2000 Philippe De Muyter <phdm@macqel.be> + + * cp-demangle.c (stdio.h): File included unconditionaly. + (template_arg_list_new): Parameter list is PARAMS ((void)), not (). + * dyn-string.c (stdio.h): File included. + * partition.c (partition_print): No `&' needed to take the address of + a function. + +2000-06-07 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * configure.in (ac_libiberty_warn_cflags): Add -pedantic. + + * choose-temp.c (try, choose_temp_base, make_temp_file): Constify. + + * cp-demangle.c (demangle_char): Change parameter from char to int. + (demangle_expression, demangle_expr_primary): Remove extra + semi-colon in prototype. + + * dyn-string.c (dyn_string_append_char): Change parameter from + char to int. + + * memcmp.c (memcmp): Constify. + + * mkstemps.c (gcc_uint64_t): Mark GNUC `long long' case with + __extension__. + + * partition.c (elem_compare): Prototype. Don't cast away + const-ness. + + * setenv.c (setenv): Use braces to avoid ambiguous `else'. + +2000-06-07 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * Makefile.in (cp-demangle.o): Depend on $(INCDIR)/demangle.h. + + * cp-demangle.c: Include demangle.h. + (template_arg_list_new): DeANSIfy. + (cp_demangle): Make static and add prototype. + (operator_code, operators): Constify. + (demangle_operator_name): Likewise for variables `p1', `p2' and `p'. + +2000-06-05 Alex Samuel <samuel@codesourcery.com> + + * cp-demangle.c (demangle_prefix): Cast argument to isdigit to + unsigned char. + (demangle_unqualified_name): Likewise. + (demangle_number_literally): Likewise. + (demangle_type): Likewise. + (demangle_substitution): Likewise. + (is_mangled_char): Likewise, for isalnum. + +2000-06-04 Alex Samuel <samuel@codesourcery.com> + * Makefile.in (CFILES): Add cp-demangle.c and dyn-string.c. (REQUIRED_OFILES): Add cp-demangle.o and dyn-string.o. (cp-demangle.o): New dependency. (dyn-string.o): Likewise. + * dyn-string.c: Move here from gcc/dyn-string.c. Add new functions. + + * cplus-dem.c (libiberty_demanglers): Add initializer for new-ABI + demangler. + (cplus_demangle): Call cplus_demangle_new_abi if in new-ABI + demangling mode. + (gnu_new_abi_symbol_characters): New function. + (main): Use gnu_new_abi_symbol_characters. * cp-demangle.c: New + file. + * cp-demangle.c: New file. + +Tue May 30 16:45:25 2000 Andrew Cagney <cagney@b1.cygnus.com> + + * floatformat.c: Add name to each floatformat field. + +Tue May 30 15:07:52 2000 Jeffrey A Law (law@cygnus.com) + + * Makefile.in (objalloc.o): Depend on config.h + +2000-05-29 Zack Weinberg <zack@wolery.cumb.org> + + * hashtab.c, partition.c, sort.c, xmemdup.c: Include string.h + if HAVE_STRING_H. + * pexecute.c, xexit.c: Include stdlib.h if HAVE_STDLIB_H. + * objalloc.c: Include config.h. Include stdlib.h and don't + declare malloc or free if HAVE_STDLIB_H. + * strerror.c, strsignal.c: Include stdlib.h if HAVE_STDLIB_H, + else declare malloc without prototype. Include string.h if + HAVE_STRING_H, else declare memset without prototype. Don't + include stddef.h. + +2000-05-23 Mike Stump <mrs@wrs.com> + + * Makefile.in (xmalloc.o): Add dependency for config.h, fixes make + -j3. + +2000-05-18 J. David Anglin <dave@hiauly1.hia.nrc.ca> + + * xmalloc.c: Include config.h for HAVE_SBRK definition. + +2000-05-16 Horst von Brand <vonbrand@sleipnir.valparaiso.cl> + + * hashtab.c (hash_pointer): Delete low-order bits which are + probably zero, also eliminate a warning on alpha. + +2000-05-15 David Edelsohn <edelsohn@gnu.org> + + * Makefile.in: Change "pic" to depend on $(PICFLAG), not + on $(enable_shared). + +2000-05-10 Jakub Jelinek <jakub@redhat.com> + + * config.table: Use mh-sparcpic for sparc*-*-*. + +2000-05-08 Nick Clifton <nickc@cygnus.com> + + * Makefile.in (CFILES): Add strncmp.c. + (NEEDED): Add strncmp. + +2000-05-04 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * cplus-dem.c (cplus_demangle_opname, demangle_function_name): + Cast the arguments to `islower' to `unsigned char'. + (print_demangler_list): Prototype. + +Thu May 4 17:14:41 2000 Philippe De Muyter <phdm@macqel.be> + + * sort.c (UCHAR_MAX): Provide fallback definition. + +2000-04-29 Alexandre Oliva <aoliva@cygnus.com> + + * Makefile.in (maintainer-clean-subdir): Fix handling of empty + SUBDIRS. + +2000-04-28 Kenneth Block <block@zk3.dec.com> + Jason Merrill <jason@casey.cygnus.com> + + * cplus-dem.c (libiberty_demanglers): New table for demangle styles. + (cplus_demangle_set_style): New function for setting style. + (cplus_demangle_name_to_style): New function to translate name. + +2000-04-27 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * aclocal.m4: New file with new test libiberty_AC_FUNC_STRNCMP. + + * configure.in (AC_CHECK_HEADERS): Add sys/mman.h fcntl.h. + (libiberty_AC_FUNC_STRNCMP): Invoke. + + * strncmp.c: New file. + +Thu Apr 27 16:58:43 MET DST 2000 Jan Hubicka <jh@suse.cz> + + * hashtab.c (htab_expand): Add prototype. + (find_empty_slot_for_expand): Likewise. + +2000-04-24 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> + + * hashtab.c (hash_pointer, eq_pointer): Make definition static to + match prototype. + (htab_expand): Cast the return value of xcalloc. + +2000-04-24 Mark Mitchell <mark@codesourcery.com> + + * hashtab.c (hash_pointer): New function. + (eq_pointer): Likewise. + (htab_hash_pointer): New variable. + (htab_eq_pointer): Likewise. + +2000-04-23 Mark Mitchell <mark@codesourcery.com> + + * sort.c (sort_pointers): Fix endianness bugs. + + * sort.c: New file. + * Makefile.in (CFILES): Add sort.c + (REQUIRED_OFILES): Add sort.o. + (sort.o): New target. + +2000-04-21 Michael Sokolov <msokolov@ivan.Harhan.ORG> + + * Makefile.in (*-subdir): Revamp slightly to avoid losing on + 4.3BSD systems. + +Tue Apr 18 16:23:31 2000 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> + + * hashtab.c: Various minor cleanups. + (htab_find_slot_with_hash): INSERT is now enum insert_option. + (htab_find_slot): Likewise. + +2000-04-16 Dave Pitts <dpitts@cozx.com> + + * cplus-dem.c (cplus_demangle_opname): Changed to use islower. + +2000-04-05 Richard Henderson <rth@cygnus.com> + + * splay-tree.c (splay_tree_remove): New. + +2000-03-30 Mark Mitchell <mark@codesourcery.com> + + * hashtab.c (find_empty_slot_for_expand): Use hashval_t for hash + codes. + (htab_find_with_hash): Likewise. + (htab_find_slot_with_hash): Likewise. + +2000-03-29 Zack Weinberg <zack@wolery.cumb.org> + + * hashtab.c (htab_find_with_hash): Avoid calculating hash2 + unless it will be used. Rearrange loop for better + optimization. + (higher_prime_number): Add static prototype. + Thu Mar 16 01:33:58 2000 Jeffrey A Law (law@cygnus.com) * Makefile.in (partition.o): Depend on config.h @@ -32,7 +756,7 @@ Thu Mar 16 01:33:58 2000 Jeffrey A Law (law@cygnus.com) (REQUIRED_OFILES): Add partition.o. (partition.o): New rule. * partition.c: New file. - + 2000-03-09 Zack Weinberg <zack@wolery.cumb.org> * hashtab.c (htab_create): Set del_f. @@ -3016,7 +3740,7 @@ Thu Feb 11 22:20:47 1993 Fred Fish (fnf@cygnus.com) * cplus-dem.c (string_prepends): Used now, remove #if 0. * cplus-dem.c (demangle_signature): Call demangle_qualified with prepending. - * cplus_dem.c (gnu_special): Recognize static data members that + * cplus-dem.c (gnu_special): Recognize static data members that use qualified names. * cplus-dem.c (demangle_qualified): Accumulate qualifiers in a temporary buffer and the prepend or append them to the result, diff --git a/contrib/binutils/libiberty/Makefile.in b/contrib/binutils/libiberty/Makefile.in index 5858a50..0eab5a6 100644 --- a/contrib/binutils/libiberty/Makefile.in +++ b/contrib/binutils/libiberty/Makefile.in @@ -1,6 +1,6 @@ # # Makefile -# Copyright (C) 1990, 91, 00 - 99, 2000 +# Copyright (C) 1990, 91-99, 2000 # Free Software Foundation # # This file is part of the libiberty library. @@ -108,8 +108,9 @@ INCDIR=$(srcdir)/$(MULTISRCTOP)../include COMPILE.c = $(CC) -c @DEFS@ $(LIBCFLAGS) -I. -I$(INCDIR) $(HDEFINES) @ac_libiberty_warn_cflags@ .c.o: - test x"$(enable_shared)" != xyes || \ - $(COMPILE.c) $(PICFLAG) $< -o pic/$@ + if [ x"$(PICFLAG)" != x ]; then \ + $(COMPILE.c) $(PICFLAG) $< -o pic/$@; \ + else true; fi $(COMPILE.c) $< info: info-subdir @@ -125,26 +126,27 @@ HFILES = alloca-conf.h # configure.in. CFILES = asprintf.c alloca.c argv.c atexit.c basename.c bcmp.c bcopy.c \ bzero.c calloc.c choose-temp.c clock.c concat.c cplus-dem.c \ - cp-demangle.c dyn-string.c fdmatch.c \ - fnmatch.c getcwd.c getpwd.c getopt.c getopt1.c getpagesize.c \ - getruntime.c floatformat.c hashtab.c hex.c index.c insque.c memchr.c \ + cp-demangle.c dyn-string.c fdmatch.c fnmatch.c getcwd.c \ + getpwd.c getopt.c getopt1.c getpagesize.c getruntime.c \ + floatformat.c hashtab.c hex.c index.c insque.c md5.c memchr.c \ memcmp.c memcpy.c memmove.c memset.c mkstemps.c objalloc.c obstack.c \ - partition.c pexecute.c putenv.c random.c rename.c rindex.c \ - setenv.c sigsetmask.c spaces.c splay-tree.c strcasecmp.c \ - strncasecmp.c strchr.c strdup.c strerror.c strrchr.c \ - strsignal.c strstr.c strtod.c strtol.c strtoul.c tmpnam.c \ - vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c waitpid.c \ - xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c + partition.c pexecute.c putenv.c random.c rename.c rindex.c setenv.c \ + sigsetmask.c safe-ctype.c sort.c spaces.c splay-tree.c strcasecmp.c \ + strncasecmp.c strchr.c strdup.c strerror.c strncmp.c strrchr.c \ + strsignal.c strstr.c strtod.c strtol.c strtoul.c tmpnam.c vasprintf.c \ + vfork.c vfprintf.c vprintf.c vsprintf.c waitpid.c xatexit.c xexit.c \ + xmalloc.c xmemdup.c xstrdup.c xstrerror.c # These are always included in the library. -REQUIRED_OFILES = argv.o choose-temp.o concat.o cplus-dem.o cp-demangle.o \ - dyn-string.o fdmatch.o fnmatch.o getopt.o getopt1.o getpwd.o getruntime.o \ - hashtab.o hex.o floatformat.o objalloc.o obstack.o partition.o pexecute.o \ - spaces.o splay-tree.o strerror.o strsignal.o xatexit.o xexit.o xmalloc.o \ - xmemdup.o xstrdup.o xstrerror.o +REQUIRED_OFILES = argv.o choose-temp.o concat.o cplus-dem.o cp-demangle.o \ + dyn-string.o fdmatch.o fnmatch.o getopt.o getopt1.o getpwd.o \ + getruntime.o hashtab.o hex.o floatformat.o md5.o objalloc.o obstack.o \ + partition.o pexecute.o safe-ctype.o sort.o spaces.o splay-tree.o \ + strerror.o strsignal.o xatexit.o xexit.o xmalloc.o xmemdup.o \ + xstrdup.o xstrerror.o $(TARGETLIB): $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS) $(ALLOCA) - rm -f $(TARGETLIB) + -rm -f $(TARGETLIB) $(AR) $(AR_FLAGS) $(TARGETLIB) \ $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS) $(ALLOCA) $(RANLIB) $(TARGETLIB) @@ -168,7 +170,7 @@ install_to_tooldir: all # to include there. Do not add anything LGPL to this list; libstdc++ # can't use anything encumbering. NEEDED = atexit calloc memchr memcmp memcpy memmove memset rename strchr \ - strerror strrchr strstr strtol strtoul tmpnam vfprintf vprintf \ + strerror strncmp strrchr strstr strtol strtoul tmpnam vfprintf vprintf \ vfork waitpid bcmp bcopy bzero needed-list: Makefile rm -f needed-list; touch needed-list; \ @@ -186,7 +188,7 @@ required-list: Makefile echo $(REQUIRED_OFILES) > required-list stamp-picdir: - if [ x"$(enable_shared)" = xyes ] && [ ! -d pic ]; then \ + if [ x"$(PICFLAG)" != x ] && [ ! -d pic ]; then \ mkdir pic; \ else true; fi touch stamp-picdir @@ -212,19 +214,20 @@ ls: # Cleaning has to be done carefully to ensure that we don't clean our SUBDIRS # multiple times, hence our explicit recursion with an empty SUBDIRS. mostlyclean: mostlyclean-subdir - rm -rf *.o pic core errs \#* *.E a.out - rm -f needed.awk needed2.awk errors dummy needed-list config.h stamp-* - rm -f $(CONFIG_H) $(NEEDED_LIST) stamp-picdir + -rm -rf *.o pic core errs \#* *.E a.out + -rm -f needed.awk needed2.awk errors dummy needed-list config.h stamp-* + -rm -f $(CONFIG_H) $(NEEDED_LIST) stamp-picdir @$(MULTICLEAN) multi-clean DO=mostlyclean clean: clean-subdir $(MAKE) SUBDIRS="" mostlyclean - rm -f *.a required-list tmpmulti.out + -rm -f *.a required-list tmpmulti.out @$(MULTICLEAN) multi-clean DO=clean distclean: distclean-subdir $(MAKE) SUBDIRS="" clean @$(MULTICLEAN) multi-clean DO=distclean - rm -f *~ Makefile config.status xhost-mkfrag TAGS multilib.out - rm -f config.log + -rm -f *~ Makefile config.status xhost-mkfrag TAGS multilib.out + -rm -f config.log + -rmdir testsuite 2>/dev/null maintainer-clean realclean: maintainer-clean-subdir $(MAKE) SUBDIRS="" distclean @@ -245,9 +248,10 @@ all-subdir check-subdir installcheck-subdir info-subdir \ install-info-subdir clean-info-subdir dvi-subdir install-subdir \ etags-subdir mostlyclean-subdir clean-subdir distclean-subdir \ maintainer-clean-subdir: - @target=`echo $@ | sed -e 's/-subdir//'`; \ - for dir in . $(SUBDIRS) ; do \ - test $$dir = . || (cd $$dir && $(MAKE) $$target) || exit 1; \ + @subdirs='$(SUBDIRS)'; \ + target=`echo $@ | sed -e 's/-subdir//'`; \ + for dir in $$subdirs ; do \ + cd $$dir && $(MAKE) $$target; \ done $(REQUIRED_OFILES) $(EXTRA_OFILES) $(LIBOBJS) $(ALLOCA): stamp-picdir @@ -273,19 +277,26 @@ getruntime.o: config.h $(INCDIR)/libiberty.h hex.o: $(INCDIR)/libiberty.h floatformat.o: $(INCDIR)/floatformat.h mkstemps.o: config.h -objalloc.o: $(INCDIR)/objalloc.h +md5.o: config.h +objalloc.o: config.h $(INCDIR)/objalloc.h obstack.o: config.h $(INCDIR)/obstack.h partition.o: config.h $(INCDIR)/partition.h pexecute.o: config.h $(INCDIR)/libiberty.h +rename.o: config.h setenv.o: config.h +sort.o: config.h $(INCDIR)/sort.h $(INCDIR)/ansidecl.h spaces.o: $(INCDIR)/libiberty.h splay-tree.o: config.h $(INCDIR)/libiberty.h $(INCDIR)/splay-tree.h $(INCDIR)/ansidecl.h strerror.o: config.h $(INCDIR)/libiberty.h strsignal.o: config.h $(INCDIR)/libiberty.h +strtol.o: config.h +strtoul.o: config.h +vasprintf.o: config.h xatexit.o: $(INCDIR)/libiberty.h -xexit.o: $(INCDIR)/libiberty.h -xmalloc.o: $(INCDIR)/libiberty.h +xexit.o: config.h $(INCDIR)/libiberty.h +xmalloc.o: config.h $(INCDIR)/libiberty.h xmemdup.o: config.h $(INCDIR)/libiberty.h xstrdup.o: config.h $(INCDIR)/libiberty.h xstrerror.o: config.h $(INCDIR)/libiberty.h +waitpid.o: config.h hashtab.o: config.h $(INCDIR)/libiberty.h $(INCDIR)/hashtab.h $(INCDIR)/ansidecl.h diff --git a/contrib/binutils/libiberty/aclocal.m4 b/contrib/binutils/libiberty/aclocal.m4 new file mode 100644 index 0000000..c562835 --- /dev/null +++ b/contrib/binutils/libiberty/aclocal.m4 @@ -0,0 +1,136 @@ +dnl See whether strncmp reads past the end of its string parameters. +dnl On some versions of SunOS4 at least, strncmp reads a word at a time +dnl but erroneously reads past the end of strings. This can cause +dnl a SEGV in some cases. +AC_DEFUN(libiberty_AC_FUNC_STRNCMP, +[AC_REQUIRE([AC_FUNC_MMAP]) +AC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works, +[AC_TRY_RUN([ +/* Test by Jim Wilson and Kaveh Ghazi. + Check whether strncmp reads past the end of its string parameters. */ +#include <sys/types.h> + +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif + +#ifdef HAVE_SYS_MMAN_H +#include <sys/mman.h> +#endif + +#ifndef MAP_ANON +#ifdef MAP_ANONYMOUS +#define MAP_ANON MAP_ANONYMOUS +#else +#define MAP_ANON MAP_FILE +#endif +#endif + +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif +#ifndef O_RDONLY +#define O_RDONLY 0 +#endif + +#define MAP_LEN 0x10000 + +main () +{ +#if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE) + char *p; + int dev_zero; + + dev_zero = open ("/dev/zero", O_RDONLY); + if (dev_zero < 0) + exit (1); + + p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, dev_zero, 0); + if (p == (char *)-1) + exit (2); + else + { + char *string = "__si_type_info"; + char *q = (char *) p + MAP_LEN - strlen (string) - 2; + char *r = (char *) p + 0xe; + + strcpy (q, string); + strcpy (r, string); + strncmp (r, q, 14); + } +#endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */ + exit (0); +} +], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no, + ac_cv_func_strncmp_works=no) +rm -f core core.* *.core]) +if test $ac_cv_func_strncmp_works = no ; then + LIBOBJS="$LIBOBJS strncmp.o" +fi +]) + +dnl See if errno must be declared even when <errno.h> is included. +AC_DEFUN(libiberty_AC_DECLARE_ERRNO, +[AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno, +[AC_TRY_COMPILE( +[#include <errno.h>], +[int x = errno;], +libiberty_cv_declare_errno=no, +libiberty_cv_declare_errno=yes)]) +if test $libiberty_cv_declare_errno = yes +then AC_DEFINE(NEED_DECLARATION_ERRNO, 1, + [Define if errno must be declared even when <errno.h> is included.]) +fi +]) + +# FIXME: We temporarily define our own version of AC_PROG_CC. This is +# copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS. We +# are probably using a cross compiler, which will not be able to fully +# link an executable. This should really be fixed in autoconf +# itself. + +AC_DEFUN(LIB_AC_PROG_CC, +[AC_BEFORE([$0], [AC_PROG_CPP])dnl +AC_PROVIDE([AC_PROG_CC]) +AC_CHECK_PROG(CC, gcc, gcc) +if test -z "$CC"; then + AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc) + test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH]) +fi + +AC_PROG_CC_GNU + +if test $ac_cv_prog_gcc = yes; then + GCC=yes + ac_libiberty_warn_cflags='-W -Wall -Wtraditional -pedantic' +dnl Check whether -g works, even if CFLAGS is set, in case the package +dnl plays around with CFLAGS (such as to build both debugging and +dnl normal versions of a library), tasteless as that idea is. + ac_test_CFLAGS="${CFLAGS+set}" + ac_save_CFLAGS="$CFLAGS" + CFLAGS= + AC_PROG_CC_G + if test "$ac_test_CFLAGS" = set; then + CFLAGS="$ac_save_CFLAGS" + elif test $ac_cv_prog_cc_g = yes; then + CFLAGS="-g -O2" + else + CFLAGS="-O2" + fi +else + GCC= + ac_libiberty_warn_cflags= + test "${CFLAGS+set}" = set || CFLAGS="-g" +fi +AC_SUBST(ac_libiberty_warn_cflags) +]) + +# Work around a bug in autoheader. This can go away when we switch to +# autoconf >2.50. The use of define instead of AC_DEFUN is +# deliberate. +define(AC_DEFINE_NOAUTOHEADER, +[cat >> confdefs.h <<\EOF +[#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1) +EOF +]) diff --git a/contrib/binutils/libiberty/argv.c b/contrib/binutils/libiberty/argv.c index f596ffd..7aec9c0 100644 --- a/contrib/binutils/libiberty/argv.c +++ b/contrib/binutils/libiberty/argv.c @@ -25,10 +25,7 @@ Boston, MA 02111-1307, USA. */ #include "ansidecl.h" #include "libiberty.h" -#ifdef isspace -#undef isspace -#endif -#define isspace(ch) ((ch) == ' ' || (ch) == '\t') +#define ISBLANK(ch) ((ch) == ' ' || (ch) == '\t') /* Routines imported from standard C runtime libraries. */ @@ -227,7 +224,7 @@ char *input; do { /* Pick off argv[argc] */ - while (isspace (*input)) + while (ISBLANK (*input)) { input++; } @@ -260,7 +257,7 @@ char *input; arg = copybuf; while (*input != EOS) { - if (isspace (*input) && !squote && !dquote && !bsquote) + if (ISBLANK (*input) && !squote && !dquote && !bsquote) { break; } @@ -326,7 +323,7 @@ char *input; argc++; argv[argc] = NULL; - while (isspace (*input)) + while (ISBLANK (*input)) { input++; } diff --git a/contrib/binutils/libiberty/basename.c b/contrib/binutils/libiberty/basename.c index 7698f06..ca089eb 100644 --- a/contrib/binutils/libiberty/basename.c +++ b/contrib/binutils/libiberty/basename.c @@ -20,7 +20,7 @@ BUGS #include "ansidecl.h" #include "libiberty.h" -#include <ctype.h> +#include "safe-ctype.h" #ifndef DIR_SEPARATOR #define DIR_SEPARATOR '/' @@ -50,7 +50,7 @@ basename (name) #if defined (HAVE_DOS_BASED_FILE_SYSTEM) /* Skip over the disk name in MSDOS pathnames. */ - if (isalpha (name[0]) && name[1] == ':') + if (ISALPHA (name[0]) && name[1] == ':') name += 2; #endif diff --git a/contrib/binutils/libiberty/bsearch.c b/contrib/binutils/libiberty/bsearch.c new file mode 100644 index 0000000..6a8ee33 --- /dev/null +++ b/contrib/binutils/libiberty/bsearch.c @@ -0,0 +1,75 @@ +/* + * Copyright (c) 1990 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. [rescinded 22 July 1999] + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include "config.h" +#include "ansidecl.h" +#include <sys/types.h> /* size_t */ +#include <stdio.h> + +/* + * Perform a binary search. + * + * The code below is a bit sneaky. After a comparison fails, we + * divide the work in half by moving either left or right. If lim + * is odd, moving left simply involves halving lim: e.g., when lim + * is 5 we look at item 2, so we change lim to 2 so that we will + * look at items 0 & 1. If lim is even, the same applies. If lim + * is odd, moving right again involes halving lim, this time moving + * the base up one item past p: e.g., when lim is 5 we change base + * to item 3 and make lim 2 so that we will look at items 3 and 4. + * If lim is even, however, we have to shrink it by one before + * halving: e.g., when lim is 4, we still looked at item 2, so we + * have to make lim 3, then halve, obtaining 1, so that we will only + * look at item 3. + */ +void * +bsearch(key, base0, nmemb, size, compar) + register void *key; + void *base0; + size_t nmemb; + register size_t size; + register int (*compar)(); +{ + register char *base = base0; + register int lim, cmp; + register void *p; + + for (lim = nmemb; lim != 0; lim >>= 1) { + p = base + (lim >> 1) * size; + cmp = (*compar)(key, p); + if (cmp == 0) + return (p); + if (cmp > 0) { /* key > p: move right */ + base = (char *)p + size; + lim--; + } /* else move left */ + } + return (NULL); +} diff --git a/contrib/binutils/libiberty/choose-temp.c b/contrib/binutils/libiberty/choose-temp.c index 826d818..1a475dd 100644 --- a/contrib/binutils/libiberty/choose-temp.c +++ b/contrib/binutils/libiberty/choose-temp.c @@ -79,9 +79,11 @@ extern int mkstemps (); If success, DIR is returned. Otherwise NULL is returned. */ -static char * +static const char *try PARAMS ((const char *, const char *)); + +static const char * try (dir, base) - char *dir, *base; + const char *dir, *base; { if (base != 0) return base; @@ -102,7 +104,7 @@ try (dir, base) char * choose_temp_base () { - char *base = 0; + const char *base = 0; char *temp_filename; int len; static char tmp[] = { DIR_SEPARATOR, 't', 'm', 'p', 0 }; @@ -147,7 +149,7 @@ char * make_temp_file (suffix) const char *suffix; { - char *base = 0; + const char *base = 0; char *temp_filename; int base_len, suffix_len; int fd; diff --git a/contrib/binutils/libiberty/config.in b/contrib/binutils/libiberty/config.in index 6e64208..1fb946a 100644 --- a/contrib/binutils/libiberty/config.in +++ b/contrib/binutils/libiberty/config.in @@ -3,6 +3,9 @@ /* Define if using alloca.c. */ #undef C_ALLOCA +/* Define to empty if the keyword does not work. */ +#undef const + /* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems. This function is required for alloca.c support on those systems. */ #undef CRAY_STACKSEG_END @@ -13,12 +16,18 @@ /* Define if you have <alloca.h> and it should be used (not on Ultrix). */ #undef HAVE_ALLOCA_H +/* Define if you have a working `mmap' system call. */ +#undef HAVE_MMAP + /* Define if you have <sys/wait.h> that is POSIX.1 compatible. */ #undef HAVE_SYS_WAIT_H /* Define if you have <vfork.h>. */ #undef HAVE_VFORK_H +/* Define as __inline if that's what the C compiler calls it. */ +#undef inline + /* Define to `int' if <sys/types.h> doesn't define. */ #undef pid_t @@ -37,21 +46,12 @@ /* Define if you have the ANSI C header files. */ #undef STDC_HEADERS +/* Define if you can safely include both <sys/time.h> and <time.h>. */ +#undef TIME_WITH_SYS_TIME + /* Define vfork as fork if vfork does not work. */ #undef vfork -/* Define if you have the sys_errlist variable. */ -#undef HAVE_SYS_ERRLIST - -/* Define if you have the sys_nerr variable. */ -#undef HAVE_SYS_NERR - -/* Define if you have the sys_siglist variable. */ -#undef HAVE_SYS_SIGLIST - -/* Define if you have the strerror function. */ -#undef HAVE_STRERROR - /* Define if you have the asprintf function. */ #undef HAVE_ASPRINTF @@ -67,6 +67,9 @@ /* Define if you have the bcopy function. */ #undef HAVE_BCOPY +/* Define if you have the bsearch function. */ +#undef HAVE_BSEARCH + /* Define if you have the bzero function. */ #undef HAVE_BZERO @@ -196,6 +199,12 @@ /* Define if you have the waitpid function. */ #undef HAVE_WAITPID +/* Define if you have the <fcntl.h> header file. */ +#undef HAVE_FCNTL_H + +/* Define if you have the <limits.h> header file. */ +#undef HAVE_LIMITS_H + /* Define if you have the <stdlib.h> header file. */ #undef HAVE_STDLIB_H @@ -208,6 +217,9 @@ /* Define if you have the <sys/file.h> header file. */ #undef HAVE_SYS_FILE_H +/* Define if you have the <sys/mman.h> header file. */ +#undef HAVE_SYS_MMAN_H + /* Define if you have the <sys/param.h> header file. */ #undef HAVE_SYS_PARAM_H @@ -220,5 +232,21 @@ /* Define if you have the <sys/time.h> header file. */ #undef HAVE_SYS_TIME_H +/* Define if you have the <time.h> header file. */ +#undef HAVE_TIME_H + /* Define if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H + +/* Define if errno must be declared even when <errno.h> is included. */ +#undef NEED_DECLARATION_ERRNO + +/* Define if you have the sys_errlist variable. */ +#undef HAVE_SYS_ERRLIST + +/* Define if you have the sys_nerr variable. */ +#undef HAVE_SYS_NERR + +/* Define if you have the sys_siglist variable. */ +#undef HAVE_SYS_SIGLIST + diff --git a/contrib/binutils/libiberty/config.table b/contrib/binutils/libiberty/config.table index 4e33746..ea3312b 100644 --- a/contrib/binutils/libiberty/config.table +++ b/contrib/binutils/libiberty/config.table @@ -27,6 +27,7 @@ if [ "${shared}" = "yes" ]; then i[3456]86-*-*) frags="${frags} ../../config/mh-x86pic" ;; powerpc*-*-aix*) ;; powerpc*-*-*) frags="${frags} ../../config/mh-ppcpic" ;; + sparc*-*-*) frags="${frags} ../../config/mh-sparcpic" ;; *-*-*) frags="${frags} ../../config/mh-${host_cpu}pic" ;; esac fi diff --git a/contrib/binutils/libiberty/config/mh-openedition b/contrib/binutils/libiberty/config/mh-openedition index 6e8e354..8de8ed1 100644 --- a/contrib/binutils/libiberty/config/mh-openedition +++ b/contrib/binutils/libiberty/config/mh-openedition @@ -1,3 +1,3 @@ -HDEFINES = -D_ALL_SOURCE +HDEFINES = -D_ALL_SOURCE -DLE370 CC=c89 diff --git a/contrib/binutils/libiberty/configure b/contrib/binutils/libiberty/configure index 02c826d..ca24ef9 100755 --- a/contrib/binutils/libiberty/configure +++ b/contrib/binutils/libiberty/configure @@ -733,20 +733,11 @@ fi fi -# FIXME: We temporarily define our own version of AC_PROG_CC. This is -# copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS. We -# are probably using a cross compiler, which will not be able to fully -# link an executable. This should really be fixed in autoconf -# itself. - - - - # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:750: checking for $ac_word" >&5 +echo "configure:741: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -776,7 +767,7 @@ if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:780: checking for $ac_word" >&5 +echo "configure:771: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -825,7 +816,7 @@ fi fi echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:829: checking whether we are using GNU C" >&5 +echo "configure:820: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -834,7 +825,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:838: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:829: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -845,12 +836,12 @@ echo "$ac_t""$ac_cv_prog_gcc" 1>&6 if test $ac_cv_prog_gcc = yes; then GCC=yes - ac_libiberty_warn_cflags='-W -Wall -Wtraditional' + ac_libiberty_warn_cflags='-W -Wall -Wtraditional -pedantic' ac_test_CFLAGS="${CFLAGS+set}" ac_save_CFLAGS="$CFLAGS" CFLAGS= echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:854: checking whether ${CC-cc} accepts -g" >&5 +echo "configure:845: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -879,8 +870,9 @@ else fi + echo $ac_n "checking for POSIXized ISC""... $ac_c" 1>&6 -echo "configure:884: checking for POSIXized ISC" >&5 +echo "configure:876: checking for POSIXized ISC" >&5 if test -d /etc/conf/kconfig.d && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1 then @@ -900,6 +892,121 @@ else ISC= fi +echo $ac_n "checking for working const""... $ac_c" 1>&6 +echo "configure:897: checking for working const" >&5 +if eval "test \"`echo '$''{'ac_cv_c_const'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 902 "configure" +#include "confdefs.h" + +int main() { + +/* Ultrix mips cc rejects this. */ +typedef int charset[2]; const charset x; +/* SunOS 4.1.1 cc rejects this. */ +char const *const *ccp; +char **p; +/* NEC SVR4.0.2 mips cc rejects this. */ +struct point {int x, y;}; +static struct point const zero = {0,0}; +/* AIX XL C 1.02.0.0 rejects this. + It does not let you subtract one const X* pointer from another in an arm + of an if-expression whose if-part is not a constant expression */ +const char *g = "string"; +ccp = &g + (g ? g-g : 0); +/* HPUX 7.0 cc rejects these. */ +++ccp; +p = (char**) ccp; +ccp = (char const *const *) p; +{ /* SCO 3.2v4 cc rejects this. */ + char *t; + char const *s = 0 ? (char *) 0 : (char const *) 0; + + *t++ = 0; +} +{ /* Someone thinks the Sun supposedly-ANSI compiler will reject this. */ + int x[] = {25, 17}; + const int *foo = &x[0]; + ++foo; +} +{ /* Sun SC1.0 ANSI compiler rejects this -- but not the above. */ + typedef const int *iptr; + iptr p = 0; + ++p; +} +{ /* AIX XL C 1.02.0.0 rejects this saying + "k.c", line 2.27: 1506-025 (S) Operand must be a modifiable lvalue. */ + struct s { int j; const int *ap[3]; }; + struct s *b; b->j = 5; +} +{ /* ULTRIX-32 V3.1 (Rev 9) vcc rejects this */ + const int foo = 10; +} + +; return 0; } +EOF +if { (eval echo configure:951: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_c_const=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_c_const=no +fi +rm -f conftest* +fi + +echo "$ac_t""$ac_cv_c_const" 1>&6 +if test $ac_cv_c_const = no; then + cat >> confdefs.h <<\EOF +#define const +EOF + +fi + +echo $ac_n "checking for inline""... $ac_c" 1>&6 +echo "configure:972: checking for inline" >&5 +if eval "test \"`echo '$''{'ac_cv_c_inline'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + ac_cv_c_inline=no +for ac_kw in inline __inline__ __inline; do + cat > conftest.$ac_ext <<EOF +#line 979 "configure" +#include "confdefs.h" + +int main() { +} $ac_kw foo() { +; return 0; } +EOF +if { (eval echo configure:986: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_c_inline=$ac_kw; break +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 +fi +rm -f conftest* +done + +fi + +echo "$ac_t""$ac_cv_c_inline" 1>&6 +case "$ac_cv_c_inline" in + inline | yes) ;; + no) cat >> confdefs.h <<\EOF +#define inline +EOF + ;; + *) cat >> confdefs.h <<EOF +#define inline $ac_cv_c_inline +EOF + ;; +esac + @@ -918,7 +1025,7 @@ fi # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:922: checking for a BSD compatible install" >&5 +echo "configure:1029: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -979,7 +1086,7 @@ host_makefile_frag=${frag} # able to link anything, it had better be able to at least compile # something. echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:983: checking how to run the C preprocessor" >&5 +echo "configure:1090: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -994,13 +1101,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext <<EOF -#line 998 "configure" +#line 1105 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1004: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1111: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1011,13 +1118,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext <<EOF -#line 1015 "configure" +#line 1122 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1021: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1128: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1028,13 +1135,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext <<EOF -#line 1032 "configure" +#line 1139 "configure" #include "confdefs.h" #include <assert.h> Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1038: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1145: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1058,21 +1165,21 @@ else fi echo "$ac_t""$CPP" 1>&6 -for ac_hdr in sys/file.h sys/param.h stdlib.h string.h unistd.h strings.h sys/time.h sys/resource.h sys/stat.h +for ac_hdr in sys/file.h sys/param.h limits.h stdlib.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1066: checking for $ac_hdr" >&5 +echo "configure:1173: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1071 "configure" +#line 1178 "configure" #include "confdefs.h" #include <$ac_hdr> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1076: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1183: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1099,12 +1206,12 @@ fi done echo $ac_n "checking for sys/wait.h that is POSIX.1 compatible""... $ac_c" 1>&6 -echo "configure:1103: checking for sys/wait.h that is POSIX.1 compatible" >&5 +echo "configure:1210: checking for sys/wait.h that is POSIX.1 compatible" >&5 if eval "test \"`echo '$''{'ac_cv_header_sys_wait_h'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1108 "configure" +#line 1215 "configure" #include "confdefs.h" #include <sys/types.h> #include <sys/wait.h> @@ -1120,7 +1227,7 @@ wait (&s); s = WIFEXITED (s) ? WEXITSTATUS (s) : 1; ; return 0; } EOF -if { (eval echo configure:1124: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1231: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_sys_wait_h=yes else @@ -1140,6 +1247,75 @@ EOF fi +echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6 +echo "configure:1252: checking whether time.h and sys/time.h may both be included" >&5 +if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1257 "configure" +#include "confdefs.h" +#include <sys/types.h> +#include <sys/time.h> +#include <time.h> +int main() { +struct tm *tp; +; return 0; } +EOF +if { (eval echo configure:1266: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + ac_cv_header_time=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + ac_cv_header_time=no +fi +rm -f conftest* +fi + +echo "$ac_t""$ac_cv_header_time" 1>&6 +if test $ac_cv_header_time = yes; then + cat >> confdefs.h <<\EOF +#define TIME_WITH_SYS_TIME 1 +EOF + +fi + + +echo $ac_n "checking whether errno must be declared""... $ac_c" 1>&6 +echo "configure:1288: checking whether errno must be declared" >&5 +if eval "test \"`echo '$''{'libiberty_cv_declare_errno'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 1293 "configure" +#include "confdefs.h" +#include <errno.h> +int main() { +int x = errno; +; return 0; } +EOF +if { (eval echo configure:1300: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + libiberty_cv_declare_errno=no +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + libiberty_cv_declare_errno=yes +fi +rm -f conftest* +fi + +echo "$ac_t""$libiberty_cv_declare_errno" 1>&6 +if test $libiberty_cv_declare_errno = yes +then cat >> confdefs.h <<\EOF +#define NEED_DECLARATION_ERRNO 1 +EOF + +fi + # This is the list of functions which libiberty will provide if they # are not available on the host. @@ -1149,6 +1325,7 @@ funcs="$funcs atexit" funcs="$funcs basename" funcs="$funcs bcmp" funcs="$funcs bcopy" +funcs="$funcs bsearch" funcs="$funcs bzero" funcs="$funcs calloc" funcs="$funcs clock" @@ -1193,15 +1370,15 @@ checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gett # These are neither executed nor required, but they help keep # autoheader happy without adding a bunch of text to acconfig.h. if test "x" = "y"; then - for ac_func in asprintf atexit basename bcmp bcopy bzero calloc clock getcwd + for ac_func in asprintf atexit basename bcmp bcopy bsearch bzero calloc clock do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1200: checking for $ac_func" >&5 +echo "configure:1377: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1205 "configure" +#line 1382 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1224,7 +1401,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1228: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1405: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1248,15 +1425,15 @@ else fi done - for ac_func in getpagesize index insque mkstemps memchr memcmp memcpy memmove + for ac_func in getcwd getpagesize index insque mkstemps memchr memcmp memcpy do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1255: checking for $ac_func" >&5 +echo "configure:1432: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1260 "configure" +#line 1437 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1279,7 +1456,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1283: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1460: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1303,15 +1480,15 @@ else fi done - for ac_func in memset putenv random rename rindex sigsetmask strcasecmp + for ac_func in memmove memset putenv random rename rindex sigsetmask do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1310: checking for $ac_func" >&5 +echo "configure:1487: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1315 "configure" +#line 1492 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1334,7 +1511,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1338: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1515: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1358,15 +1535,15 @@ else fi done - for ac_func in setenv strchr strdup strncasecmp strrchr strstr strtod strtol + for ac_func in strcasecmp setenv strchr strdup strncasecmp strrchr strstr do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1365: checking for $ac_func" >&5 +echo "configure:1542: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1370 "configure" +#line 1547 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1389,7 +1566,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1393: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1570: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1413,15 +1590,15 @@ else fi done - for ac_func in strtoul tmpnam vasprintf vfprintf vprintf vsprintf waitpid + for ac_func in strtod strtol strtoul tmpnam vasprintf vfprintf vprintf do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1420: checking for $ac_func" >&5 +echo "configure:1597: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1425 "configure" +#line 1602 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1444,7 +1621,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1448: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1625: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1468,27 +1645,15 @@ else fi done - cat >> confdefs.h <<\EOF -#define HAVE_SYS_ERRLIST 1 -EOF - - cat >> confdefs.h <<\EOF -#define HAVE_SYS_NERR 1 -EOF - - cat >> confdefs.h <<\EOF -#define HAVE_SYS_SIGLIST 1 -EOF - - for ac_func in getrusage on_exit psignal strerror strsignal sysconf times + for ac_func in vsprintf waitpid getrusage on_exit psignal strerror strsignal do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1487: checking for $ac_func" >&5 +echo "configure:1652: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1492 "configure" +#line 1657 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1511,7 +1676,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1515: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1680: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1535,15 +1700,15 @@ else fi done - for ac_func in sbrk gettimeofday + for ac_func in sysconf times sbrk gettimeofday do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1542: checking for $ac_func" >&5 +echo "configure:1707: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1547 "configure" +#line 1712 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1566,7 +1731,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1570: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1735: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1590,6 +1755,18 @@ else fi done + cat >> confdefs.h <<\EOF +#define HAVE_SYS_ERRLIST 1 +EOF + + cat >> confdefs.h <<\EOF +#define HAVE_SYS_NERR 1 +EOF + + cat >> confdefs.h <<\EOF +#define HAVE_SYS_SIGLIST 1 +EOF + fi # For each of these functions, if the host does not provide the @@ -1705,24 +1882,22 @@ if test -z "${setobjs}"; then # provides from our shell variables, so that they appear to be # missing. - funcs="`echo $funcs | sed -e 's/random//'`" - LIBOBJS="$LIBOBJS random.o" - vars="`echo $vars | sed -e 's/sys_siglist//'`" - checkfuncs="`echo $checkfuncs | sed -e 's/strsignal//' -e 's/psignal//'`" + # DJ - only if we're *building* cygwin, not just building *with* cygwin + + if test -n "${with_target_subdir}" + then + funcs="`echo $funcs | sed -e 's/random//'`" + LIBOBJS="$LIBOBJS random.o" + vars="`echo $vars | sed -e 's/sys_siglist//'`" + checkfuncs="`echo $checkfuncs | sed -e 's/strsignal//' -e 's/psignal//'`" + fi ;; *-*-mingw32*) # Under mingw32, sys_nerr and sys_errlist exist, but they are # macros, so the test below won't find them. - vars="`echo $vars | sed -e 's/sys_nerr//' -e 's/sys_errlist//'`" - cat >> confdefs.h <<\EOF -#define HAVE_SYS_NERR 1 -EOF - - cat >> confdefs.h <<\EOF -#define HAVE_SYS_ERRLIST 1 -EOF - + libiberty_cv_var_sys_nerr=yes + libiberty_cv_var_sys_errlist=yes ;; *-*-uwin*) @@ -1733,14 +1908,8 @@ EOF # Under uwin 2.0+, sys_nerr and sys_errlist exist, but they are # macros (actually, these are imported from a DLL, but the end effect # is the same), so the test below won't find them. - cat >> confdefs.h <<\EOF -#define HAVE_SYS_NERR 1 -EOF - - cat >> confdefs.h <<\EOF -#define HAVE_SYS_ERRLIST 1 -EOF - + libiberty_cv_var_sys_nerr=yes + libiberty_cv_var_sys_errlist=yes ;; esac @@ -1748,7 +1917,7 @@ EOF # We haven't set the list of objects yet. Use the standard autoconf # tests. This will only work if the compiler works. echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:1752: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:1921: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. @@ -1759,12 +1928,12 @@ cross_compiling=$ac_cv_prog_cc_cross cat > conftest.$ac_ext << EOF -#line 1763 "configure" +#line 1932 "configure" #include "confdefs.h" main(){return(0);} EOF -if { (eval echo configure:1768: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1937: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -1790,19 +1959,19 @@ if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:1794: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:1963: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross for ac_func in $funcs do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1801: checking for $ac_func" >&5 +echo "configure:1970: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1806 "configure" +#line 1975 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -1825,7 +1994,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:1829: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1998: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -1872,19 +2041,19 @@ EOF # The Ultrix 4.2 mips builtin alloca declared by alloca.h only works # for constant arguments. Useless! echo $ac_n "checking for working alloca.h""... $ac_c" 1>&6 -echo "configure:1876: checking for working alloca.h" >&5 +echo "configure:2045: checking for working alloca.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_alloca_h'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1881 "configure" +#line 2050 "configure" #include "confdefs.h" #include <alloca.h> int main() { char *p = alloca(2 * sizeof(int)); ; return 0; } EOF -if { (eval echo configure:1888: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2057: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ac_cv_header_alloca_h=yes else @@ -1905,12 +2074,12 @@ EOF fi echo $ac_n "checking for alloca""... $ac_c" 1>&6 -echo "configure:1909: checking for alloca" >&5 +echo "configure:2078: checking for alloca" >&5 if eval "test \"`echo '$''{'ac_cv_func_alloca_works'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1914 "configure" +#line 2083 "configure" #include "confdefs.h" #ifdef __GNUC__ @@ -1938,7 +2107,7 @@ int main() { char *p = (char *) alloca(1); ; return 0; } EOF -if { (eval echo configure:1942: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2111: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ac_cv_func_alloca_works=yes else @@ -1970,12 +2139,12 @@ EOF echo $ac_n "checking whether alloca needs Cray hooks""... $ac_c" 1>&6 -echo "configure:1974: checking whether alloca needs Cray hooks" >&5 +echo "configure:2143: checking whether alloca needs Cray hooks" >&5 if eval "test \"`echo '$''{'ac_cv_os_cray'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 1979 "configure" +#line 2148 "configure" #include "confdefs.h" #if defined(CRAY) && ! defined(CRAY2) webecray @@ -2000,12 +2169,12 @@ echo "$ac_t""$ac_cv_os_cray" 1>&6 if test $ac_cv_os_cray = yes; then for ac_func in _getb67 GETB67 getb67; do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2004: checking for $ac_func" >&5 +echo "configure:2173: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2009 "configure" +#line 2178 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2028,7 +2197,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2032: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2201: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2055,7 +2224,7 @@ done fi echo $ac_n "checking stack direction for C alloca""... $ac_c" 1>&6 -echo "configure:2059: checking stack direction for C alloca" >&5 +echo "configure:2228: checking stack direction for C alloca" >&5 if eval "test \"`echo '$''{'ac_cv_c_stack_direction'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -2063,7 +2232,7 @@ else ac_cv_c_stack_direction=0 else cat > conftest.$ac_ext <<EOF -#line 2067 "configure" +#line 2236 "configure" #include "confdefs.h" find_stack_direction () { @@ -2082,7 +2251,7 @@ main () exit (find_stack_direction() < 0); } EOF -if { (eval echo configure:2086: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2255: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_c_stack_direction=1 else @@ -2107,12 +2276,12 @@ fi esac echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:2111: checking for ANSI C header files" >&5 +echo "configure:2280: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2116 "configure" +#line 2285 "configure" #include "confdefs.h" #include <stdlib.h> #include <stdarg.h> @@ -2120,7 +2289,7 @@ else #include <float.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2124: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2293: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -2137,7 +2306,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 2141 "configure" +#line 2310 "configure" #include "confdefs.h" #include <string.h> EOF @@ -2155,7 +2324,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext <<EOF -#line 2159 "configure" +#line 2328 "configure" #include "confdefs.h" #include <stdlib.h> EOF @@ -2176,7 +2345,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext <<EOF -#line 2180 "configure" +#line 2349 "configure" #include "confdefs.h" #include <ctype.h> #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -2187,7 +2356,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:2191: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2360: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else @@ -2211,12 +2380,12 @@ EOF fi echo $ac_n "checking for pid_t""... $ac_c" 1>&6 -echo "configure:2215: checking for pid_t" >&5 +echo "configure:2384: checking for pid_t" >&5 if eval "test \"`echo '$''{'ac_cv_type_pid_t'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2220 "configure" +#line 2389 "configure" #include "confdefs.h" #include <sys/types.h> #if STDC_HEADERS @@ -2245,17 +2414,17 @@ fi ac_safe=`echo "vfork.h" | sed 'y%./+-%__p_%'` echo $ac_n "checking for vfork.h""... $ac_c" 1>&6 -echo "configure:2249: checking for vfork.h" >&5 +echo "configure:2418: checking for vfork.h" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2254 "configure" +#line 2423 "configure" #include "confdefs.h" #include <vfork.h> EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:2259: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:2428: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -2280,18 +2449,18 @@ else fi echo $ac_n "checking for working vfork""... $ac_c" 1>&6 -echo "configure:2284: checking for working vfork" >&5 +echo "configure:2453: checking for working vfork" >&5 if eval "test \"`echo '$''{'ac_cv_func_vfork_works'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test "$cross_compiling" = yes; then echo $ac_n "checking for vfork""... $ac_c" 1>&6 -echo "configure:2290: checking for vfork" >&5 +echo "configure:2459: checking for vfork" >&5 if eval "test \"`echo '$''{'ac_cv_func_vfork'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2295 "configure" +#line 2464 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char vfork(); below. */ @@ -2314,7 +2483,7 @@ vfork(); ; return 0; } EOF -if { (eval echo configure:2318: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2487: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_vfork=yes" else @@ -2336,7 +2505,7 @@ fi ac_cv_func_vfork_works=$ac_cv_func_vfork else cat > conftest.$ac_ext <<EOF -#line 2340 "configure" +#line 2509 "configure" #include "confdefs.h" /* Thanks to Paul Eggert for this test. */ #include <stdio.h> @@ -2431,7 +2600,7 @@ main() { } } EOF -if { (eval echo configure:2435: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:2604: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then ac_cv_func_vfork_works=yes else @@ -2458,19 +2627,19 @@ fi fi for v in $vars; do echo $ac_n "checking for $v""... $ac_c" 1>&6 -echo "configure:2462: checking for $v" >&5 +echo "configure:2631: checking for $v" >&5 if eval "test \"`echo '$''{'libiberty_cv_var_$v'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2467 "configure" +#line 2636 "configure" #include "confdefs.h" int *p; int main() { extern int $v; p = &$v; ; return 0; } EOF -if { (eval echo configure:2474: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2643: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "libiberty_cv_var_$v=yes" else @@ -2496,12 +2665,109 @@ EOF for ac_func in $checkfuncs do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:2500: checking for $ac_func" >&5 +echo "configure:2669: checking for $ac_func" >&5 +if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2674 "configure" +#include "confdefs.h" +/* System header to define __stub macros and hopefully few prototypes, + which can conflict with char $ac_func(); below. */ +#include <assert.h> +/* Override any gcc2 internal prototype to avoid an error. */ +/* We use char because int might match the return type of a gcc2 + builtin and then its argument prototype would still apply. */ +char $ac_func(); + +int main() { + +/* The GNU C library defines this for functions which it implements + to always fail with ENOSYS. Some functions are actually named + something starting with __ and the normal name is an alias. */ +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) +choke me +#else +$ac_func(); +#endif + +; return 0; } +EOF +if { (eval echo configure:2697: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then + rm -rf conftest* + eval "ac_cv_func_$ac_func=yes" +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_func_$ac_func=no" +fi +rm -f conftest* +fi + +if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_func=HAVE_`echo $ac_func | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'` + cat >> confdefs.h <<EOF +#define $ac_tr_func 1 +EOF + +else + echo "$ac_t""no" 1>&6 +fi +done + +fi + +for ac_hdr in unistd.h +do +ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` +echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 +echo "configure:2727: checking for $ac_hdr" >&5 +if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext <<EOF +#line 2732 "configure" +#include "confdefs.h" +#include <$ac_hdr> +EOF +ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +{ (eval echo configure:2737: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +if test -z "$ac_err"; then + rm -rf conftest* + eval "ac_cv_header_$ac_safe=yes" +else + echo "$ac_err" >&5 + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + eval "ac_cv_header_$ac_safe=no" +fi +rm -f conftest* +fi +if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then + echo "$ac_t""yes" 1>&6 + ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'` + cat >> confdefs.h <<EOF +#define $ac_tr_hdr 1 +EOF + +else + echo "$ac_t""no" 1>&6 +fi +done + +for ac_func in getpagesize +do +echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 +echo "configure:2766: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <<EOF -#line 2505 "configure" +#line 2771 "configure" #include "confdefs.h" /* System header to define __stub macros and hopefully few prototypes, which can conflict with char $ac_func(); below. */ @@ -2524,7 +2790,7 @@ $ac_func(); ; return 0; } EOF -if { (eval echo configure:2528: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:2794: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -2548,8 +2814,269 @@ else fi done +echo $ac_n "checking for working mmap""... $ac_c" 1>&6 +echo "configure:2819: checking for working mmap" >&5 +if eval "test \"`echo '$''{'ac_cv_func_mmap_fixed_mapped'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + ac_cv_func_mmap_fixed_mapped=no +else + cat > conftest.$ac_ext <<EOF +#line 2827 "configure" +#include "confdefs.h" + +/* Thanks to Mike Haertel and Jim Avera for this test. + Here is a matrix of mmap possibilities: + mmap private not fixed + mmap private fixed at somewhere currently unmapped + mmap private fixed at somewhere already mapped + mmap shared not fixed + mmap shared fixed at somewhere currently unmapped + mmap shared fixed at somewhere already mapped + For private mappings, we should verify that changes cannot be read() + back from the file, nor mmap's back from the file at a different + address. (There have been systems where private was not correctly + implemented like the infamous i386 svr4.0, and systems where the + VM page cache was not coherent with the filesystem buffer cache + like early versions of FreeBSD and possibly contemporary NetBSD.) + For shared mappings, we should conversely verify that changes get + propogated back to all the places they're supposed to be. + + Grep wants private fixed already mapped. + The main things grep needs to know about mmap are: + * does it exist and is it safe to write into the mmap'd area + * how to use it (BSD variants) */ +#include <sys/types.h> +#include <fcntl.h> +#include <sys/mman.h> + +/* This mess was copied from the GNU getpagesize.h. */ +#ifndef HAVE_GETPAGESIZE +# ifdef HAVE_UNISTD_H +# include <unistd.h> +# endif + +/* Assume that all systems that can run configure have sys/param.h. */ +# ifndef HAVE_SYS_PARAM_H +# define HAVE_SYS_PARAM_H 1 +# endif + +# ifdef _SC_PAGESIZE +# define getpagesize() sysconf(_SC_PAGESIZE) +# else /* no _SC_PAGESIZE */ +# ifdef HAVE_SYS_PARAM_H +# include <sys/param.h> +# ifdef EXEC_PAGESIZE +# define getpagesize() EXEC_PAGESIZE +# else /* no EXEC_PAGESIZE */ +# ifdef NBPG +# define getpagesize() NBPG * CLSIZE +# ifndef CLSIZE +# define CLSIZE 1 +# endif /* no CLSIZE */ +# else /* no NBPG */ +# ifdef NBPC +# define getpagesize() NBPC +# else /* no NBPC */ +# ifdef PAGESIZE +# define getpagesize() PAGESIZE +# endif /* PAGESIZE */ +# endif /* no NBPC */ +# endif /* no NBPG */ +# endif /* no EXEC_PAGESIZE */ +# else /* no HAVE_SYS_PARAM_H */ +# define getpagesize() 8192 /* punt totally */ +# endif /* no HAVE_SYS_PARAM_H */ +# endif /* no _SC_PAGESIZE */ + +#endif /* no HAVE_GETPAGESIZE */ + +#ifdef __cplusplus +extern "C" { void *malloc(unsigned); } +#else +char *malloc(); +#endif + +int +main() +{ + char *data, *data2, *data3; + int i, pagesize; + int fd; + + pagesize = getpagesize(); + + /* + * First, make a file with some known garbage in it. + */ + data = malloc(pagesize); + if (!data) + exit(1); + for (i = 0; i < pagesize; ++i) + *(data + i) = rand(); + umask(0); + fd = creat("conftestmmap", 0600); + if (fd < 0) + exit(1); + if (write(fd, data, pagesize) != pagesize) + exit(1); + close(fd); + + /* + * Next, try to mmap the file at a fixed address which + * already has something else allocated at it. If we can, + * also make sure that we see the same garbage. + */ + fd = open("conftestmmap", O_RDWR); + if (fd < 0) + exit(1); + data2 = malloc(2 * pagesize); + if (!data2) + exit(1); + data2 += (pagesize - ((int) data2 & (pagesize - 1))) & (pagesize - 1); + if (data2 != mmap(data2, pagesize, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_FIXED, fd, 0L)) + exit(1); + for (i = 0; i < pagesize; ++i) + if (*(data + i) != *(data2 + i)) + exit(1); + + /* + * Finally, make sure that changes to the mapped area + * do not percolate back to the file as seen by read(). + * (This is a bug on some variants of i386 svr4.0.) + */ + for (i = 0; i < pagesize; ++i) + *(data2 + i) = *(data2 + i) + 1; + data3 = malloc(pagesize); + if (!data3) + exit(1); + if (read(fd, data3, pagesize) != pagesize) + exit(1); + for (i = 0; i < pagesize; ++i) + if (*(data + i) != *(data3 + i)) + exit(1); + close(fd); + unlink("conftestmmap"); + exit(0); +} + +EOF +if { (eval echo configure:2967: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + ac_cv_func_mmap_fixed_mapped=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + ac_cv_func_mmap_fixed_mapped=no +fi +rm -fr conftest* +fi + +fi + +echo "$ac_t""$ac_cv_func_mmap_fixed_mapped" 1>&6 +if test $ac_cv_func_mmap_fixed_mapped = yes; then + cat >> confdefs.h <<\EOF +#define HAVE_MMAP 1 +EOF + fi + +echo $ac_n "checking for working strncmp""... $ac_c" 1>&6 +echo "configure:2991: checking for working strncmp" >&5 +if eval "test \"`echo '$''{'ac_cv_func_strncmp_works'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + if test "$cross_compiling" = yes; then + ac_cv_func_strncmp_works=no +else + cat > conftest.$ac_ext <<EOF +#line 2999 "configure" +#include "confdefs.h" + +/* Test by Jim Wilson and Kaveh Ghazi. + Check whether strncmp reads past the end of its string parameters. */ +#include <sys/types.h> + +#ifdef HAVE_FCNTL_H +#include <fcntl.h> +#endif + +#ifdef HAVE_SYS_MMAN_H +#include <sys/mman.h> +#endif + +#ifndef MAP_ANON +#ifdef MAP_ANONYMOUS +#define MAP_ANON MAP_ANONYMOUS +#else +#define MAP_ANON MAP_FILE +#endif +#endif + +#ifndef MAP_FILE +#define MAP_FILE 0 +#endif +#ifndef O_RDONLY +#define O_RDONLY 0 +#endif + +#define MAP_LEN 0x10000 + +main () +{ +#if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE) + char *p; + int dev_zero; + + dev_zero = open ("/dev/zero", O_RDONLY); + if (dev_zero < 0) + exit (1); + + p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE, + MAP_ANON|MAP_PRIVATE, dev_zero, 0); + if (p == (char *)-1) + exit (2); + else + { + char *string = "__si_type_info"; + char *q = (char *) p + MAP_LEN - strlen (string) - 2; + char *r = (char *) p + 0xe; + + strcpy (q, string); + strcpy (r, string); + strncmp (r, q, 14); + } +#endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */ + exit (0); +} + +EOF +if { (eval echo configure:3060: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +then + ac_cv_func_strncmp_works=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -fr conftest* + ac_cv_func_strncmp_works=no +fi +rm -fr conftest* +fi + +rm -f core core.* *.core +fi + +echo "$ac_t""$ac_cv_func_strncmp_works" 1>&6 +if test $ac_cv_func_strncmp_works = no ; then + LIBOBJS="$LIBOBJS strncmp.o" +fi + + # Install a library built with a cross compiler in $(tooldir) rather # than $(libdir). if test -z "${with_cross_host}"; then @@ -2705,8 +3232,8 @@ s%@build_vendor@%$build_vendor%g s%@build_os@%$build_os%g s%@AR@%$AR%g s%@RANLIB@%$RANLIB%g -s%@ac_libiberty_warn_cflags@%$ac_libiberty_warn_cflags%g s%@CC@%$CC%g +s%@ac_libiberty_warn_cflags@%$ac_libiberty_warn_cflags%g s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g s%@INSTALL_DATA@%$INSTALL_DATA%g diff --git a/contrib/binutils/libiberty/configure.in b/contrib/binutils/libiberty/configure.in index cc1b2c2..af80e0d 100644 --- a/contrib/binutils/libiberty/configure.in +++ b/contrib/binutils/libiberty/configure.in @@ -36,51 +36,11 @@ dnl to call AC_CHECK_PROG. AC_CHECK_TOOL(AR, ar) AC_CHECK_TOOL(RANLIB, ranlib, :) -# FIXME: We temporarily define our own version of AC_PROG_CC. This is -# copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS. We -# are probably using a cross compiler, which will not be able to fully -# link an executable. This should really be fixed in autoconf -# itself. - -AC_DEFUN(LIB_AC_PROG_CC, -[AC_BEFORE([$0], [AC_PROG_CPP])dnl -AC_PROVIDE([AC_PROG_CC]) -AC_CHECK_PROG(CC, gcc, gcc) -if test -z "$CC"; then - AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc) - test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH]) -fi - -AC_PROG_CC_GNU - -if test $ac_cv_prog_gcc = yes; then - GCC=yes - ac_libiberty_warn_cflags='-W -Wall -Wtraditional' -dnl Check whether -g works, even if CFLAGS is set, in case the package -dnl plays around with CFLAGS (such as to build both debugging and -dnl normal versions of a library), tasteless as that idea is. - ac_test_CFLAGS="${CFLAGS+set}" - ac_save_CFLAGS="$CFLAGS" - CFLAGS= - AC_PROG_CC_G - if test "$ac_test_CFLAGS" = set; then - CFLAGS="$ac_save_CFLAGS" - elif test $ac_cv_prog_cc_g = yes; then - CFLAGS="-g -O2" - else - CFLAGS="-O2" - fi -else - GCC= - ac_libiberty_warn_cflags= - test "${CFLAGS+set}" = set || CFLAGS="-g" -fi -]) -AC_SUBST(ac_libiberty_warn_cflags) - LIB_AC_PROG_CC AC_ISC_POSIX +AC_C_CONST +AC_C_INLINE dnl When we start using libtool: dnl Default to a non shared library. This may be overridden by the @@ -109,8 +69,11 @@ AC_SUBST_FILE(host_makefile_frag) # It's OK to check for header files. Although the compiler may not be # able to link anything, it had better be able to at least compile # something. -AC_CHECK_HEADERS(sys/file.h sys/param.h stdlib.h string.h unistd.h strings.h sys/time.h sys/resource.h sys/stat.h) +AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h) AC_HEADER_SYS_WAIT +AC_HEADER_TIME + +libiberty_AC_DECLARE_ERRNO # This is the list of functions which libiberty will provide if they # are not available on the host. @@ -120,6 +83,7 @@ funcs="$funcs atexit" funcs="$funcs basename" funcs="$funcs bcmp" funcs="$funcs bcopy" +funcs="$funcs bsearch" funcs="$funcs bzero" funcs="$funcs calloc" funcs="$funcs clock" @@ -164,16 +128,16 @@ checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gett # These are neither executed nor required, but they help keep # autoheader happy without adding a bunch of text to acconfig.h. if test "x" = "y"; then - AC_CHECK_FUNCS(asprintf atexit basename bcmp bcopy bzero calloc clock getcwd) - AC_CHECK_FUNCS(getpagesize index insque mkstemps memchr memcmp memcpy memmove) - AC_CHECK_FUNCS(memset putenv random rename rindex sigsetmask strcasecmp) - AC_CHECK_FUNCS(setenv strchr strdup strncasecmp strrchr strstr strtod strtol) - AC_CHECK_FUNCS(strtoul tmpnam vasprintf vfprintf vprintf vsprintf waitpid) - AC_DEFINE(HAVE_SYS_ERRLIST) - AC_DEFINE(HAVE_SYS_NERR) - AC_DEFINE(HAVE_SYS_SIGLIST) - AC_CHECK_FUNCS(getrusage on_exit psignal strerror strsignal sysconf times) - AC_CHECK_FUNCS(sbrk gettimeofday) + AC_CHECK_FUNCS(asprintf atexit basename bcmp bcopy bsearch bzero calloc clock) + AC_CHECK_FUNCS(getcwd getpagesize index insque mkstemps memchr memcmp memcpy) + AC_CHECK_FUNCS(memmove memset putenv random rename rindex sigsetmask) + AC_CHECK_FUNCS(strcasecmp setenv strchr strdup strncasecmp strrchr strstr) + AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf) + AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal) + AC_CHECK_FUNCS(sysconf times sbrk gettimeofday) + AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.]) + AC_DEFINE(HAVE_SYS_NERR, 1, [Define if you have the sys_nerr variable.]) + AC_DEFINE(HAVE_SYS_SIGLIST, 1, [Define if you have the sys_siglist variable.]) fi # For each of these functions, if the host does not provide the @@ -212,7 +176,7 @@ if test -n "${with_target_subdir}"; then # dont have to check them here. # Of the functions in $checkfuncs, newlib only has strerror. - AC_DEFINE(HAVE_STRERROR) + AC_DEFINE_NOAUTOHEADER(HAVE_STRERROR) setobjs=yes @@ -253,7 +217,7 @@ if test -z "${setobjs}"; then # don't have to check them here. # Of the functions in $checkfuncs, VxWorks only has strerror. - AC_DEFINE(HAVE_STRERROR) + AC_DEFINE_NOAUTOHEADER(HAVE_STRERROR) setobjs=yes ;; @@ -277,18 +241,22 @@ if test -z "${setobjs}"; then # provides from our shell variables, so that they appear to be # missing. - funcs="`echo $funcs | sed -e 's/random//'`" - LIBOBJS="$LIBOBJS random.o" - vars="`echo $vars | sed -e 's/sys_siglist//'`" - checkfuncs="`echo $checkfuncs | sed -e 's/strsignal//' -e 's/psignal//'`" + # DJ - only if we're *building* cygwin, not just building *with* cygwin + + if test -n "${with_target_subdir}" + then + funcs="`echo $funcs | sed -e 's/random//'`" + LIBOBJS="$LIBOBJS random.o" + vars="`echo $vars | sed -e 's/sys_siglist//'`" + checkfuncs="`echo $checkfuncs | sed -e 's/strsignal//' -e 's/psignal//'`" + fi ;; *-*-mingw32*) # Under mingw32, sys_nerr and sys_errlist exist, but they are # macros, so the test below won't find them. - vars="`echo $vars | sed -e 's/sys_nerr//' -e 's/sys_errlist//'`" - AC_DEFINE(HAVE_SYS_NERR) - AC_DEFINE(HAVE_SYS_ERRLIST) + libiberty_cv_var_sys_nerr=yes + libiberty_cv_var_sys_errlist=yes ;; *-*-uwin*) @@ -299,8 +267,8 @@ if test -z "${setobjs}"; then # Under uwin 2.0+, sys_nerr and sys_errlist exist, but they are # macros (actually, these are imported from a DLL, but the end effect # is the same), so the test below won't find them. - AC_DEFINE(HAVE_SYS_NERR) - AC_DEFINE(HAVE_SYS_ERRLIST) + libiberty_cv_var_sys_nerr=yes + libiberty_cv_var_sys_errlist=yes ;; esac @@ -352,6 +320,8 @@ EOF AC_CHECK_FUNCS($checkfuncs) fi +libiberty_AC_FUNC_STRNCMP + # Install a library built with a cross compiler in $(tooldir) rather # than $(libdir). if test -z "${with_cross_host}"; then diff --git a/contrib/binutils/libiberty/cp-demangle.c b/contrib/binutils/libiberty/cp-demangle.c index 1eb2402..1cc4847 100644 --- a/contrib/binutils/libiberty/cp-demangle.c +++ b/contrib/binutils/libiberty/cp-demangle.c @@ -1,7 +1,9 @@ -/* Demangler for IA64 / g++ standard C++ ABI. - Copyright (C) 2000 CodeSourcery LLC. +/* Demangler for IA64 / g++ V3 ABI. + Copyright (C) 2000 Free Software Foundation, Inc. Written by Alex Samuel <samuel@codesourcery.com>. + This file is part of GNU CC. + This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or @@ -18,10 +20,11 @@ */ /* This file implements demangling of C++ names mangled according to - the IA64 / g++ standard C++ ABI. Use the cp_demangle function to + the IA64 / g++ V3 ABI. Use the cp_demangle function to demangle a mangled name, or compile with the preprocessor macro STANDALONE_DEMANGLER defined to create a demangling filter - executable. */ + executable (functionally similar to c++filt, but includes this + demangler only). */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -61,6 +64,10 @@ (((CHAR) >= 'a' && (CHAR) <= 'z') \ || ((CHAR) >= 'A' && (CHAR) <= 'Z')) +/* The prefix prepended by GCC to an identifier represnting the + anonymous namespace. */ +#define ANONYMOUS_NAMESPACE_PREFIX "_GLOBAL_" + /* If flag_verbose is zero, some simplifications will be made to the output to make it easier to read and supress details that are generally not of interest to the average C++ programmer. @@ -72,13 +79,22 @@ static int flag_verbose; specification -- don't demangle special g++ manglings. */ static int flag_strict; -/* String_list_t is an extended form of dyn_string_t which provides a link - field. A string_list_t may safely be cast to and used as a - dyn_string_t. */ +/* String_list_t is an extended form of dyn_string_t which provides a + link field and a caret position for additions to the string. A + string_list_t may safely be cast to and used as a dyn_string_t. */ struct string_list_def { + /* The dyn_string; must be first. */ struct dyn_string string; + + /* The position at which additional text is added to this string + (using the result_add* macros). This value is an offset from the + end of the string, not the beginning (and should be + non-positive). */ + int caret_position; + + /* The next string in the list. */ struct string_list_def *next; }; @@ -91,17 +107,10 @@ struct substitution_def /* The demangled text of the substitution. */ dyn_string_t text; - /* The template parameter that this represents, indexed from zero. - If this is not a template paramter number, the value is - NOT_TEMPLATE_PARM. */ - int template_parm_number; - /* Whether this substitution represents a template item. */ int template_p : 1; }; -#define NOT_TEMPLATE_PARM (-1) - /* Data structure representing a template argument list. */ struct template_arg_list_def @@ -172,7 +181,7 @@ typedef const char *status_t; #define STATUS_INTERNAL_ERROR "Internal error." /* This status code indicates a failure in malloc or realloc. */ -static const char* const status_allocation_failed = "Allocation failed."; +static const char *const status_allocation_failed = "Allocation failed."; #define STATUS_ALLOCATION_FAILED status_allocation_failed /* Non-zero if STATUS indicates that no error has occurred. */ @@ -196,8 +205,8 @@ static string_list_t string_list_new PARAMS ((int)); static void string_list_delete PARAMS ((string_list_t)); -static status_t result_close_template_list - PARAMS ((demangling_t)); +static status_t result_add_separated_char + PARAMS ((demangling_t, int)); static status_t result_push PARAMS ((demangling_t)); static string_list_t result_pop @@ -205,7 +214,7 @@ static string_list_t result_pop static int substitution_start PARAMS ((demangling_t)); static status_t substitution_add - PARAMS ((demangling_t, int, int, int)); + PARAMS ((demangling_t, int, int)); static dyn_string_t substitution_get PARAMS ((demangling_t, int, int *)); #ifdef CP_DEMANGLE_DEBUG @@ -272,30 +281,56 @@ static void demangling_delete /* Returns the string containing the current demangled result. */ #define result_string(DM) (&(DM)->result->string) -/* Appends a dyn_string_t to the demangled result. */ -#define result_append_string(DM, STRING) \ - (dyn_string_append (&(DM)->result->string, (STRING)) \ +/* Returns the position at which new text is inserted into the + demangled result. */ +#define result_caret_pos(DM) \ + (result_length (DM) + \ + ((string_list_t) result_string (DM))->caret_position) + +/* Adds a dyn_string_t to the demangled result. */ +#define result_add_string(DM, STRING) \ + (dyn_string_insert (&(DM)->result->string, \ + result_caret_pos (DM), (STRING)) \ + ? STATUS_OK : STATUS_ALLOCATION_FAILED) + +/* Adds NUL-terminated string CSTR to the demangled result. */ +#define result_add(DM, CSTR) \ + (dyn_string_insert_cstr (&(DM)->result->string, \ + result_caret_pos (DM), (CSTR)) \ ? STATUS_OK : STATUS_ALLOCATION_FAILED) -/* Appends NUL-terminated string CSTR to the demangled result. */ -#define result_append(DM, CSTR) \ - (dyn_string_append_cstr (&(DM)->result->string, (CSTR)) \ +/* Adds character CHAR to the demangled result. */ +#define result_add_char(DM, CHAR) \ + (dyn_string_insert_char (&(DM)->result->string, \ + result_caret_pos (DM), (CHAR)) \ ? STATUS_OK : STATUS_ALLOCATION_FAILED) -/* Appends character CHAR to the demangled result. */ -#define result_append_char(DM, CHAR) \ - (dyn_string_append_char (&(DM)->result->string, (CHAR)) \ +/* Inserts a dyn_string_t to the demangled result at position POS. */ +#define result_insert_string(DM, POS, STRING) \ + (dyn_string_insert (&(DM)->result->string, (POS), (STRING)) \ + ? STATUS_OK : STATUS_ALLOCATION_FAILED) + +/* Inserts NUL-terminated string CSTR to the demangled result at + position POS. */ +#define result_insert(DM, POS, CSTR) \ + (dyn_string_insert_cstr (&(DM)->result->string, (POS), (CSTR)) \ + ? STATUS_OK : STATUS_ALLOCATION_FAILED) + +/* Inserts character CHAR to the demangled result at position POS. */ +#define result_insert_char(DM, POS, CHAR) \ + (dyn_string_insert_char (&(DM)->result->string, (POS), (CHAR)) \ ? STATUS_OK : STATUS_ALLOCATION_FAILED) /* The length of the current demangled result. */ #define result_length(DM) \ dyn_string_length (&(DM)->result->string) -/* Appends a space to the demangled result if the last character is - not a space. */ -#define result_append_space(DM) \ - (dyn_string_append_space (&(DM)->result->string) \ - ? STATUS_OK : STATUS_ALLOCATION_FAILED) +/* Appends a (less-than, greater-than) character to the result in DM + to (open, close) a template argument or parameter list. Appends a + space first if necessary to prevent spurious elision of angle + brackets with the previous character. */ +#define result_open_template_list(DM) result_add_separated_char(DM, '<') +#define result_close_template_list(DM) result_add_separated_char(DM, '>') /* Appends a base 10 representation of VALUE to DS. STATUS_OK on success. On failure, deletes DS and returns an error code. */ @@ -357,6 +392,7 @@ string_list_new (length) int length; { string_list_t s = (string_list_t) malloc (sizeof (struct string_list_def)); + s->caret_position = 0; if (s == NULL) return NULL; if (!dyn_string_init ((dyn_string_t) s, length)) @@ -378,29 +414,23 @@ string_list_delete (node) } } -/* Appends a greater-than character to the demangled result. If the - last character is a greater-than character, a space is inserted - first, so that the two greater-than characters don't look like a - right shift token. */ +/* Appends CHARACTER to the demangled result. If the current trailing + character of the result is CHARACTER, a space is inserted first. */ static status_t -result_close_template_list (dm) +result_add_separated_char (dm, character) demangling_t dm; + int character; { - dyn_string_t s = &dm->result->string; + char *result = dyn_string_buf (result_string (dm)); + int caret_pos = result_caret_pos (dm); - /* Add a space if the last character is already a closing angle - bracket, so that a nested template arg list doesn't look like - it's closed with a right-shift operator. */ - if (dyn_string_last_char (s) == '>') - { - if (!dyn_string_append_char (s, ' ')) - return STATUS_ALLOCATION_FAILED; - } - - /* Add closing angle brackets. */ - if (!dyn_string_append_char (s, '>')) - return STATUS_ALLOCATION_FAILED; + /* Add a space if the last character is already the character we + want to add. */ + if (caret_pos > 0 && result[caret_pos - 1] == character) + RETURN_IF_ERROR (result_add_char (dm, ' ')); + /* Add the character. */ + RETURN_IF_ERROR (result_add_char (dm, character)); return STATUS_OK; } @@ -438,6 +468,51 @@ result_pop (dm) return top; } +/* Returns the current value of the caret for the result string. The + value is an offet from the end of the result string. */ + +static int +result_get_caret (dm) + demangling_t dm; +{ + return ((string_list_t) result_string (dm))->caret_position; +} + +/* Sets the value of the caret for the result string, counted as an + offet from the end of the result string. */ + +static void +result_set_caret (dm, position) + demangling_t dm; + int position; +{ + ((string_list_t) result_string (dm))->caret_position = position; +} + +/* Shifts the position of the next addition to the result by + POSITION_OFFSET. A negative value shifts the caret to the left. */ + +static void +result_shift_caret (dm, position_offset) + demangling_t dm; + int position_offset; +{ + ((string_list_t) result_string (dm))->caret_position += position_offset; +} + +/* Returns non-zero if the character that comes right before the place + where text will be added to the result is a space. In this case, + the caller should supress adding another space. */ + +static int +result_previous_char_is_space (dm) + demangling_t dm; +{ + char *result = dyn_string_buf (result_string (dm)); + int pos = result_caret_pos (dm); + return pos > 0 && result[pos - 1] == ' '; +} + /* Returns the start position of a fragment of the demangled result that will be a substitution candidate. Should be called at the start of productions that can add substitutions. */ @@ -446,24 +521,18 @@ static int substitution_start (dm) demangling_t dm; { - return result_length (dm); + return result_caret_pos (dm); } /* Adds the suffix of the current demangled result of DM starting at START_POSITION as a potential substitution. If TEMPLATE_P is - non-zero, this potential substitution is a template-id. - - If TEMPLATE_PARM_NUMBER is not NOT_TEMPLATE_PARM, the substitution - is for that particular <template-param>, and is distinct from other - otherwise-identical types and other <template-param>s with - different indices. */ + non-zero, this potential substitution is a template-id. */ static status_t -substitution_add (dm, start_position, template_p, template_parm_number) +substitution_add (dm, start_position, template_p) demangling_t dm; int start_position; int template_p; - int template_parm_number; { dyn_string_t result = result_string (dm); dyn_string_t substitution = dyn_string_new (0); @@ -475,29 +544,20 @@ substitution_add (dm, start_position, template_p, template_parm_number) /* Extract the substring of the current demangling result that represents the subsitution candidate. */ if (!dyn_string_substring (substitution, - result, start_position, result_length (dm))) + result, start_position, result_caret_pos (dm))) { dyn_string_delete (substitution); return STATUS_ALLOCATION_FAILED; } - /* Check whether SUBSTITUTION already occurs. */ - for (i = 0; i < dm->num_substitutions; ++i) - if (dyn_string_eq (dm->substitutions[i].text, substitution) - && dm->substitutions[i].template_parm_number == template_parm_number) - /* Found SUBSTITUTION already present. */ - { - /* Callers expect this function to take ownership of - SUBSTITUTION, so delete it. */ - dyn_string_delete (substitution); - return STATUS_OK; - } - /* If there's no room for the new entry, grow the array. */ if (dm->substitutions_allocated == dm->num_substitutions) { size_t new_array_size; - dm->substitutions_allocated *= 2; + if (dm->substitutions_allocated > 0) + dm->substitutions_allocated *= 2; + else + dm->substitutions_allocated = 2; new_array_size = sizeof (struct substitution_def) * dm->substitutions_allocated; @@ -512,10 +572,9 @@ substitution_add (dm, start_position, template_p, template_parm_number) } /* Add the substitution to the array. */ + i = dm->num_substitutions++; dm->substitutions[i].text = substitution; dm->substitutions[i].template_p = template_p; - dm->substitutions[i].template_parm_number = template_parm_number; - ++dm->num_substitutions; #ifdef CP_DEMANGLE_DEBUG substitutions_print (dm, stderr); @@ -801,7 +860,7 @@ static status_t demangle_nested_name static status_t demangle_prefix PARAMS ((demangling_t, int *)); static status_t demangle_unqualified_name - PARAMS ((demangling_t)); + PARAMS ((demangling_t, int *)); static status_t demangle_source_name PARAMS ((demangling_t)); static status_t demangle_number @@ -812,12 +871,18 @@ static status_t demangle_identifier PARAMS ((demangling_t, int, dyn_string_t)); static status_t demangle_operator_name PARAMS ((demangling_t, int, int *)); +static status_t demangle_nv_offset + PARAMS ((demangling_t)); +static status_t demangle_v_offset + PARAMS ((demangling_t)); +static status_t demangle_call_offset + PARAMS ((demangling_t)); static status_t demangle_special_name PARAMS ((demangling_t)); static status_t demangle_ctor_dtor_name PARAMS ((demangling_t)); static status_t demangle_type_ptr - PARAMS ((demangling_t)); + PARAMS ((demangling_t, int *, int)); static status_t demangle_type PARAMS ((demangling_t)); static status_t demangle_CV_qualifiers @@ -825,15 +890,15 @@ static status_t demangle_CV_qualifiers static status_t demangle_builtin_type PARAMS ((demangling_t)); static status_t demangle_function_type - PARAMS ((demangling_t, int)); + PARAMS ((demangling_t, int *)); static status_t demangle_bare_function_type - PARAMS ((demangling_t, int)); + PARAMS ((demangling_t, int *)); static status_t demangle_class_enum_type PARAMS ((demangling_t, int *)); static status_t demangle_array_type - PARAMS ((demangling_t)); -static status_t demangle_template_param PARAMS ((demangling_t, int *)); +static status_t demangle_template_param + PARAMS ((demangling_t)); static status_t demangle_template_args PARAMS ((demangling_t)); static status_t demangle_literal @@ -847,19 +912,21 @@ static status_t demangle_scope_expression static status_t demangle_expr_primary PARAMS ((demangling_t)); static status_t demangle_substitution - PARAMS ((demangling_t, int *, int *)); + PARAMS ((demangling_t, int *)); static status_t demangle_local_name PARAMS ((demangling_t)); static status_t demangle_discriminator PARAMS ((demangling_t, int)); static status_t cp_demangle PARAMS ((const char *, dyn_string_t)); +#ifdef IN_LIBGCC2 static status_t cp_demangle_type PARAMS ((const char*, dyn_string_t)); +#endif /* When passed to demangle_bare_function_type, indicates that the function's return type is not encoded before its parameter types. */ -#define BFT_NO_RETURN_TYPE -1 +#define BFT_NO_RETURN_TYPE NULL /* Check that the next character is C. If so, consume it. If not, return an error. */ @@ -910,7 +977,7 @@ static status_t demangle_encoding (dm) demangling_t dm; { - int template_p; + int encode_return_type; int start_position; template_arg_list_t old_arg_list = current_template_arg_list (dm); char peek = peek_char (dm); @@ -919,25 +986,25 @@ demangle_encoding (dm) /* Remember where the name starts. If it turns out to be a template function, we'll have to insert the return type here. */ - start_position = result_length (dm); + start_position = result_caret_pos (dm); if (peek == 'G' || peek == 'T') RETURN_IF_ERROR (demangle_special_name (dm)); else { /* Now demangle the name. */ - RETURN_IF_ERROR (demangle_name (dm, &template_p)); + RETURN_IF_ERROR (demangle_name (dm, &encode_return_type)); /* If there's anything left, the name was a function name, with - maybe its return type, and its parameters types, following. */ + maybe its return type, and its parameter types, following. */ if (!end_of_name_p (dm) && peek_char (dm) != 'E') { - if (template_p) + if (encode_return_type) /* Template functions have their return type encoded. The return type should be inserted at start_position. */ RETURN_IF_ERROR - (demangle_bare_function_type (dm, start_position)); + (demangle_bare_function_type (dm, &start_position)); else /* Non-template functions don't have their return type encoded. */ @@ -968,24 +1035,32 @@ demangle_encoding (dm) ::= <substitution> */ static status_t -demangle_name (dm, template_p) +demangle_name (dm, encode_return_type) demangling_t dm; - int *template_p; + int *encode_return_type; { - int special_std_substitution; int start = substitution_start (dm); + char peek = peek_char (dm); + int is_std_substitution = 0; + + /* Generally, the return type is encoded if the function is a + template-id, and suppressed otherwise. There are a few cases, + though, in which the return type is not encoded even for a + templated function. In these cases, this flag is set. */ + int suppress_return_type = 0; DEMANGLE_TRACE ("name", dm); - switch (peek_char (dm)) + switch (peek) { case 'N': /* This is a <nested-name>. */ - RETURN_IF_ERROR (demangle_nested_name (dm, template_p)); + RETURN_IF_ERROR (demangle_nested_name (dm, encode_return_type)); break; case 'Z': RETURN_IF_ERROR (demangle_local_name (dm)); + *encode_return_type = 0; break; case 'S': @@ -995,49 +1070,46 @@ demangle_name (dm, template_p) { (void) next_char (dm); (void) next_char (dm); - RETURN_IF_ERROR (result_append (dm, "std::")); - RETURN_IF_ERROR (demangle_unqualified_name (dm)); + RETURN_IF_ERROR (result_add (dm, "std::")); + RETURN_IF_ERROR + (demangle_unqualified_name (dm, &suppress_return_type)); + is_std_substitution = 1; } else - { - RETURN_IF_ERROR (demangle_substitution (dm, template_p, - &special_std_substitution)); - if (special_std_substitution) - { - /* This was the magic `std::' substitution. We can have - a <nested-name> or one of the unscoped names - following. */ - RETURN_IF_ERROR (result_append (dm, "::")); - RETURN_IF_ERROR (demangle_name (dm, template_p)); - } - } + RETURN_IF_ERROR (demangle_substitution (dm, encode_return_type)); /* Check if a template argument list immediately follows. If so, then we just demangled an <unqualified-template-name>. */ if (peek_char (dm) == 'I') { - RETURN_IF_ERROR (substitution_add (dm, start, 0, - NOT_TEMPLATE_PARM)); + /* A template name of the form std::<unqualified-name> is a + substitution candidate. */ + if (is_std_substitution) + RETURN_IF_ERROR (substitution_add (dm, start, 0)); + /* Demangle the <template-args> here. */ RETURN_IF_ERROR (demangle_template_args (dm)); + *encode_return_type = !suppress_return_type; } + else + *encode_return_type = 0; + break; default: /* This is an <unscoped-name> or <unscoped-template-name>. */ - RETURN_IF_ERROR (demangle_unqualified_name (dm)); + RETURN_IF_ERROR (demangle_unqualified_name (dm, &suppress_return_type)); /* If the <unqualified-name> is followed by template args, this is an <unscoped-template-name>. */ if (peek_char (dm) == 'I') { /* Add a substitution for the unqualified template name. */ - RETURN_IF_ERROR (substitution_add (dm, start, 0, - NOT_TEMPLATE_PARM)); + RETURN_IF_ERROR (substitution_add (dm, start, 0)); RETURN_IF_ERROR (demangle_template_args (dm)); - *template_p = 1; + *encode_return_type = !suppress_return_type; } else - *template_p = 0; + *encode_return_type = 0; break; } @@ -1047,12 +1119,12 @@ demangle_name (dm, template_p) /* Demangles and emits a <nested-name>. - <nested-name> ::= N [<CV-qualifiers>] <prefix> <component> E */ + <nested-name> ::= N [<CV-qualifiers>] <prefix> <unqulified-name> E */ static status_t -demangle_nested_name (dm, template_p) +demangle_nested_name (dm, encode_return_type) demangling_t dm; - int *template_p; + int *encode_return_type; { char peek; @@ -1063,23 +1135,33 @@ demangle_nested_name (dm, template_p) peek = peek_char (dm); if (peek == 'r' || peek == 'V' || peek == 'K') { + dyn_string_t cv_qualifiers; status_t status; - /* Snarf up and emit CV qualifiers. */ - dyn_string_t cv_qualifiers = dyn_string_new (24); + /* Snarf up CV qualifiers. */ + cv_qualifiers = dyn_string_new (24); if (cv_qualifiers == NULL) return STATUS_ALLOCATION_FAILED; - demangle_CV_qualifiers (dm, cv_qualifiers); - status = result_append_string (dm, cv_qualifiers); + + /* Emit them, preceded by a space. */ + status = result_add_char (dm, ' '); + if (STATUS_NO_ERROR (status)) + status = result_add_string (dm, cv_qualifiers); + /* The CV qualifiers that occur in a <nested-name> will be + qualifiers for member functions. These are placed at the end + of the function. Therefore, shift the caret to the left by + the length of the qualifiers, so other text is inserted + before them and they stay at the end. */ + result_shift_caret (dm, -dyn_string_length (cv_qualifiers) - 1); + /* Clean up. */ dyn_string_delete (cv_qualifiers); RETURN_IF_ERROR (status); - RETURN_IF_ERROR (result_append_space (dm)); } - - RETURN_IF_ERROR (demangle_prefix (dm, template_p)); - /* No need to demangle the final <component>; demangle_prefix will - handle it. */ + + RETURN_IF_ERROR (demangle_prefix (dm, encode_return_type)); + /* No need to demangle the final <unqualified-name>; demangle_prefix + will handle it. */ RETURN_IF_ERROR (demangle_char (dm, 'E')); return STATUS_OK; @@ -1087,41 +1169,52 @@ demangle_nested_name (dm, template_p) /* Demangles and emits a <prefix>. - <prefix> ::= <prefix> <component> + <prefix> ::= <prefix> <unqualified-name> ::= <template-prefix> <template-args> ::= # empty ::= <substitution> <template-prefix> ::= <prefix> - ::= <substitution> - - <component> ::= <unqualified-name> - ::= <local-name> */ + ::= <substitution> */ static status_t -demangle_prefix (dm, template_p) +demangle_prefix (dm, encode_return_type) demangling_t dm; - int *template_p; + int *encode_return_type; { int start = substitution_start (dm); int nested = 0; - /* TEMPLATE_P is updated as we decend the nesting chain. After - <template-args>, it is set to non-zero; after everything else it - is set to zero. */ + /* ENCODE_RETURN_TYPE is updated as we decend the nesting chain. + After <template-args>, it is set to non-zero; after everything + else it is set to zero. */ + + /* Generally, the return type is encoded if the function is a + template-id, and suppressed otherwise. There are a few cases, + though, in which the return type is not encoded even for a + templated function. In these cases, this flag is set. */ + int suppress_return_type = 0; DEMANGLE_TRACE ("prefix", dm); while (1) { char peek; - int unused; if (end_of_name_p (dm)) return "Unexpected end of name in <compound-name>."; peek = peek_char (dm); + /* We'll initialize suppress_return_type to false, and set it to true + if we end up demangling a constructor name. However, make + sure we're not actually about to demangle template arguments + -- if so, this is the <template-args> following a + <template-prefix>, so we'll want the previous flag value + around. */ + if (peek != 'I') + suppress_return_type = 0; + if (IS_DIGIT ((unsigned char) peek) || (peek >= 'a' && peek <= 'z') || peek == 'C' || peek == 'D' @@ -1129,31 +1222,36 @@ demangle_prefix (dm, template_p) { /* We have another level of scope qualification. */ if (nested) - RETURN_IF_ERROR (result_append (dm, "::")); + RETURN_IF_ERROR (result_add (dm, "::")); else nested = 1; if (peek == 'S') /* The substitution determines whether this is a - template-id. */ - RETURN_IF_ERROR (demangle_substitution (dm, template_p, - &unused)); + template-id. */ + RETURN_IF_ERROR (demangle_substitution (dm, encode_return_type)); else { - RETURN_IF_ERROR (demangle_unqualified_name (dm)); - *template_p = 0; + /* It's just a name. */ + RETURN_IF_ERROR + (demangle_unqualified_name (dm, &suppress_return_type)); + *encode_return_type = 0; } } else if (peek == 'Z') RETURN_IF_ERROR (demangle_local_name (dm)); else if (peek == 'I') { - if (*template_p) - return STATUS_INTERNAL_ERROR; - /* The template name is a substitution candidate. */ - RETURN_IF_ERROR (substitution_add (dm, start, 0, NOT_TEMPLATE_PARM)); RETURN_IF_ERROR (demangle_template_args (dm)); - *template_p = 1; + + /* Now we want to indicate to the caller that we've + demangled template arguments, thus the prefix was a + <template-prefix>. That's so that the caller knows to + demangle the function's return type, if this turns out to + be a function name. But, if it's a member template + constructor or a templated conversion operator, report it + as untemplated. Those never get encoded return types. */ + *encode_return_type = !suppress_return_type; } else if (peek == 'E') /* All done. */ @@ -1161,38 +1259,56 @@ demangle_prefix (dm, template_p) else return "Unexpected character in <compound-name>."; - /* Add a new substitution for the prefix thus far. */ - RETURN_IF_ERROR (substitution_add (dm, start, *template_p, - NOT_TEMPLATE_PARM)); + if (peek != 'S' + && peek_char (dm) != 'E') + /* Add a new substitution for the prefix thus far. */ + RETURN_IF_ERROR (substitution_add (dm, start, *encode_return_type)); } } -/* Demangles and emits an <unqualified-name>. If the - <unqualified-name> is a function and the first element in the - argument list should be taken to be its return type, - ENCODE_RETURN_TYPE is non-zero. +/* Demangles and emits an <unqualified-name>. If this + <unqualified-name> is for a special function type that should never + have its return type encoded (particularly, a constructor or + conversion operator), *SUPPRESS_RETURN_TYPE is set to 1; otherwise, + it is set to zero. <unqualified-name> ::= <operator-name> ::= <special-name> ::= <source-name> */ static status_t -demangle_unqualified_name (dm) +demangle_unqualified_name (dm, suppress_return_type) demangling_t dm; + int *suppress_return_type; { char peek = peek_char (dm); DEMANGLE_TRACE ("unqualified-name", dm); + /* By default, don't force suppression of the return type (though + non-template functions still don't get a return type encoded). */ + *suppress_return_type = 0; + if (IS_DIGIT ((unsigned char) peek)) RETURN_IF_ERROR (demangle_source_name (dm)); else if (peek >= 'a' && peek <= 'z') { int num_args; + + /* Conversion operators never have a return type encoded. */ + if (peek == 'c' && peek_char_next (dm) == 'v') + *suppress_return_type = 1; + RETURN_IF_ERROR (demangle_operator_name (dm, 0, &num_args)); } else if (peek == 'C' || peek == 'D') - RETURN_IF_ERROR (demangle_ctor_dtor_name (dm)); + { + /* Constructors never have a return type encoded. */ + if (peek == 'C') + *suppress_return_type = 1; + + RETURN_IF_ERROR (demangle_ctor_dtor_name (dm)); + } else return "Unexpected character in <unqualified-name>."; @@ -1222,7 +1338,7 @@ demangle_source_name (dm) dm->last_source_name)); /* Emit it. */ - RETURN_IF_ERROR (result_append_string (dm, dm->last_source_name)); + RETURN_IF_ERROR (result_add_string (dm, dm->last_source_name)); return STATUS_OK; } @@ -1330,6 +1446,29 @@ demangle_identifier (dm, length, identifier) return STATUS_ALLOCATION_FAILED; } + /* GCC encodes anonymous namespaces using a `_GLOBAL_[_.$]N.' + followed by the source file name and some random characters. + Unless we're in strict mode, decipher these names appropriately. */ + if (!flag_strict) + { + char *name = dyn_string_buf (identifier); + int prefix_length = strlen (ANONYMOUS_NAMESPACE_PREFIX); + + /* Compare the first, fixed part. */ + if (strncmp (name, ANONYMOUS_NAMESPACE_PREFIX, prefix_length) == 0) + { + name += prefix_length; + /* The next character might be a period, an underscore, or + dollar sign, depending on the target architecture's + assembler's capabilities. After that comes an `N'. */ + if ((*name == '.' || *name == '_' || *name == '$') + && *(name + 1) == 'N') + /* This looks like the anonymous namespace identifier. + Replace it with something comprehensible. */ + dyn_string_copy_cstr (identifier, "(anonymous namespace)"); + } + } + return STATUS_OK; } @@ -1388,7 +1527,7 @@ demangle_identifier (dm, length, identifier) ::= qu # ? ::= sz # sizeof ::= cv <type> # cast - ::= vx <source-name> # vendor extended operator */ + ::= v [0-9] <source-name> # vendor extended operator */ static status_t demangle_operator_name (dm, short_name, num_args) @@ -1449,6 +1588,7 @@ demangle_operator_name (dm, short_name, num_args) { "pm", "->*" , 2 }, { "pp", "++" , 1 }, { "ps", "+" , 1 }, + { "pt", "->" , 2 }, { "qu", "?" , 3 }, { "rM", "%=" , 2 }, { "rS", ">>=" , 2 }, @@ -1467,10 +1607,10 @@ demangle_operator_name (dm, short_name, num_args) DEMANGLE_TRACE ("operator-name", dm); - /* Is this a vendor extended operator? */ - if (c0 == 'v' && c1 == 'x') + /* Is this a vendor-extended operator? */ + if (c0 == 'v' && IS_DIGIT (c1)) { - RETURN_IF_ERROR (result_append (dm, "operator")); + RETURN_IF_ERROR (result_add (dm, "operator ")); RETURN_IF_ERROR (demangle_source_name (dm)); *num_args = 0; return STATUS_OK; @@ -1479,7 +1619,7 @@ demangle_operator_name (dm, short_name, num_args) /* Is this a conversion operator? */ if (c0 == 'c' && c1 == 'v') { - RETURN_IF_ERROR (result_append (dm, "operator ")); + RETURN_IF_ERROR (result_add (dm, "operator ")); /* Demangle the converted-to type. */ RETURN_IF_ERROR (demangle_type (dm)); *num_args = 0; @@ -1497,8 +1637,8 @@ demangle_operator_name (dm, short_name, num_args) /* Found it. */ { if (!short_name) - RETURN_IF_ERROR (result_append (dm, "operator")); - RETURN_IF_ERROR (result_append (dm, p->name)); + RETURN_IF_ERROR (result_add (dm, "operator")); + RETURN_IF_ERROR (result_add (dm, p->name)); *num_args = p->num_args; return STATUS_OK; @@ -1516,22 +1656,157 @@ demangle_operator_name (dm, short_name, num_args) } } +/* Demangles and omits an <nv-offset>. + + <nv-offset> ::= <offset number> # non-virtual base override */ + +static status_t +demangle_nv_offset (dm) + demangling_t dm; +{ + dyn_string_t number; + status_t status = STATUS_OK; + + DEMANGLE_TRACE ("h-offset", dm); + + /* Demangle the offset. */ + number = dyn_string_new (4); + if (number == NULL) + return STATUS_ALLOCATION_FAILED; + demangle_number_literally (dm, number, 10, 1); + + /* Don't display the offset unless in verbose mode. */ + if (flag_verbose) + { + status = result_add (dm, " [nv:"); + if (STATUS_NO_ERROR (status)) + status = result_add_string (dm, number); + if (STATUS_NO_ERROR (status)) + status = result_add_char (dm, ']'); + } + + /* Clean up. */ + dyn_string_delete (number); + RETURN_IF_ERROR (status); + return STATUS_OK; +} + +/* Demangles and emits a <v-offset>. + + <v-offset> ::= <offset number> _ <virtual offset number> + # virtual base override, with vcall offset */ + +static status_t +demangle_v_offset (dm) + demangling_t dm; +{ + dyn_string_t number; + status_t status = STATUS_OK; + + DEMANGLE_TRACE ("v-offset", dm); + + /* Demangle the offset. */ + number = dyn_string_new (4); + if (number == NULL) + return STATUS_ALLOCATION_FAILED; + demangle_number_literally (dm, number, 10, 1); + + /* Don't display the offset unless in verbose mode. */ + if (flag_verbose) + { + status = result_add (dm, " [v:"); + if (STATUS_NO_ERROR (status)) + status = result_add_string (dm, number); + if (STATUS_NO_ERROR (status)) + result_add_char (dm, ','); + } + dyn_string_delete (number); + RETURN_IF_ERROR (status); + + /* Demangle the separator. */ + RETURN_IF_ERROR (demangle_char (dm, '_')); + + /* Demangle the vcall offset. */ + number = dyn_string_new (4); + if (number == NULL) + return STATUS_ALLOCATION_FAILED; + demangle_number_literally (dm, number, 10, 1); + + /* Don't display the vcall offset unless in verbose mode. */ + if (flag_verbose) + { + status = result_add_string (dm, number); + if (STATUS_NO_ERROR (status)) + status = result_add_char (dm, ']'); + } + dyn_string_delete (number); + RETURN_IF_ERROR (status); + + return STATUS_OK; +} + +/* Demangles and emits a <call-offset>. + + <call-offset> ::= h <nv-offset> _ + ::= v <v-offset> _ */ + +static status_t +demangle_call_offset (dm) + demangling_t dm; +{ + DEMANGLE_TRACE ("call-offset", dm); + + switch (peek_char (dm)) + { + case 'h': + advance_char (dm); + /* Demangle the offset. */ + RETURN_IF_ERROR (demangle_nv_offset (dm)); + /* Demangle the separator. */ + RETURN_IF_ERROR (demangle_char (dm, '_')); + break; + + case 'v': + advance_char (dm); + /* Demangle the offset. */ + RETURN_IF_ERROR (demangle_v_offset (dm)); + /* Demangle the separator. */ + RETURN_IF_ERROR (demangle_char (dm, '_')); + break; + + default: + return "Unrecognized <call-offset>."; + } + + return STATUS_OK; +} + /* Demangles and emits a <special-name>. <special-name> ::= GV <object name> # Guard variable - ::= Th[n] <offset number> _ <base name> <base encoding> - # non-virtual base override thunk - ::= Tv[n] <offset number> _ <vcall offset number> - _ <base encoding> - # virtual base override thunk ::= TV <type> # virtual table ::= TT <type> # VTT ::= TI <type> # typeinfo structure ::= TS <type> # typeinfo name + Other relevant productions include thunks: + + <special-name> ::= T <call-offset> <base encoding> + # base is the nominal target function of thunk + + <special-name> ::= Tc <call-offset> <call-offset> <base encoding> + # base is the nominal target function of thunk + # first call-offset is 'this' adjustment + # second call-offset is result adjustment + + where + + <call-offset> ::= h <nv-offset> _ + ::= v <v-offset> _ + Also demangles the special g++ manglings, - <special-name> ::= CT <type> <offset number> _ <base type> + <special-name> ::= TC <type> <offset number> _ <base type> # construction vtable ::= TF <type> # typeinfo function (old ABI only) ::= TJ <type> # java Class structure */ @@ -1551,7 +1826,7 @@ demangle_special_name (dm) /* A guard variable name. Consume the G. */ advance_char (dm); RETURN_IF_ERROR (demangle_char (dm, 'V')); - RETURN_IF_ERROR (result_append (dm, "guard variable for ")); + RETURN_IF_ERROR (result_add (dm, "guard variable for ")); RETURN_IF_ERROR (demangle_name (dm, &unused)); } else if (peek == 'T') @@ -1566,108 +1841,77 @@ demangle_special_name (dm) case 'V': /* Virtual table. */ advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "vtable for ")); + RETURN_IF_ERROR (result_add (dm, "vtable for ")); RETURN_IF_ERROR (demangle_type (dm)); break; case 'T': /* VTT structure. */ advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "VTT for ")); + RETURN_IF_ERROR (result_add (dm, "VTT for ")); RETURN_IF_ERROR (demangle_type (dm)); break; case 'I': /* Typeinfo structure. */ advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "typeinfo for ")); + RETURN_IF_ERROR (result_add (dm, "typeinfo for ")); RETURN_IF_ERROR (demangle_type (dm)); break; case 'F': /* Typeinfo function. Used only in old ABI with new mangling. */ advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "typeinfo fn for ")); + RETURN_IF_ERROR (result_add (dm, "typeinfo fn for ")); RETURN_IF_ERROR (demangle_type (dm)); break; case 'S': /* Character string containing type name, used in typeinfo. */ advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "typeinfo name for ")); + RETURN_IF_ERROR (result_add (dm, "typeinfo name for ")); RETURN_IF_ERROR (demangle_type (dm)); break; case 'J': /* The java Class variable corresponding to a C++ class. */ advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "java Class for ")); + RETURN_IF_ERROR (result_add (dm, "java Class for ")); RETURN_IF_ERROR (demangle_type (dm)); break; case 'h': /* Non-virtual thunk. */ advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "non-virtual thunk")); - /* Demangle and emit the offset. */ - number = dyn_string_new (4); - if (number == NULL) - return STATUS_ALLOCATION_FAILED; - demangle_number_literally (dm, number, 10, 1); - /* Don't display the offset unless in verbose mode. */ - if (flag_verbose) - { - status = result_append_char (dm, ' '); - if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, number); - } - dyn_string_delete (number); - RETURN_IF_ERROR (status); + RETURN_IF_ERROR (result_add (dm, "non-virtual thunk")); + RETURN_IF_ERROR (demangle_nv_offset (dm)); /* Demangle the separator. */ RETURN_IF_ERROR (demangle_char (dm, '_')); /* Demangle and emit the target name and function type. */ - RETURN_IF_ERROR (result_append (dm, " to ")); + RETURN_IF_ERROR (result_add (dm, " to ")); RETURN_IF_ERROR (demangle_encoding (dm)); break; case 'v': /* Virtual thunk. */ advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "virtual thunk ")); - /* Demangle and emit the offset. */ - number = dyn_string_new (4); - if (number == NULL) - return STATUS_ALLOCATION_FAILED; - demangle_number_literally (dm, number, 10, 1); - /* Don't display the offset unless in verbose mode. */ - if (flag_verbose) - { - status = result_append_string (dm, number); - if (STATUS_NO_ERROR (status)) - result_append_char (dm, ' '); - } - dyn_string_delete (number); - RETURN_IF_ERROR (status); - /* Demangle the separator. */ - RETURN_IF_ERROR (demangle_char (dm, '_')); - /* Demangle and emit the vcall offset. */ - number = dyn_string_new (4); - if (number == NULL) - return STATUS_ALLOCATION_FAILED; - demangle_number_literally (dm, number, 10, 1); - /* Don't display the vcall offset unless in verbose mode. */ - if (flag_verbose) - { - status = result_append_string (dm, number); - if (STATUS_NO_ERROR (status)) - status = result_append_char (dm, ' '); - } - dyn_string_delete (number); - RETURN_IF_ERROR (status); + RETURN_IF_ERROR (result_add (dm, "virtual thunk")); + RETURN_IF_ERROR (demangle_v_offset (dm)); /* Demangle the separator. */ RETURN_IF_ERROR (demangle_char (dm, '_')); /* Demangle and emit the target function. */ - RETURN_IF_ERROR (result_append (dm, "to ")); + RETURN_IF_ERROR (result_add (dm, " to ")); + RETURN_IF_ERROR (demangle_encoding (dm)); + break; + + case 'c': + /* Covariant return thunk. */ + advance_char (dm); + RETURN_IF_ERROR (result_add (dm, "covariant return thunk")); + RETURN_IF_ERROR (demangle_call_offset (dm)); + RETURN_IF_ERROR (demangle_call_offset (dm)); + /* Demangle and emit the target function. */ + RETURN_IF_ERROR (result_add (dm, " to ")); RETURN_IF_ERROR (demangle_encoding (dm)); break; @@ -1678,7 +1922,7 @@ demangle_special_name (dm) dyn_string_t derived_type; advance_char (dm); - RETURN_IF_ERROR (result_append (dm, "construction vtable for ")); + RETURN_IF_ERROR (result_add (dm, "construction vtable for ")); /* Demangle the derived type off to the side. */ RETURN_IF_ERROR (result_push (dm)); @@ -1702,17 +1946,17 @@ demangle_special_name (dm) /* Emit the derived type. */ if (STATUS_NO_ERROR (status)) - status = result_append (dm, "-in-"); + status = result_add (dm, "-in-"); if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, derived_type); + status = result_add_string (dm, derived_type); dyn_string_delete (derived_type); /* Don't display the offset unless in verbose mode. */ if (flag_verbose) { - status = result_append_char (dm, ' '); + status = result_add_char (dm, ' '); if (STATUS_NO_ERROR (status)) - result_append_string (dm, number); + result_add_string (dm, number); } dyn_string_delete (number); RETURN_IF_ERROR (status); @@ -1736,7 +1980,6 @@ demangle_special_name (dm) ::= C1 # complete object (in-charge) ctor ::= C2 # base object (not-in-charge) ctor ::= C3 # complete object (in-charge) allocating ctor - ::= C4 # base object (not-in-charge) allocating ctor ::= D0 # deleting (in-charge) dtor ::= D1 # complete object (in-charge) dtor ::= D2 # base object (not-in-charge) dtor */ @@ -1749,8 +1992,7 @@ demangle_ctor_dtor_name (dm) { "in-charge", "not-in-charge", - "in-charge allocating", - "not-in-charge allocating" + "allocating" }; static const char *const dtor_flavors[] = { @@ -1768,16 +2010,16 @@ demangle_ctor_dtor_name (dm) { /* A constructor name. Consume the C. */ advance_char (dm); - if (peek_char (dm) < '1' || peek_char (dm) > '4') + if (peek_char (dm) < '1' || peek_char (dm) > '3') return "Unrecognized constructor."; - RETURN_IF_ERROR (result_append_string (dm, dm->last_source_name)); + RETURN_IF_ERROR (result_add_string (dm, dm->last_source_name)); /* Print the flavor of the constructor if in verbose mode. */ flavor = next_char (dm) - '1'; if (flag_verbose) { - RETURN_IF_ERROR (result_append (dm, "[")); - RETURN_IF_ERROR (result_append (dm, ctor_flavors[flavor])); - RETURN_IF_ERROR (result_append_char (dm, ']')); + RETURN_IF_ERROR (result_add (dm, "[")); + RETURN_IF_ERROR (result_add (dm, ctor_flavors[flavor])); + RETURN_IF_ERROR (result_add_char (dm, ']')); } } else if (peek == 'D') @@ -1786,15 +2028,15 @@ demangle_ctor_dtor_name (dm) advance_char (dm); if (peek_char (dm) < '0' || peek_char (dm) > '2') return "Unrecognized destructor."; - RETURN_IF_ERROR (result_append_char (dm, '~')); - RETURN_IF_ERROR (result_append_string (dm, dm->last_source_name)); + RETURN_IF_ERROR (result_add_char (dm, '~')); + RETURN_IF_ERROR (result_add_string (dm, dm->last_source_name)); /* Print the flavor of the destructor if in verbose mode. */ flavor = next_char (dm) - '0'; if (flag_verbose) { - RETURN_IF_ERROR (result_append (dm, " [")); - RETURN_IF_ERROR (result_append (dm, dtor_flavors[flavor])); - RETURN_IF_ERROR (result_append_char (dm, ']')); + RETURN_IF_ERROR (result_add (dm, " [")); + RETURN_IF_ERROR (result_add (dm, dtor_flavors[flavor])); + RETURN_IF_ERROR (result_add_char (dm, ']')); } } else @@ -1810,6 +2052,19 @@ demangle_ctor_dtor_name (dm) a pointer to data or pointer to function to construct the right output syntax. C++'s pointer syntax is hairy. + This function adds substitution candidates for every nested + pointer/reference type it processes, including the outermost, final + type, assuming the substitution starts at SUBSTITUTION_START in the + demangling result. For example, if this function demangles + `PP3Foo', it will add a substitution for `Foo', `Foo*', and + `Foo**', in that order. + + *INSERT_POS is a quantity used internally, when this function calls + itself recursively, to figure out where to insert pointer + punctuation on the way up. On entry to this function, INSERT_POS + should point to a temporary value, but that value need not be + initialized. + <type> ::= P <type> ::= R <type> ::= <pointer-to-member-type> @@ -1817,105 +2072,152 @@ demangle_ctor_dtor_name (dm) <pointer-to-member-type> ::= M </class/ type> </member/ type> */ static status_t -demangle_type_ptr (dm) +demangle_type_ptr (dm, insert_pos, substitution_start) demangling_t dm; + int *insert_pos; + int substitution_start; { - char next; status_t status; - - /* Collect pointer symbols into this string. */ - dyn_string_t symbols = dyn_string_new (10); + int is_substitution_candidate = 1; DEMANGLE_TRACE ("type*", dm); - if (symbols == NULL) - return STATUS_ALLOCATION_FAILED; - /* Scan forward, collecting pointers and references into symbols, until we hit something else. Then emit the type. */ - while (1) + switch (peek_char (dm)) { - next = peek_char (dm); - if (next == 'P') - { - if (!dyn_string_append_char (symbols, '*')) - return STATUS_ALLOCATION_FAILED; - advance_char (dm); - } - else if (next == 'R') - { - if (!dyn_string_append_char (symbols, '&')) - return STATUS_ALLOCATION_FAILED; - advance_char (dm); - } - else if (next == 'M') - { - /* Pointer-to-member. */ - dyn_string_t class_type; - - /* Eat the 'M'. */ - advance_char (dm); - - /* Capture the type of which this is a pointer-to-member. */ - RETURN_IF_ERROR (result_push (dm)); - RETURN_IF_ERROR (demangle_type (dm)); - class_type = (dyn_string_t) result_pop (dm); - - /* Build the pointer-to-member notation. It comes before - other pointer and reference qualifiers -- */ - if (!dyn_string_prepend_cstr (symbols, "::*")) - return STATUS_ALLOCATION_FAILED; - if (!dyn_string_prepend (symbols, class_type)) - return STATUS_ALLOCATION_FAILED; - dyn_string_delete (class_type); + case 'P': + /* A pointer. Snarf the `P'. */ + advance_char (dm); + /* Demangle the underlying type. */ + RETURN_IF_ERROR (demangle_type_ptr (dm, insert_pos, + substitution_start)); + /* Insert an asterisk where we're told to; it doesn't + necessarily go at the end. */ + RETURN_IF_ERROR (result_insert_char (dm, *insert_pos, '*')); + /* The next (outermost) pointer or reference character should go + after this one. */ + ++(*insert_pos); + break; - if (peek_char (dm) == 'F') - continue; + case 'R': + /* A reference. Snarf the `R'. */ + advance_char (dm); + /* Demangle the underlying type. */ + RETURN_IF_ERROR (demangle_type_ptr (dm, insert_pos, + substitution_start)); + /* Insert an ampersand where we're told to; it doesn't + necessarily go at the end. */ + RETURN_IF_ERROR (result_insert_char (dm, *insert_pos, '&')); + /* The next (outermost) pointer or reference character should go + after this one. */ + ++(*insert_pos); + break; - /* Demangle the type of the pointed-to member. */ + case 'M': + { + /* A pointer-to-member. */ + dyn_string_t class_type; + + /* Eat the 'M'. */ + advance_char (dm); + + /* Capture the type of which this is a pointer-to-member. */ + RETURN_IF_ERROR (result_push (dm)); + RETURN_IF_ERROR (demangle_type (dm)); + class_type = (dyn_string_t) result_pop (dm); + + if (peek_char (dm) == 'F') + /* A pointer-to-member function. We want output along the + lines of `void (C::*) (int, int)'. Demangle the function + type, which would in this case give `void () (int, int)' + and set *insert_pos to the spot between the first + parentheses. */ + status = demangle_type_ptr (dm, insert_pos, substitution_start); + else if (peek_char (dm) == 'A') + /* A pointer-to-member array variable. We want output that + looks like `int (Klass::*) [10]'. Demangle the array type + as `int () [10]', and set *insert_pos to the spot between + the parentheses. */ + status = demangle_array_type (dm, insert_pos); + else + { + /* A pointer-to-member variable. Demangle the type of the + pointed-to member. */ status = demangle_type (dm); /* Make it pretty. */ - if (STATUS_NO_ERROR (status)) - status = result_append_space (dm); - /* Add the pointer-to-member syntax, and other pointer and - reference symbols. */ - if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, symbols); - /* Clean up. */ - dyn_string_delete (symbols); - - RETURN_IF_ERROR (status); - return STATUS_OK; + if (STATUS_NO_ERROR (status) + && !result_previous_char_is_space (dm)) + status = result_add_char (dm, ' '); + /* The pointer-to-member notation (e.g. `C::*') follows the + member's type. */ + *insert_pos = result_caret_pos (dm); } - else if (next == 'F') - { - /* Ooh, tricky, a pointer-to-function. */ - int position = result_length (dm); - status = result_append_char (dm, '('); - if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, symbols); - if (STATUS_NO_ERROR (status)) - status = result_append_char (dm, ')'); - dyn_string_delete (symbols); - RETURN_IF_ERROR (status); - RETURN_IF_ERROR (demangle_function_type (dm, position)); - return STATUS_OK; - } - else - { - /* No more pointe or reference tokens. Finish up. */ - status = demangle_type (dm); + /* Build the pointer-to-member notation. */ + if (STATUS_NO_ERROR (status)) + status = result_insert (dm, *insert_pos, "::*"); + if (STATUS_NO_ERROR (status)) + status = result_insert_string (dm, *insert_pos, class_type); + /* There may be additional levels of (pointer or reference) + indirection in this type. If so, the `*' and `&' should be + added after the pointer-to-member notation (e.g. `C::*&' for + a reference to a pointer-to-member of class C). */ + *insert_pos += dyn_string_length (class_type) + 3; - if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, symbols); - dyn_string_delete (symbols); - RETURN_IF_ERROR (status); + /* Clean up. */ + dyn_string_delete (class_type); - RETURN_IF_ERROR (status); - return STATUS_OK; - } + RETURN_IF_ERROR (status); + } + break; + + case 'F': + /* Ooh, tricky, a pointer-to-function. When we demangle the + function type, the return type should go at the very + beginning. */ + *insert_pos = result_caret_pos (dm); + /* The parentheses indicate this is a function pointer or + reference type. */ + RETURN_IF_ERROR (result_add (dm, "()")); + /* Now demangle the function type. The return type will be + inserted before the `()', and the argument list will go after + it. */ + RETURN_IF_ERROR (demangle_function_type (dm, insert_pos)); + /* We should now have something along the lines of + `void () (int, int)'. The pointer or reference characters + have to inside the first set of parentheses. *insert_pos has + already been updated to point past the end of the return + type. Move it one character over so it points inside the + `()'. */ + ++(*insert_pos); + break; + + case 'A': + /* An array pointer or reference. demangle_array_type will figure + out where the asterisks and ampersands go. */ + RETURN_IF_ERROR (demangle_array_type (dm, insert_pos)); + break; + + default: + /* No more pointer or reference tokens; this is therefore a + pointer to data. Finish up by demangling the underlying + type. */ + RETURN_IF_ERROR (demangle_type (dm)); + /* The pointer or reference characters follow the underlying + type, as in `int*&'. */ + *insert_pos = result_caret_pos (dm); + /* Because of the production <type> ::= <substitution>, + demangle_type will already have added the underlying type as + a substitution candidate. Don't do it again. */ + is_substitution_candidate = 0; + break; } + + if (is_substitution_candidate) + RETURN_IF_ERROR (substitution_add (dm, substitution_start, 0)); + + return STATUS_OK; } /* Demangles and emits a <type>. @@ -1926,6 +2228,7 @@ demangle_type_ptr (dm) ::= <array-type> ::= <pointer-to-member-type> ::= <template-param> + ::= <template-template-param> <template-args> ::= <CV-qualifiers> <type> ::= P <type> # pointer-to ::= R <type> # reference-to @@ -1941,22 +2244,28 @@ demangle_type (dm) int start = substitution_start (dm); char peek = peek_char (dm); char peek_next; - int template_p = 0; - int special_std_substitution; - int is_builtin_type = 0; + int encode_return_type = 0; template_arg_list_t old_arg_list = current_template_arg_list (dm); - int template_parm = NOT_TEMPLATE_PARM; + int insert_pos; + + /* A <type> can be a <substitution>; therefore, this <type> is a + substitution candidate unless a special condition holds (see + below). */ + int is_substitution_candidate = 1; DEMANGLE_TRACE ("type", dm); /* A <class-enum-type> can start with a digit (a <source-name>), an N (a <nested-name>), or a Z (a <local-name>). */ if (IS_DIGIT ((unsigned char) peek) || peek == 'N' || peek == 'Z') - RETURN_IF_ERROR (demangle_class_enum_type (dm, &template_p)); - else if (peek >= 'a' && peek <= 'z') + RETURN_IF_ERROR (demangle_class_enum_type (dm, &encode_return_type)); + /* Lower-case letters begin <builtin-type>s, except for `r', which + denotes restrict. */ + else if (peek >= 'a' && peek <= 'z' && peek != 'r') { RETURN_IF_ERROR (demangle_builtin_type (dm)); - is_builtin_type = 1; + /* Built-in types are not substitution candidates. */ + is_substitution_candidate = 0; } else switch (peek) @@ -1964,37 +2273,36 @@ demangle_type (dm) case 'r': case 'V': case 'K': + /* CV-qualifiers (including restrict). We have to demangle + them off to the side, since C++ syntax puts them in a funny + place for qualified pointer and reference types. */ { status_t status; dyn_string_t cv_qualifiers = dyn_string_new (24); + int old_caret_position = result_get_caret (dm); if (cv_qualifiers == NULL) return STATUS_ALLOCATION_FAILED; + /* Decode all adjacent CV qualifiers. */ demangle_CV_qualifiers (dm, cv_qualifiers); - - /* If the qualifiers apply to a pointer or reference, they - need to come after the whole qualified type. */ - if (peek_char (dm) == 'P' || peek_char (dm) == 'R') - { - status = demangle_type (dm); - if (STATUS_NO_ERROR (status)) - status = result_append_space (dm); - if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, cv_qualifiers); - } - /* Otherwise, the qualifiers come first. */ - else - { - status = result_append_string (dm, cv_qualifiers); - if (STATUS_NO_ERROR (status)) - status = result_append_space (dm); - if (STATUS_NO_ERROR (status)) - status = demangle_type (dm); - } - + /* Emit them, and shift the caret left so that the + underlying type will be emitted before the qualifiers. */ + status = result_add_string (dm, cv_qualifiers); + result_shift_caret (dm, -dyn_string_length (cv_qualifiers)); + /* Clean up. */ dyn_string_delete (cv_qualifiers); RETURN_IF_ERROR (status); + /* Also prepend a blank, if needed. */ + RETURN_IF_ERROR (result_add_char (dm, ' ')); + result_shift_caret (dm, -1); + + /* Demangle the underlying type. It will be emitted before + the CV qualifiers, since we moved the caret. */ + RETURN_IF_ERROR (demangle_type (dm)); + + /* Put the caret back where it was previously. */ + result_set_caret (dm, old_caret_position); } break; @@ -2002,11 +2310,32 @@ demangle_type (dm) return "Non-pointer or -reference function type."; case 'A': - RETURN_IF_ERROR (demangle_array_type (dm)); + RETURN_IF_ERROR (demangle_array_type (dm, NULL)); break; case 'T': - RETURN_IF_ERROR (demangle_template_param (dm, &template_parm)); + /* It's either a <template-param> or a + <template-template-param>. In either case, demangle the + `T' token first. */ + RETURN_IF_ERROR (demangle_template_param (dm)); + + /* Check for a template argument list; if one is found, it's a + <template-template-param> ::= <template-param> + ::= <substitution> */ + if (peek_char (dm) == 'I') + { + /* Add a substitution candidate. The template parameter + `T' token is a substitution candidate by itself, + without the template argument list. */ + RETURN_IF_ERROR (substitution_add (dm, start, encode_return_type)); + + /* Now demangle the template argument list. */ + RETURN_IF_ERROR (demangle_template_args (dm)); + /* The entire type, including the template template + parameter and its argument list, will be added as a + substitution candidate below. */ + } + break; case 'S': @@ -2016,37 +2345,77 @@ demangle_type (dm) or underscore. */ peek_next = peek_char_next (dm); if (IS_DIGIT (peek_next) || peek_next == '_') - RETURN_IF_ERROR (demangle_substitution (dm, &template_p, - &special_std_substitution)); + { + RETURN_IF_ERROR (demangle_substitution (dm, &encode_return_type)); + + /* The substituted name may have been a template name. + Check if template arguments follow, and if so, demangle + them. */ + if (peek_char (dm) == 'I') + RETURN_IF_ERROR (demangle_template_args (dm)); + else + /* A substitution token is not itself a substitution + candidate. (However, if the substituted template is + instantiated, the resulting type is.) */ + is_substitution_candidate = 0; + } else - demangle_class_enum_type (dm, &template_p); + { + /* Now some trickiness. We have a special substitution + here. Often, the special substitution provides the + name of a template that's subsequently instantiated, + for instance `SaIcE' => std::allocator<char>. In these + cases we need to add a substitution candidate for the + entire <class-enum-type> and thus don't want to clear + the is_substitution_candidate flag. + + However, it's possible that what we have here is a + substitution token representing an entire type, such as + `Ss' => std::string. In this case, we mustn't add a + new substitution candidate for this substitution token. + To detect this case, remember where the start of the + substitution token is. */ + const char *next = dm->next; + /* Now demangle the <class-enum-type>. */ + RETURN_IF_ERROR + (demangle_class_enum_type (dm, &encode_return_type)); + /* If all that was just demangled is the two-character + special substitution token, supress the addition of a + new candidate for it. */ + if (dm->next == next + 2) + is_substitution_candidate = 0; + } + break; case 'P': case 'R': case 'M': - RETURN_IF_ERROR (demangle_type_ptr (dm)); + RETURN_IF_ERROR (demangle_type_ptr (dm, &insert_pos, start)); + /* demangle_type_ptr adds all applicable substitution + candidates. */ + is_substitution_candidate = 0; break; case 'C': /* A C99 complex type. */ - RETURN_IF_ERROR (result_append (dm, "complex ")); + RETURN_IF_ERROR (result_add (dm, "complex ")); advance_char (dm); RETURN_IF_ERROR (demangle_type (dm)); break; case 'G': /* A C99 imaginary type. */ - RETURN_IF_ERROR (result_append (dm, "imaginary ")); + RETURN_IF_ERROR (result_add (dm, "imaginary ")); advance_char (dm); RETURN_IF_ERROR (demangle_type (dm)); break; case 'U': - /* Vendor extended type qualifier. */ + /* Vendor-extended type qualifier. */ advance_char (dm); RETURN_IF_ERROR (demangle_source_name (dm)); - RETURN_IF_ERROR (result_append_char (dm, ' ')); + RETURN_IF_ERROR (result_add_char (dm, ' ')); RETURN_IF_ERROR (demangle_type (dm)); break; @@ -2054,13 +2423,12 @@ demangle_type (dm) return "Unexpected character in <type>."; } - /* Unqualified builin types are not substitution candidates. */ - if (!is_builtin_type) + if (is_substitution_candidate) /* Add a new substitution for the type. If this type was a <template-param>, pass its index since from the point of - substitutions, a <template-param> token is a substitution + substitutions; a <template-param> token is a substitution candidate distinct from the type that is substituted for it. */ - RETURN_IF_ERROR (substitution_add (dm, start, template_p, template_parm)); + RETURN_IF_ERROR (substitution_add (dm, start, encode_return_type)); /* Pop off template argument lists added during mangling of this type. */ @@ -2147,7 +2515,7 @@ demangle_builtin_type (dm) if (type_name == NULL) return "Unrecognized <builtin-type> code."; - RETURN_IF_ERROR (result_append (dm, type_name)); + RETURN_IF_ERROR (result_add (dm, type_name)); advance_char (dm); return STATUS_OK; } @@ -2199,16 +2567,18 @@ demangle_CV_qualifiers (dm, qualifiers) } } -/* Demangles and emits a <function-type> FUNCTION_NAME_POS is the +/* Demangles and emits a <function-type>. *FUNCTION_NAME_POS is the position in the result string of the start of the function - identifier, at which the function's return type will be inserted. + identifier, at which the function's return type will be inserted; + *FUNCTION_NAME_POS is updated to position past the end of the + function's return type. <function-type> ::= F [Y] <bare-function-type> E */ static status_t demangle_function_type (dm, function_name_pos) demangling_t dm; - int function_name_pos; + int *function_name_pos; { DEMANGLE_TRACE ("function-type", dm); RETURN_IF_ERROR (demangle_char (dm, 'F')); @@ -2216,7 +2586,7 @@ demangle_function_type (dm, function_name_pos) { /* Indicate this function has C linkage if in verbose mode. */ if (flag_verbose) - RETURN_IF_ERROR (result_append (dm, " [extern \"C\"] ")); + RETURN_IF_ERROR (result_add (dm, " [extern \"C\"] ")); advance_char (dm); } RETURN_IF_ERROR (demangle_bare_function_type (dm, function_name_pos)); @@ -2234,7 +2604,7 @@ demangle_function_type (dm, function_name_pos) static status_t demangle_bare_function_type (dm, return_type_pos) demangling_t dm; - int return_type_pos; + int *return_type_pos; { /* Sequence is the index of the current function parameter, counting from zero. The value -1 denotes the return type. */ @@ -2243,7 +2613,7 @@ demangle_bare_function_type (dm, return_type_pos) DEMANGLE_TRACE ("bare-function-type", dm); - RETURN_IF_ERROR (result_append_char (dm, '(')); + RETURN_IF_ERROR (result_add_char (dm, '(')); while (!end_of_name_p (dm) && peek_char (dm) != 'E') { if (sequence == -1) @@ -2259,10 +2629,16 @@ demangle_bare_function_type (dm, return_type_pos) /* Add a space to the end of the type. Insert the return type where we've been asked to. */ - if (!dyn_string_append_space (return_type) - || !dyn_string_insert (result_string (dm), return_type_pos, - return_type)) + if (!dyn_string_append_space (return_type)) status = STATUS_ALLOCATION_FAILED; + if (STATUS_NO_ERROR (status)) + { + if (!dyn_string_insert (result_string (dm), *return_type_pos, + return_type)) + status = STATUS_ALLOCATION_FAILED; + else + *return_type_pos += dyn_string_length (return_type); + } dyn_string_delete (return_type); RETURN_IF_ERROR (status); @@ -2273,60 +2649,103 @@ demangle_bare_function_type (dm, return_type_pos) the only type in a parameter list; in that case, we want to print `foo ()' instead of `foo (void)'. */ if (peek_char (dm) == 'v') + /* Consume the v. */ + advance_char (dm); + else { - /* Consume the v. */ - advance_char (dm); - continue; + /* Separate parameter types by commas. */ + if (sequence > 0) + RETURN_IF_ERROR (result_add (dm, ", ")); + /* Demangle the type. */ + RETURN_IF_ERROR (demangle_type (dm)); } - /* Separate parameter types by commas. */ - if (sequence > 0) - RETURN_IF_ERROR (result_append (dm, ", ")); - /* Demangle the type. */ - RETURN_IF_ERROR (demangle_type (dm)); } ++sequence; } - RETURN_IF_ERROR (result_append_char (dm, ')')); + RETURN_IF_ERROR (result_add_char (dm, ')')); + + /* We should have demangled at least one parameter type (which would + be void, for a function that takes no parameters), plus the + return type, if we were supposed to demangle that. */ + if (sequence == -1) + return "Missing function return type."; + else if (sequence == 0) + return "Missing function parameter."; return STATUS_OK; } -/* Demangles and emits a <class-enum-type>. *TEMPLATE_P is set to +/* Demangles and emits a <class-enum-type>. *ENCODE_RETURN_TYPE is set to non-zero if the type is a template-id, zero otherwise. <class-enum-type> ::= <name> */ static status_t -demangle_class_enum_type (dm, template_p) +demangle_class_enum_type (dm, encode_return_type) demangling_t dm; - int *template_p; + int *encode_return_type; { DEMANGLE_TRACE ("class-enum-type", dm); - RETURN_IF_ERROR (demangle_name (dm, template_p)); + RETURN_IF_ERROR (demangle_name (dm, encode_return_type)); return STATUS_OK; } /* Demangles and emits an <array-type>. - <array-type> ::= A [<dimension number>] _ <element type> */ + If PTR_INSERT_POS is not NULL, the array type is formatted as a + pointer or reference to an array, except that asterisk and + ampersand punctuation is omitted (since it's not know at this + point). *PTR_INSERT_POS is set to the position in the demangled + name at which this punctuation should be inserted. For example, + `A10_i' is demangled to `int () [10]' and *PTR_INSERT_POS points + between the parentheses. + + If PTR_INSERT_POS is NULL, the array type is assumed not to be + pointer- or reference-qualified. Then, for example, `A10_i' is + demangled simply as `int[10]'. + + <array-type> ::= A [<dimension number>] _ <element type> + ::= A <dimension expression> _ <element type> */ static status_t -demangle_array_type (dm) +demangle_array_type (dm, ptr_insert_pos) demangling_t dm; + int *ptr_insert_pos; { - status_t status; - dyn_string_t array_size = dyn_string_new (10); + status_t status = STATUS_OK; + dyn_string_t array_size = NULL; + char peek; - if (array_size == NULL) - return STATUS_ALLOCATION_FAILED; + DEMANGLE_TRACE ("array-type", dm); - status = demangle_char (dm, 'A'); + RETURN_IF_ERROR (demangle_char (dm, 'A')); /* Demangle the array size into array_size. */ - if (STATUS_NO_ERROR (status)) - status = demangle_number_literally (dm, array_size, 10, 0); + peek = peek_char (dm); + if (peek == '_') + /* Array bound is omitted. This is a C99-style VLA. */ + ; + else if (IS_DIGIT (peek_char (dm))) + { + /* It looks like a constant array bound. */ + array_size = dyn_string_new (10); + if (array_size == NULL) + return STATUS_ALLOCATION_FAILED; + status = demangle_number_literally (dm, array_size, 10, 0); + } + else + { + /* Anything is must be an expression for a nont-constant array + bound. This happens if the array type occurs in a template + and the array bound references a template parameter. */ + RETURN_IF_ERROR (result_push (dm)); + RETURN_IF_ERROR (demangle_expression (dm)); + array_size = (dyn_string_t) result_pop (dm); + } + /* array_size may have been allocated by now, so we can't use + RETURN_IF_ERROR until it's been deallocated. */ /* Demangle the base type of the array. */ if (STATUS_NO_ERROR (status)) @@ -2334,30 +2753,40 @@ demangle_array_type (dm) if (STATUS_NO_ERROR (status)) status = demangle_type (dm); + if (ptr_insert_pos != NULL) + { + /* This array is actually part of an pointer- or + reference-to-array type. Format appropriately, except we + don't know which and how much punctuation to use. */ + if (STATUS_NO_ERROR (status)) + status = result_add (dm, " () "); + /* Let the caller know where to insert the punctuation. */ + *ptr_insert_pos = result_caret_pos (dm) - 2; + } + /* Emit the array dimension syntax. */ if (STATUS_NO_ERROR (status)) - status = result_append_char (dm, '['); - if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, array_size); + status = result_add_char (dm, '['); + if (STATUS_NO_ERROR (status) && array_size != NULL) + status = result_add_string (dm, array_size); if (STATUS_NO_ERROR (status)) - status = result_append_char (dm, ']'); - dyn_string_delete (array_size); + status = result_add_char (dm, ']'); + if (array_size != NULL) + dyn_string_delete (array_size); RETURN_IF_ERROR (status); return STATUS_OK; } -/* Demangles and emits a <template-param>. The zero-indexed position - in the parameter list is placed in *TEMPLATE_PARM_NUMBER. +/* Demangles and emits a <template-param>. <template-param> ::= T_ # first template parameter ::= T <parameter-2 number> _ */ static status_t -demangle_template_param (dm, template_parm_number) +demangle_template_param (dm) demangling_t dm; - int *template_parm_number; { int parm_number; template_arg_list_t current_arg_list = current_template_arg_list (dm); @@ -2385,12 +2814,8 @@ demangle_template_param (dm, template_parm_number) /* parm_number exceeded the number of arguments in the current template argument list. */ return "Template parameter number out of bounds."; - RETURN_IF_ERROR (result_append_string (dm, (dyn_string_t) arg)); - - if (peek_char (dm) == 'I') - RETURN_IF_ERROR (demangle_template_args (dm)); + RETURN_IF_ERROR (result_add_string (dm, (dyn_string_t) arg)); - *template_parm_number = parm_number; return STATUS_OK; } @@ -2419,7 +2844,7 @@ demangle_template_args (dm) return STATUS_ALLOCATION_FAILED; RETURN_IF_ERROR (demangle_char (dm, 'I')); - RETURN_IF_ERROR (result_append_char (dm, '<')); + RETURN_IF_ERROR (result_open_template_list (dm)); do { string_list_t arg; @@ -2427,7 +2852,7 @@ demangle_template_args (dm) if (first) first = 0; else - RETURN_IF_ERROR (result_append (dm, ", ")); + RETURN_IF_ERROR (result_add (dm, ", ")); /* Capture the template arg. */ RETURN_IF_ERROR (result_push (dm)); @@ -2435,7 +2860,7 @@ demangle_template_args (dm) arg = result_pop (dm); /* Emit it in the demangled name. */ - RETURN_IF_ERROR (result_append_string (dm, (dyn_string_t) arg)); + RETURN_IF_ERROR (result_add_string (dm, (dyn_string_t) arg)); /* Save it for use in expanding <template-param>s. */ template_arg_list_add_arg (arg_list, arg); @@ -2511,9 +2936,9 @@ demangle_literal (dm) corresponding to false or true, respectively. */ value = peek_char (dm); if (value == '0') - RETURN_IF_ERROR (result_append (dm, "false")); + RETURN_IF_ERROR (result_add (dm, "false")); else if (value == '1') - RETURN_IF_ERROR (result_append (dm, "true")); + RETURN_IF_ERROR (result_add (dm, "true")); else return "Unrecognized bool constant."; /* Consume the 0 or 1. */ @@ -2531,10 +2956,10 @@ demangle_literal (dm) value_string = dyn_string_new (0); status = demangle_number_literally (dm, value_string, 10, 1); if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, value_string); + status = result_add_string (dm, value_string); /* For long integers, append an l. */ if (code == 'l' && STATUS_NO_ERROR (status)) - status = result_append_char (dm, code); + status = result_add_char (dm, code); dyn_string_delete (value_string); RETURN_IF_ERROR (status); @@ -2544,9 +2969,9 @@ demangle_literal (dm) literal's type explicitly using cast syntax. */ } - RETURN_IF_ERROR (result_append_char (dm, '(')); + RETURN_IF_ERROR (result_add_char (dm, '(')); RETURN_IF_ERROR (demangle_type (dm)); - RETURN_IF_ERROR (result_append_char (dm, ')')); + RETURN_IF_ERROR (result_add_char (dm, ')')); value_string = dyn_string_new (0); if (value_string == NULL) @@ -2554,7 +2979,7 @@ demangle_literal (dm) status = demangle_number_literally (dm, value_string, 10, 1); if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, value_string); + status = result_add_string (dm, value_string); dyn_string_delete (value_string); RETURN_IF_ERROR (status); @@ -2595,6 +3020,7 @@ demangle_template_arg (dm) /* Expression. */ advance_char (dm); RETURN_IF_ERROR (demangle_expression (dm)); + RETURN_IF_ERROR (demangle_char (dm, 'E')); break; default: @@ -2641,30 +3067,30 @@ demangle_expression (dm) /* If it's binary, do an operand first. */ if (num_args > 1) { - status = result_append_char (dm, '('); + status = result_add_char (dm, '('); if (STATUS_NO_ERROR (status)) status = demangle_expression (dm); if (STATUS_NO_ERROR (status)) - status = result_append_char (dm, ')'); + status = result_add_char (dm, ')'); } /* Emit the operator. */ if (STATUS_NO_ERROR (status)) - status = result_append_string (dm, operator_name); + status = result_add_string (dm, operator_name); dyn_string_delete (operator_name); RETURN_IF_ERROR (status); /* Emit its second (if binary) or only (if unary) operand. */ - RETURN_IF_ERROR (result_append_char (dm, '(')); + RETURN_IF_ERROR (result_add_char (dm, '(')); RETURN_IF_ERROR (demangle_expression (dm)); - RETURN_IF_ERROR (result_append_char (dm, ')')); + RETURN_IF_ERROR (result_add_char (dm, ')')); /* The ternary operator takes a third operand. */ if (num_args == 3) { - RETURN_IF_ERROR (result_append (dm, ":(")); + RETURN_IF_ERROR (result_add (dm, ":(")); RETURN_IF_ERROR (demangle_expression (dm)); - RETURN_IF_ERROR (result_append_char (dm, ')')); + RETURN_IF_ERROR (result_add_char (dm, ')')); } } @@ -2683,7 +3109,7 @@ demangle_scope_expression (dm) RETURN_IF_ERROR (demangle_char (dm, 's')); RETURN_IF_ERROR (demangle_char (dm, 'r')); RETURN_IF_ERROR (demangle_type (dm)); - RETURN_IF_ERROR (result_append (dm, "::")); + RETURN_IF_ERROR (result_add (dm, "::")); RETURN_IF_ERROR (demangle_encoding (dm)); return STATUS_OK; } @@ -2699,12 +3125,11 @@ demangle_expr_primary (dm) demangling_t dm; { char peek = peek_char (dm); - int unused; DEMANGLE_TRACE ("expr-primary", dm); if (peek == 'T') - RETURN_IF_ERROR (demangle_template_param (dm, &unused)); + RETURN_IF_ERROR (demangle_template_param (dm)); else if (peek == 'L') { /* Consume the `L'. */ @@ -2725,10 +3150,7 @@ demangle_expr_primary (dm) } /* Demangles and emits a <substitution>. Sets *TEMPLATE_P to non-zero - if the substitution is the name of a template, zero otherwise. If - the substitution token is St, which corresponds to the `::std::' - namespace and can appear in a non-nested name, sets - *SPECIAL_STD_SUBSTITUTION to non-zero; zero otherwise. + if the substitution is the name of a template, zero otherwise. <substitution> ::= S <seq-id> _ ::= S_ @@ -2744,14 +3166,13 @@ demangle_expr_primary (dm) ::= So # ::std::basic_ostream<char, std::char_traits<char> > ::= Sd # ::std::basic_iostream<char, - std::char_traits<char> > + std::char_traits<char> > */ static status_t -demangle_substitution (dm, template_p, special_std_substitution) +demangle_substitution (dm, template_p) demangling_t dm; int *template_p; - int *special_std_substitution; { int seq_id; int peek; @@ -2760,7 +3181,6 @@ demangle_substitution (dm, template_p, special_std_substitution) DEMANGLE_TRACE ("substitution", dm); RETURN_IF_ERROR (demangle_char (dm, 'S')); - *special_std_substitution = 0; /* Scan the substitution sequence index. A missing number denotes the first index. */ @@ -2780,18 +3200,17 @@ demangle_substitution (dm, template_p, special_std_substitution) switch (peek) { case 't': - RETURN_IF_ERROR (result_append (dm, "std")); - *special_std_substitution = 1; + RETURN_IF_ERROR (result_add (dm, "std")); break; case 'a': - RETURN_IF_ERROR (result_append (dm, "std::allocator")); + RETURN_IF_ERROR (result_add (dm, "std::allocator")); new_last_source_name = "allocator"; *template_p = 1; break; case 'b': - RETURN_IF_ERROR (result_append (dm, "std::basic_string")); + RETURN_IF_ERROR (result_add (dm, "std::basic_string")); new_last_source_name = "basic_string"; *template_p = 1; break; @@ -2799,12 +3218,12 @@ demangle_substitution (dm, template_p, special_std_substitution) case 's': if (!flag_verbose) { - RETURN_IF_ERROR (result_append (dm, "std::string")); + RETURN_IF_ERROR (result_add (dm, "std::string")); new_last_source_name = "string"; } else { - RETURN_IF_ERROR (result_append (dm, "std::basic_string<char, std::char_traits<char>, std::allocator<char> >")); + RETURN_IF_ERROR (result_add (dm, "std::basic_string<char, std::char_traits<char>, std::allocator<char> >")); new_last_source_name = "basic_string"; } *template_p = 0; @@ -2813,12 +3232,12 @@ demangle_substitution (dm, template_p, special_std_substitution) case 'i': if (!flag_verbose) { - RETURN_IF_ERROR (result_append (dm, "std::istream")); + RETURN_IF_ERROR (result_add (dm, "std::istream")); new_last_source_name = "istream"; } else { - RETURN_IF_ERROR (result_append (dm, "std::basic_istream<char, std::char_traints<char> >")); + RETURN_IF_ERROR (result_add (dm, "std::basic_istream<char, std::char_traints<char> >")); new_last_source_name = "basic_istream"; } *template_p = 0; @@ -2827,12 +3246,12 @@ demangle_substitution (dm, template_p, special_std_substitution) case 'o': if (!flag_verbose) { - RETURN_IF_ERROR (result_append (dm, "std::ostream")); + RETURN_IF_ERROR (result_add (dm, "std::ostream")); new_last_source_name = "ostream"; } else { - RETURN_IF_ERROR (result_append (dm, "std::basic_ostream<char, std::char_traits<char> >")); + RETURN_IF_ERROR (result_add (dm, "std::basic_ostream<char, std::char_traits<char> >")); new_last_source_name = "basic_ostream"; } *template_p = 0; @@ -2841,12 +3260,12 @@ demangle_substitution (dm, template_p, special_std_substitution) case 'd': if (!flag_verbose) { - RETURN_IF_ERROR (result_append (dm, "std::iostream")); + RETURN_IF_ERROR (result_add (dm, "std::iostream")); new_last_source_name = "iostream"; } else { - RETURN_IF_ERROR (result_append (dm, "std::basic_iostream<char, std::char_traits<char> >")); + RETURN_IF_ERROR (result_add (dm, "std::basic_iostream<char, std::char_traits<char> >")); new_last_source_name = "basic_iostream"; } *template_p = 0; @@ -2877,7 +3296,7 @@ demangle_substitution (dm, template_p, special_std_substitution) return "Substitution number out of range."; /* Emit the substitution text. */ - RETURN_IF_ERROR (result_append_string (dm, text)); + RETURN_IF_ERROR (result_add_string (dm, text)); RETURN_IF_ERROR (demangle_char (dm, '_')); return STATUS_OK; @@ -2897,12 +3316,12 @@ demangle_local_name (dm) RETURN_IF_ERROR (demangle_char (dm, 'Z')); RETURN_IF_ERROR (demangle_encoding (dm)); RETURN_IF_ERROR (demangle_char (dm, 'E')); - RETURN_IF_ERROR (result_append (dm, "'s ")); + RETURN_IF_ERROR (result_add (dm, "::")); if (peek_char (dm) == 's') { /* Local character string literal. */ - RETURN_IF_ERROR (result_append (dm, "string literal")); + RETURN_IF_ERROR (result_add (dm, "string literal")); /* Consume the s. */ advance_char (dm); RETURN_IF_ERROR (demangle_discriminator (dm, 0)); @@ -2910,7 +3329,6 @@ demangle_local_name (dm) else { int unused; - RETURN_IF_ERROR (result_append (dm, "local ")); /* Local name for some other entity. Demangle its name. */ RETURN_IF_ERROR (demangle_name (dm, &unused)); RETURN_IF_ERROR (demangle_discriminator (dm, 1)); @@ -2933,14 +3351,14 @@ demangle_discriminator (dm, suppress_first) int suppress_first; { /* Output for <discriminator>s to the demangled name is completely - supressed if not in verbose mode. */ + suppressed if not in verbose mode. */ if (peek_char (dm) == '_') { /* Consume the underscore. */ advance_char (dm); if (flag_verbose) - RETURN_IF_ERROR (result_append (dm, " [#")); + RETURN_IF_ERROR (result_add (dm, " [#")); /* Check if there's a number following the underscore. */ if (IS_DIGIT ((unsigned char) peek_char (dm))) { @@ -2958,15 +3376,15 @@ demangle_discriminator (dm, suppress_first) { if (flag_verbose) /* A missing digit correspond to one. */ - RETURN_IF_ERROR (result_append_char (dm, '1')); + RETURN_IF_ERROR (result_add_char (dm, '1')); } if (flag_verbose) - RETURN_IF_ERROR (result_append_char (dm, ']')); + RETURN_IF_ERROR (result_add_char (dm, ']')); } else if (!suppress_first) { if (flag_verbose) - RETURN_IF_ERROR (result_append (dm, " [#0]")); + RETURN_IF_ERROR (result_add (dm, " [#0]")); } return STATUS_OK; @@ -3025,6 +3443,7 @@ cp_demangle (name, result) dyn_string_t. On success, returns STATUS_OK. On failiure, returns an error message, and the contents of RESULT are unchanged. */ +#ifdef IN_LIBGCC2 static status_t cp_demangle_type (type_name, result) const char* type_name; @@ -3062,12 +3481,9 @@ cp_demangle_type (type_name, result) return status; } - -#ifdef IN_LIBGCC2 - extern char *__cxa_demangle PARAMS ((const char *, char *, size_t *, int *)); -/* ABI-mandated entry point in the C++ runtime library for performing +/* ia64 ABI-mandated entry point in the C++ runtime library for performing demangling. MANGLED_NAME is a NUL-terminated character string containing the name to be demangled. @@ -3181,13 +3597,21 @@ __cxa_demangle (mangled_name, output_buffer, length, status) If the demangling failes, returns NULL. */ char * -cplus_demangle_new_abi (mangled) +cplus_demangle_v3 (mangled) const char* mangled; { + dyn_string_t demangled; + status_t status; + + /* If this isn't a mangled name, don't pretend to demangle it. */ + if (strncmp (mangled, "_Z", 2) != 0) + return NULL; + /* Create a dyn_string to hold the demangled name. */ - dyn_string_t demangled = dyn_string_new (0); + demangled = dyn_string_new (0); /* Attempt the demangling. */ - status_t status = cp_demangle ((char *) mangled, demangled); + status = cp_demangle ((char *) mangled, demangled); + if (STATUS_NO_ERROR (status)) /* Demangling succeeded. */ { @@ -3221,7 +3645,8 @@ static void print_usage /* Non-zero if CHAR is a character than can occur in a mangled name. */ #define is_mangled_char(CHAR) \ - (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) || (CHAR) == '_') + (IS_ALPHA (CHAR) || IS_DIGIT (CHAR) \ + || (CHAR) == '_' || (CHAR) == '.' || (CHAR) == '$') /* The name of this program, as invoked. */ const char* program_name; @@ -3234,7 +3659,7 @@ print_usage (fp, exit_value) int exit_value; { fprintf (fp, "Usage: %s [options] [names ...]\n", program_name); - fprintf (fp, "Options:\n", program_name); + fprintf (fp, "Options:\n"); fprintf (fp, " -h,--help Display this message.\n"); fprintf (fp, " -s,--strict Demangle standard names only.\n"); fprintf (fp, " -v,--verbose Produce verbose demanglings.\n"); diff --git a/contrib/binutils/libiberty/cplus-dem.c b/contrib/binutils/libiberty/cplus-dem.c index 8a672c6..a42f45e 100644 --- a/contrib/binutils/libiberty/cplus-dem.c +++ b/contrib/binutils/libiberty/cplus-dem.c @@ -1,5 +1,6 @@ /* Demangler for GNU C++ - Copyright 1989, 91, 94, 95, 96, 97, 98, 1999 Free Software Foundation, Inc. + Copyright 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, + 2000 Free Software Foundation, Inc. Written by James Clark (jjc@jclark.uucp) Rewritten by Fred Fish (fnf@cygnus.com) for ARM and Lucid demangling Modified by Satish Pai (pai@apollo.hp.com) for HP demangling @@ -33,7 +34,8 @@ Boston, MA 02111-1307, USA. */ #include "config.h" #endif -#include <ctype.h> +#include "safe-ctype.h" + #include <sys/types.h> #include <string.h> #include <stdio.h> @@ -51,6 +53,8 @@ char * realloc (); #include "libiberty.h" +static char *ada_demangle PARAMS ((const char *, int)); + #define min(X,Y) (((X) < (Y)) ? (X) : (Y)) /* A value at least one greater than the maximum number of characters @@ -98,7 +102,7 @@ mystrstr (s1, s2) #define CPLUS_MARKER '$' #endif -enum demangling_styles current_demangling_style = gnu_demangling; +enum demangling_styles current_demangling_style = auto_demangling; static char cplus_markers[] = { CPLUS_MARKER, '.', '$', '\0' }; @@ -291,9 +295,21 @@ struct demangler_engine libiberty_demanglers[] = } , { - GNU_NEW_ABI_DEMANGLING_STYLE_STRING, - gnu_new_abi_demangling, - "GNU (g++) new-ABI-style demangling" + GNU_V3_DEMANGLING_STYLE_STRING, + gnu_v3_demangling, + "GNU (g++) V3 ABI-style demangling" + } + , + { + JAVA_DEMANGLING_STYLE_STRING, + java_demangling, + "Java style demangling" + } + , + { + GNAT_DEMANGLING_STYLE_STRING, + gnat_demangling, + "GNAT style demangling" } , { @@ -512,6 +528,9 @@ static void recursively_demangle PARAMS ((struct work_stuff *, const char **, string *, int)); +static void +grow_vect PARAMS ((void **, size_t *, size_t, int)); + /* Translate count to integer, consuming tokens in the process. Conversion terminates on the first non-digit character. @@ -526,10 +545,10 @@ consume_count (type) { int count = 0; - if (! isdigit ((unsigned char)**type)) + if (! ISDIGIT ((unsigned char)**type)) return -1; - while (isdigit ((unsigned char)**type)) + while (ISDIGIT ((unsigned char)**type)) { count *= 10; @@ -540,7 +559,7 @@ consume_count (type) ten. */ if ((count % 10) != 0) { - while (isdigit ((unsigned char) **type)) + while (ISDIGIT ((unsigned char) **type)) (*type)++; return -1; } @@ -566,7 +585,7 @@ consume_count_with_underscores (mangled) if (**mangled == '_') { (*mangled)++; - if (!isdigit ((unsigned char)**mangled)) + if (!ISDIGIT ((unsigned char)**mangled)) return -1; idx = consume_count (mangled); @@ -698,14 +717,14 @@ cplus_demangle_opname (opname, result, options) } } else if (opname[0] == '_' && opname[1] == '_' - && islower((unsigned char)opname[2]) - && islower((unsigned char)opname[3])) + && ISLOWER((unsigned char)opname[2]) + && ISLOWER((unsigned char)opname[3])) { if (opname[4] == '\0') { /* Operator. */ size_t i; - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { if (strlen (optable[i].in) == 2 && memcmp (optable[i].in, opname + 2, 2) == 0) @@ -723,7 +742,7 @@ cplus_demangle_opname (opname, result, options) { /* Assignment. */ size_t i; - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { if (strlen (optable[i].in) == 3 && memcmp (optable[i].in, opname + 2, 3) == 0) @@ -747,7 +766,7 @@ cplus_demangle_opname (opname, result, options) && memcmp (opname + 3, "assign_", 7) == 0) { size_t i; - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { len1 = len - 10; if ((int) strlen (optable[i].in) == len1 @@ -764,7 +783,7 @@ cplus_demangle_opname (opname, result, options) else { size_t i; - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { len1 = len - 3; if ((int) strlen (optable[i].in) == len1 @@ -811,7 +830,7 @@ cplus_mangle_opname (opname, options) int len; len = strlen (opname); - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { if ((int) strlen (optable[i].out) == len && (options & DMGL_ANSI) == (optable[i].flags & DMGL_ANSI) @@ -891,13 +910,20 @@ cplus_demangle (mangled, options) char *ret; struct work_stuff work[1]; memset ((char *) work, 0, sizeof (work)); - work -> options = options; - if ((work -> options & DMGL_STYLE_MASK) == 0) - work -> options |= (int) current_demangling_style & DMGL_STYLE_MASK; + work->options = options; + if ((work->options & DMGL_STYLE_MASK) == 0) + work->options |= (int) current_demangling_style & DMGL_STYLE_MASK; + + /* The V3 ABI demangling is implemented elsewhere. */ + if (GNU_V3_DEMANGLING || AUTO_DEMANGLING) + { + ret = cplus_demangle_v3 (mangled); + if (ret || GNU_V3_DEMANGLING) + return ret; + } - /* The new-ABI demangling is implemented elsewhere. */ - if (GNU_NEW_ABI_DEMANGLING) - return cplus_demangle_new_abi (mangled); + if (GNAT_DEMANGLING) + return ada_demangle(mangled,options); ret = internal_cplus_demangle (work, mangled); squangle_mop_up (work); @@ -905,6 +931,139 @@ cplus_demangle (mangled, options) } +/* Assuming *OLD_VECT points to an array of *SIZE objects of size + ELEMENT_SIZE, grow it to contain at least MIN_SIZE objects, + updating *OLD_VECT and *SIZE as necessary. */ + +static void +grow_vect (old_vect, size, min_size, element_size) + void **old_vect; + size_t *size; + size_t min_size; + int element_size; +{ + if (*size < min_size) + { + *size *= 2; + if (*size < min_size) + *size = min_size; + *old_vect = xrealloc (*old_vect, *size * element_size); + } +} + +/* Demangle ada names: + 1. Discard final __{DIGIT}+ or ${DIGIT}+ + 2. Convert other instances of embedded "__" to `.'. + 3. Discard leading _ada_. + 4. Remove everything after first ___ if it is followed by 'X'. + 5. Put symbols that should be suppressed in <...> brackets. + The resulting string is valid until the next call of ada_demangle. */ + +static char * +ada_demangle (mangled, option) + const char *mangled; + int option ATTRIBUTE_UNUSED; +{ + int i, j; + int len0; + const char* p; + char *demangled = NULL; + int at_start_name; + int changed; + char *demangling_buffer = NULL; + size_t demangling_buffer_size = 0; + + changed = 0; + + if (strncmp (mangled, "_ada_", 5) == 0) + { + mangled += 5; + changed = 1; + } + + if (mangled[0] == '_' || mangled[0] == '<') + goto Suppress; + + p = strstr (mangled, "___"); + if (p == NULL) + len0 = strlen (mangled); + else + { + if (p[3] == 'X') + { + len0 = p - mangled; + changed = 1; + } + else + goto Suppress; + } + + /* Make demangled big enough for possible expansion by operator name. */ + grow_vect ((void **) &(demangling_buffer), + &demangling_buffer_size, 2 * len0 + 1, + sizeof (char)); + demangled = demangling_buffer; + + if (ISDIGIT ((unsigned char) mangled[len0 - 1])) { + for (i = len0 - 2; i >= 0 && ISDIGIT ((unsigned char) mangled[i]); i -= 1) + ; + if (i > 1 && mangled[i] == '_' && mangled[i - 1] == '_') + { + len0 = i - 1; + changed = 1; + } + else if (mangled[i] == '$') + { + len0 = i; + changed = 1; + } + } + + for (i = 0, j = 0; i < len0 && ! ISALPHA ((unsigned char)mangled[i]); + i += 1, j += 1) + demangled[j] = mangled[i]; + + at_start_name = 1; + while (i < len0) + { + at_start_name = 0; + + if (i < len0 - 2 && mangled[i] == '_' && mangled[i + 1] == '_') + { + demangled[j] = '.'; + changed = at_start_name = 1; + i += 2; j += 1; + } + else + { + demangled[j] = mangled[i]; + i += 1; j += 1; + } + } + demangled[j] = '\000'; + + for (i = 0; demangled[i] != '\0'; i += 1) + if (ISUPPER ((unsigned char)demangled[i]) || demangled[i] == ' ') + goto Suppress; + + if (! changed) + return NULL; + else + return demangled; + + Suppress: + grow_vect ((void **) &(demangling_buffer), + &demangling_buffer_size, strlen (mangled) + 3, + sizeof (char)); + demangled = demangling_buffer; + if (mangled[0] == '<') + strcpy (demangled, mangled); + else + sprintf (demangled, "<%s>", mangled); + + return demangled; +} + /* This function performs most of what cplus_demangle use to do, but to be able to demangle a name with a B, K or n code, we need to have a longer term memory of what types have been seen. The original @@ -920,7 +1079,7 @@ internal_cplus_demangle (work, mangled) string decl; int success = 0; char *demangled = NULL; - int s1,s2,s3,s4; + int s1, s2, s3, s4; s1 = work->constructor; s2 = work->destructor; s3 = work->static_type; @@ -973,7 +1132,7 @@ internal_cplus_demangle (work, mangled) work->destructor = s2; work->static_type = s3; work->type_quals = s4; - return (demangled); + return demangled; } @@ -1134,7 +1293,7 @@ mop_up (work, declp, success) else { string_appendn (declp, "", 1); - demangled = declp -> b; + demangled = declp->b; } return (demangled); } @@ -1374,7 +1533,7 @@ demangle_signature (work, mangled, declp) if (HP_DEMANGLING) { (*mangled)++; - while (**mangled && isdigit ((unsigned char)**mangled)) + while (**mangled && ISDIGIT ((unsigned char)**mangled)) (*mangled)++; } else @@ -1573,9 +1732,7 @@ demangle_expression (work, mangled, s, tk) len = strlen (*mangled); - for (i = 0; - i < sizeof (optable) / sizeof (optable [0]); - ++i) + for (i = 0; i < ARRAY_SIZE (optable); ++i) { size_t l = strlen (optable[i].in); @@ -1709,7 +1866,7 @@ demangle_real_value (work, mangled, s) string_appendn (s, "-", 1); (*mangled)++; } - while (isdigit ((unsigned char)**mangled)) + while (ISDIGIT ((unsigned char)**mangled)) { string_appendn (s, *mangled, 1); (*mangled)++; @@ -1718,7 +1875,7 @@ demangle_real_value (work, mangled, s) { string_appendn (s, ".", 1); (*mangled)++; - while (isdigit ((unsigned char)**mangled)) + while (ISDIGIT ((unsigned char)**mangled)) { string_appendn (s, *mangled, 1); (*mangled)++; @@ -1728,7 +1885,7 @@ demangle_real_value (work, mangled, s) { string_appendn (s, "e", 1); (*mangled)++; - while (isdigit ((unsigned char)**mangled)) + while (ISDIGIT ((unsigned char)**mangled)) { string_appendn (s, *mangled, 1); (*mangled)++; @@ -2579,20 +2736,20 @@ demangle_prefix (work, mangled, declp) } else if (work -> static_type) { - if (!isdigit ((unsigned char)scan[0]) && (scan[0] != 't')) + if (!ISDIGIT ((unsigned char)scan[0]) && (scan[0] != 't')) { success = 0; } } else if ((scan == *mangled) - && (isdigit ((unsigned char)scan[2]) || (scan[2] == 'Q') + && (ISDIGIT ((unsigned char)scan[2]) || (scan[2] == 'Q') || (scan[2] == 't') || (scan[2] == 'K') || (scan[2] == 'H'))) { /* The ARM says nothing about the mangling of local variables. But cfront mangles local variables by prepending __<nesting_level> to them. As an extension to ARM demangling we handle this case. */ if ((LUCID_DEMANGLING || ARM_DEMANGLING || HP_DEMANGLING) - && isdigit ((unsigned char)scan[2])) + && ISDIGIT ((unsigned char)scan[2])) { *mangled = scan + 2; consume_count (mangled); @@ -2629,7 +2786,7 @@ demangle_prefix (work, mangled, declp) /* EDG template? */ demangle_arm_hp_template (work, mangled, strlen (*mangled), declp); } - else if ((scan == *mangled) && !isdigit ((unsigned char)scan[2]) + else if ((scan == *mangled) && !ISDIGIT ((unsigned char)scan[2]) && (scan[2] != 't')) { /* Mangled name starts with "__". Skip over any leading '_' characters, @@ -2751,7 +2908,7 @@ gnu_special (work, mangled, declp) 1); break; default: - if (isdigit((unsigned char)*mangled[0])) + if (ISDIGIT((unsigned char)*mangled[0])) { n = consume_count(mangled); /* We may be seeing a too-large size, or else a @@ -3278,13 +3435,13 @@ get_count (type, count) const char *p; int n; - if (!isdigit ((unsigned char)**type)) + if (!ISDIGIT ((unsigned char)**type)) return (0); else { *count = **type - '0'; (*type)++; - if (isdigit ((unsigned char)**type)) + if (ISDIGIT ((unsigned char)**type)) { p = *type; n = *count; @@ -3294,7 +3451,7 @@ get_count (type, count) n += *p - '0'; p++; } - while (isdigit ((unsigned char)*p)); + while (ISDIGIT ((unsigned char)*p)); if (*p == '_') { *type = p + 1; @@ -3424,7 +3581,7 @@ do_type (work, mangled, result) if (**mangled != 'Q') string_prepend (&decl, SCOPE_STRING (work)); - if (isdigit ((unsigned char)**mangled)) + if (ISDIGIT ((unsigned char)**mangled)) { n = consume_count (mangled); if (n == -1 @@ -3744,7 +3901,7 @@ demangle_fund_type (work, mangled, result) break; case 'G': (*mangled)++; - if (!isdigit ((unsigned char)**mangled)) + if (!ISDIGIT ((unsigned char)**mangled)) { success = 0; break; @@ -3856,12 +4013,12 @@ do_hpacc_template_const_value (work, mangled, result) } /* We have to be looking at an integer now */ - if (!(isdigit ((unsigned char)**mangled))) + if (!(ISDIGIT ((unsigned char)**mangled))) return 0; /* We only deal with integral values for template parameters -- so it's OK to look only for digits */ - while (isdigit ((unsigned char)**mangled)) + while (ISDIGIT ((unsigned char)**mangled)) { char_str[0] = **mangled; string_append (result, char_str); @@ -3940,10 +4097,10 @@ snarf_numeric_literal (args, arg) else if (**args == '+') (*args)++; - if (!isdigit ((unsigned char)**args)) + if (!ISDIGIT ((unsigned char)**args)) return 0; - while (isdigit ((unsigned char)**args)) + while (ISDIGIT ((unsigned char)**args)) { char_str[0] = **args; string_append (arg, char_str); @@ -4449,7 +4606,7 @@ demangle_function_name (work, mangled, declp, scan) if (declp->p - declp->b >= 10 /* op$assign_ */ && memcmp (declp->b + 3, "assign_", 7) == 0) { - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { int len = declp->p - declp->b - 10; if ((int) strlen (optable[i].in) == len @@ -4465,7 +4622,7 @@ demangle_function_name (work, mangled, declp, scan) } else { - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { int len = declp->p - declp->b - 3; if ((int) strlen (optable[i].in) == len @@ -4507,13 +4664,13 @@ demangle_function_name (work, mangled, declp, scan) } } else if (declp->b[0] == '_' && declp->b[1] == '_' - && islower((unsigned char)declp->b[2]) - && islower((unsigned char)declp->b[3])) + && ISLOWER((unsigned char)declp->b[2]) + && ISLOWER((unsigned char)declp->b[3])) { if (declp->b[4] == '\0') { /* Operator. */ - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { if (strlen (optable[i].in) == 2 && memcmp (optable[i].in, declp->b + 2, 2) == 0) @@ -4530,7 +4687,7 @@ demangle_function_name (work, mangled, declp, scan) if (declp->b[2] == 'a' && declp->b[5] == '\0') { /* Assignment. */ - for (i = 0; i < sizeof (optable) / sizeof (optable[0]); i++) + for (i = 0; i < ARRAY_SIZE (optable); i++) { if (strlen (optable[i].in) == 3 && memcmp (optable[i].in, declp->b + 2, 3) == 0) @@ -4816,7 +4973,7 @@ static const char * hp_symbol_characters PARAMS ((void)); static const char * -gnu_new_abi_symbol_characters PARAMS ((void)); +gnu_v3_symbol_characters PARAMS ((void)); /* Return the string of non-alnum characters that may occur as a valid symbol component, in the standard assembler symbol @@ -4867,13 +5024,13 @@ hp_symbol_characters () /* Return the string of non-alnum characters that may occur - as a valid symbol component in the GNU standard C++ ABI mangling + as a valid symbol component in the GNU C++ V3 ABI mangling scheme. */ static const char * -gnu_new_abi_symbol_characters () +gnu_v3_symbol_characters () { - return "_"; + return "_$."; } @@ -4945,14 +5102,17 @@ main (argc, argv) case gnu_demangling: case lucid_demangling: case arm_demangling: + case java_demangling: case edg_demangling: + case gnat_demangling: + case auto_demangling: valid_symbols = standard_symbol_characters (); break; case hp_demangling: valid_symbols = hp_symbol_characters (); break; - case gnu_new_abi_demangling: - valid_symbols = gnu_new_abi_symbol_characters (); + case gnu_v3_demangling: + valid_symbols = gnu_v3_symbol_characters (); break; default: /* Folks should explicitly indicate the appropriate alphabet for @@ -4966,7 +5126,7 @@ main (argc, argv) int i = 0; c = getchar (); /* Try to read a label. */ - while (c != EOF && (isalnum (c) || strchr (valid_symbols, c))) + while (c != EOF && (ISALNUM (c) || strchr (valid_symbols, c))) { if (i >= MBUF_SIZE-1) break; diff --git a/contrib/binutils/libiberty/dyn-string.c b/contrib/binutils/libiberty/dyn-string.c index 69897f8..34f88ad 100644 --- a/contrib/binutils/libiberty/dyn-string.c +++ b/contrib/binutils/libiberty/dyn-string.c @@ -305,6 +305,30 @@ dyn_string_insert_cstr (dest, pos, src) return 1; } +/* Inserts character C into DEST starting at position POS. DEST is + expanded as necessary. Returns 1 on success. On failure, + RETURN_ON_ALLOCATION_FAILURE, deletes DEST and returns 0. */ + +int +dyn_string_insert_char (dest, pos, c) + dyn_string_t dest; + int pos; + int c; +{ + int i; + + if (dyn_string_resize (dest, dest->length + 1) == NULL) + return 0; + /* Make room for the insertion. Be sure to copy the NUL. */ + for (i = dest->length; i >= pos; --i) + dest->s[i + 1] = dest->s[i]; + /* Add the new character. */ + dest->s[pos] = c; + /* Compute the new length. */ + ++dest->length; + return 1; +} + /* Append S to DS, resizing DS if necessary. Returns 1 on success. On failure, if RETURN_ON_ALLOCATION_FAILURE, deletes DEST and returns 0. */ diff --git a/contrib/binutils/libiberty/floatformat.c b/contrib/binutils/libiberty/floatformat.c index 1d8f16d..3cb78f5 100644 --- a/contrib/binutils/libiberty/floatformat.c +++ b/contrib/binutils/libiberty/floatformat.c @@ -1,5 +1,5 @@ /* IEEE floating point support routines, for GDB, the GNU Debugger. - Copyright (C) 1991, 1994, 1999 Free Software Foundation, Inc. + Copyright (C) 1991, 1994, 1999, 2000 Free Software Foundation, Inc. This file is part of GDB. @@ -36,19 +36,27 @@ extern char *memset (); /* floatformats for IEEE single and double, big and little endian. */ const struct floatformat floatformat_ieee_single_big = { - floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23, floatformat_intbit_no + floatformat_big, 32, 0, 1, 8, 127, 255, 9, 23, + floatformat_intbit_no, + "floatformat_ieee_single_big" }; const struct floatformat floatformat_ieee_single_little = { - floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23, floatformat_intbit_no + floatformat_little, 32, 0, 1, 8, 127, 255, 9, 23, + floatformat_intbit_no, + "floatformat_ieee_single_little" }; const struct floatformat floatformat_ieee_double_big = { - floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52, floatformat_intbit_no + floatformat_big, 64, 0, 1, 11, 1023, 2047, 12, 52, + floatformat_intbit_no, + "floatformat_ieee_double_big" }; const struct floatformat floatformat_ieee_double_little = { - floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52, floatformat_intbit_no + floatformat_little, 64, 0, 1, 11, 1023, 2047, 12, 52, + floatformat_intbit_no, + "floatformat_ieee_double_little" }; /* floatformat for IEEE double, little endian byte order, with big endian word @@ -56,24 +64,30 @@ const struct floatformat floatformat_ieee_double_little = const struct floatformat floatformat_ieee_double_littlebyte_bigword = { - floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52, floatformat_intbit_no + floatformat_littlebyte_bigword, 64, 0, 1, 11, 1023, 2047, 12, 52, + floatformat_intbit_no, + "floatformat_ieee_double_little" }; const struct floatformat floatformat_i387_ext = { floatformat_little, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, - floatformat_intbit_yes + floatformat_intbit_yes, + "floatformat_i387_ext" }; const struct floatformat floatformat_m68881_ext = { /* Note that the bits from 16 to 31 are unused. */ - floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64, floatformat_intbit_yes + floatformat_big, 96, 0, 1, 15, 0x3fff, 0x7fff, 32, 64, + floatformat_intbit_yes, + "floatformat_m68881_ext" }; const struct floatformat floatformat_i960_ext = { /* Note that the bits from 0 to 15 are unused. */ floatformat_little, 96, 16, 17, 15, 0x3fff, 0x7fff, 32, 64, - floatformat_intbit_yes + floatformat_intbit_yes, + "floatformat_i960_ext" }; const struct floatformat floatformat_m88110_ext = { @@ -81,17 +95,20 @@ const struct floatformat floatformat_m88110_ext = /* Harris uses raw format 128 bytes long, but the number is just an ieee double, and the last 64 bits are wasted. */ floatformat_big,128, 0, 1, 11, 0x3ff, 0x7ff, 12, 52, - floatformat_intbit_no + floatformat_intbit_no, + "floatformat_m88110_ext(harris)" #else floatformat_big, 80, 0, 1, 15, 0x3fff, 0x7fff, 16, 64, - floatformat_intbit_yes + floatformat_intbit_yes, + "floatformat_m88110_ext" #endif /* HARRIS_FLOAT_FORMAT */ }; const struct floatformat floatformat_arm_ext = { /* Bits 1 to 16 are unused. */ floatformat_big, 96, 0, 17, 15, 0x3fff, 0x7fff, 32, 64, - floatformat_intbit_yes + floatformat_intbit_yes, + "floatformat_arm_ext" }; static unsigned long get_field PARAMS ((unsigned char *, diff --git a/contrib/binutils/libiberty/fnmatch.c b/contrib/binutils/libiberty/fnmatch.c index 0a9bfe6..eb898ee 100644 --- a/contrib/binutils/libiberty/fnmatch.c +++ b/contrib/binutils/libiberty/fnmatch.c @@ -1,7 +1,7 @@ /* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc. -NOTE: The canonical source of this file is maintained with the GNU C Library. -Bugs can be reported to bug-glibc@prep.ai.mit.edu. +NOTE: This source is derived from an old version taken from the GNU C +Library (glibc). This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the @@ -45,8 +45,7 @@ Boston, MA 02111-1307, USA. */ #include <errno.h> #include <fnmatch.h> -#include <ctype.h> - +#include <safe-ctype.h> /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C @@ -74,8 +73,7 @@ fnmatch (pattern, string, flags) register const char *p = pattern, *n = string; register unsigned char c; -/* Note that this evalutes C many times. */ -#define FOLD(c) ((flags & FNM_CASEFOLD) && isupper (c) ? tolower (c) : (c)) +#define FOLD(c) ((flags & FNM_CASEFOLD) ? TOLOWER (c) : (c)) while ((c = *p++) != '\0') { diff --git a/contrib/binutils/libiberty/getcwd.c b/contrib/binutils/libiberty/getcwd.c index 47b1c1e..3445563 100644 --- a/contrib/binutils/libiberty/getcwd.c +++ b/contrib/binutils/libiberty/getcwd.c @@ -29,6 +29,12 @@ BUGS #include <sys/param.h> #endif #include <errno.h> +#ifdef HAVE_STRING_H +#include <string.h> +#endif +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif extern char *getwd (); extern int errno; diff --git a/contrib/binutils/libiberty/getopt.c b/contrib/binutils/libiberty/getopt.c index c41531e..fd302b6 100644 --- a/contrib/binutils/libiberty/getopt.c +++ b/contrib/binutils/libiberty/getopt.c @@ -6,8 +6,8 @@ Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98 Free Software Foundation, Inc. - NOTE: The canonical source of this file is maintained with the GNU C Library. - Bugs can be reported to bug-glibc@gnu.org. + NOTE: This source is derived from an old version taken from the GNU C + Library (glibc). This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the diff --git a/contrib/binutils/libiberty/getopt1.c b/contrib/binutils/libiberty/getopt1.c index ff25737..a3637c2 100644 --- a/contrib/binutils/libiberty/getopt1.c +++ b/contrib/binutils/libiberty/getopt1.c @@ -2,8 +2,8 @@ Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 Free Software Foundation, Inc. - NOTE: The canonical source of this file is maintained with the GNU C Library. - Bugs can be reported to bug-glibc@gnu.org. + NOTE: This source is derived from an old version taken from the GNU C + Library (glibc). This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the diff --git a/contrib/binutils/libiberty/getruntime.c b/contrib/binutils/libiberty/getruntime.c index b855ea6..4abfa83 100644 --- a/contrib/binutils/libiberty/getruntime.c +++ b/contrib/binutils/libiberty/getruntime.c @@ -26,10 +26,20 @@ Boston, MA 02111-1307, USA. */ single way is available for all host systems, nor are there reliable ways to find out which way is correct for a given host. */ -#include <time.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 #if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H) -#include <sys/time.h> #include <sys/resource.h> #endif diff --git a/contrib/binutils/libiberty/hashtab.c b/contrib/binutils/libiberty/hashtab.c index 16c5d3e..122ed43 100644 --- a/contrib/binutils/libiberty/hashtab.c +++ b/contrib/binutils/libiberty/hashtab.c @@ -1,5 +1,5 @@ /* An expandable hash tables datatype. - Copyright (C) 1999 Free Software Foundation, Inc. + Copyright (C) 1999, 2000 Free Software Foundation, Inc. Contributed by Vladimir Makarov (vmakarov@cygnus.com). This file is part of the libiberty library. @@ -41,6 +41,10 @@ Boston, MA 02111-1307, USA. */ #include <stdlib.h> #endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif + #include <stdio.h> #include "libiberty.h" @@ -48,44 +52,113 @@ Boston, MA 02111-1307, USA. */ /* This macro defines reserved value for empty table entry. */ -#define EMPTY_ENTRY ((void *) 0) +#define EMPTY_ENTRY ((PTR) 0) /* This macro defines reserved value for table entry which contained a deleted element. */ -#define DELETED_ENTRY ((void *) 1) +#define DELETED_ENTRY ((PTR) 1) + +static unsigned long higher_prime_number PARAMS ((unsigned long)); +static hashval_t hash_pointer PARAMS ((const void *)); +static int eq_pointer PARAMS ((const void *, const void *)); +static int htab_expand PARAMS ((htab_t)); +static PTR *find_empty_slot_for_expand PARAMS ((htab_t, hashval_t)); -/* The following function returns the nearest prime number which is - greater than given source number. */ +/* At some point, we could make these be NULL, and modify the + hash-table routines to handle NULL specially; that would avoid + function-call overhead for the common case of hashing pointers. */ +htab_hash htab_hash_pointer = hash_pointer; +htab_eq htab_eq_pointer = eq_pointer; + +/* The following function returns a nearest prime number which is + greater than N, and near a power of two. */ static unsigned long higher_prime_number (n) unsigned long n; { - unsigned long i; - - n |= 0x01; /* Force N to be odd. */ - if (n < 9) - return n; /* All odd numbers < 9 are prime. */ + /* These are primes that are near, but slightly smaller than, a + power of two. */ + static unsigned long primes[] = { + 2, + 7, + 13, + 31, + 61, + 127, + 251, + 509, + 1021, + 2039, + 4093, + 8191, + 16381, + 32749, + 65521, + 131071, + 262139, + 524287, + 1048573, + 2097143, + 4194301, + 8388593, + 16777213, + 33554393, + 67108859, + 134217689, + 268435399, + 536870909, + 1073741789, + 2147483647, + 4294967291 + }; + + unsigned long* low = &primes[0]; + unsigned long* high = &primes[sizeof(primes) / sizeof(primes[0])]; + + while (low != high) + { + unsigned long* mid = low + (high - low) / 2; + if (n > *mid) + low = mid + 1; + else + high = mid; + } - next: - n += 2; - i = 3; - do + /* If we've run out of primes, abort. */ + if (n > *low) { - if (n % i == 0) - goto next; - i += 2; + fprintf (stderr, "Cannot find prime bigger than %lu\n", n); + abort (); } - while ((i * i) <= n); - return n; + return *low; +} + +/* Returns a hash code for P. */ + +static hashval_t +hash_pointer (p) + const PTR p; +{ + return (hashval_t) ((long)p >> 3); +} + +/* Returns non-zero if P1 and P2 are equal. */ + +static int +eq_pointer (p1, p2) + const PTR p1; + const PTR p2; +{ + return p1 == p2; } /* This function creates table with length slightly longer than given source length. Created hash table is initiated as empty (all the hash table entries are EMPTY_ENTRY). The function returns the - created hash table. */ + created hash table. Memory allocation must not fail. */ htab_t htab_create (size, hash_f, eq_f, del_f) @@ -98,11 +171,46 @@ htab_create (size, hash_f, eq_f, del_f) size = higher_prime_number (size); result = (htab_t) xcalloc (1, sizeof (struct htab)); - result->entries = (void **) xcalloc (size, sizeof (void *)); + result->entries = (PTR *) xcalloc (size, sizeof (PTR)); result->size = size; result->hash_f = hash_f; result->eq_f = eq_f; result->del_f = del_f; + result->return_allocation_failure = 0; + return result; +} + +/* This function creates table with length slightly longer than given + source length. The created hash table is initiated as empty (all the + hash table entries are EMPTY_ENTRY). The function returns the created + hash table. Memory allocation may fail; it may return NULL. */ + +htab_t +htab_try_create (size, hash_f, eq_f, del_f) + size_t size; + htab_hash hash_f; + htab_eq eq_f; + htab_del del_f; +{ + htab_t result; + + size = higher_prime_number (size); + result = (htab_t) calloc (1, sizeof (struct htab)); + if (result == NULL) + return NULL; + + result->entries = (PTR *) calloc (size, sizeof (PTR)); + if (result->entries == NULL) + { + free (result); + return NULL; + } + + result->size = size; + result->hash_f = hash_f; + result->eq_f = eq_f; + result->del_f = del_f; + result->return_allocation_failure = 1; return result; } @@ -114,13 +222,12 @@ htab_delete (htab) htab_t htab; { int i; + if (htab->del_f) for (i = htab->size - 1; i >= 0; i--) - { - if (htab->entries[i] != EMPTY_ENTRY - && htab->entries[i] != DELETED_ENTRY) - (*htab->del_f) (htab->entries[i]); - } + if (htab->entries[i] != EMPTY_ENTRY + && htab->entries[i] != DELETED_ENTRY) + (*htab->del_f) (htab->entries[i]); free (htab->entries); free (htab); @@ -133,15 +240,14 @@ htab_empty (htab) htab_t htab; { int i; + if (htab->del_f) for (i = htab->size - 1; i >= 0; i--) - { - if (htab->entries[i] != EMPTY_ENTRY - && htab->entries[i] != DELETED_ENTRY) - (*htab->del_f) (htab->entries[i]); - } + if (htab->entries[i] != EMPTY_ENTRY + && htab->entries[i] != DELETED_ENTRY) + (*htab->del_f) (htab->entries[i]); - memset (htab->entries, 0, htab->size * sizeof (void *)); + memset (htab->entries, 0, htab->size * sizeof (PTR)); } /* Similar to htab_find_slot, but without several unwanted side effects: @@ -150,22 +256,23 @@ htab_empty (htab) hash table. This function also assumes there are no deleted entries in the table. HASH is the hash value for the element to be inserted. */ -static void ** + +static PTR * find_empty_slot_for_expand (htab, hash) htab_t htab; - unsigned int hash; + hashval_t hash; { size_t size = htab->size; - unsigned int hash2 = 1 + hash % (size - 2); + hashval_t hash2 = 1 + hash % (size - 2); unsigned int index = hash % size; for (;;) { - void **slot = htab->entries + index; + PTR *slot = htab->entries + index; + if (*slot == EMPTY_ENTRY) return slot; - - if (*slot == DELETED_ENTRY) + else if (*slot == DELETED_ENTRY) abort (); index += hash2; @@ -178,21 +285,32 @@ find_empty_slot_for_expand (htab, hash) entries and repeatedly inserts the table elements. The occupancy of the table after the call will be about 50%. Naturally the hash table must already exist. Remember also that the place of the - table entries is changed. */ + table entries is changed. If memory allocation failures are allowed, + this function will return zero, indicating that the table could not be + expanded. If all goes well, it will return a non-zero value. */ -static void +static int htab_expand (htab) htab_t htab; { - void **oentries; - void **olimit; - void **p; + PTR *oentries; + PTR *olimit; + PTR *p; oentries = htab->entries; olimit = oentries + htab->size; htab->size = higher_prime_number (htab->size * 2); - htab->entries = xcalloc (htab->size, sizeof (void **)); + + if (htab->return_allocation_failure) + { + PTR *nentries = (PTR *) calloc (htab->size, sizeof (PTR *)); + if (nentries == NULL) + return 0; + htab->entries = nentries; + } + else + htab->entries = (PTR *) xcalloc (htab->size, sizeof (PTR *)); htab->n_elements -= htab->n_deleted; htab->n_deleted = 0; @@ -200,56 +318,69 @@ htab_expand (htab) p = oentries; do { - void *x = *p; + PTR x = *p; + if (x != EMPTY_ENTRY && x != DELETED_ENTRY) { - void **q = find_empty_slot_for_expand (htab, (*htab->hash_f) (x)); + PTR *q = find_empty_slot_for_expand (htab, (*htab->hash_f) (x)); + *q = x; } + p++; } while (p < olimit); + free (oentries); + return 1; } /* This function searches for a hash table entry equal to the given element. It cannot be used to insert or delete an element. */ -void * +PTR htab_find_with_hash (htab, element, hash) htab_t htab; - const void *element; - unsigned int hash; + const PTR element; + hashval_t hash; { - unsigned int index, hash2; + unsigned int index; + hashval_t hash2; size_t size; + PTR entry; htab->searches++; size = htab->size; - hash2 = 1 + hash % (size - 2); index = hash % size; + entry = htab->entries[index]; + if (entry == EMPTY_ENTRY + || (entry != DELETED_ENTRY && (*htab->eq_f) (entry, element))) + return entry; + + hash2 = 1 + hash % (size - 2); + for (;;) { - void *entry = htab->entries[index]; - if (entry == EMPTY_ENTRY) - return NULL; - else if (entry != DELETED_ENTRY && (*htab->eq_f) (entry, element)) - return entry; - htab->collisions++; index += hash2; if (index >= size) index -= size; + + entry = htab->entries[index]; + if (entry == EMPTY_ENTRY + || (entry != DELETED_ENTRY && (*htab->eq_f) (entry, element))) + return entry; } } /* Like htab_find_slot_with_hash, but compute the hash value from the element. */ -void * + +PTR htab_find (htab, element) htab_t htab; - const void *element; + const PTR element; { return htab_find_with_hash (htab, element, (*htab->hash_f) (element)); } @@ -258,21 +389,25 @@ htab_find (htab, element) equal to the given element. To delete an entry, call this with INSERT = 0, then call htab_clear_slot on the slot returned (possibly after doing some checks). To insert an entry, call this with - INSERT = 1, then write the value you want into the returned slot. */ + INSERT = 1, then write the value you want into the returned slot. + When inserting an entry, NULL may be returned if memory allocation + fails. */ -void ** +PTR * htab_find_slot_with_hash (htab, element, hash, insert) htab_t htab; - const void *element; - unsigned int hash; - int insert; + const PTR element; + hashval_t hash; + enum insert_option insert; { - void **first_deleted_slot; - unsigned int index, hash2; + PTR *first_deleted_slot; + unsigned int index; + hashval_t hash2; size_t size; - if (insert && htab->size * 3 <= htab->n_elements * 4) - htab_expand (htab); + if (insert == INSERT && htab->size * 3 <= htab->n_elements * 4 + && htab_expand (htab) == 0) + return NULL; size = htab->size; hash2 = 1 + hash % (size - 2); @@ -283,10 +418,10 @@ htab_find_slot_with_hash (htab, element, hash, insert) for (;;) { - void *entry = htab->entries[index]; + PTR entry = htab->entries[index]; if (entry == EMPTY_ENTRY) { - if (!insert) + if (insert == NO_INSERT) return NULL; htab->n_elements++; @@ -305,11 +440,8 @@ htab_find_slot_with_hash (htab, element, hash, insert) if (!first_deleted_slot) first_deleted_slot = &htab->entries[index]; } - else - { - if ((*htab->eq_f) (entry, element)) - return &htab->entries[index]; - } + else if ((*htab->eq_f) (entry, element)) + return &htab->entries[index]; htab->collisions++; index += hash2; @@ -320,11 +452,12 @@ htab_find_slot_with_hash (htab, element, hash, insert) /* Like htab_find_slot_with_hash, but compute the hash value from the element. */ -void ** + +PTR * htab_find_slot (htab, element, insert) htab_t htab; - const void *element; - int insert; + const PTR element; + enum insert_option insert; { return htab_find_slot_with_hash (htab, element, (*htab->hash_f) (element), insert); @@ -337,11 +470,11 @@ htab_find_slot (htab, element, insert) void htab_remove_elt (htab, element) htab_t htab; - void *element; + PTR element; { - void **slot; + PTR *slot; - slot = htab_find_slot (htab, element, 0); + slot = htab_find_slot (htab, element, NO_INSERT); if (*slot == EMPTY_ENTRY) return; @@ -359,13 +492,15 @@ htab_remove_elt (htab, element) void htab_clear_slot (htab, slot) htab_t htab; - void **slot; + PTR *slot; { if (slot < htab->entries || slot >= htab->entries + htab->size || *slot == EMPTY_ENTRY || *slot == DELETED_ENTRY) abort (); + if (htab->del_f) (*htab->del_f) (*slot); + *slot = DELETED_ENTRY; htab->n_deleted++; } @@ -379,14 +514,15 @@ void htab_traverse (htab, callback, info) htab_t htab; htab_trav callback; - void *info; + PTR info; { - void **slot, **limit; - slot = htab->entries; - limit = slot + htab->size; + PTR *slot = htab->entries; + PTR *limit = slot + htab->size; + do { - void *x = *slot; + PTR x = *slot; + if (x != EMPTY_ENTRY && x != DELETED_ENTRY) if (!(*callback) (slot, info)) break; @@ -394,7 +530,7 @@ htab_traverse (htab, callback, info) while (++slot < limit); } -/* The following function returns current size of given hash table. */ +/* Return the current size of given hash table. */ size_t htab_size (htab) @@ -403,8 +539,7 @@ htab_size (htab) return htab->size; } -/* The following function returns current number of elements in given - hash table. */ +/* Return the current number of elements in given hash table. */ size_t htab_elements (htab) @@ -413,17 +548,15 @@ htab_elements (htab) return htab->n_elements - htab->n_deleted; } -/* The following function returns number of percents of fixed - collisions during all work with given hash table. */ +/* Return the fraction of fixed collisions during all work with given + hash table. */ double htab_collisions (htab) htab_t htab; { - int searches; - - searches = htab->searches; - if (searches == 0) + if (htab->searches == 0) return 0.0; - return (double)htab->collisions / (double)searches; + + return (double) htab->collisions / (double) htab->searches; } diff --git a/contrib/binutils/libiberty/md5.c b/contrib/binutils/libiberty/md5.c new file mode 100644 index 0000000..20c3cd1 --- /dev/null +++ b/contrib/binutils/libiberty/md5.c @@ -0,0 +1,421 @@ +/* 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. + + NOTE: This source is derived from an old version taken from the GNU C + Library (glibc). + + This program is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the + Free Software Foundation; either version 2, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Written by Ulrich Drepper <drepper@gnu.ai.mit.edu>, 1995. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <sys/types.h> + +#if STDC_HEADERS || defined _LIBC +# include <stdlib.h> +# include <string.h> +#else +# ifndef HAVE_MEMCPY +# define memcpy(d, s, n) bcopy ((s), (d), (n)) +# endif +#endif + +#include "ansidecl.h" +#include "md5.h" + +#ifdef _LIBC +# include <endian.h> +# if __BYTE_ORDER == __BIG_ENDIAN +# define WORDS_BIGENDIAN 1 +# endif +#endif + +#ifdef WORDS_BIGENDIAN +# define SWAP(n) \ + (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24)) +#else +# define SWAP(n) (n) +#endif + + +/* This array contains the bytes used to pad the buffer to the next + 64-byte boundary. (RFC 1321, 3.1: Step 1) */ +static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ }; + + +/* Initialize structure containing state of computation. + (RFC 1321, 3.3: Step 3) */ +void +md5_init_ctx (ctx) + struct md5_ctx *ctx; +{ + ctx->A = 0x67452301; + ctx->B = 0xefcdab89; + ctx->C = 0x98badcfe; + ctx->D = 0x10325476; + + ctx->total[0] = ctx->total[1] = 0; + ctx->buflen = 0; +} + +/* 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. */ +void * +md5_read_ctx (ctx, resbuf) + 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); + + return resbuf; +} + +/* Process the remaining bytes in the internal buffer and the usual + prolog according to the standard and write the result to RESBUF. + + IMPORTANT: On some systems it is required that RESBUF is correctly + aligned for a 32 bits value. */ +void * +md5_finish_ctx (ctx, resbuf) + struct md5_ctx *ctx; + void *resbuf; +{ + /* Take yet unprocessed bytes into account. */ + md5_uint32 bytes = ctx->buflen; + size_t pad; + + /* Now count remaining bytes. */ + ctx->total[0] += bytes; + if (ctx->total[0] < bytes) + ++ctx->total[1]; + + 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)); + + /* Process last bytes. */ + md5_process_block (ctx->buffer, bytes + pad + 8, ctx); + + return md5_read_ctx (ctx, resbuf); +} + +/* Compute MD5 message digest for bytes read from STREAM. The + resulting message digest number will be written into the 16 bytes + beginning at RESBLOCK. */ +int +md5_stream (stream, resblock) + FILE *stream; + void *resblock; +{ + /* Important: BLOCKSIZE must be a multiple of 64. */ +#define BLOCKSIZE 4096 + struct md5_ctx ctx; + char buffer[BLOCKSIZE + 72]; + size_t sum; + + /* Initialize the computation context. */ + md5_init_ctx (&ctx); + + /* Iterate over full file contents. */ + while (1) + { + /* We read the file in blocks of BLOCKSIZE bytes. One call of the + computation function processes the whole buffer so that with the + next round of the loop another block can be read. */ + size_t n; + sum = 0; + + /* Read block. Take care for partial reads. */ + do + { + n = fread (buffer + sum, 1, BLOCKSIZE - sum, stream); + + sum += n; + } + while (sum < BLOCKSIZE && n != 0); + if (n == 0 && ferror (stream)) + return 1; + + /* If end of file is reached, end the loop. */ + if (n == 0) + break; + + /* Process buffer with BLOCKSIZE bytes. Note that + BLOCKSIZE % 64 == 0 + */ + md5_process_block (buffer, BLOCKSIZE, &ctx); + } + + /* Add the last bytes if necessary. */ + if (sum > 0) + md5_process_bytes (buffer, sum, &ctx); + + /* Construct result in desired memory. */ + md5_finish_ctx (&ctx, resblock); + return 0; +} + +/* Compute MD5 message digest for LEN bytes beginning at BUFFER. The + result is always in little endian byte order, so that a byte-wise + output yields to the wanted ASCII representation of the message + digest. */ +void * +md5_buffer (buffer, len, resblock) + const char *buffer; + size_t len; + void *resblock; +{ + struct md5_ctx ctx; + + /* Initialize the computation context. */ + md5_init_ctx (&ctx); + + /* Process whole buffer but last len % 64 bytes. */ + md5_process_bytes (buffer, len, &ctx); + + /* Put result in desired memory area. */ + return md5_finish_ctx (&ctx, resblock); +} + + +void +md5_process_bytes (buffer, len, ctx) + const void *buffer; + size_t len; + struct md5_ctx *ctx; +{ + /* When we already have some bits in our internal buffer concatenate + both inputs first. */ + if (ctx->buflen != 0) + { + size_t left_over = ctx->buflen; + size_t add = 128 - left_over > len ? len : 128 - left_over; + + memcpy (&ctx->buffer[left_over], buffer, add); + ctx->buflen += add; + + if (left_over + add > 64) + { + md5_process_block (ctx->buffer, (left_over + add) & ~63, ctx); + /* The regions in the following copy operation cannot overlap. */ + memcpy (ctx->buffer, &ctx->buffer[(left_over + add) & ~63], + (left_over + add) & 63); + ctx->buflen = (left_over + add) & 63; + } + + buffer = (const char *) buffer + add; + len -= add; + } + + /* Process available complete blocks. */ + if (len > 64) + { + md5_process_block (buffer, len & ~63, ctx); + buffer = (const char *) buffer + (len & ~63); + len &= 63; + } + + /* Move remaining bytes in internal buffer. */ + if (len > 0) + { + memcpy (ctx->buffer, buffer, len); + ctx->buflen = len; + } +} + + +/* These are the four functions used in the four steps of the MD5 algorithm + and defined in the RFC 1321. The first function is a little bit optimized + (as found in Colin Plumbs public domain implementation). */ +/* #define FF(b, c, d) ((b & c) | (~b & d)) */ +#define FF(b, c, d) (d ^ (b & (c ^ d))) +#define FG(b, c, d) FF (d, b, c) +#define FH(b, c, d) (b ^ c ^ d) +#define FI(b, c, d) (c ^ (b | ~d)) + +/* Process LEN bytes of BUFFER, accumulating context into CTX. + It is assumed that LEN % 64 == 0. */ + +void +md5_process_block (buffer, len, ctx) + const void *buffer; + size_t len; + struct md5_ctx *ctx; +{ + md5_uint32 correct_words[16]; + const md5_uint32 *words = buffer; + size_t nwords = len / sizeof (md5_uint32); + const md5_uint32 *endp = words + nwords; + md5_uint32 A = ctx->A; + md5_uint32 B = ctx->B; + md5_uint32 C = ctx->C; + md5_uint32 D = ctx->D; + + /* First increment the byte count. RFC 1321 specifies the possible + 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]; + + /* Process all bytes in the buffer with 64 bytes in each round of + the loop. */ + while (words < endp) + { + md5_uint32 *cwp = correct_words; + md5_uint32 A_save = A; + md5_uint32 B_save = B; + md5_uint32 C_save = C; + md5_uint32 D_save = D; + + /* First round: using the given function, the context and a constant + the next context is computed. Because the algorithms processing + unit is a 32-bit word and it is determined to work on words in + little endian byte order we perhaps have to change the byte order + before the computation. To reduce the work for the next steps + we store the swapped words in the array CORRECT_WORDS. */ + +#define OP(a, b, c, d, s, T) \ + do \ + { \ + a += FF (b, c, d) + (*cwp++ = SWAP (*words)) + T; \ + ++words; \ + CYCLIC (a, s); \ + a += b; \ + } \ + while (0) + + /* It is unfortunate that C does not provide an operator for + cyclic rotation. Hope the C compiler is smart enough. */ +#define CYCLIC(w, s) (w = (w << s) | (w >> (32 - s))) + + /* Before we start, one word to the strange constants. + They are defined in RFC 1321 as + + T[i] = (int) (4294967296.0 * fabs (sin (i))), i=1..64 + */ + + /* Round 1. */ + OP (A, B, C, D, 7, 0xd76aa478); + OP (D, A, B, C, 12, 0xe8c7b756); + OP (C, D, A, B, 17, 0x242070db); + OP (B, C, D, A, 22, 0xc1bdceee); + OP (A, B, C, D, 7, 0xf57c0faf); + OP (D, A, B, C, 12, 0x4787c62a); + OP (C, D, A, B, 17, 0xa8304613); + OP (B, C, D, A, 22, 0xfd469501); + OP (A, B, C, D, 7, 0x698098d8); + OP (D, A, B, C, 12, 0x8b44f7af); + OP (C, D, A, B, 17, 0xffff5bb1); + OP (B, C, D, A, 22, 0x895cd7be); + OP (A, B, C, D, 7, 0x6b901122); + OP (D, A, B, C, 12, 0xfd987193); + OP (C, D, A, B, 17, 0xa679438e); + OP (B, C, D, A, 22, 0x49b40821); + + /* For the second to fourth round we have the possibly swapped words + in CORRECT_WORDS. Redefine the macro to take an additional first + argument specifying the function to use. */ +#undef OP +#define OP(f, a, b, c, d, k, s, T) \ + do \ + { \ + a += f (b, c, d) + correct_words[k] + T; \ + CYCLIC (a, s); \ + a += b; \ + } \ + while (0) + + /* Round 2. */ + OP (FG, A, B, C, D, 1, 5, 0xf61e2562); + OP (FG, D, A, B, C, 6, 9, 0xc040b340); + OP (FG, C, D, A, B, 11, 14, 0x265e5a51); + OP (FG, B, C, D, A, 0, 20, 0xe9b6c7aa); + OP (FG, A, B, C, D, 5, 5, 0xd62f105d); + OP (FG, D, A, B, C, 10, 9, 0x02441453); + OP (FG, C, D, A, B, 15, 14, 0xd8a1e681); + OP (FG, B, C, D, A, 4, 20, 0xe7d3fbc8); + OP (FG, A, B, C, D, 9, 5, 0x21e1cde6); + OP (FG, D, A, B, C, 14, 9, 0xc33707d6); + OP (FG, C, D, A, B, 3, 14, 0xf4d50d87); + OP (FG, B, C, D, A, 8, 20, 0x455a14ed); + OP (FG, A, B, C, D, 13, 5, 0xa9e3e905); + OP (FG, D, A, B, C, 2, 9, 0xfcefa3f8); + OP (FG, C, D, A, B, 7, 14, 0x676f02d9); + OP (FG, B, C, D, A, 12, 20, 0x8d2a4c8a); + + /* Round 3. */ + OP (FH, A, B, C, D, 5, 4, 0xfffa3942); + OP (FH, D, A, B, C, 8, 11, 0x8771f681); + OP (FH, C, D, A, B, 11, 16, 0x6d9d6122); + OP (FH, B, C, D, A, 14, 23, 0xfde5380c); + OP (FH, A, B, C, D, 1, 4, 0xa4beea44); + OP (FH, D, A, B, C, 4, 11, 0x4bdecfa9); + OP (FH, C, D, A, B, 7, 16, 0xf6bb4b60); + OP (FH, B, C, D, A, 10, 23, 0xbebfbc70); + OP (FH, A, B, C, D, 13, 4, 0x289b7ec6); + OP (FH, D, A, B, C, 0, 11, 0xeaa127fa); + OP (FH, C, D, A, B, 3, 16, 0xd4ef3085); + OP (FH, B, C, D, A, 6, 23, 0x04881d05); + OP (FH, A, B, C, D, 9, 4, 0xd9d4d039); + OP (FH, D, A, B, C, 12, 11, 0xe6db99e5); + OP (FH, C, D, A, B, 15, 16, 0x1fa27cf8); + OP (FH, B, C, D, A, 2, 23, 0xc4ac5665); + + /* Round 4. */ + OP (FI, A, B, C, D, 0, 6, 0xf4292244); + OP (FI, D, A, B, C, 7, 10, 0x432aff97); + OP (FI, C, D, A, B, 14, 15, 0xab9423a7); + OP (FI, B, C, D, A, 5, 21, 0xfc93a039); + OP (FI, A, B, C, D, 12, 6, 0x655b59c3); + OP (FI, D, A, B, C, 3, 10, 0x8f0ccc92); + OP (FI, C, D, A, B, 10, 15, 0xffeff47d); + OP (FI, B, C, D, A, 1, 21, 0x85845dd1); + OP (FI, A, B, C, D, 8, 6, 0x6fa87e4f); + OP (FI, D, A, B, C, 15, 10, 0xfe2ce6e0); + OP (FI, C, D, A, B, 6, 15, 0xa3014314); + OP (FI, B, C, D, A, 13, 21, 0x4e0811a1); + OP (FI, A, B, C, D, 4, 6, 0xf7537e82); + OP (FI, D, A, B, C, 11, 10, 0xbd3af235); + OP (FI, C, D, A, B, 2, 15, 0x2ad7d2bb); + OP (FI, B, C, D, A, 9, 21, 0xeb86d391); + + /* Add the starting values of the context. */ + A += A_save; + B += B_save; + C += C_save; + D += D_save; + } + + /* Put checksum in context given as argument. */ + ctx->A = A; + ctx->B = B; + ctx->C = C; + ctx->D = D; +} diff --git a/contrib/binutils/libiberty/memcmp.c b/contrib/binutils/libiberty/memcmp.c index 127ae0c..0fd21ca 100644 --- a/contrib/binutils/libiberty/memcmp.c +++ b/contrib/binutils/libiberty/memcmp.c @@ -25,8 +25,8 @@ int DEFUN(memcmp, (str1, str2, count), const PTR str1 AND const PTR str2 AND size_t count) { - register unsigned char *s1 = (unsigned char*)str1; - register unsigned char *s2 = (unsigned char*)str2; + register const unsigned char *s1 = (const unsigned char*)str1; + register const unsigned char *s2 = (const unsigned char*)str2; while (count-- > 0) { diff --git a/contrib/binutils/libiberty/mkstemps.c b/contrib/binutils/libiberty/mkstemps.c index 16c16a2..4b89162 100644 --- a/contrib/binutils/libiberty/mkstemps.c +++ b/contrib/binutils/libiberty/mkstemps.c @@ -20,6 +20,7 @@ #include "config.h" #endif +#include <sys/types.h> #ifdef HAVE_STDLIB_H #include <stdlib.h> #endif @@ -39,7 +40,7 @@ /* We need to provide a type for gcc_uint64_t. */ #ifdef __GNUC__ -typedef unsigned long long gcc_uint64_t; +__extension__ typedef unsigned long long gcc_uint64_t; #else typedef unsigned long gcc_uint64_t; #endif diff --git a/contrib/binutils/libiberty/objalloc.c b/contrib/binutils/libiberty/objalloc.c index 57754a8..5099569 100644 --- a/contrib/binutils/libiberty/objalloc.c +++ b/contrib/binutils/libiberty/objalloc.c @@ -18,6 +18,8 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "ansidecl.h" +#include "config.h" + #include "objalloc.h" /* Get a definition for NULL. */ @@ -33,11 +35,16 @@ Boston, MA 02111-1307, USA. */ #include <stddef.h> #endif +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#else /* For systems with larger pointers than ints, this must be declared. */ extern PTR malloc PARAMS ((size_t)); extern void free PARAMS ((PTR)); #endif +#endif + /* These routines allocate space for an object. Freeing allocated space may or may not free all more recently allocated space. diff --git a/contrib/binutils/libiberty/obstack.c b/contrib/binutils/libiberty/obstack.c index bc318b3..0d4a4c8 100644 --- a/contrib/binutils/libiberty/obstack.c +++ b/contrib/binutils/libiberty/obstack.c @@ -2,8 +2,8 @@ Copyright (C) 1988,89,90,91,92,93,94,96,97 Free Software Foundation, Inc. - NOTE: The canonical source of this file is maintained with the GNU C Library. - Bugs can be reported to bug-glibc@gnu.org. + NOTE: This source is derived from an old version taken from the GNU C + Library (glibc). This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the diff --git a/contrib/binutils/libiberty/partition.c b/contrib/binutils/libiberty/partition.c index c1d5847..a5a7349 100644 --- a/contrib/binutils/libiberty/partition.c +++ b/contrib/binutils/libiberty/partition.c @@ -27,9 +27,15 @@ #include <stdlib.h> #endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif + #include "libiberty.h" #include "partition.h" +static int elem_compare PARAMS ((const void *, const void *)); + /* Creates a partition of NUM_ELEMENTS elements. Initially each element is in a class by itself. */ @@ -124,8 +130,8 @@ elem_compare (elem1, elem2) const void *elem1; const void *elem2; { - int e1 = * (int *) elem1; - int e2 = * (int *) elem2; + int e1 = * (const int *) elem1; + int e2 = * (const int *) elem2; if (e1 < e2) return -1; else if (e1 > e2) @@ -171,7 +177,7 @@ partition_print (part, fp) c = elements[c].next - elements; } /* Sort them. */ - qsort ((void *) class_elements, count, sizeof (int), &elem_compare); + qsort ((void *) class_elements, count, sizeof (int), elem_compare); /* Print them. */ fputc ('(', fp); for (i = 0; i < count; ++i) diff --git a/contrib/binutils/libiberty/pexecute.c b/contrib/binutils/libiberty/pexecute.c index 56ddec7..32943af 100644 --- a/contrib/binutils/libiberty/pexecute.c +++ b/contrib/binutils/libiberty/pexecute.c @@ -29,31 +29,24 @@ Boston, MA 02111-1307, USA. */ #include <stdio.h> #include <errno.h> +#ifdef NEED_DECLARATION_ERRNO +extern int errno; +#endif #ifdef HAVE_STRING_H #include <string.h> #endif #ifdef HAVE_UNISTD_H #include <unistd.h> #endif -#define ISSPACE (x) isspace(x) +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif #ifdef HAVE_SYS_WAIT_H #include <sys/wait.h> #endif -#ifdef vfork /* Autoconf may define this to fork for us. */ -# define VFORK_STRING "fork" -#else -# define VFORK_STRING "vfork" -#endif -#ifdef HAVE_VFORK_H -#include <vfork.h> -#endif -#ifdef VMS -#define vfork() (decc$$alloc_vfork_blocks() >= 0 ? \ - lib$get_current_invo_context(decc$$get_vfork_jmpbuf()) : -1) -#endif /* VMS */ - #include "libiberty.h" +#include "safe-ctype.h" /* stdin file number. */ #define STDIN_FILE_NO 0 @@ -151,9 +144,9 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) if ((flags & PEXECUTE_ONE) != PEXECUTE_ONE) abort (); -#ifdef __GO32__ +#ifdef __DJGPP__ /* ??? What are the possible return values from spawnv? */ - rc = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (1, program, argv); + rc = (flags & PEXECUTE_SEARCH ? spawnvp : spawnv) (P_WAIT, program, argv); #else char *scmd, *rf; FILE *argfile; @@ -202,7 +195,7 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) if (rc == -1) { *errmsg_fmt = install_error_msg; - *errmsg_arg = program; + *errmsg_arg = (char *)program; return -1; } @@ -211,6 +204,13 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) return last_pid; } +/* Use ECHILD if available, otherwise use EINVAL. */ +#ifdef ECHILD +#define PWAIT_ERROR ECHILD +#else +#define PWAIT_ERROR EINVAL +#endif + int pwait (pid, status, flags) int pid; @@ -222,13 +222,16 @@ pwait (pid, status, flags) /* Called twice for the same child? */ || pid == last_reaped) { - /* ??? ECHILD would be a better choice. Can we use it here? */ - errno = EINVAL; + errno = PWAIT_ERROR; return -1; } /* ??? Here's an opportunity to canonicalize the values in STATUS. Needed? */ +#ifdef __DJGPP__ + *status = (last_status >> 8); +#else *status = last_status; +#endif last_reaped = last_pid; return last_pid; } @@ -698,9 +701,10 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) /* Fork a subprocess; wait and retry if it fails. */ sleep_interval = 1; + pid = -1; for (retries = 0; retries < 4; retries++) { - pid = vfork (); + pid = fork (); if (pid >= 0) break; sleep (sleep_interval); @@ -710,11 +714,9 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) switch (pid) { case -1: - { - *errmsg_fmt = VFORK_STRING; - *errmsg_arg = NULL; - return -1; - } + *errmsg_fmt = "fork"; + *errmsg_arg = NULL; + return -1; case 0: /* child */ /* Move the input and output pipes into place, if necessary. */ @@ -738,7 +740,6 @@ pexecute (program, argv, this_pname, temp_base, errmsg_fmt, errmsg_arg, flags) /* Exec the program. */ (*func) (program, argv); - /* Note: Calling fprintf and exit here doesn't seem right for vfork. */ fprintf (stderr, "%s: ", this_pname); fprintf (stderr, install_error_msg, program); fprintf (stderr, ": %s\n", xstrerror (errno)); diff --git a/contrib/binutils/libiberty/rename.c b/contrib/binutils/libiberty/rename.c index ae26e2d..2e9dec1 100644 --- a/contrib/binutils/libiberty/rename.c +++ b/contrib/binutils/libiberty/rename.c @@ -3,7 +3,13 @@ /* Rename a file. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include <errno.h> +#ifdef HAVE_UNISTD_H +#include <unistd.h> +#endif int rename (zfrom, zto) diff --git a/contrib/binutils/libiberty/safe-ctype.c b/contrib/binutils/libiberty/safe-ctype.c new file mode 100644 index 0000000..0c2be3e --- /dev/null +++ b/contrib/binutils/libiberty/safe-ctype.c @@ -0,0 +1,163 @@ +/* <ctype.h> replacement macros. + + Copyright (C) 2000 Free Software Foundation, Inc. + Contributed by Zack Weinberg <zackw@stanford.edu>. + +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., 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +/* This is a compatible replacement of the standard C library's <ctype.h> + with the following properties: + + - Implements all isxxx() macros required by C99. + - Also implements some character classes useful when + parsing C-like languages. + - Does not change behavior depending on the current locale. + - Behaves properly for all values in the range of a signed or + unsigned char. */ + +#include "ansidecl.h" +#include <safe-ctype.h> +#include <stdio.h> /* for EOF */ + +/* Shorthand */ +#define bl _sch_isblank +#define cn _sch_iscntrl +#define di _sch_isdigit +#define is _sch_isidst +#define lo _sch_islower +#define nv _sch_isnvsp +#define pn _sch_ispunct +#define pr _sch_isprint +#define sp _sch_isspace +#define up _sch_isupper +#define vs _sch_isvsp +#define xd _sch_isxdigit + +/* Masks. */ +#define L lo|is |pr /* lower case letter */ +#define XL lo|is|xd|pr /* lowercase hex digit */ +#define U up|is |pr /* upper case letter */ +#define XU up|is|xd|pr /* uppercase hex digit */ +#define D di |xd|pr /* decimal digit */ +#define P pn |pr /* punctuation */ +#define _ pn|is |pr /* underscore */ + +#define C cn /* control character */ +#define Z nv |cn /* NUL */ +#define M nv|sp |cn /* cursor movement: \f \v */ +#define V vs|sp |cn /* vertical space: \r \n */ +#define T nv|sp|bl|cn /* tab */ +#define S nv|sp|bl|pr /* space */ + +/* Are we ASCII? */ +#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \ + && 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \ + && EOF == -1 + +const unsigned short _sch_istable[256] = +{ + Z, C, C, C, C, C, C, C, /* NUL SOH STX ETX EOT ENQ ACK BEL */ + C, T, V, M, M, V, C, C, /* BS HT LF VT FF CR SO SI */ + C, C, C, C, C, C, C, C, /* DLE DC1 DC2 DC3 DC4 NAK SYN ETB */ + C, C, C, C, C, C, C, C, /* CAN EM SUB ESC FS GS RS US */ + S, P, P, P, P, P, P, P, /* SP ! " # $ % & ' */ + P, P, P, P, P, P, P, P, /* ( ) * + , - . / */ + D, D, D, D, D, D, D, D, /* 0 1 2 3 4 5 6 7 */ + D, D, P, P, P, P, P, P, /* 8 9 : ; < = > ? */ + P, XU, XU, XU, XU, XU, XU, U, /* @ A B C D E F G */ + U, U, U, U, U, U, U, U, /* H I J K L M N O */ + U, U, U, U, U, U, U, U, /* P Q R S T U V W */ + U, U, U, P, P, P, P, _, /* X Y Z [ \ ] ^ _ */ + P, XL, XL, XL, XL, XL, XL, L, /* ` a b c d e f g */ + L, L, L, L, L, L, L, L, /* h i j k l m n o */ + L, L, L, L, L, L, L, L, /* p q r s t u v w */ + L, L, L, P, P, P, P, C, /* x y z { | } ~ DEL */ + + /* high half of unsigned char is locale-specific, so all tests are + false in "C" locale */ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +}; + +const unsigned char _sch_tolower[256] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, + + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + + 91, 92, 93, 94, 95, 96, + + 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', + 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', + + 123,124,125,126,127, + + 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143, + 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159, + 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175, + 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191, + + 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207, + 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223, + 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239, + 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255, +}; + +const unsigned char _sch_toupper[256] = +{ + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, + + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + + 91, 92, 93, 94, 95, 96, + + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', + 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', + + 123,124,125,126,127, + + 128,129,130,131, 132,133,134,135, 136,137,138,139, 140,141,142,143, + 144,145,146,147, 148,149,150,151, 152,153,154,155, 156,157,158,159, + 160,161,162,163, 164,165,166,167, 168,169,170,171, 172,173,174,175, + 176,177,178,179, 180,181,182,183, 184,185,186,187, 188,189,190,191, + + 192,193,194,195, 196,197,198,199, 200,201,202,203, 204,205,206,207, + 208,209,210,211, 212,213,214,215, 216,217,218,219, 220,221,222,223, + 224,225,226,227, 228,229,230,231, 232,233,234,235, 236,237,238,239, + 240,241,242,243, 244,245,246,247, 248,249,250,251, 252,253,254,255, +}; + +#else + #error "Unsupported host character set" +#endif /* not ASCII */ diff --git a/contrib/binutils/libiberty/setenv.c b/contrib/binutils/libiberty/setenv.c index eec1300..f025716 100644 --- a/contrib/binutils/libiberty/setenv.c +++ b/contrib/binutils/libiberty/setenv.c @@ -63,7 +63,7 @@ setenv (name, value, replace) const char *value; int replace; { - register char **ep; + register char **ep = 0; register size_t size; const size_t namelen = strlen (name); const size_t vallen = strlen (value) + 1; @@ -72,11 +72,13 @@ setenv (name, value, replace) size = 0; if (__environ != NULL) - for (ep = __environ; *ep != NULL; ++ep) - if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=') - break; - else - ++size; + { + for (ep = __environ; *ep != NULL; ++ep) + if (!strncmp (*ep, name, namelen) && (*ep)[namelen] == '=') + break; + else + ++size; + } if (__environ == NULL || *ep == NULL) { diff --git a/contrib/binutils/libiberty/sigsetmask.c b/contrib/binutils/libiberty/sigsetmask.c index 2a09e6a..db6408d 100644 --- a/contrib/binutils/libiberty/sigsetmask.c +++ b/contrib/binutils/libiberty/sigsetmask.c @@ -12,6 +12,8 @@ #include <sys/types.h> #include <signal.h> +extern void abort PARAMS ((void)) ATTRIBUTE_NORETURN; + #ifdef SIG_SETMASK int DEFUN(sigsetmask,(set), diff --git a/contrib/binutils/libiberty/sort.c b/contrib/binutils/libiberty/sort.c new file mode 100644 index 0000000..90c97e0 --- /dev/null +++ b/contrib/binutils/libiberty/sort.c @@ -0,0 +1,190 @@ +/* Sorting algorithms. + Copyright (C) 2000 Free Software Foundation, Inc. + Contributed by Mark Mitchell <mark@codesourcery.com>. + +This file is part of GNU CC. + +GNU CC 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. + +GNU CC 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, 59 Temple Place - Suite 330, +Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include "libiberty.h" +#include "sort.h" +#ifdef HAVE_LIMITS_H +#include <limits.h> +#endif +#ifdef HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif +#ifdef HAVE_STRING_H +#include <string.h> +#endif + +#ifndef UCHAR_MAX +#define UCHAR_MAX ((unsigned char)(-1)) +#endif + +/* POINTERS and WORK are both arrays of N pointers. When this + function returns POINTERS will be sorted in ascending order. */ + +void sort_pointers (n, pointers, work) + size_t n; + void **pointers; + void **work; +{ + /* The type of a single digit. This can be any unsigned integral + type. When changing this, DIGIT_MAX should be changed as + well. */ + typedef unsigned char digit_t; + + /* The maximum value a single digit can have. */ +#define DIGIT_MAX (UCHAR_MAX + 1) + + /* The Ith entry is the number of elements in *POINTERSP that have I + in the digit on which we are currently sorting. */ + unsigned int count[DIGIT_MAX]; + /* Nonzero if we are running on a big-endian machine. */ + int big_endian_p; + size_t i; + size_t j; + + /* The algorithm used here is radix sort which takes time linear in + the number of elements in the array. */ + + /* The algorithm here depends on being able to swap the two arrays + an even number of times. */ + if ((sizeof (void *) / sizeof (digit_t)) % 2 != 0) + abort (); + + /* Figure out the endianness of the machine. */ + for (i = 0, j = 0; i < sizeof (size_t); ++i) + { + j *= (UCHAR_MAX + 1); + j += i; + } + big_endian_p = (((char *)&j)[0] == 0); + + /* Move through the pointer values from least significant to most + significant digits. */ + for (i = 0; i < sizeof (void *) / sizeof (digit_t); ++i) + { + digit_t *digit; + digit_t *bias; + digit_t *top; + unsigned int *countp; + void **pointerp; + + /* The offset from the start of the pointer will depend on the + endianness of the machine. */ + if (big_endian_p) + j = sizeof (void *) / sizeof (digit_t) - i; + else + j = i; + + /* Now, perform a stable sort on this digit. We use counting + sort. */ + memset (count, 0, DIGIT_MAX * sizeof (unsigned int)); + + /* Compute the address of the appropriate digit in the first and + one-past-the-end elements of the array. On a little-endian + machine, the least-significant digit is closest to the front. */ + bias = ((digit_t *) pointers) + j; + top = ((digit_t *) (pointers + n)) + j; + + /* Count how many there are of each value. At the end of this + loop, COUNT[K] will contain the number of pointers whose Ith + digit is K. */ + for (digit = bias; + digit < top; + digit += sizeof (void *) / sizeof (digit_t)) + ++count[*digit]; + + /* Now, make COUNT[K] contain the number of pointers whose Ith + digit is less than or equal to K. */ + for (countp = count + 1; countp < count + DIGIT_MAX; ++countp) + *countp += countp[-1]; + + /* Now, drop the pointers into their correct locations. */ + for (pointerp = pointers + n - 1; pointerp >= pointers; --pointerp) + work[--count[((digit_t *) pointerp)[j]]] = *pointerp; + + /* Swap WORK and POINTERS so that POINTERS contains the sorted + array. */ + pointerp = pointers; + pointers = work; + work = pointerp; + } +} + +/* Everything below here is a unit test for the routines in this + file. */ + +#ifdef UNIT_TEST + +#include <stdio.h> + +void *xmalloc (n) + size_t n; +{ + return malloc (n); +} + +int main (int argc, char **argv) +{ + int k; + int result; + size_t i; + void **pointers; + void **work; + + if (argc > 1) + k = atoi (argv[1]); + else + k = 10; + + pointers = xmalloc (k * sizeof (void *)); + work = xmalloc (k * sizeof (void *)); + + for (i = 0; i < k; ++i) + { + pointers[i] = (void *) random (); + printf ("%x\n", pointers[i]); + } + + sort_pointers (k, pointers, work); + + printf ("\nSorted\n\n"); + + result = 0; + + for (i = 0; i < k; ++i) + { + printf ("%x\n", pointers[i]); + if (i > 0 && (char*) pointers[i] < (char*) pointers[i - 1]) + result = 1; + } + + free (pointers); + free (work); + + return result; +} + +#endif diff --git a/contrib/binutils/libiberty/splay-tree.c b/contrib/binutils/libiberty/splay-tree.c index 22ea07d..52b57c0 100644 --- a/contrib/binutils/libiberty/splay-tree.c +++ b/contrib/binutils/libiberty/splay-tree.c @@ -1,5 +1,5 @@ /* A splay-tree datatype. - Copyright (C) 1998, 1999 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. Contributed by Mark Mitchell (mark@markmitchell.com). This file is part of GNU CC. @@ -32,6 +32,8 @@ Boston, MA 02111-1307, USA. */ #include <stdlib.h> #endif +#include <stdio.h> + #include "libiberty.h" #include "splay-tree.h" @@ -303,12 +305,53 @@ splay_tree_insert (sp, key, value) node->right->left = 0; } - sp->root = node; - } + sp->root = node; + } return sp->root; } +/* Remove KEY from SP. It is not an error if it did not exist. */ + +void +splay_tree_remove (sp, key) + splay_tree sp; + splay_tree_key key; +{ + splay_tree_splay (sp, key); + + if (sp->root && (*sp->comp) (sp->root->key, key) == 0) + { + splay_tree_node left, right; + + left = sp->root->left; + right = sp->root->right; + + /* Delete the root node itself. */ + if (sp->delete_value) + (*sp->delete_value) (sp->root->value); + free (sp->root); + + /* One of the children is now the root. Doesn't matter much + which, so long as we preserve the properties of the tree. */ + if (left) + { + sp->root = left; + + /* If there was a right child as well, hang it off the + right-most leaf of the left child. */ + if (right) + { + while (left->right) + left = left->right; + left->right = right; + } + } + else + sp->root = right; + } +} + /* Lookup KEY in SP, returning VALUE if present, and NULL otherwise. */ @@ -325,6 +368,72 @@ splay_tree_lookup (sp, key) return 0; } +/* Return the immediate predecessor KEY, or NULL if there is no + predecessor. KEY need not be present in the tree. */ + +splay_tree_node +splay_tree_predecessor (sp, key) + splay_tree sp; + splay_tree_key key; +{ + int comparison; + splay_tree_node node; + + /* If the tree is empty, there is certainly no predecessor. */ + if (!sp->root) + return NULL; + + /* Splay the tree around KEY. That will leave either the KEY + itself, its predecessor, or its successor at the root. */ + splay_tree_splay (sp, key); + comparison = (*sp->comp)(sp->root->key, key); + + /* If the predecessor is at the root, just return it. */ + if (comparison < 0) + return sp->root; + + /* Otherwise, find the leftmost element of the right subtree. */ + node = sp->root->left; + if (node) + while (node->right) + node = node->right; + + return node; +} + +/* Return the immediate successor KEY, or NULL if there is no + predecessor. KEY need not be present in the tree. */ + +splay_tree_node +splay_tree_successor (sp, key) + splay_tree sp; + splay_tree_key key; +{ + int comparison; + splay_tree_node node; + + /* If the tree is empty, there is certainly no predecessor. */ + if (!sp->root) + return NULL; + + /* Splay the tree around KEY. That will leave either the KEY + itself, its predecessor, or its successor at the root. */ + splay_tree_splay (sp, key); + comparison = (*sp->comp)(sp->root->key, key); + + /* If the successor is at the root, just return it. */ + if (comparison > 0) + return sp->root; + + /* Otherwise, find the rightmost element of the left subtree. */ + node = sp->root->right; + if (node) + while (node->left) + node = node->left; + + return node; +} + /* Call FN, passing it the DATA, for every node in SP, following an in-order traversal. If FN every returns a non-zero value, the iteration ceases immediately, and the value is returned. diff --git a/contrib/binutils/libiberty/strerror.c b/contrib/binutils/libiberty/strerror.c index 644cc75..0dd2220 100644 --- a/contrib/binutils/libiberty/strerror.c +++ b/contrib/binutils/libiberty/strerror.c @@ -25,14 +25,17 @@ /* Routines imported from standard C runtime libraries. */ -#ifdef __STDC__ -#include <stddef.h> -extern void *malloc (size_t size); /* 4.10.3.3 */ -extern void *memset (void *s, int c, size_t n); /* 4.11.6.1 */ -#else /* !__STDC__ */ -extern char *malloc (); /* Standard memory allocater */ -extern char *memset (); -#endif /* __STDC__ */ +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#else +extern PTR malloc (); +#endif + +#ifdef HAVE_STRING_H +#include <string.h> +#else +extern PTR memset (); +#endif #ifndef MAX # define MAX(a,b) ((a) > (b) ? (a) : (b)) diff --git a/contrib/binutils/libiberty/strncmp.c b/contrib/binutils/libiberty/strncmp.c new file mode 100644 index 0000000..b3b9de1 --- /dev/null +++ b/contrib/binutils/libiberty/strncmp.c @@ -0,0 +1,28 @@ +/* strncmp -- compare two strings, stop after n bytes. + This function is in the public domain. */ + +#include <ansidecl.h> +#ifdef __STDC__ +#include <stddef.h> +#else +#define size_t unsigned long +#endif + +int +strncmp(s1, s2, n) + const char *s1, *s2; + register size_t n; +{ + register unsigned char u1, u2; + + while (n-- > 0) + { + u1 = (unsigned char) *s1++; + u2 = (unsigned char) *s2++; + if (u1 != u2) + return u1 - u2; + if (u1 == '\0') + return 0; + } + return 0; +} diff --git a/contrib/binutils/libiberty/strsignal.c b/contrib/binutils/libiberty/strsignal.c index c7bb10c..5625323 100644 --- a/contrib/binutils/libiberty/strsignal.c +++ b/contrib/binutils/libiberty/strsignal.c @@ -23,14 +23,17 @@ /* Routines imported from standard C runtime libraries. */ -#ifdef __STDC__ -#include <stddef.h> -extern void *malloc (size_t size); /* 4.10.3.3 */ -extern void *memset (void *s, int c, size_t n); /* 4.11.6.1 */ -#else /* !__STDC__ */ -extern char *malloc (); /* Standard memory allocater */ -extern char *memset (); -#endif /* __STDC__ */ +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#else +extern PTR malloc (); +#endif + +#ifdef HAVE_STRING_H +#include <string.h> +#else +extern PTR memset (); +#endif /* Undefine the macro we used to hide the definition of sys_siglist found in the system header files. */ diff --git a/contrib/binutils/libiberty/strtod.c b/contrib/binutils/libiberty/strtod.c index c86c73d..90292c2 100644 --- a/contrib/binutils/libiberty/strtod.c +++ b/contrib/binutils/libiberty/strtod.c @@ -22,7 +22,8 @@ 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. */ -#include <ctype.h> +#include "ansidecl.h" +#include "safe-ctype.h" extern double atof (); @@ -42,7 +43,7 @@ strtod (str, ptr) p = str; - while (isspace (*p)) + while (ISSPACE (*p)) ++p; if (*p == '+' || *p == '-') @@ -88,10 +89,10 @@ strtod (str, ptr) } /* digits, with 0 or 1 periods in it. */ - if (isdigit (*p) || *p == '.') + if (ISDIGIT (*p) || *p == '.') { int got_dot = 0; - while (isdigit (*p) || (!got_dot && *p == '.')) + while (ISDIGIT (*p) || (!got_dot && *p == '.')) { if (*p == '.') got_dot = 1; @@ -105,9 +106,9 @@ strtod (str, ptr) i = 1; if (p[i] == '+' || p[i] == '-') ++i; - if (isdigit (p[i])) + if (ISDIGIT (p[i])) { - while (isdigit (p[i])) + while (ISDIGIT (p[i])) ++i; *ptr = p + i; return atof (str); diff --git a/contrib/binutils/libiberty/strtol.c b/contrib/binutils/libiberty/strtol.c index 5467cc3..7095c72 100644 --- a/contrib/binutils/libiberty/strtol.c +++ b/contrib/binutils/libiberty/strtol.c @@ -28,13 +28,20 @@ * SUCH DAMAGE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_LIMITS_H #include <limits.h> -#include <ctype.h> +#endif +#ifdef HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif #include <errno.h> -#if 0 -#include <stdlib.h> +#ifdef NEED_DECLARATION_ERRNO +extern int errno; #endif -#include "ansidecl.h" +#include "safe-ctype.h" /* FIXME: It'd be nice to configure around these, but the include files are too painful. These macros should at least be more portable than hardwired hex @@ -77,7 +84,7 @@ strtol(nptr, endptr, base) */ do { c = *s++; - } while (isspace(c)); + } while (ISSPACE(c)); if (c == '-') { neg = 1; c = *s++; @@ -113,10 +120,10 @@ strtol(nptr, endptr, base) cutlim = cutoff % (unsigned long)base; cutoff /= (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) + if (ISDIGIT(c)) c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else if (ISALPHA(c)) + c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10; else break; if (c >= base) diff --git a/contrib/binutils/libiberty/strtoul.c b/contrib/binutils/libiberty/strtoul.c index 2ec3204..66420f2 100644 --- a/contrib/binutils/libiberty/strtoul.c +++ b/contrib/binutils/libiberty/strtoul.c @@ -28,13 +28,24 @@ * SUCH DAMAGE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_LIMITS_H #include <limits.h> -#include <ctype.h> +#endif +#ifdef HAVE_SYS_PARAM_H +#include <sys/param.h> +#endif #include <errno.h> +#ifdef NEED_DECLARATION_ERRNO +extern int errno; +#endif #if 0 #include <stdlib.h> #endif #include "ansidecl.h" +#include "safe-ctype.h" #ifndef ULONG_MAX #define ULONG_MAX ((unsigned long)(~0L)) /* 0xFFFFFFFF */ @@ -63,7 +74,7 @@ strtoul(nptr, endptr, base) */ do { c = *s++; - } while (isspace(c)); + } while (ISSPACE(c)); if (c == '-') { neg = 1; c = *s++; @@ -80,10 +91,10 @@ strtoul(nptr, endptr, base) cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; for (acc = 0, any = 0;; c = *s++) { - if (isdigit(c)) + if (ISDIGIT(c)) c -= '0'; - else if (isalpha(c)) - c -= isupper(c) ? 'A' - 10 : 'a' - 10; + else if (ISALPHA(c)) + c -= ISUPPER(c) ? 'A' - 10 : 'a' - 10; else break; if (c >= base) diff --git a/contrib/binutils/libiberty/vasprintf.c b/contrib/binutils/libiberty/vasprintf.c index b959f5f..c34585d 100644 --- a/contrib/binutils/libiberty/vasprintf.c +++ b/contrib/binutils/libiberty/vasprintf.c @@ -18,21 +18,31 @@ License along with libiberty; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifdef __STDC__ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include <ansidecl.h> +#ifdef ANSI_PROTOTYPES #include <stdarg.h> #else #include <varargs.h> #endif #include <stdio.h> #include <string.h> -#include <ansidecl.h> +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#else +extern unsigned long strtoul (); +extern PTR malloc (); +#endif +#include "libiberty.h" #ifdef TEST int global_total_width; #endif -unsigned long strtoul (); -char *malloc (); + +static int int_vasprintf PARAMS ((char **, const char *, va_list *)); static int int_vasprintf (result, format, args) @@ -60,7 +70,7 @@ int_vasprintf (result, format, args) total_width += abs (va_arg (ap, int)); } else - total_width += strtoul (p, &p, 10); + total_width += strtoul (p, (char **) &p, 10); if (*p == '.') { ++p; @@ -70,7 +80,7 @@ int_vasprintf (result, format, args) total_width += abs (va_arg (ap, int)); } else - total_width += strtoul (p, &p, 10); + total_width += strtoul (p, (char **) &p, 10); } while (strchr ("hlL", *p)) ++p; @@ -132,33 +142,33 @@ vasprintf (result, format, args) } #ifdef TEST -void -checkit -#ifdef __STDC__ - (const char* format, ...) -#else - (va_alist) - va_dcl -#endif +static void checkit PARAMS ((const char *, ...)); + +static void +checkit VPARAMS ((const char* format, ...)) { va_list args; char *result; +#ifndef ANSI_PROTOTYPES + const char *format; +#endif -#ifdef __STDC__ - va_start (args, format); -#else - char *format; - va_start (args); - format = va_arg (args, char *); + VA_START (args, format); + +#ifndef ANSI_PROTOTYPES + format = va_arg (args, const char *); #endif + vasprintf (&result, format, args); - if (strlen (result) < global_total_width) + if (strlen (result) < (size_t) global_total_width) printf ("PASS: "); else printf ("FAIL: "); printf ("%d %s\n", global_total_width, result); } +extern int main PARAMS ((void)); + int main () { @@ -169,5 +179,7 @@ main () checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\ 777777777777777777333333333333366666666666622222222222777777777777733333"); checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx"); + + return 0; } #endif /* TEST */ diff --git a/contrib/binutils/libiberty/vfork.c b/contrib/binutils/libiberty/vfork.c index 86c4591..5e877210 100644 --- a/contrib/binutils/libiberty/vfork.c +++ b/contrib/binutils/libiberty/vfork.c @@ -1,6 +1,10 @@ /* Emulate vfork using just plain fork, for systems without a real vfork. This function is in the public domain. */ +#include "ansidecl.h" + +extern int fork PARAMS ((void)); + int vfork () { diff --git a/contrib/binutils/libiberty/waitpid.c b/contrib/binutils/libiberty/waitpid.c index 23db0b9..2848309 100644 --- a/contrib/binutils/libiberty/waitpid.c +++ b/contrib/binutils/libiberty/waitpid.c @@ -1,3 +1,10 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_SYS_WAIT_H +#include <sys/wait.h> +#endif + int waitpid (pid, stat_loc, options) int pid, *stat_loc, options; diff --git a/contrib/binutils/libiberty/xexit.c b/contrib/binutils/libiberty/xexit.c index 431bbe0..e8b1ed1 100644 --- a/contrib/binutils/libiberty/xexit.c +++ b/contrib/binutils/libiberty/xexit.c @@ -17,10 +17,15 @@ License along with libiberty; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include "ansidecl.h" +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#include <stdio.h> +#ifdef HAVE_STDLIB_H +#include <stdlib.h> +#endif #include "libiberty.h" -#include <stdio.h> /* This variable is set by xatexit if it is called. This way, xmalloc doesn't drag xatexit into the link. */ diff --git a/contrib/binutils/libiberty/xmalloc.c b/contrib/binutils/libiberty/xmalloc.c index 621c6d2..3ea2d4a 100644 --- a/contrib/binutils/libiberty/xmalloc.c +++ b/contrib/binutils/libiberty/xmalloc.c @@ -17,6 +17,9 @@ License along with libiberty; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "ansidecl.h" #include "libiberty.h" @@ -61,6 +64,31 @@ xmalloc_set_program_name (s) #endif /* HAVE_SBRK */ } +void +xmalloc_failed (size) + size_t size; +{ +#ifdef HAVE_SBRK + extern char **environ; + size_t allocated; + + if (first_break != NULL) + allocated = (char *) sbrk (0) - first_break; + else + allocated = (char *) sbrk (0) - (char *) &environ; + fprintf (stderr, + "\n%s%sCannot allocate %lu bytes after allocating %lu bytes\n", + name, *name ? ": " : "", + (unsigned long) size, (unsigned long) allocated); +#else /* HAVE_SBRK */ + fprintf (stderr, + "\n%s%sCannot allocate %lu bytes\n", + name, *name ? ": " : "", + (unsigned long) size); +#endif /* HAVE_SBRK */ + xexit (1); +} + PTR xmalloc (size) size_t size; @@ -71,27 +99,8 @@ xmalloc (size) size = 1; newmem = malloc (size); if (!newmem) - { -#ifdef HAVE_SBRK - extern char **environ; - size_t allocated; - - if (first_break != NULL) - allocated = (char *) sbrk (0) - first_break; - else - allocated = (char *) sbrk (0) - (char *) &environ; - fprintf (stderr, - "\n%s%sCannot allocate %lu bytes after allocating %lu bytes\n", - name, *name ? ": " : "", - (unsigned long) size, (unsigned long) allocated); -#else /* HAVE_SBRK */ - fprintf (stderr, - "\n%s%sCannot allocate %lu bytes\n", - name, *name ? ": " : "", - (unsigned long) size); -#endif /* HAVE_SBRK */ - xexit (1); - } + xmalloc_failed (size); + return (newmem); } @@ -106,27 +115,8 @@ xcalloc (nelem, elsize) newmem = calloc (nelem, elsize); if (!newmem) - { -#ifdef HAVE_SBRK - extern char **environ; - size_t allocated; - - if (first_break != NULL) - allocated = (char *) sbrk (0) - first_break; - else - allocated = (char *) sbrk (0) - (char *) &environ; - fprintf (stderr, - "\n%s%sCannot allocate %lu bytes after allocating %lu bytes\n", - name, *name ? ": " : "", - (unsigned long) (nelem * elsize), (unsigned long) allocated); -#else /* HAVE_SBRK */ - fprintf (stderr, - "\n%s%sCannot allocate %lu bytes\n", - name, *name ? ": " : "", - (unsigned long) (nelem * elsize)); -#endif /* HAVE_SBRK */ - xexit (1); - } + xmalloc_failed (nelem * elsize); + return (newmem); } @@ -144,26 +134,7 @@ xrealloc (oldmem, size) else newmem = realloc (oldmem, size); if (!newmem) - { -#ifdef HAVE_SBRK - extern char **environ; - size_t allocated; - - if (first_break != NULL) - allocated = (char *) sbrk (0) - first_break; - else - allocated = (char *) sbrk (0) - (char *) &environ; - fprintf (stderr, - "\n%s%sCannot reallocate %lu bytes after allocating %lu bytes\n", - name, *name ? ": " : "", - (unsigned long) size, (unsigned long) allocated); -#else /* HAVE_SBRK */ - fprintf (stderr, - "\n%s%sCannot reallocate %lu bytes\n", - name, *name ? ": " : "", - (unsigned long) size); -#endif /* HAVE_SBRK */ - xexit (1); - } + xmalloc_failed (size); + return (newmem); } diff --git a/contrib/binutils/libiberty/xmemdup.c b/contrib/binutils/libiberty/xmemdup.c index f780041..fdb17a5 100644 --- a/contrib/binutils/libiberty/xmemdup.c +++ b/contrib/binutils/libiberty/xmemdup.c @@ -9,6 +9,9 @@ #include "libiberty.h" #include <sys/types.h> /* For size_t. */ +#ifdef HAVE_STRING_H +#include <string.h> +#endif PTR xmemdup (input, copy_size, alloc_size) |