In many systems, malloc() can allocate outside the brk area. The
calculation with sbrk() misses those allocations. When LLgen or ncgg
reported the memory usage, the value was probably too low.
Add USEMALLOC and enable it by default. You can switch back to brk()
by removing `#define USEMALLOC` in memory.c.
USEMALLOC tells the allocator to use malloc() and realloc(), not
brk(). This might help systems where brk() doesn't work, or where
malloc() can allocate outside the brk area.
My build shows no changes in share/ack/examples (except hilo_bas.*).
Option -u was passing an offset from modulptr(0) in ALLOMODL to the
string in argv. If entername() would move ALLOMODL to make room in
ALLOGCHR, then the offset would become invalid, so the string would
get lost. This fix copies the string into ALLOMODL.
This was often not a problem because the initial size of ALLOGCHR in
mach.h is probably large enough for -u. This became a problem when I
caused the initial allocations to fail, and then only because the B
runtime uses -u.
Also move the declarations of `incore` and `core_alloc` to "memory.h".
Also correct SYMDEBUG to SYMDBUG. (I don't know if SYMDBUG works
because our build system never defines it.)
ind_t becomes an alias of size_t. ind_t becomes unsigned, so I edit
some code that was using negative ind_t. Some casts disappear, like
(long)sizeof(...) because the size is already a size_t. There are
changes to overflow checks. Callers with a size too big for size_t
must check it before calling the memory allocator. An overflow check
of BASE + incr in memory.c sbreak() now happens on all platforms, not
only when a pointer is smaller than a long.
My build shows no changes in share/ack/examples (except hilo_bas.*
changing with every build).
Remove some declarations (not all correct) and #include <errno.h>,
<time.h>, and <unistd.h> to get the correct declarations.
Disable mount(2), umount(2), and stime(2) because BSD (around
4.3BSD-Reno) lost compatibility with these Unix v7 functions.
em libmon vanished decades ago (or never existed), and also ass appears to have
a different idea of what the em opcodes are to everything else and gets
confused.
CS eliminates outer expressions before inner ones, as `x * y * z`
before `x * y`. It does this by reversing the order of expressions in
the code. This almost always works, but it sometimes doesn't work if
a STI changes the value number of a LOI. In code like `expr1 LOI
expr2 STI expr2 LOI`, CS might eliminate the inner `expr2` before the
outer `expr2 LOI`. This caused a read after free because the
occurrence of `expr2 LOI` pointed to the eliminated lines of `expr2`.
This bug went unnoticed until my recent changes caused CS to crash
with a double free. I did not get the crash in OpenBSD, but I saw the
crash in Travis, then David Given reproduced the crash in Linux. See
the discussion in https://github.com/davidgiven/ack/pull/73
the -U command line option, and one via file scanning. Turns out only the
second would increment the number of global names, so adding names with -U
would cause names found via scanning to fall off the end of the list! This
wouldn't cause linker errors because fixups don't use the list, but would cause
the generated symbol table in the output to be incorrect.