1987-03-09 19:15:41 +00:00
|
|
|
/*
|
|
|
|
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
* See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*/
|
1985-01-10 13:35:39 +00:00
|
|
|
#ifndef lint
|
1994-06-24 11:31:16 +00:00
|
|
|
static char rcsid[] = "$Id$";
|
1985-01-10 13:35:39 +00:00
|
|
|
#endif
|
|
|
|
|
2006-07-22 17:58:49 +00:00
|
|
|
#include <stdio.h>
|
2017-01-18 18:55:56 +00:00
|
|
|
#include <stdlib.h>
|
2017-01-15 11:04:47 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
2006-07-22 17:58:49 +00:00
|
|
|
#include "arch.h"
|
2019-03-22 19:15:40 +00:00
|
|
|
#include "object.h"
|
2006-07-22 17:58:49 +00:00
|
|
|
#include "out.h"
|
|
|
|
#include "ranlib.h"
|
2019-03-24 09:08:45 +00:00
|
|
|
#include "object.h"
|
1985-01-10 13:35:39 +00:00
|
|
|
#include "const.h"
|
|
|
|
#include "debug.h"
|
2019-03-24 09:08:45 +00:00
|
|
|
#include "finish.h"
|
|
|
|
#include "extract.h"
|
1985-01-10 13:35:39 +00:00
|
|
|
#include "defs.h"
|
|
|
|
#include "memory.h"
|
2019-03-24 09:08:45 +00:00
|
|
|
#include "scan.h"
|
|
|
|
#include "error.h"
|
|
|
|
#include "save.h"
|
1985-01-10 13:35:39 +00:00
|
|
|
|
|
|
|
#define ENDLIB ((long)0)
|
|
|
|
|
|
|
|
static struct ar_hdr arhdr;
|
|
|
|
|
2019-03-24 09:08:45 +00:00
|
|
|
|
|
|
|
void notelib(long pos);
|
|
|
|
|
1985-01-10 13:35:39 +00:00
|
|
|
/*
|
|
|
|
* First read a long telling how many ranlib structs there are, then
|
|
|
|
* the structs themselves. Second read a long telling how many chars there are
|
|
|
|
* in the string table, then the string table itself.
|
|
|
|
* We keep only one ranlib table in core, so this table always starts at offset
|
|
|
|
* (ind_t)0 from its base.
|
|
|
|
*/
|
2019-03-24 09:08:45 +00:00
|
|
|
static long getsymdeftable(void)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
register ind_t off;
|
|
|
|
register struct ranlib *ran;
|
|
|
|
register long count;
|
|
|
|
register long nran, nchar;
|
2019-05-10 17:15:18 +00:00
|
|
|
extern long rd_int4();
|
2019-03-24 09:08:45 +00:00
|
|
|
extern FILE* infile;
|
1985-01-10 13:35:39 +00:00
|
|
|
|
2019-05-10 17:15:18 +00:00
|
|
|
count = nran = rd_int4(infile);
|
1985-01-10 13:35:39 +00:00
|
|
|
debug("%ld ranlib structs, ", nran, 0, 0, 0);
|
2018-11-12 03:51:17 +00:00
|
|
|
if (nran > SIZE_MAX / sizeof(struct ranlib))
|
|
|
|
off = BADOFF; /* nran * size would overflow. */
|
|
|
|
else
|
|
|
|
off = hard_alloc(ALLORANL, nran * sizeof(struct ranlib));
|
1985-01-10 13:35:39 +00:00
|
|
|
if (off == BADOFF)
|
|
|
|
fatal("no space for ranlib structs");
|
|
|
|
ran = (struct ranlib *)address(ALLORANL, off);
|
1986-10-20 10:17:57 +00:00
|
|
|
rd_ranlib(infile, ran, count);
|
2019-05-10 17:15:18 +00:00
|
|
|
nchar = rd_int4(infile);
|
1985-01-10 13:35:39 +00:00
|
|
|
debug("%ld ranlib chars\n", nchar, 0, 0, 0);
|
2018-11-12 03:51:17 +00:00
|
|
|
if (nchar != (size_t)nchar ||
|
|
|
|
(off = hard_alloc(ALLORANL, nchar)) == BADOFF)
|
1985-01-10 13:35:39 +00:00
|
|
|
fatal("no space for ranlib strings");
|
1986-10-20 10:17:57 +00:00
|
|
|
rd_bytes(infile, address(ALLORANL, off), nchar);
|
1985-01-10 13:35:39 +00:00
|
|
|
ran = (struct ranlib *)address(ALLORANL, (ind_t)0);
|
|
|
|
while (count--) {
|
|
|
|
/*
|
|
|
|
* Adjust because names are now in core, not on file.
|
|
|
|
* Note that `ran_off' is measured from the beginning of the
|
|
|
|
* string area, NOT from the beginning of the file.
|
|
|
|
*/
|
|
|
|
if (ran->ran_off >= nchar)
|
|
|
|
fatal("bad ranlib string offset");
|
|
|
|
ran->ran_off += off;
|
|
|
|
ran++;
|
|
|
|
}
|
|
|
|
return nran;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern char *modulname;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process archive with table of contents. The table of contents tells
|
|
|
|
* of symbols in which module they are defined. We scan the table for
|
|
|
|
* symbols that are known but not yet defined. Then we extract all necessary
|
|
|
|
* information from the corresponding module. This module may need symbols that
|
|
|
|
* were defined in modules located before this one in the archive, so we
|
|
|
|
* scan the table again. We perform these actions as long as new symbols
|
|
|
|
* are defined.
|
|
|
|
*/
|
2019-03-24 09:08:45 +00:00
|
|
|
void arch(void)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
long nran;
|
|
|
|
bool resolved;
|
|
|
|
|
|
|
|
nran = getsymdeftable();
|
|
|
|
|
|
|
|
savemagic();
|
|
|
|
do {
|
|
|
|
register ind_t ranindex;
|
|
|
|
register long count;
|
|
|
|
|
|
|
|
debug("(re)scan ranlib table\n", 0, 0, 0, 0);
|
|
|
|
ranindex = (ind_t)0;
|
|
|
|
count = nran;
|
|
|
|
resolved = FALSE;
|
|
|
|
while (count > 0) {
|
|
|
|
register struct ranlib *ran;
|
|
|
|
register char *string;
|
|
|
|
register struct outname *name;
|
|
|
|
register long pos;
|
|
|
|
extern int hash();
|
|
|
|
extern struct outname *searchname();
|
|
|
|
|
|
|
|
ran = (struct ranlib *)address(ALLORANL, ranindex);
|
|
|
|
string = address(ALLORANL, (ind_t)ran->ran_off);
|
|
|
|
name = searchname(string, hash(string));
|
|
|
|
if (name == (struct outname *)0 || !ISUNDEFINED(name)) {
|
|
|
|
ranindex += sizeof(struct ranlib);
|
|
|
|
count--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
seek(ran->ran_pos);
|
|
|
|
get_archive_header(&arhdr);
|
|
|
|
modulname = arhdr.ar_name;
|
1990-03-15 10:44:14 +00:00
|
|
|
verbose("defines %s", string, 0, 0, 0);
|
1985-01-10 13:35:39 +00:00
|
|
|
resolved = TRUE;
|
|
|
|
/*
|
|
|
|
* This archive member is going to be linked,
|
|
|
|
* so we don't need to know what else it defines.
|
|
|
|
* Note that we assume that all ranlib information of
|
|
|
|
* one archive member is contiguous.
|
|
|
|
*/
|
|
|
|
pos = ran->ran_pos;
|
|
|
|
do {
|
|
|
|
count--; ran++;
|
|
|
|
ranindex += sizeof(struct ranlib);
|
|
|
|
} while (count > 0 && ran->ran_pos == pos);
|
|
|
|
notelib(pos);
|
|
|
|
savehdr(&arhdr);
|
|
|
|
extract();
|
|
|
|
}
|
|
|
|
} while (resolved);
|
|
|
|
|
|
|
|
dealloc(ALLORANL);
|
|
|
|
notelib(ENDLIB);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An archive member that will be loaded is remembered by storing its position
|
|
|
|
* in the archive into the table of positions.
|
|
|
|
*/
|
2019-03-24 09:08:45 +00:00
|
|
|
void notelib(long pos)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
register ind_t off;
|
|
|
|
|
2018-11-12 03:51:17 +00:00
|
|
|
if ((off = hard_alloc(ALLOARCH, sizeof(long))) == BADOFF)
|
1985-01-10 13:35:39 +00:00
|
|
|
fatal("no space for archive position");
|
|
|
|
*(long *)address(ALLOARCH, off) = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Index of position of first archive member of next archive.
|
|
|
|
*/
|
|
|
|
static ind_t posindex = (ind_t)0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the archive in pass 2.
|
|
|
|
* We walk through the table of positions telling at what byte offset the
|
|
|
|
* archive header + module is located, until this position is ENDLIB, meaning
|
|
|
|
* that we've processed all needed modules in this archive. Each group of
|
|
|
|
* positions of an archive is terminated with ENDLIB.
|
|
|
|
*/
|
2019-03-24 09:08:45 +00:00
|
|
|
void arch2(void)
|
1985-01-10 13:35:39 +00:00
|
|
|
{
|
|
|
|
register long *pos;
|
|
|
|
register ind_t localpos;
|
|
|
|
|
|
|
|
localpos = posindex;
|
|
|
|
for ( pos = (long *)address(ALLOARCH, localpos);
|
|
|
|
*pos != ENDLIB;
|
|
|
|
pos++, localpos += sizeof(long)
|
|
|
|
) {
|
|
|
|
seek(*pos);
|
|
|
|
get_archive_header(&arhdr);
|
|
|
|
modulname = arhdr.ar_name;
|
|
|
|
debug("%s: archive member\n", modulname, 0, 0, 0);
|
|
|
|
finish();
|
|
|
|
}
|
|
|
|
localpos += sizeof(long); /* Skip ENDLIB. */
|
|
|
|
posindex = localpos; /* Remember for next call. */
|
|
|
|
}
|