64-bit obstack support

Alan Modra amodra@gmail.com
Mon Jul 14 02:04:00 GMT 2014


64-bit obstack support, >2G obstacks

An update, importing a newer version of glibc's obstack support (with
new bugs, use of glibc macros, fixed).  Plus fix some thinkos in my
first patch, like including config.h in obstack.h.  And gcc tweaks.

- Get rid of "int" and "long" size parameters and vars in obstacks.
  If we want to keep compatibility with OBSTACK_INTERFACE_VERSION==1
  obstack struct and functions, we can make them "unsigned int" and
  "unsigned long" allowing larger than 2G obstacks even on 32-bit
  hosts.  For 64-bit hosts OBSTACK_INTERFACE_VERSION==2 we make them
  all "size_t".
- Using "long" as obstack_chunk_alloc function parameter type is
  simply a bug, since malloc etc. always take a size_t, and long might
  be smaller than size_t.  (long is 32-bit on Microsoft 64-bit.)
- Use obstack_room throughout whenever checking space left in obstacks
  (next_free + desired > chunk_limit may wrap the lhs for chunks
  allocated near the top of memory).  To support >2G on 32-bit, temp.i
  needs to be unsigned, so size_t rather than ptrdiff_t.
- Steal lots of fixes from glibc by importing glibc's obstack.{h,c}
  and fix recent regressions.
- Don't roll our own slow memcpy in _obstack_newchunk.
- Rename obstack_free to _obstack_free for consistency with other
  obstack.c functions.
- Move OBSTACK_INTERFACE_VERSION to obstack.h, in order to make it
  possible to force compilation of version 1 obstack, with a nod
  toward glibc being able to compile obstack.c twice.

Since I imported obstack.h and obtack.c from glibc, the changelog
shows deltas from glibc versions, and the diff for obstack.h and
obstack.c is against glibc and made with -uw to better see the real
changes.

I removed the use of gettext.h and exitfail.h in obstack.c.  We
don't have those files in binutils/gdb/gcc and it hardly seems worth
importing them from gnulib.

Outside of obstack.{h,c} the changes are relatively minor, and can be
applied before the obstack patches.  My plan of attach is to get those
patches, minus the configury changes, applied first.  So I'd like
permission to apply the gdb and gcc changes now.  They have been
tested independently of the obstack changes.  Next, apply the obstack
changes to binutils/gdb/gcc, and finally backport to glibc.

I'm ambivalent over whether the configury changes are really
desirable.  Their aim is to allow the new obstack.h to be used with
current glibc when sizeof(size_t)==sizeof(int), ie. on most 32-bit
targets.  Under those conditions the obstack ABI is unchanged so it is
possible to save some code space by using glibc's _obstack_begin,
_obstack_newchunk etc., at the cost of losing >2G obstacks.  Now it's
a brave person who would want >2G obstacks on a 32-bit host so you
don't lose much.  However, the configury changes are an added
complication that I haven't yet tested for cross-compilation, and only
help in the transition period until glibc is released with >2G obstack
support.

include/
	PR gdb/17133
	* obstack.h: Import current glibc file.  On top of that..
	Formatting.
	(__OBSTACK_INTERFACE_VERSION): Define.
	(__OBSTACK_ELIDE_CODE): Define.
	(__OBSTACK_SIZE_T, __CHUNK_SIZE_T): Define.
	(__PTR_INT_TYPE): Rename from PTR_INT_TYPE.
	(__attribute_pure__): Define without reference to glibc macro.
	(__extension__): Avoid warning when __GNUC_MINOR__ undefined.
	(struct obstack): Make chunk_size a __CHUNK_SIZE_T, and temp union
	with __OBSTACK_SIZE_T.  Correct chunkfun prototype to take a size_t.
	(_obstack_newchunk): Update prototype.
	(_obstack_begin, _obstack_begin_1, _obstack_memory_used): Likewise.
	(__obstack_free): Define as _obstack_free.
	(obstack_init, obstack_begin, obstack_specify_allocation_with_arg,
	obstack_chunkfun): Update alloc function casts, formatting.
	For __STDC__ versions of the following macros:
	(obstack_object_size): Return __OBSTACK_SIZE_T.
	(obstack_room): Likewise, and rename __o.
	(obstack_make_room): Make __len __OBSTACK_SIZE_T, and use obstack_room.
	(obstack_grow, obstack_grow0, obstack_1grow, obstack_ptr_grow,
	obstack_int_grow, obstack_blank): Likewise.
	(obstack_finish): Use unsigned comparision when comparing aligned
	next_free against chunk_limit.
	(obstack_free): Cast OBJ to remove possible const qualifier.
	Don't wrap __obstack_free in parentheses.
	For !__STDC__ versions of the following macros:
	(obstack_object_size, obstack_room): Return __OBSTACK_SIZE_T.
	(obstack_make_room): Use temp.i and obstack_room.
	(obstack_grow, obstack_grow0, obstack_1grow, obstack_ptr_grow,
	obstack_int_grow, obstack_blank): Likewise.
	(obstack_finish): Use temp.p.  Use unsigned comparision when
	comparing aligned next_free against chunk_limit.
	(obstack_free): Use temp.p and same comparisons as __STDC__ version.
	Don't wrap __obstack_free in parentheses.
libiberty/
	PR gdb/17133
	* obstack.c: Import current glibc file.  On top of that..
	Include gnu-versions.h.  Don't include exitfail.h and gettext.h.
	(OBSTACK_INTERFACE_VERSION): Delete.
	(ELIDE_CODE): Delete.  Test __OBSTACK_ELIDE_CODE instead.
	(COPYING_UNIT): Delete.
	(print_and_abort, obstack_alloc_failed_handler): Conditionally define.
	(_obstack_compat): Likewise.
	(_Noreturn): Don't rely on this being defined, define ..
	(__attribute_noreturn__): ..and use this instead.
	(EXIT_FAILURE): Define.
	(CALL_CHUNKFUN): Update chunkfun cast.
	(chunkfun_t, freefun_t): New typdefs.
	(_obstack_begin_worker): Split out from ..
	(_obstack_begin, _obstack_begin_1): ..here.  Make "size" param
	 __CHUNK_SIZE_T, and correct chunkfun prototype.
	(_obstack_newchunk): Make "length" param __OBSTACK_SIZE_T and local
	vars size_t.  Use memcpy to move existing object.
	(obstack_free): Only define alias for version 1 interface.
	(_obstack_memory_used): Return and use __OBSTACK_SIZE_T local.
	* obstacks.texi: Update function signatures.
	* configure.ac: Get size of size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
binutils/
	* configure.ac: Get size of int and size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
gas/
	* config/bfin-parse.y: Don't include obstack.h.
	* config/obj-aout.c: Likewise.
	* config/obj-coff.c: Likewise.
	* config/obj-som.c: Likewise.
	* config/tc-bfin.c: Likewise.
	* config/tc-i960.c: Likewise.
	* config/tc-rl78.c: Likewise.
	* config/tc-rx.c: Likewise.
	* config/tc-tic4x.c: Likewise.
	* expr.c: Likewise.
	* listing.c: Likewise.
	* config/obj-elf.c (elf_file_symbol): Make name_length a size_t.
	* config/tc-aarch64.c (symbol_locate): Likewise.
	* config/tc-arm.c (symbol_locate): Likewise.
	* config/tc-mmix.c (mmix_handle_mmixal): Make len_0 a size_t.
	* config/tc-score.c (s3_build_score_ops_hsh): Make len a size_t.
	(s3_build_dependency_insn_hsh): Likewise.
	* config/tc-score7.c (s7_build_score_ops_hsh): Likewise.
	(s7_build_dependency_insn_hsh): Likewise.
	* frags.c (frag_grow): Make parameter a size_t, and use size_t locals.
	(frag_new): Make parameter a size_t.
	(frag_var_init): Make max_chars and var parameters size_t.
	(frag_var, frag_variant): Likewise.
	(frag_room): Return a size_t.
	(frag_align_pattern): Make n_fill parameter a size_t.
	* frags.h: Update function prototypes.
	* symbols.c (save_symbol_name): Make name_length a size_t.
	* configure.ac: Get size of int and size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
gdb/
	* charset.c (convert_between_encodings): Cast result of obstack_base.
	* cp-valprint.c (cp_print_value_fields): Use size_t locals.
	* hppa-tdep.c (internalize_unwinds): Change "size" parm to size_t.
	(read_unwind_info): Use size_t for some locals.
	* jit.c (finalize_symtab): Likewise.
	* utils.c (hashtab_obstack_allocate): Likewise.
	* symmisc.c (print_objfile_statistics): Update format strings.
	* configure.ac: Get size of int and size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
ld/
	* configure.ac: Get size of int and size_t.
	* config.in: Regenerate.
	* configure: Regenerate.
gcc/
	* gengtype.h (obstack_chunk_alloc, obstack_chunk_free): Remove cast.
	* coretypes.h (obstack_chunk_alloc, obstack_chunk_free): Likewise.
	(gcc_obstack_init): Use obstack_specify_allocation in place of
	_obstack_begin.
	* genautomata.c (next_sep_el): Cast result of obstack_base to (char *).
	(regexp_representation): Likewise.
	* godump.c (go_output_type): Likewise.
	* configure.ac: Check size of size_t.
	* configure: Regenerate.
	* config.in: Regenerate.
gcc/java/
	* mangle.c (finish_mangling): Cast result of obstack_base to (char *).
	* typeck.c (build_java_argument_signature): Likewise.
	(build_java_signature): Likewise.
gcc/objc/
	* objc-encoding.c (encode_array): Cast result of obstack_base.
	(encode_type): Likewise.
libcpp/
	* symtab.c (ht_create): Use obstack_specify_allocation in place of
	_obstack_begin.
	* files.c (_cpp_init_files): Likewise.
	* init.c (cpp_create_reader): Likewise.
	* identifiers.c (_cpp_init_hashtable): Likewise.
	* configure.ac: Check size of size_t.
	* configure: Regenerate.
	* config.in: Regenerate.
libvtv/
	* vtv-malloc.c: Include config.h.
	* configure.ac: Generate config.h.  Check size of int and size_t.
	* configure: Regenerate.
	* config.in: Generate.
libsanitizer/
	* configure.ac: Check size of int and size_t.
	* configure: Regenerate.
	* config.in: Regenerate.

-- 
Alan Modra
Australia Development Lab, IBM
-------------- next part --------------
A non-text attachment was scrubbed...
Name: obstack.diff
Type: text/x-diff
Size: 29592 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb/attachments/20140714/db1a2fad/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: binobstack.diff
Type: text/x-diff
Size: 28424 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb/attachments/20140714/db1a2fad/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gccobstack.diff
Type: text/x-diff
Size: 12271 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/gdb/attachments/20140714/db1a2fad/attachment-0002.bin>


More information about the Gdb mailing list