Merge pull request #136 from kernigh/kernigh-led-malloc
Fewer calls to brk() and sbrk()
This commit is contained in:
		
						commit
						2e71c027a3
					
				
					 15 changed files with 264 additions and 109 deletions
				
			
		| 
						 | 
				
			
			@ -37,12 +37,10 @@ extern		fatal();
 | 
			
		|||
extern		comfatal();
 | 
			
		||||
extern		copyfile();
 | 
			
		||||
extern void install();
 | 
			
		||||
extern char	*sbrk();
 | 
			
		||||
 | 
			
		||||
main(argc,argv) register string	argv[]; {
 | 
			
		||||
	register string arg;
 | 
			
		||||
	string libpath();
 | 
			
		||||
	char	*beg_sbrk = 0;
 | 
			
		||||
 | 
			
		||||
	/* Initialize */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -129,8 +127,6 @@ main(argc,argv) register string	argv[]; {
 | 
			
		|||
		argc--;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (verbose) beg_sbrk = sbrk(0);
 | 
			
		||||
 | 
			
		||||
#ifdef NON_CORRECTING
 | 
			
		||||
	if ((subpars_sim) && (!non_corr)) {
 | 
			
		||||
	    fprintf(stderr,"option -s illegal without -n, turned off\n");
 | 
			
		||||
| 
						 | 
				
			
			@ -206,7 +202,6 @@ main(argc,argv) register string	argv[]; {
 | 
			
		|||
		fprintf(stderr, "number of tokens: %d\n", ntokens);
 | 
			
		||||
		fprintf(stderr, "number of term structures: %d\n", nterms);
 | 
			
		||||
		fprintf(stderr, "number of alternation structures: %d\n", nalts);
 | 
			
		||||
		fprintf(stderr, "total memory used: %ld\n", (long)(sbrk(0) - beg_sbrk));
 | 
			
		||||
	}
 | 
			
		||||
	exit(0);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -41,6 +41,9 @@ getsymdeftable()
 | 
			
		|||
 | 
			
		||||
	count = nran = rd_long(infile);
 | 
			
		||||
	debug("%ld ranlib structs, ", nran, 0, 0, 0);
 | 
			
		||||
	if (nran > SIZE_MAX / sizeof(struct ranlib))
 | 
			
		||||
		off = BADOFF;	/* nran * size would overflow. */
 | 
			
		||||
	else
 | 
			
		||||
		off = hard_alloc(ALLORANL, nran * sizeof(struct ranlib));
 | 
			
		||||
	if (off == BADOFF)
 | 
			
		||||
		fatal("no space for ranlib structs");
 | 
			
		||||
| 
						 | 
				
			
			@ -48,7 +51,8 @@ getsymdeftable()
 | 
			
		|||
	rd_ranlib(infile, ran, count);
 | 
			
		||||
	nchar = rd_long(infile);
 | 
			
		||||
	debug("%ld ranlib chars\n", nchar, 0, 0, 0);
 | 
			
		||||
	if ((off = hard_alloc(ALLORANL, nchar)) == BADOFF)
 | 
			
		||||
	if (nchar != (size_t)nchar ||
 | 
			
		||||
	    (off = hard_alloc(ALLORANL, nchar)) == BADOFF)
 | 
			
		||||
		fatal("no space for ranlib strings");
 | 
			
		||||
	rd_bytes(infile, address(ALLORANL, off), nchar);
 | 
			
		||||
	ran = (struct ranlib *)address(ALLORANL, (ind_t)0);
 | 
			
		||||
| 
						 | 
				
			
			@ -144,7 +148,7 @@ notelib(pos)
 | 
			
		|||
{
 | 
			
		||||
	register ind_t	off;
 | 
			
		||||
 | 
			
		||||
	if ((off = hard_alloc(ALLOARCH, (long)sizeof(long))) == BADOFF)
 | 
			
		||||
	if ((off = hard_alloc(ALLOARCH, sizeof(long))) == BADOFF)
 | 
			
		||||
		fatal("no space for archive position");
 | 
			
		||||
	*(long *)address(ALLOARCH, off) = pos;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,7 +17,6 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
#include "orig.h"
 | 
			
		||||
#include "scan.h"
 | 
			
		||||
 | 
			
		||||
extern bool	incore;
 | 
			
		||||
extern unsigned short	NLocals;
 | 
			
		||||
extern int	flagword;
 | 
			
		||||
extern struct outname	*searchname();
 | 
			
		||||
| 
						 | 
				
			
			@ -127,8 +126,6 @@ handle_relos(head, sects, names)
 | 
			
		|||
	register int		sectindex;
 | 
			
		||||
	register int		nrelo;
 | 
			
		||||
	register char		*emit;
 | 
			
		||||
	extern char		*getemit();
 | 
			
		||||
	extern struct outrelo	*nextrelo();
 | 
			
		||||
	static long zeros[MAXSECT];
 | 
			
		||||
 | 
			
		||||
	if (incore) {
 | 
			
		||||
| 
						 | 
				
			
			@ -169,7 +166,6 @@ handle_relos(head, sects, names)
 | 
			
		|||
				    long sz = sects[sectindex].os_flen;
 | 
			
		||||
				    long sf = 0;
 | 
			
		||||
				    long blksz;
 | 
			
		||||
				    char *getblk();
 | 
			
		||||
 | 
			
		||||
				    emit = getblk(sz, &blksz, sectindex);
 | 
			
		||||
				    while (sz) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,6 +15,7 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
#include <stdlib.h>
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <out.h>
 | 
			
		||||
#include "const.h"
 | 
			
		||||
#include "debug.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -23,7 +24,6 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
#include "orig.h"
 | 
			
		||||
#include "sym.h"
 | 
			
		||||
 | 
			
		||||
extern bool	incore;
 | 
			
		||||
#ifndef NOSTATISTICS
 | 
			
		||||
int		statistics;
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -37,7 +37,7 @@ static			first_pass();
 | 
			
		|||
static uint32_t		number(const char *);
 | 
			
		||||
static void		setlign(int, uint32_t);
 | 
			
		||||
static void		setbase(int, uint32_t);
 | 
			
		||||
static struct outname	*makename();
 | 
			
		||||
static void		enterundef(const char *, int);
 | 
			
		||||
static			pass1();
 | 
			
		||||
static			evaluate();
 | 
			
		||||
static void		norm_commons();
 | 
			
		||||
| 
						 | 
				
			
			@ -130,8 +130,6 @@ first_pass(argv)
 | 
			
		|||
	register char		*argp;
 | 
			
		||||
	int			sectno;
 | 
			
		||||
	int			h;
 | 
			
		||||
	extern int		atoi();
 | 
			
		||||
	extern char		*strchr();
 | 
			
		||||
	extern int		hash();
 | 
			
		||||
	extern struct outname	*searchname();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -236,7 +234,7 @@ first_pass(argv)
 | 
			
		|||
				fatal("-u needs symbol name");
 | 
			
		||||
			h = hash(*argv);
 | 
			
		||||
			if (searchname(*argv, h) == (struct outname *)0)
 | 
			
		||||
				entername(makename(*argv), h);
 | 
			
		||||
				enterundef(*argv, h);
 | 
			
		||||
			break;
 | 
			
		||||
		case 'v':
 | 
			
		||||
			Verbose = 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -331,17 +329,34 @@ setbase(int sectno, uint32_t base)
 | 
			
		|||
	sect_base[sectno] = base;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct outname *
 | 
			
		||||
makename(string)
 | 
			
		||||
	char	*string;
 | 
			
		||||
/*
 | 
			
		||||
 * Do -u name by entering the undefined name in the symbol table.
 | 
			
		||||
 */
 | 
			
		||||
static void
 | 
			
		||||
enterundef(const char *string, int hashval)
 | 
			
		||||
{
 | 
			
		||||
	static struct outname	namebuf;
 | 
			
		||||
	struct outname	namebuf;
 | 
			
		||||
	size_t		len;
 | 
			
		||||
	char		*buf;
 | 
			
		||||
 | 
			
		||||
	namebuf.on_foff = string - core_position - mems[ALLOMODL].mem_base;
 | 
			
		||||
	/*
 | 
			
		||||
	 * Copy string to ALLOMODL, because entername() uses
 | 
			
		||||
	 * modulptr(namebuf.on_foff) but may move ALLOMODL to make
 | 
			
		||||
	 * room in ALLOGCHR.  It also needs namebuf.on_foff != 0.
 | 
			
		||||
	 */
 | 
			
		||||
	len = strlen(string) + 1;
 | 
			
		||||
	buf = core_alloc(ALLOMODL, 1 + len);
 | 
			
		||||
	if (buf == NULL)
 | 
			
		||||
		fatal("no space for -u %s", string);
 | 
			
		||||
	memcpy(buf + 1, string, len);
 | 
			
		||||
 | 
			
		||||
	namebuf.on_foff = buf + 1 - modulptr(0);
 | 
			
		||||
	namebuf.on_type = S_UND + S_EXT;
 | 
			
		||||
	namebuf.on_valu = (long)0;
 | 
			
		||||
	entername(&namebuf, hashval);
 | 
			
		||||
 | 
			
		||||
	return &namebuf;
 | 
			
		||||
	/* buf might have moved; find it again and free it. */
 | 
			
		||||
	core_free(ALLOMODL, modulptr(namebuf.on_foff) - 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,6 +21,13 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
 * (70000 - 65536).
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * 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.
 | 
			
		||||
 */
 | 
			
		||||
#define USEMALLOC
 | 
			
		||||
 | 
			
		||||
#include <assert.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -34,8 +41,10 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
#include "object.h"
 | 
			
		||||
#include "sym.h"
 | 
			
		||||
 | 
			
		||||
#ifndef USEMALLOC
 | 
			
		||||
static void copy_down(struct memory* mem, ind_t dist);
 | 
			
		||||
static void copy_up(struct memory* mem, ind_t dist);
 | 
			
		||||
#endif
 | 
			
		||||
static void free_saved_moduls(void);
 | 
			
		||||
 | 
			
		||||
struct memory	mems[NMEMS];
 | 
			
		||||
| 
						 | 
				
			
			@ -43,6 +52,11 @@ struct memory	mems[NMEMS];
 | 
			
		|||
bool	incore = TRUE;	/* TRUE while everything can be kept in core. */
 | 
			
		||||
ind_t	core_position = (ind_t)0;	/* Index of current module. */
 | 
			
		||||
 | 
			
		||||
#ifdef USEMALLOC
 | 
			
		||||
static size_t modl_initial_size;
 | 
			
		||||
static bool frozen = FALSE;		/* TRUE after freeze_core(). */
 | 
			
		||||
 | 
			
		||||
#else /* ifndef USEMALLOC */
 | 
			
		||||
#define GRANULE		64	/* power of 2 */
 | 
			
		||||
 | 
			
		||||
static char *BASE;
 | 
			
		||||
| 
						 | 
				
			
			@ -50,14 +64,10 @@ static ind_t refused;
 | 
			
		|||
 | 
			
		||||
static int sbreak(ind_t incr)
 | 
			
		||||
{
 | 
			
		||||
	unsigned int	inc;
 | 
			
		||||
 | 
			
		||||
	incr = (incr + (GRANULE - 1)) & ~(GRANULE - 1);
 | 
			
		||||
 | 
			
		||||
	inc = incr;
 | 
			
		||||
	if ((refused && refused < incr) ||
 | 
			
		||||
	    (sizeof(char *) < sizeof(long) &&
 | 
			
		||||
	     (inc != incr || BASE + inc < BASE)) ||
 | 
			
		||||
	    BASE + incr < BASE ||
 | 
			
		||||
	    brk(BASE + incr) == -1) {
 | 
			
		||||
		if (!refused || refused > incr)
 | 
			
		||||
			refused = incr;
 | 
			
		||||
| 
						 | 
				
			
			@ -66,6 +76,7 @@ static int sbreak(ind_t incr)
 | 
			
		|||
	BASE += incr;
 | 
			
		||||
	return 0;
 | 
			
		||||
}
 | 
			
		||||
#endif /* ndef USEMALLOC */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Initialize some pieces of core. We hope that this will be our last
 | 
			
		||||
| 
						 | 
				
			
			@ -73,6 +84,53 @@ static int sbreak(ind_t incr)
 | 
			
		|||
 */
 | 
			
		||||
void init_core(void)
 | 
			
		||||
{
 | 
			
		||||
#ifdef USEMALLOC
 | 
			
		||||
	struct memory *failed_mem = NULL;
 | 
			
		||||
	struct memory *mem;
 | 
			
		||||
	bool string_area;
 | 
			
		||||
 | 
			
		||||
#include "mach.h"
 | 
			
		||||
	modl_initial_size = mems[ALLOMODL].mem_left;
 | 
			
		||||
 | 
			
		||||
	for (mem = mems; mem < &mems[NMEMS]; mem++) {
 | 
			
		||||
		string_area = mem == &mems[ALLOLCHR] || mem == &mems[ALLOGCHR];
 | 
			
		||||
		/* String areas need at least one byte. */
 | 
			
		||||
		if (string_area && mem->mem_left == 0)
 | 
			
		||||
			mem->mem_left++;
 | 
			
		||||
		/* Don't malloc() size zero. */
 | 
			
		||||
		if (mem->mem_left > 0) {
 | 
			
		||||
			mem->mem_base = malloc(mem->mem_left);
 | 
			
		||||
			if (mem->mem_base == NULL) {
 | 
			
		||||
				failed_mem = mem;
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		mem->mem_full = 0;
 | 
			
		||||
		if (string_area) {
 | 
			
		||||
			mem->mem_left--;
 | 
			
		||||
			mem->mem_full++;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if (failed_mem != NULL) {
 | 
			
		||||
		incore = FALSE;	/* In core strategy failed. */
 | 
			
		||||
		/* Undo allocations. */
 | 
			
		||||
		for (mem = mems; mem != failed_mem; mem++)
 | 
			
		||||
			free(mem->mem_base);
 | 
			
		||||
		/* Allocate only the string areas. */
 | 
			
		||||
		for (mem = mems; mem < &mems[NMEMS]; mem++) {
 | 
			
		||||
			if (mem == &mems[ALLOLCHR] || mem == &mems[ALLOGCHR]) {
 | 
			
		||||
				mem->mem_base = malloc(1);
 | 
			
		||||
				if (mem->mem_base == NULL)
 | 
			
		||||
					fatal("no core at all");
 | 
			
		||||
				mem->mem_left = 0;
 | 
			
		||||
				mem->mem_full = 1;
 | 
			
		||||
			} else {
 | 
			
		||||
				mem->mem_base = NULL;
 | 
			
		||||
				mem->mem_left = mem->mem_full = 0;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
#else /* ifndef USEMALLOC */
 | 
			
		||||
	register char		*base;
 | 
			
		||||
	register ind_t		total_size;
 | 
			
		||||
	register struct memory	*mem;
 | 
			
		||||
| 
						 | 
				
			
			@ -131,6 +189,7 @@ void init_core(void)
 | 
			
		|||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
#endif /* ndef USEMALLOC */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -143,6 +202,29 @@ move_up(piece, incr)
 | 
			
		|||
	register int		piece;
 | 
			
		||||
	register ind_t		incr;
 | 
			
		||||
{
 | 
			
		||||
#ifdef USEMALLOC
 | 
			
		||||
	size_t oldsize = mems[piece].mem_full + mems[piece].mem_left;
 | 
			
		||||
	size_t newsize;
 | 
			
		||||
	char *newbase;
 | 
			
		||||
 | 
			
		||||
	if (frozen)
 | 
			
		||||
		return 0;	/* Can't realloc() frozen core. */
 | 
			
		||||
 | 
			
		||||
	/* We realloc() this piece without moving the other pieces. */
 | 
			
		||||
	while (incr > 0) {
 | 
			
		||||
		newsize = oldsize + incr;
 | 
			
		||||
		if (newsize > oldsize) {
 | 
			
		||||
			newbase = realloc(mems[piece].mem_base, newsize);
 | 
			
		||||
			if (newbase != NULL) {
 | 
			
		||||
				mems[piece].mem_base = newbase;
 | 
			
		||||
				mems[piece].mem_left += incr;
 | 
			
		||||
				return incr;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		incr -= INCRSIZE < incr ? INCRSIZE : incr;
 | 
			
		||||
	}
 | 
			
		||||
	return 0;
 | 
			
		||||
#else /* ifndef USEMALLOC */
 | 
			
		||||
	register struct memory	*mem;
 | 
			
		||||
#ifndef NOSTATISTICS
 | 
			
		||||
	extern int statistics;
 | 
			
		||||
| 
						 | 
				
			
			@ -150,12 +232,10 @@ move_up(piece, incr)
 | 
			
		|||
 | 
			
		||||
	debug("move_up(%d, %d)\n", piece, (int)incr, 0, 0);
 | 
			
		||||
	while (incr > 0 && sbreak(incr) == -1)
 | 
			
		||||
		incr -= INCRSIZE;
 | 
			
		||||
		incr -= INCRSIZE < incr ? INCRSIZE : incr;
 | 
			
		||||
 | 
			
		||||
	if (incr <= 0) {
 | 
			
		||||
		incr = 0;
 | 
			
		||||
	if (incr == 0)
 | 
			
		||||
		return (ind_t) 0;
 | 
			
		||||
	}
 | 
			
		||||
#ifndef NOSTATISTICS
 | 
			
		||||
	if (statistics) fprintf(stderr,"moving up %lx\n", (long) incr);
 | 
			
		||||
#endif
 | 
			
		||||
| 
						 | 
				
			
			@ -164,6 +244,7 @@ move_up(piece, incr)
 | 
			
		|||
 | 
			
		||||
	mems[piece].mem_left += incr;
 | 
			
		||||
	return incr;
 | 
			
		||||
#endif /* ndef USEMALLOC */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extern int	passnumber;
 | 
			
		||||
| 
						 | 
				
			
			@ -181,6 +262,73 @@ compact(int piece, ind_t incr, int flag)
 | 
			
		|||
#define FREEZE 1
 | 
			
		||||
#define FORCED 2
 | 
			
		||||
{
 | 
			
		||||
#ifdef USEMALLOC
 | 
			
		||||
	struct memory	*mem;
 | 
			
		||||
	size_t		newsize, oldsize;
 | 
			
		||||
	char		*newbase;
 | 
			
		||||
 | 
			
		||||
	if (frozen)
 | 
			
		||||
		return incr == 0; /* Can't realloc() frozen core. */
 | 
			
		||||
	/*
 | 
			
		||||
	 * We realloc() to shrink most pieces.
 | 
			
		||||
	 * We can't control how realloc() moves the pieces.
 | 
			
		||||
	 */
 | 
			
		||||
	for (mem = mems; mem < &mems[NMEMS]; mem++) {
 | 
			
		||||
		if (mem == &mems[piece])
 | 
			
		||||
			continue;
 | 
			
		||||
		if (flag == FREEZE && mem == &mems[ALLOMODL])
 | 
			
		||||
			continue;
 | 
			
		||||
		if (mem->mem_full == 0) {
 | 
			
		||||
			/* Don't try to realloc() to size zero. */
 | 
			
		||||
			free(mem->mem_base);
 | 
			
		||||
			mem->mem_base = NULL;
 | 
			
		||||
			mem->mem_left = 0;
 | 
			
		||||
		} else {
 | 
			
		||||
			newbase = realloc(mem->mem_base, mem->mem_full);
 | 
			
		||||
			if (newbase != NULL) {
 | 
			
		||||
				mem->mem_base = newbase;
 | 
			
		||||
				mem->mem_left = 0;
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	/*
 | 
			
		||||
	 * After FREEZE, we must be able to grow ALLOMODL without
 | 
			
		||||
	 * moving it.  The old allocator allowed ALLOMODL to grow in
 | 
			
		||||
	 * the brk area, but we can't call realloc() later, so we must
 | 
			
		||||
	 * leave some extra space in ALLOMODL now.
 | 
			
		||||
	 */
 | 
			
		||||
	if (flag == FREEZE) {
 | 
			
		||||
		mem = &mems[ALLOMODL];
 | 
			
		||||
		oldsize = mem->mem_full + mem->mem_left;
 | 
			
		||||
		newsize = mem->mem_full + modl_initial_size / 2;
 | 
			
		||||
		/* Don't shrink ALLOMODL. */
 | 
			
		||||
		while (newsize > oldsize) {
 | 
			
		||||
			newbase = realloc(mem->mem_base, newsize);
 | 
			
		||||
			if (newbase != NULL) {
 | 
			
		||||
				mem->mem_base = newbase;
 | 
			
		||||
				mem->mem_left = newsize - mem->mem_full;
 | 
			
		||||
				break;
 | 
			
		||||
			}
 | 
			
		||||
			newsize -= INCRSIZE < newsize ? INCRSIZE : newsize;
 | 
			
		||||
		}
 | 
			
		||||
		frozen = TRUE;	/* Prevent later realloc(). */
 | 
			
		||||
	}
 | 
			
		||||
	/* Now grow our piece. */
 | 
			
		||||
	if (incr == 0)
 | 
			
		||||
		return TRUE;
 | 
			
		||||
	mem = &mems[piece];
 | 
			
		||||
	oldsize = mem->mem_full + mem->mem_left;
 | 
			
		||||
	newsize = oldsize + incr;
 | 
			
		||||
	if (newsize < mem->mem_full)
 | 
			
		||||
		return FALSE;	/* The size overflowed. */
 | 
			
		||||
	newbase = realloc(mem->mem_base, newsize);
 | 
			
		||||
	if (newbase == NULL)
 | 
			
		||||
		return FALSE;
 | 
			
		||||
	mem->mem_base = newbase;
 | 
			
		||||
	mem->mem_left += incr;
 | 
			
		||||
	return TRUE;
 | 
			
		||||
 | 
			
		||||
#else /* ifndef USEMALLOC */
 | 
			
		||||
	register ind_t		gain, size;
 | 
			
		||||
	register struct memory	*mem;
 | 
			
		||||
	int min = piece, max = piece;
 | 
			
		||||
| 
						 | 
				
			
			@ -306,8 +454,10 @@ compact(int piece, ind_t incr, int flag)
 | 
			
		|||
		assert(mem->mem_base + mem->mem_full + mem->mem_left == (mem+1)->mem_base);
 | 
			
		||||
	}
 | 
			
		||||
	return gain >= incr;
 | 
			
		||||
#endif /* ndef USEMALLOC */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifndef USEMALLOC
 | 
			
		||||
/*
 | 
			
		||||
 * The bytes of `mem' must be moved `dist' down in the address space.
 | 
			
		||||
 * We copy the bytes from low to high, because the tail of the new area may
 | 
			
		||||
| 
						 | 
				
			
			@ -348,6 +498,7 @@ static void copy_up(struct memory* mem, ind_t dist)
 | 
			
		|||
		*--new = *--old;
 | 
			
		||||
	mem->mem_base = new;
 | 
			
		||||
}
 | 
			
		||||
#endif /* ndef USEMALLOC */
 | 
			
		||||
 | 
			
		||||
static int alloctype = NORMAL;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -358,14 +509,14 @@ static int alloctype = NORMAL;
 | 
			
		|||
 * how many times the area is moved, because of another allocate, this offset
 | 
			
		||||
 * remains valid.
 | 
			
		||||
 */
 | 
			
		||||
ind_t alloc(int piece, long size)
 | 
			
		||||
ind_t alloc(int piece, size_t size)
 | 
			
		||||
{
 | 
			
		||||
	register ind_t		incr = 0;
 | 
			
		||||
	ind_t			left = mems[piece].mem_left;
 | 
			
		||||
	register ind_t		full = mems[piece].mem_full;
 | 
			
		||||
 | 
			
		||||
	assert(passnumber == FIRST || (!incore && piece == ALLOMODL));
 | 
			
		||||
	if (size == (long)0)
 | 
			
		||||
	if (size == 0)
 | 
			
		||||
		return full;
 | 
			
		||||
	if (size != (ind_t)size)
 | 
			
		||||
		return BADOFF;
 | 
			
		||||
| 
						 | 
				
			
			@ -373,13 +524,18 @@ ind_t alloc(int piece, long size)
 | 
			
		|||
	case ALLOMODL:
 | 
			
		||||
	case ALLORANL:
 | 
			
		||||
		size = int_align(size);
 | 
			
		||||
		if (size == 0)
 | 
			
		||||
			return BADOFF;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (size - left > 0)
 | 
			
		||||
	if (size > left) {
 | 
			
		||||
		incr = ((size - left + (INCRSIZE - 1)) / INCRSIZE) * INCRSIZE;
 | 
			
		||||
		if (incr == 0)
 | 
			
		||||
			return BADOFF;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (incr == 0 ||
 | 
			
		||||
	    (incr < left + full && (incr -= move_up(piece, left + full)) <= 0) ||
 | 
			
		||||
	    (incr < left + full && move_up(piece, left + full) >= incr) ||
 | 
			
		||||
	    move_up(piece, incr) == incr ||
 | 
			
		||||
	    compact(piece, size, alloctype)) {
 | 
			
		||||
		mems[piece].mem_full += size;
 | 
			
		||||
| 
						 | 
				
			
			@ -396,7 +552,7 @@ ind_t alloc(int piece, long size)
 | 
			
		|||
 * attempt fails, release the space occupied by other pieces and try again.
 | 
			
		||||
 */
 | 
			
		||||
ind_t
 | 
			
		||||
hard_alloc(int piece, long size)
 | 
			
		||||
hard_alloc(int piece, size_t size)
 | 
			
		||||
{
 | 
			
		||||
	register ind_t	ret;
 | 
			
		||||
	register int	i;
 | 
			
		||||
| 
						 | 
				
			
			@ -477,9 +633,7 @@ dealloc(int piece)
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
char *
 | 
			
		||||
core_alloc(piece, size)
 | 
			
		||||
	register int	piece;
 | 
			
		||||
	register long	size;
 | 
			
		||||
core_alloc(int piece, size_t size)
 | 
			
		||||
{
 | 
			
		||||
	register ind_t	off;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -493,16 +647,8 @@ void core_free(int piece, char* p)
 | 
			
		|||
	char	*q = address(piece, mems[piece].mem_full);
 | 
			
		||||
 | 
			
		||||
	assert(p < q);
 | 
			
		||||
	switch(sizeof(unsigned) == sizeof(char *)) {
 | 
			
		||||
	case 1:
 | 
			
		||||
		mems[piece].mem_full -= (unsigned) (q - p);
 | 
			
		||||
		mems[piece].mem_left += (unsigned) (q - p);
 | 
			
		||||
		break;
 | 
			
		||||
	default:
 | 
			
		||||
	mems[piece].mem_full -= (ind_t) q - (ind_t) p;
 | 
			
		||||
	mems[piece].mem_left += (ind_t) q - (ind_t) p;
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,18 +4,21 @@
 | 
			
		|||
 */
 | 
			
		||||
/* $Id$ */
 | 
			
		||||
 | 
			
		||||
#include <stdbool.h>
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
 | 
			
		||||
#define ALLOEMIT	0			/* Section contents. */
 | 
			
		||||
#define ALLORELO	(ALLOEMIT + MAXSECT)	/* Relocation table. */
 | 
			
		||||
#define ALLOLOCL	(ALLORELO + 1)		/* Saved local names. */
 | 
			
		||||
#define ALLOGLOB	(ALLOLOCL + 1)		/* Saved global names. */
 | 
			
		||||
#define ALLOLCHR	(ALLOGLOB + 1)		/* Strings of local names. */
 | 
			
		||||
#define ALLOGCHR	(ALLOLCHR + 1)		/* Strings of global names. */
 | 
			
		||||
#ifdef SYMDEBUG
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
#define ALLODBUG	(ALLOGCHR + 1)		/* Symbolic debugging info. */
 | 
			
		||||
#else /* SYMDEBUG */
 | 
			
		||||
#define ALLODBUG	ALLOGCHR
 | 
			
		||||
#endif /* SYMDEBUG */
 | 
			
		||||
#define ALLOSYMB	(ALLODBUG + 1)		/* Symbol table. */
 | 
			
		||||
#define ALLOSYMB	(ALLODBUG + 1)
 | 
			
		||||
#else /* SYMDBUG */
 | 
			
		||||
#define ALLOSYMB	(ALLOGCHR + 1)		/* Symbol table. */
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
#define ALLOARCH	(ALLOSYMB + 1)		/* Archive positions. */
 | 
			
		||||
#define ALLOMODL	(ALLOARCH + 1)		/* Modules. */
 | 
			
		||||
#define ALLORANL	(ALLOMODL + 1)		/* Ranlib information. */
 | 
			
		||||
| 
						 | 
				
			
			@ -23,7 +26,7 @@
 | 
			
		|||
 | 
			
		||||
#define BADOFF		((ind_t)-1)
 | 
			
		||||
 | 
			
		||||
typedef long		ind_t;
 | 
			
		||||
typedef size_t		ind_t;
 | 
			
		||||
 | 
			
		||||
struct memory {
 | 
			
		||||
	char	*mem_base;
 | 
			
		||||
| 
						 | 
				
			
			@ -35,13 +38,15 @@ extern struct memory	mems[];
 | 
			
		|||
#define address(piece,offset)	(mems[(piece)].mem_base+(offset))
 | 
			
		||||
#define modulptr(offset)	(mems[ALLOMODL].mem_base+core_position+(offset))
 | 
			
		||||
 | 
			
		||||
#define int_align(sz)		(((sz)+(sizeof(int)-1))&~(int)(sizeof(int)-1))
 | 
			
		||||
#define int_align(sz)		(((sz)+(sizeof(int)-1))&~(sizeof(int)-1))
 | 
			
		||||
 | 
			
		||||
extern bool		incore;
 | 
			
		||||
extern ind_t		core_position;
 | 
			
		||||
extern void         init_core(void);
 | 
			
		||||
extern ind_t        hard_alloc(int piece, long size);
 | 
			
		||||
extern ind_t        alloc(int piece, long size);
 | 
			
		||||
extern ind_t        hard_alloc(int piece, size_t size);
 | 
			
		||||
extern ind_t        alloc(int piece, size_t size);
 | 
			
		||||
extern void         dealloc(int piece);
 | 
			
		||||
extern char         *core_alloc(int piece, size_t size);
 | 
			
		||||
extern void         core_free(int piece, char* p);
 | 
			
		||||
extern void         write_bytes(void);
 | 
			
		||||
extern void         namecpy(struct outname* name, unsigned nname, long offchar);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,10 +21,10 @@
 | 
			
		|||
		-----------------------------------------------
 | 
			
		||||
			Strings of global names *
 | 
			
		||||
		-----------------------------------------------
 | 
			
		||||
#ifdef SYMDEBUG
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
			Symbolic debugging information
 | 
			
		||||
		-----------------------------------------------
 | 
			
		||||
#endif /* SYMDEBUG */
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
			Symbol table *
 | 
			
		||||
		-----------------------------------------------
 | 
			
		||||
			Archive positions *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,6 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
static void generate_section_names();
 | 
			
		||||
 | 
			
		||||
extern struct outhead	outhead;
 | 
			
		||||
extern bool		incore;
 | 
			
		||||
extern int		flagword;
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -60,11 +59,10 @@ generate_section_names()
 | 
			
		|||
{
 | 
			
		||||
	register struct outname	*name;
 | 
			
		||||
	register int		sectindex;
 | 
			
		||||
	register long		size;
 | 
			
		||||
	register size_t		size;
 | 
			
		||||
	extern struct outsect	outsect[];
 | 
			
		||||
	extern char		*core_alloc();
 | 
			
		||||
 | 
			
		||||
	size = (long)outhead.oh_nsect * sizeof(struct outname);
 | 
			
		||||
	size = outhead.oh_nsect * sizeof(struct outname);
 | 
			
		||||
	name = (struct outname *)core_alloc(ALLOGLOB, size);
 | 
			
		||||
	if (name == (struct outname *)0)
 | 
			
		||||
		return;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,9 +21,6 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
#include "const.h"
 | 
			
		||||
#include "memory.h"
 | 
			
		||||
 | 
			
		||||
extern bool	incore;
 | 
			
		||||
extern char	*core_alloc();
 | 
			
		||||
 | 
			
		||||
void
 | 
			
		||||
savemagic()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			@ -32,7 +29,7 @@ savemagic()
 | 
			
		|||
	if (!incore)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	if ((p = core_alloc(ALLOMODL, (long)sizeof(int))) != (char *)0) {
 | 
			
		||||
	if ((p = core_alloc(ALLOMODL, sizeof(int))) != (char *)0) {
 | 
			
		||||
		*(unsigned short *)p = AALMAG;
 | 
			
		||||
		core_position += sizeof(int);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +44,7 @@ savehdr(hdr)
 | 
			
		|||
	if (!incore)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	if ((p=core_alloc(ALLOMODL,(long)sizeof(struct ar_hdr)))!=(char *)0) {
 | 
			
		||||
	if ((p=core_alloc(ALLOMODL, sizeof(struct ar_hdr)))!=(char *)0) {
 | 
			
		||||
		*(struct ar_hdr *)p = *hdr;
 | 
			
		||||
		core_position += int_align(sizeof(struct ar_hdr));
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -66,7 +63,7 @@ savechar(piece, off)
 | 
			
		|||
	register int	piece;
 | 
			
		||||
	register ind_t	off;
 | 
			
		||||
{
 | 
			
		||||
	register long	len;
 | 
			
		||||
	register size_t	len;
 | 
			
		||||
	register ind_t	newoff;
 | 
			
		||||
 | 
			
		||||
	if (off == (ind_t)0)
 | 
			
		||||
| 
						 | 
				
			
			@ -104,7 +101,7 @@ savelocal(name)
 | 
			
		|||
		return;
 | 
			
		||||
 | 
			
		||||
	new = (struct outname *)
 | 
			
		||||
			core_alloc(ALLOLOCL, (long)sizeof(struct outname));
 | 
			
		||||
			core_alloc(ALLOLOCL, sizeof(struct outname));
 | 
			
		||||
	if (new != (struct outname *)0) {
 | 
			
		||||
		*new = *name;
 | 
			
		||||
		new->on_foff = savindex;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,11 +13,11 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
#include <stdbool.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
#include "arch.h"
 | 
			
		||||
#include "out.h"
 | 
			
		||||
#include "ranlib.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -35,8 +35,6 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
#define IND_DBUG(x)	(IND_RELO(x) + sizeof(ind_t))
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
 | 
			
		||||
extern char 	*core_alloc();
 | 
			
		||||
extern bool	incore;
 | 
			
		||||
extern int	infile;
 | 
			
		||||
extern int	passnumber;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -46,17 +44,17 @@ char		*modulname;	/* Name of object module. */
 | 
			
		|||
long		objectsize;
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
 | 
			
		||||
static long	align(long size);
 | 
			
		||||
static size_t	align(size_t size);
 | 
			
		||||
static char	*modulbase;
 | 
			
		||||
static long	modulsize(struct outhead* head);
 | 
			
		||||
static size_t	modulsize(struct outhead* head);
 | 
			
		||||
static void can_modul(void);
 | 
			
		||||
static bool	all_alloc(void);
 | 
			
		||||
static bool	direct_alloc(struct outhead* head);
 | 
			
		||||
static bool	indirect_alloc(struct outhead* head);
 | 
			
		||||
static bool putemitindex(ind_t sectindex, ind_t emitoff, int allopiece);
 | 
			
		||||
static bool	putreloindex(ind_t relooff, long nrelobytes);
 | 
			
		||||
static bool	putreloindex(ind_t relooff, size_t nrelobytes);
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
static bool	putdbugindex(ind_t dbugoff, long ndbugbytes);
 | 
			
		||||
static bool	putdbugindex(ind_t dbugoff, size_t ndbugbytes);
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
static void get_indirect(struct outhead* head, struct outsect* sect);
 | 
			
		||||
static void read_modul(void);
 | 
			
		||||
| 
						 | 
				
			
			@ -77,7 +75,6 @@ getfile(filename)
 | 
			
		|||
	unsigned short	magic_number;
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
	struct stat	statbuf;
 | 
			
		||||
	extern int	fstat();
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
 | 
			
		||||
	archname = (char *)0;
 | 
			
		||||
| 
						 | 
				
			
			@ -196,7 +193,7 @@ all_alloc(void)
 | 
			
		|||
{
 | 
			
		||||
	struct outhead	head;
 | 
			
		||||
 | 
			
		||||
	if (hard_alloc(ALLOMODL, (long)sizeof(struct outhead)) == BADOFF)
 | 
			
		||||
	if (hard_alloc(ALLOMODL, sizeof(struct outhead)) == BADOFF)
 | 
			
		||||
		fatal("no space for module header");
 | 
			
		||||
	rd_ohead((struct outhead *)modulptr(IND_HEAD));
 | 
			
		||||
	/*
 | 
			
		||||
| 
						 | 
				
			
			@ -218,7 +215,7 @@ direct_alloc(head)
 | 
			
		|||
	ind_t		sectindex = IND_SECT(*head);
 | 
			
		||||
	register struct outsect *sects;
 | 
			
		||||
	unsigned short	nsect = head->oh_nsect;
 | 
			
		||||
	long		size, rest;
 | 
			
		||||
	size_t		size, rest;
 | 
			
		||||
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
	rest = nsect * sizeof(ind_t) + sizeof(ind_t) + sizeof(ind_t);
 | 
			
		||||
| 
						 | 
				
			
			@ -260,8 +257,7 @@ indirect_alloc(head)
 | 
			
		|||
	ind_t		relooff = IND_RELO(*head);
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
	ind_t		dbugoff = IND_DBUG(*head);
 | 
			
		||||
	extern long	objectsize;
 | 
			
		||||
	long		dbugsize = objectsize - OFF_DBUG(*head);
 | 
			
		||||
	size_t		dbugsize = objectsize - OFF_DBUG(*head);
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
 | 
			
		||||
	assert(incore);
 | 
			
		||||
| 
						 | 
				
			
			@ -271,12 +267,14 @@ indirect_alloc(head)
 | 
			
		|||
		sectindex += sizeof(struct outsect);
 | 
			
		||||
		emitoff += sizeof(ind_t);
 | 
			
		||||
	}
 | 
			
		||||
	if (nrelo > SIZE_MAX / sizeof(struct outrelo))
 | 
			
		||||
		return FALSE;	/* nrelo * size would overflow */
 | 
			
		||||
#ifdef SYMDBUG
 | 
			
		||||
	return	putreloindex(relooff, (long)nrelo * sizeof(struct outrelo))
 | 
			
		||||
	return	putreloindex(relooff, nrelo * sizeof(struct outrelo))
 | 
			
		||||
		&&
 | 
			
		||||
		putdbugindex(dbugoff, dbugsize);
 | 
			
		||||
#else /* SYMDBUG */
 | 
			
		||||
	return putreloindex(relooff, (long)nrelo * sizeof(struct outrelo));
 | 
			
		||||
	return putreloindex(relooff, nrelo * sizeof(struct outrelo));
 | 
			
		||||
#endif /* SYMDBUG */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -302,6 +300,8 @@ putemitindex(ind_t sectindex, ind_t emitoff, int allopiece)
 | 
			
		|||
 | 
			
		||||
	flen = ((struct outsect *)modulptr(sectindex))->os_flen;
 | 
			
		||||
	if (flen && zero) {
 | 
			
		||||
		if (zero != (size_t)zero)
 | 
			
		||||
			return FALSE;
 | 
			
		||||
		if ((emitindex = alloc(allopiece, zero)) != BADOFF){
 | 
			
		||||
			register char *p = address(allopiece, emitindex);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -313,6 +313,8 @@ putemitindex(ind_t sectindex, ind_t emitoff, int allopiece)
 | 
			
		|||
	}
 | 
			
		||||
	zeros[allopiece - ALLOEMIT] =
 | 
			
		||||
	 zero + ((struct outsect *) modulptr(sectindex))->os_size - flen;
 | 
			
		||||
	if (flen != (size_t)flen)
 | 
			
		||||
		return FALSE;
 | 
			
		||||
	if ((emitindex = alloc(allopiece, flen)) != BADOFF) {
 | 
			
		||||
		*(ind_t *)modulptr(emitoff) = emitindex;
 | 
			
		||||
		return TRUE;
 | 
			
		||||
| 
						 | 
				
			
			@ -325,7 +327,7 @@ putemitindex(ind_t sectindex, ind_t emitoff, int allopiece)
 | 
			
		|||
 * offset at `relooff'.
 | 
			
		||||
 */
 | 
			
		||||
static bool
 | 
			
		||||
putreloindex(ind_t relooff, long nrelobytes)
 | 
			
		||||
putreloindex(ind_t relooff, size_t nrelobytes)
 | 
			
		||||
{
 | 
			
		||||
	ind_t		reloindex;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -340,7 +342,7 @@ putreloindex(ind_t relooff, long nrelobytes)
 | 
			
		|||
 * Allocate space for debugging information and put the offset at `dbugoff'.
 | 
			
		||||
 */
 | 
			
		||||
static bool
 | 
			
		||||
putdbugindex(ind_t dbugoff, long ndbugbytes)
 | 
			
		||||
putdbugindex(ind_t dbugoff, size_t ndbugbytes)
 | 
			
		||||
{
 | 
			
		||||
	ind_t		dbugindex;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -417,12 +419,12 @@ read_modul(void)
 | 
			
		|||
	char		*chars;
 | 
			
		||||
	ind_t		sectindex, nameindex, charindex;
 | 
			
		||||
	unsigned short	nsect, nname;
 | 
			
		||||
	long		size;
 | 
			
		||||
	size_t		size;
 | 
			
		||||
	long		nchar;
 | 
			
		||||
 | 
			
		||||
	assert(passnumber == SECOND);
 | 
			
		||||
	assert(!incore);
 | 
			
		||||
	if (hard_alloc(ALLOMODL, (long)sizeof(struct outhead)) == BADOFF)
 | 
			
		||||
	if (hard_alloc(ALLOMODL, sizeof(struct outhead)) == BADOFF)
 | 
			
		||||
		fatal("no space for module header");
 | 
			
		||||
	head = (struct outhead *)modulptr(IND_HEAD);
 | 
			
		||||
	rd_ohead(head);
 | 
			
		||||
| 
						 | 
				
			
			@ -457,11 +459,10 @@ read_modul(void)
 | 
			
		|||
 * Align `size' to a multiple of the size of a double.
 | 
			
		||||
 * This is assumed to be a power of 2.
 | 
			
		||||
 */
 | 
			
		||||
static long
 | 
			
		||||
align(size)
 | 
			
		||||
	register long	size;
 | 
			
		||||
static size_t
 | 
			
		||||
align(size_t size)
 | 
			
		||||
{
 | 
			
		||||
	return (size + (sizeof(double) - 1)) & ~(int)(sizeof(double) - 1);
 | 
			
		||||
	return (size + (sizeof(double) - 1)) & ~(sizeof(double) - 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
| 
						 | 
				
			
			@ -477,9 +478,8 @@ align(size)
 | 
			
		|||
 *	6. the offset of the debugging information.
 | 
			
		||||
#endif
 | 
			
		||||
 */
 | 
			
		||||
static long
 | 
			
		||||
modulsize(head)
 | 
			
		||||
	register struct outhead	*head;
 | 
			
		||||
static size_t
 | 
			
		||||
modulsize(struct outhead *head)
 | 
			
		||||
{
 | 
			
		||||
	return	sizeof(struct outhead) +			/* 0 */
 | 
			
		||||
		head->oh_nsect * sizeof(struct outsect) +	/* 1 */
 | 
			
		||||
| 
						 | 
				
			
			@ -552,10 +552,13 @@ getemit(head, sects, sectindex)
 | 
			
		|||
{
 | 
			
		||||
	char		*ret;
 | 
			
		||||
	ind_t		off;
 | 
			
		||||
	extern char	*core_alloc();
 | 
			
		||||
	long		flen;
 | 
			
		||||
 | 
			
		||||
	if (!incore) {
 | 
			
		||||
		ret = core_alloc(ALLOMODL, sects[sectindex].os_flen);
 | 
			
		||||
		flen = sects[sectindex].os_flen;
 | 
			
		||||
		if (flen != (size_t)flen)
 | 
			
		||||
			return 0;
 | 
			
		||||
		ret = core_alloc(ALLOMODL, flen);
 | 
			
		||||
		if (ret == (char *)0)
 | 
			
		||||
			return 0;
 | 
			
		||||
		rd_outsect(sectindex);
 | 
			
		||||
| 
						 | 
				
			
			@ -581,6 +584,7 @@ getblk(totalsz, pblksz, sectindex)
 | 
			
		|||
 | 
			
		||||
	assert(!incore);
 | 
			
		||||
 | 
			
		||||
	while (sz != (size_t)sz) sz >>= 1;
 | 
			
		||||
	while (sz >= totalsz) sz >>= 1;
 | 
			
		||||
	while (sz) {
 | 
			
		||||
		ret = core_alloc(ALLOMODL, sz);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,4 +23,6 @@ extern void get_modul(void);
 | 
			
		|||
extern void skip_modul(struct outhead* head);
 | 
			
		||||
extern void startrelo(struct outhead* head);
 | 
			
		||||
extern struct outrelo* nextrelo(void);
 | 
			
		||||
extern char* getemit(struct outhead* head, struct outsect* sects, int sectindex);
 | 
			
		||||
extern char* getblk(long totalsz, long* pblksz, int sectindex);
 | 
			
		||||
extern void endemit(char* emit);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -105,9 +105,9 @@ void entername(struct outname* name, int hashval)
 | 
			
		|||
 | 
			
		||||
	debug("entername %s %d %x %x", modulptr((ind_t)name->on_foff), hashval, name->on_type, name->on_desc);
 | 
			
		||||
	savindex = savechar(ALLOGCHR, (ind_t)name->on_foff);
 | 
			
		||||
	symindex = hard_alloc(ALLOSYMB, (long)sizeof(struct symbol));
 | 
			
		||||
	symindex = hard_alloc(ALLOSYMB, sizeof(struct symbol));
 | 
			
		||||
	debug("; %ld\n", symindex, 0, 0, 0);
 | 
			
		||||
	namindex = hard_alloc(ALLOGLOB, (long)sizeof(struct outname));
 | 
			
		||||
	namindex = hard_alloc(ALLOGLOB, sizeof(struct outname));
 | 
			
		||||
	if (savindex == BADOFF || symindex == BADOFF || namindex == BADOFF)
 | 
			
		||||
		fatal("symbol table overflow");
 | 
			
		||||
	sym = (struct symbol *)address(ALLOSYMB, symindex);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,6 @@ static char rcsid[] = "$Id$";
 | 
			
		|||
extern struct outhead	outhead;
 | 
			
		||||
extern struct outsect	outsect[];
 | 
			
		||||
extern int		flagword;
 | 
			
		||||
extern bool		incore;
 | 
			
		||||
 | 
			
		||||
wr_fatal()
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,8 +11,6 @@ static char rcsid[]= "$Id$";
 | 
			
		|||
#include "extern.h"
 | 
			
		||||
 | 
			
		||||
char *filename;
 | 
			
		||||
char *beg_sbrk;
 | 
			
		||||
extern char *sbrk();
 | 
			
		||||
 | 
			
		||||
main(argc,argv) char **argv; {
 | 
			
		||||
	extern int nerrors;
 | 
			
		||||
| 
						 | 
				
			
			@ -20,8 +18,6 @@ main(argc,argv) char **argv; {
 | 
			
		|||
	extern int tabledebug;
 | 
			
		||||
	extern int verbose;
 | 
			
		||||
 | 
			
		||||
	beg_sbrk = sbrk(0);
 | 
			
		||||
 | 
			
		||||
	while (argc >1 && argv[1][0]=='-') {
 | 
			
		||||
		switch(argv[1][1]) {
 | 
			
		||||
		case 'c':
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -902,7 +902,6 @@ used(resource,use,max) char *resource; {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
statistics() {
 | 
			
		||||
	extern char *beg_sbrk,*sbrk();
 | 
			
		||||
	extern int nnodes, maxempatlen,maxrule;
 | 
			
		||||
 | 
			
		||||
	used("Registers",nregs,MAXREGS);
 | 
			
		||||
| 
						 | 
				
			
			@ -926,5 +925,4 @@ statistics() {
 | 
			
		|||
	used("Pat bytes",npatbytes+1,MAXPATBYTES);
 | 
			
		||||
	if (tabledebug)
 | 
			
		||||
		used("Source lines",maxline,MAXSOURCELINES);
 | 
			
		||||
	fprintf(stderr,"%ldK heap used\n",((long) (sbrk(0)-beg_sbrk+1023))/1024);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue