summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/ld
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/ld')
-rw-r--r--gnu/usr.bin/ld/ld.c26
-rw-r--r--gnu/usr.bin/ld/ld.h3
-rw-r--r--gnu/usr.bin/ld/lib.c23
3 files changed, 40 insertions, 12 deletions
diff --git a/gnu/usr.bin/ld/ld.c b/gnu/usr.bin/ld/ld.c
index d1bf0914d2c..319be0a3f4a 100644
--- a/gnu/usr.bin/ld/ld.c
+++ b/gnu/usr.bin/ld/ld.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ld.c,v 1.21 2002/03/31 20:48:16 fgsch Exp $ */
+/* $OpenBSD: ld.c,v 1.22 2002/04/17 15:33:16 espie Exp $ */
/* $NetBSD: ld.c,v 1.52 1998/02/20 03:12:51 jonathan Exp $ */
/*-
@@ -1237,19 +1237,37 @@ read_entry_relocation(fd, entry)
/*---------------------------------------------------------------------------*/
+int current_file;
+
+/*
+ * Check whether a library name appears in the list of files
+ * still to link in: used to avoid linking dependent libraries
+ * that will be pulled in anyways.
+ */
+int
+will_see_later(const char *name)
+{
+ int i;
+
+ for (i = current_file+1; i < number_of_files; i++)
+ if ((file_table[i].flags & E_SEARCH_DIRS) &&
+ strcmp(name, file_table[i].filename) == 0)
+ return 1;
+ return 0;
+}
+
/*
* Read in the symbols of all input files.
*/
static void
load_symbols()
{
- register int i;
if (trace_files)
fprintf(stderr, "Loading symbols:\n\n");
- for (i = 0; i < number_of_files; i++)
- read_file_symbols(&file_table[i]);
+ for (current_file = 0; current_file < number_of_files; current_file++)
+ read_file_symbols(&file_table[current_file]);
if (trace_files)
fprintf(stderr, "\n");
diff --git a/gnu/usr.bin/ld/ld.h b/gnu/usr.bin/ld/ld.h
index e0d6c66d732..3457bece18d 100644
--- a/gnu/usr.bin/ld/ld.h
+++ b/gnu/usr.bin/ld/ld.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ld.h,v 1.6 2000/09/21 12:03:12 espie Exp $ */
+/* $OpenBSD: ld.h,v 1.7 2002/04/17 15:33:16 espie Exp $ */
/*-
* This code is derived from software copyrighted by the Free Software
@@ -629,6 +629,7 @@ void each_full_file __P((void (*)(), void *));
unsigned long check_each_file __P((unsigned long (*)(), void *));
void mywrite __P((void *, int, int, FILE *));
void padfile __P((int, FILE *));
+extern int will_see_later(const char *);
/* In warnings.c: */
void perror_name __P((char *));
diff --git a/gnu/usr.bin/ld/lib.c b/gnu/usr.bin/ld/lib.c
index 01967ab7edf..1b06a17cd65 100644
--- a/gnu/usr.bin/ld/lib.c
+++ b/gnu/usr.bin/ld/lib.c
@@ -1,4 +1,4 @@
-/* * $OpenBSD: lib.c,v 1.4 2001/10/30 16:47:32 deraadt Exp $ - library routines*/
+/* * $OpenBSD: lib.c,v 1.5 2002/04/17 15:33:16 espie Exp $ - library routines*/
/*
*/
@@ -694,12 +694,6 @@ read_shared_object(fd, entry)
struct file_entry *subentry;
char *libname, name[MAXPATHLEN]; /*XXX*/
- subentry = (struct file_entry *)
- xmalloc(sizeof(struct file_entry));
- bzero(subentry, sizeof(struct file_entry));
- subentry->superfile = entry;
- subentry->flags = E_SECONDCLASS;
-
if (lseek(fd,
offset - (TEXT_START(entry->header) -
N_TXTOFF(entry->header)),
@@ -715,6 +709,21 @@ read_shared_object(fd, entry)
L_SET) == (off_t)-1)
err(1, "%s: lseek", get_file_name(entry));
(void)read(fd, name, sizeof(name)); /*XXX*/
+
+ /* Optimization */
+ if (sod.sod_library && will_see_later(name)) {
+ if ((offset = (off_t)sod.sod_next) == 0)
+ break;
+ else
+ continue;
+ }
+
+ subentry = (struct file_entry *)
+ xmalloc(sizeof(struct file_entry));
+ bzero(subentry, sizeof(struct file_entry));
+ subentry->superfile = entry;
+ subentry->flags = E_SECONDCLASS;
+
if (sod.sod_library) {
int sod_major = sod.sod_major;
int sod_minor = sod.sod_minor;