More changes to bring FreBSD in sync with Paul K's latest.

This commit is contained in:
Jordan K. Hubbard 1993-12-04 00:53:02 +00:00
parent 05e634ef64
commit 2e21ebe5ce
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=828
8 changed files with 42 additions and 282 deletions

View File

@ -1,9 +1,9 @@
# $Id: Makefile,v 1.10 1993/12/01 15:58:22 ache Exp $
# $Id: Makefile,v 1.12 1993/12/02 09:56:30 ache Exp $
#
PROG= ld
SRCS= ld.c symbol.c lib.c shlib.c warnings.c etc.c rrs.c xbits.c md.c
CFLAGS += -static -I$(.CURDIR) -I$(.CURDIR)/$(MACHINE)
CFLAGS += -I$(.CURDIR) -I$(.CURDIR)/$(MACHINE)
LDADD+= -lgnumalloc
DPADD+= /usr/lib/libgnumalloc.a

View File

@ -1,5 +1,5 @@
/*
* $Id: etc.c,v 1.2 1993/11/09 04:18:52 paul Exp $
* $Id: etc.c,v 1.4 1993/12/02 00:56:33 jkh Exp $
*/
#include <sys/param.h>
@ -72,7 +72,7 @@ fatal(fmt, va_alist)
(void)fprintf(stderr, "\n");
va_end(ap);
if (outdesc > 0)
if (outdesc >= 0)
unlink(output_filename);
exit(1);
}

View File

@ -32,7 +32,7 @@ static char sccsid[] = "@(#)ld.c 6.10 (Berkeley) 5/22/91";
Set, indirect, and warning symbol features added by Randy Smith. */
/*
* $Id: ld.c,v 1.13 1993/12/02 00:56:35 jkh Exp $
* $Id: ld.c,v 1.14 1993/12/02 05:09:52 nate Exp $
*/
/* Define how to initialize system-dependent header fields. */
@ -180,9 +180,6 @@ main(argc, argv)
make_executable = 1;
force_executable = 0;
link_mode = DYNAMIC;
#ifdef SUNOS4
link_mode |= SILLYARCHIVE;
#endif
soversion = LD_VERSION_BSD;
/* Initialize the cumulative counts of symbols. */
@ -393,12 +390,6 @@ decode_command(argc, argv)
link_mode |= FORCEARCHIVE;
else if (strcmp(string, "shareable") == 0)
link_mode |= SHAREABLE;
#ifdef SUN_COMPAT
else if (strcmp(string, "silly") == 0)
link_mode |= SILLYARCHIVE;
else if (strcmp(string, "~silly") == 0)
link_mode &= ~SILLYARCHIVE;
#endif
}
if (argv[i][1] == 'A') {
if (p != file_table)
@ -493,10 +484,6 @@ decode_option(swt, arg)
return;
if (!strcmp(swt + 1, "assert"))
return;
#ifdef SUN_COMPAT
if (!strcmp(swt + 1, "Bsilly"))
return;
#endif
if (!strcmp(swt + 1, "Ttext")) {
text_start = parse(arg, "%x", "invalid argument to -Ttext");
T_flag_specified = 1;
@ -657,38 +644,17 @@ each_file(function, arg)
for (i = 0; i < number_of_files; i++) {
register struct file_entry *entry = &file_table[i];
register struct file_entry *subentry;
if (entry->scrapped)
continue;
if (!entry->library_flag)
(*function) (entry, arg);
subentry = entry->subfiles;
for (; subentry; subentry = subentry->chain) {
if (subentry->scrapped)
continue;
(*function) (subentry, arg);
}
#ifdef SUN_COMPAT
if (entry->silly_archive) {
if (!entry->is_dynamic)
error("Silly");
if (!entry->silly_archive->library_flag)
error("Sillier");
subentry = entry->silly_archive->subfiles;
if (entry->library_flag) {
register struct file_entry *subentry = entry->subfiles;
for (; subentry; subentry = subentry->chain) {
if (subentry->scrapped)
continue;
(*function) (subentry, arg);
}
}
#endif
} else
(*function) (entry, arg);
}
}
@ -738,41 +704,15 @@ each_full_file(function, arg)
for (i = 0; i < number_of_files; i++) {
register struct file_entry *entry = &file_table[i];
register struct file_entry *subentry;
if (entry->scrapped || entry->just_syms_flag)
if (entry->scrapped ||
entry->just_syms_flag || entry->is_dynamic)
continue;
#ifdef SUN_COMPAT
if (entry->silly_archive) {
if (!entry->is_dynamic)
error("Silly");
if (!entry->silly_archive->library_flag)
error("Sillier");
subentry = entry->silly_archive->subfiles;
for (; subentry; subentry = subentry->chain) {
if (subentry->scrapped)
continue;
if (entry->library_flag) {
register struct file_entry *subentry = entry->subfiles;
for (; subentry; subentry = subentry->chain)
(*function) (subentry, arg);
}
}
#endif
if (entry->is_dynamic)
continue;
if (!entry->library_flag)
} else
(*function) (entry, arg);
subentry = entry->subfiles;
for (; subentry; subentry = subentry->chain) {
if (subentry->scrapped)
continue;
(*function) (subentry, arg);
}
}
}
@ -797,7 +737,7 @@ file_open (entry)
{
register int desc;
if (entry->superfile && entry->superfile->library_flag)
if (entry->superfile)
return file_open (entry->superfile);
if (entry == input_file)
@ -1050,7 +990,7 @@ read_file_symbols (entry)
return;
}
entry->is_dynamic = 1;
if (entry->superfile || rrs_add_shobj(entry))
if (rrs_add_shobj(entry))
read_shared_object(desc, entry);
else
entry->scrapped = 1;
@ -1355,7 +1295,7 @@ void consider_relocation();
* symbols originating from shared objects is searched for a definition.
*
* 2) Then the relocation information of each relocatable file is examined
* for possible contributions to the RRS section.
* for for possible contributions to the RRS section.
*
* 3) When this is done, the sizes and start addresses are set of all segments
* that will appear in the output file (including the RRS segment).

View File

@ -1,4 +1,4 @@
/* $Id: ld.h,v 1.5 1993/11/10 21:53:42 pk Exp $ */
/* $Id: ld.h,v 1.6 1993/12/02 00:56:37 jkh Exp $ */
/*-
* This code is derived from software copyrighted by the Free Software
* Foundation.
@ -678,11 +678,6 @@ struct file_entry {
/* For library member, points to next entry for next member. */
struct file_entry *chain;
#ifdef SUN_COMPAT
/* For shared libraries which have a .sa companion */
struct file_entry *silly_archive;
#endif
/* 1 if file is a library. */
char library_flag;
@ -727,8 +722,7 @@ int number_of_files;
#define FORCEARCHIVE 4 /* Force inclusion of all members
of archives */
#define SHAREABLE 8 /* Build a shared object */
#define SILLYARCHIVE 16 /* Process .sa companions, if any */
int link_mode;
int link_mode;
/*
* Runtime Relocation Section (RRS).
@ -875,7 +869,7 @@ void read_shared_object __P((int, struct file_entry *));
int findlib __P((struct file_entry *));
/* In shlib.c: */
char *findshlib __P((char *, int *, int *, int));
char *findshlib __P((char *, int *, int *));
void add_search_dir __P((char *));
void std_search_dirs __P((char *));

View File

@ -1,5 +1,5 @@
/*
* $Id: lib.c,v 1.3 1993/11/22 19:04:43 jkh Exp $ - library routines
* $Id: lib.c,v 1.5 1993/12/02 00:56:38 jkh Exp $ - library routines
*/
#include <sys/param.h>
@ -78,11 +78,11 @@ decode_library_subfile(desc, library_entry, subfile_offset, length_loc)
{
int bytes_read;
register int namelen;
int member_length, content_length;
int member_length;
register char *name;
struct ar_hdr hdr1;
register struct file_entry *subentry;
int starting_offset;
lseek(desc, subfile_offset, 0);
bytes_read = read(desc, &hdr1, sizeof hdr1);
@ -104,44 +104,22 @@ decode_library_subfile(desc, library_entry, subfile_offset, length_loc)
&& hdr1.ar_name[namelen] != '/';
namelen++);
starting_offset = subfile_offset + sizeof hdr1;
content_length = member_length;
#ifdef AR_EFMT1
/*
* BSD 4.4 extended AR format: #1/<namelen>, with name as the
* first <namelen> bytes of the file
*/
if ((hdr1.ar_name[0]=='#') &&
(hdr1.ar_name[1]=='1') &&
(hdr1.ar_name[2]=='/') &&
(isdigit(hdr1.ar_name[3])))
{
namelen = atoi (&hdr1.ar_name[3]);
name = (char *) xmalloc(namelen + 1);
read (desc, name, namelen);
name[namelen] = 0;
content_length -= namelen;
starting_offset += namelen;
} else
#endif
{
name = (char *) xmalloc(namelen + 1);
strncpy(name, hdr1.ar_name, namelen);
name[namelen] = 0;
}
name = (char *) xmalloc(namelen + 1);
strncpy(name, hdr1.ar_name, namelen);
name[namelen] = 0;
subentry->filename = name;
subentry->local_sym_name = name;
subentry->symbols = 0;
subentry->strings = 0;
subentry->subfiles = 0;
subentry->starting_offset = starting_offset;
subentry->starting_offset = subfile_offset + sizeof hdr1;
subentry->superfile = library_entry;
subentry->library_flag = 0;
subentry->header_read_flag = 0;
subentry->just_syms_flag = 0;
subentry->chain = 0;
subentry->total_size = content_length;
subentry->total_size = member_length;
(*length_loc) = member_length;
@ -612,109 +590,9 @@ read_shared_object (desc, entry)
enter_file_symbols (entry);
entry->strings = 0;
/*
* Load any subsidiary shared objects.
*/
/* TODO: examine needed shared objects */
if (dyn2.ld_need) {
struct link_object lobj;
off_t offset;
struct file_entry *subentry, *prev = NULL;
subentry = (struct file_entry *)
xmalloc(sizeof(struct file_entry));
bzero(subentry, sizeof(struct file_entry));
subentry->superfile = entry;
offset = (off_t)dyn2.ld_need;
while (1) {
char *libname, name[MAXPATHLEN]; /*XXX*/
lseek(desc, offset, L_SET);
if (read(desc, &lobj, sizeof(lobj)) != sizeof(lobj)) {
fatal_with_file(
"premature eof while reading link objects ",
entry);
}
md_swapin_link_object(&lobj, 1);
(void)lseek(desc, (off_t)lobj.lo_name, L_SET);
(void)read(desc, name, sizeof(name));
if (lobj.lo_library) {
int lo_major = lobj.lo_major;
int lo_minor = lobj.lo_minor;
libname = findshlib(name,
&lo_major, &lo_minor, 0);
if (libname == NULL)
fatal("no shared -l%s.%d.%d available",
name, lobj.lo_major, lobj.lo_minor);
subentry->filename = libname;
subentry->local_sym_name = concat("-l", name, "");
} else {
subentry->filename = strdup(name);
subentry->local_sym_name = strdup(name);
}
read_file_symbols(subentry);
if (prev)
prev->chain = subentry;
else
entry->subfiles = subentry;
prev = subentry;
file_open(entry);
if ((offset = (off_t)lobj.lo_next) == 0)
break;
}
}
#ifdef SUN_COMPAT
if (link_mode & SILLYARCHIVE) {
char *cp, *sa_name;
char armag[SARMAG];
int fd;
struct file_entry *subentry;
sa_name = strdup(entry->filename);
if (sa_name == NULL)
goto out;
cp = sa_name + strlen(sa_name) - 1;
while (cp > sa_name) {
if (!isdigit(*cp) && *cp != '.')
break;
--cp;
}
if (cp <= sa_name || *cp != 'o') {
/* Not in `libxxx.so.n.m' form */
free(sa_name);
goto out;
}
*cp = 'a';
if ((fd = open(sa_name, O_RDONLY, 0)) < 0)
goto out;
/* Read archive magic */
bzero(armag, SARMAG);
(void)read(fd, armag, SARMAG);
(void)close(fd);
if (strncmp(armag, ARMAG, SARMAG) != 0) {
error("%s: malformed silly archive",
get_file_name(entry));
goto out;
}
subentry = (struct file_entry *)
xmalloc(sizeof(struct file_entry));
bzero(subentry, sizeof(struct file_entry));
entry->silly_archive = subentry;
subentry->superfile = entry;
subentry->filename = sa_name;
subentry->local_sym_name = sa_name;
subentry->library_flag = 1;
search_library(file_open(subentry), subentry);
out:
}
#endif
}
#undef major
@ -733,7 +611,7 @@ struct file_entry *p;
if (p->search_dynamic_flag == 0)
goto dot_a;
fname = findshlib(p->filename, &major, &minor, 1);
fname = findshlib(p->filename, &major, &minor);
if (fname && (desc = open (fname, O_RDONLY, 0)) > 0) {
p->filename = fname;

View File

@ -27,7 +27,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: rrs.c,v 1.7 1993/12/02 00:56:39 jkh Exp $
* $Id: rrs.c,v 1.8 1993/12/02 09:32:26 ache Exp $
*/
#include <sys/param.h>
@ -1059,9 +1059,8 @@ write_rrs_text()
for (i = 0, shp = rrs_shobjs; shp; i++, shp = shp->next) {
char *name = shp->entry->local_sym_name;
if (i >= number_of_shobjs)
fatal("internal error: # of link objects exceeds %d",
number_of_shobjs);
if (shp == NULL)
fatal("internal error: shp == NULL");
lo[i].lo_name = pos;
lo[i].lo_major = shp->entry->lib_major;
@ -1076,11 +1075,10 @@ write_rrs_text()
pos += 1 + strlen(name);
lo[i].lo_next = (i == number_of_shobjs - 1) ? 0 :
(rrs_dyn2.ld_need + (i+1)*sizeof(struct link_object));
}
if (i < number_of_shobjs)
fatal("internal error: # of link objects less then expected %d",
number_of_shobjs);
}
if (shp != NULL)
fatal("internal error: shp != NULL");
md_swapout_link_object(lo, number_of_shobjs);
mywrite(lo, number_of_shobjs, sizeof(struct link_object), outdesc);

View File

@ -1,5 +1,5 @@
/*
* $Id: shlib.c,v 1.2 1993/11/09 04:19:03 paul Exp $
* $Id: shlib.c,v 1.4 1993/12/02 00:56:40 jkh Exp $
*/
#include <sys/param.h>
@ -132,10 +132,9 @@ int n1, n2;
#undef minor
char *
findshlib(name, majorp, minorp, do_dot_a)
findshlib(name, majorp, minorp)
char *name;
int *majorp, *minorp;
int do_dot_a;
{
int dewey[MAXDEWEY];
int ndewey;
@ -155,7 +154,6 @@ int do_dot_a;
for (i = 0; i < n_search_dirs; i++) {
DIR *dd = opendir(search_dirs[i]);
struct dirent *dp;
int found_dot_a = 0;
if (dd == NULL)
continue;
@ -163,16 +161,6 @@ int do_dot_a;
while ((dp = readdir(dd)) != NULL) {
int n, j, might_take_it = 0;
if (do_dot_a && path == NULL &&
dp->d_namlen == len + 2 &&
strncmp(dp->d_name, lname, len) == 0 &&
(dp->d_name+len)[0] == '.' &&
(dp->d_name+len)[1] == 'a') {
path = concat(search_dirs[i], "/", dp->d_name);
found_dot_a = 1;
}
if (dp->d_namlen < len + 4)
continue;
if (strncmp(dp->d_name, lname, len) != 0)
@ -183,12 +171,6 @@ int do_dot_a;
if ((n = getdewey(tmp, dp->d_name+len+4)) == 0)
continue;
if (major != -1 && found_dot_a) { /* XXX */
free(path);
path = NULL;
found_dot_a = 0;
}
if (major == -1 && minor == -1) {
might_take_it = 1;
} else if (major != -1 && minor == -1) {
@ -210,19 +192,12 @@ int do_dot_a;
if (path)
free(path);
path = concat(search_dirs[i], "/", dp->d_name);
found_dot_a = 0;
bcopy(tmp, dewey, sizeof(dewey));
ndewey = n;
*majorp = dewey[0];
*minorp = dewey[1];
}
closedir(dd);
if (found_dot_a)
/*
* There's a .a archive here.
*/
return path;
}
return path;

View File

@ -1,5 +1,5 @@
/*
* $Id: shlib.c,v 1.2 1993/11/09 04:19:03 paul Exp $
* $Id: shlib.c,v 1.4 1993/12/02 00:56:40 jkh Exp $
*/
#include <sys/param.h>
@ -132,10 +132,9 @@ int n1, n2;
#undef minor
char *
findshlib(name, majorp, minorp, do_dot_a)
findshlib(name, majorp, minorp)
char *name;
int *majorp, *minorp;
int do_dot_a;
{
int dewey[MAXDEWEY];
int ndewey;
@ -155,7 +154,6 @@ int do_dot_a;
for (i = 0; i < n_search_dirs; i++) {
DIR *dd = opendir(search_dirs[i]);
struct dirent *dp;
int found_dot_a = 0;
if (dd == NULL)
continue;
@ -163,16 +161,6 @@ int do_dot_a;
while ((dp = readdir(dd)) != NULL) {
int n, j, might_take_it = 0;
if (do_dot_a && path == NULL &&
dp->d_namlen == len + 2 &&
strncmp(dp->d_name, lname, len) == 0 &&
(dp->d_name+len)[0] == '.' &&
(dp->d_name+len)[1] == 'a') {
path = concat(search_dirs[i], "/", dp->d_name);
found_dot_a = 1;
}
if (dp->d_namlen < len + 4)
continue;
if (strncmp(dp->d_name, lname, len) != 0)
@ -183,12 +171,6 @@ int do_dot_a;
if ((n = getdewey(tmp, dp->d_name+len+4)) == 0)
continue;
if (major != -1 && found_dot_a) { /* XXX */
free(path);
path = NULL;
found_dot_a = 0;
}
if (major == -1 && minor == -1) {
might_take_it = 1;
} else if (major != -1 && minor == -1) {
@ -210,19 +192,12 @@ int do_dot_a;
if (path)
free(path);
path = concat(search_dirs[i], "/", dp->d_name);
found_dot_a = 0;
bcopy(tmp, dewey, sizeof(dewey));
ndewey = n;
*majorp = dewey[0];
*minorp = dewey[1];
}
closedir(dd);
if (found_dot_a)
/*
* There's a .a archive here.
*/
return path;
}
return path;