Use mmap for Boehm GC in threaded grades on Linux.

The glibc implementation of malloc (commonly used on Linux) can use sbrk
to acquire more memory, and so does Boehm GC in its default configuration
on Linux.  When both allocators are invoked simultaneously from different
threads then memory corruption may result.

configure.ac:
	Add --enable-gc-mmap option.

	Make --enable-gc-munmap imply --enable-gc-mmap.

	Detect mmap and set MR_HAVE_MMAP.

	Detect sbrk and set MR_HAVE_SBRK.

	On Linux (and potentially other platforms), build Boehm GC for
	threaded grades with -DUSE_MMAP if mmap was found.

Mmake.common.in:
	Add ENABLE_BOEHM_USE_MMAP.

runtime/mercury_conf.h.in:
	Add MR_HAVE_MMAP, although it is not used anywhere yet.

	Add MR_HAVE_SBRK.  It is only for used by the test program.

tests/hard_coded/Mmakefile:
tests/hard_coded/thread_sbrk.exp:
tests/hard_coded/thread_sbrk.exp2:
tests/hard_coded/thread_sbrk.m:
	Add test program.

NEWS:
	Announce changes.

(cherry picked from commit d63a294e1fa4b1a91b6c7acd9fe8ba45d9cffb6d)
Update expected output files for spelling change.
Fix line breaks in the debugger/tabled_typeclass expected outputs.
Delete the workaround for bug #354 in the cairo binding.

extras/graphics/mercury_cairo/Mercury.options:
	As above.
Delete an unused local variable.

library/io.m:
	As above.
Report errors for bad :- end_module declarations.

Until this diff, the compiler used to crash on such inputs, as mentioned
by Mantis bugs 41, 62 and 268.

compiler/prog_io.m:
    When reading in :- module and :- end_module items, we used to blindly
    believe what they said. We now check whether they make sense, and report
    a fatal error if they don't. Specifically,

    - if the name of the module started by a :- module declaration is
      qualified, that qualification has to match the name of the
      previously-current module, and

    - the name of the module ended by a :- end_module declaration
      has to match the name of the previously-current module.

    Simplify the code we used to use to remove the :- module/:- end_module
    wrappers around the top level module. The root of the problem used
    to be that this code used to let a malformed item list through to be
    processed by later compiler passes, which did not expect it.
    The reason WHY it let through malformed item lists seems to be
    the loosening of the checks in this code, more than a decade ago.
    This was done to account for the possibility that the final :- end_module
    in a file's item list is for a submodule of the main module, and not
    for the main module itself.

    Simplify the code for reading in the whole item list. Previously
    this was done by two mutually-recursive predicates, one of which
    read in a term for the next item and one which had the term handed
    to it by its caller. We now handle the two cases (one of which is
    needed only by the special handling required by the first item)
    in one self-recursive predicate with a maybe argument.

mdbcomp/prim_data.m:
    Add a utility predicate for use by the new code in prog_io.m.

    Remove a comment on code that duplicates the code on the declaration.

compiler/modules.m:
    Improve some code that handles lists of items.

    - Make some previously not-tail-recursive predicates tail recursive.
    - Give some predicates and variables more meaningful names.
    - Combine some checks where this allows us to reduce the number of
      traversals over the item list.

doc/reference_manual.texi:
    Fix bad punctuation, and expand the list of things
    that can be declared but not defined.

tests/invalid/bad_end_module.{m,err_exp}:
    Test the expected output.

tests/invalid/Mmakefile:
    Enable the new test case.

tests/hard_coded/sub-module/g12_fe_bug.m:
    Fix a typo in a comment.
Workaround a problem with GCC 4.9 on x86_64 systems.

configure.ac:
	Apply the same workaround for a problem with GCC labels
	on x86_64 systems with GCC 4.9 as we do with GCC 4.8.
	(XXX we should probably disable -ftree-dominator-opts on all
	GCCs that support it, but I'm not sure how widespread the problem
	with it is -- I'll look into that separately.)

runtime/mercury_stack_trace.c:
	Avoid a warning from GCC.
Break up mdbcomp/prim_data.m. The new modules have much better cohesion.

mdbcomp/sym_name.m:
    New module, containing the part of the old prim_data.m that
    dealt with sym_names.

mdbcomp/builtin_modules.m:
    New module, containing the part of the old prim_data.m that
    dealt with builtin modules.

mdbcomp/prim_data.m:
    Remove the things that are now in the two new modules.

mdbcomp/mdbcomp.m:
deep_proiler/Mmakefile:
slice/Mmakefile:
    Add the two new modules.

browser/*.m:
compiler/*.m:
deep_proiler/*.m:
mdbcomp/*.m:
slice/*.m:
    Conform to the above changes.
Break up compiler/prog_io.m.

Prog_io.m used to have three jobs.

- to manage the overall process of reading in the contents of source files;
- to search for the source files themselves; and
- to parse the top levels of items, particularly declarations.

This diff moves the code that does the second and third jobs into new modules
named prog_io_find.m and prog_io_item.m respectively. This improves the
cohesion of all three modules. It also moves the definition of the type
that records the result of the module-reading process into a new module
named prog_io_error.m, since several modules of the compiler need access
to it but not to any other part of the old prog_io.m.

compiler/prog_io_error.m:
compiler/prog_io_find.m:
compiler/prog_io_item.m:
    New modules, with contents as above.

    Note the faults of the module_error type.

compiler/prog_io.m:
    Remove the stuff moved to other modules.

    Document why the check_module_has_expected_name predicate is exported.

    Add a predicate (peek_at_file) to avoid exposing the details of how
    items are read to prog_io_find.m.

compiler/parse_tree.m:
    Add the new modules.

compiler/notes/compiler_design.html:
    Document the new modules.

compiler/timestamp.m:
    Move the type maybe_return_timestamp here from prog_io.m. This is to avoid
    situations where callers of predicates in read_modules.m need to import
    prog_io.m just for the definition of this type, just because the predicate
    in read_modules.m calls predicates in prog_io.m.

compiler/*.m:
    Conform to the changes above.
Module qualify end_module declarations.

compiler/*.m:
    Module qualify the end_module declarations. In some cases, add them.

compiler/table_gen.m:
    Remove an unused predicate, and inline another in the only place
    where it is used.

compiler/add_pragma.m:
    Give some predicates more meaningful names.
Note a couple of other places where you have to list new mdbcomp modules.

mdbcomp/mdbcomp.m:
    Note a couple of other places where you have to list new mdbcomp modules.

deep_profiling/.gitignore:
slice/.gitignore:
    Mention the recently added mdbcomp modules, to stop up git from listing
    their copies in these directories as unknown files.
Clarify the problems of submodules with no implementations.

doc/reference_manual.texi:
    As above, as requested by Julien's review comments.
extras/net: Fixes for the net library

This change fixes two problems with the net library in extras/.

The h_addr field of the hostent structure (see gethostbyname(3)) is
deprecated.  gethostbyname can return multiple addresses in a list in the
field h_addr_list.  I've updated code to use the first item in this list.
Note that use of gethostbyname is also discouraged and getaddrinfo(3) is
recommended.  In a later change I intend to update this library to use
getaddrinfo.

The library used a macro error() to retrieve the error either from errno, or
on Windows from WSAGetLastError.  WSAGetLastError is a function however the
parentheses were missing from the macro causing it to be returned as a value
rather than called.

extras/net/sockets.m:
extras/net/tcp.m:
    As above.
extras/net: Make sockets.m more thread safe

sockets.m:
    This file used a static C variable to store the most recent value of
    errno.  This has been removed and replaced with better return values
    making more calls thread safe.  Some non-thread safe calls still remain
    where the C library call itself is not thread safe.
extras/net: Document sockets.m

sockets.m:
    As above.
Enable the asm_fast* (and reg*) grades on x86_64 OS X machines.

configure.ac:
	Do not set the LLDS base grade to 'none' if we are on 64-bit OS X and
	we are using GCC 4.3 onwards.  (Older versions of GCC are either
	broken or do not work on this platform anyway.)

README.MacOS:
	Mention that the asm_fast* and reg* grades do work on x86_64
	systems.
NEWS:
	Announce that the asm_fast* and reg* grades are now supported
	on x86_64 OS X machines.
Fix white space.
Add char.det_digit_to_int/1 to the library.

library/char.m:
	As above.

NEWS:
	Announce the addition.
Add pred versions of list.filter_map_corresponding.

library/list.m:
    Add versions of the 2 and 3 argument versions of filter_map_corresponding
    that take a semidet pred, not a semidet func, since semidet preds are
    cleaner than semidet funcs.
Fix some comments in array.m.