amigaos-cross-toolchain/patches/binutils-2.14/ld/ldfile.c.diff

110 lines
2.5 KiB
Diff

--- binutils-2.14/ld/ldfile.c 2003-04-18 17:33:49.000000000 +0200
+++ binutils-2.14-patched/ld/ldfile.c 2013-04-24 18:37:50.000000000 +0200
@@ -74,6 +74,40 @@
static bfd_boolean is_sysrooted_pathname
PARAMS ((const char *, bfd_boolean));
+/* Flavour support. */
+
+static int flavors_cmp PARAMS ((const void *f1, const void *f2));
+
+static int n_flavors, flavors_len;
+static char **flavors;
+
+static int
+flavors_cmp (f1, f2)
+ const void *f1, *f2;
+{
+ return strcmp (*(char **)f1, *(char **)f2);
+}
+
+void
+ldfile_sort_flavors ()
+{
+ if (n_flavors > 1)
+ qsort ((void *) flavors, n_flavors, sizeof (char **), flavors_cmp);
+}
+
+void
+ldfile_add_flavor (name)
+ const char *name;
+{
+ n_flavors++;
+ if (flavors)
+ flavors = (char **) xrealloc ((PTR)flavors, n_flavors * sizeof (char *));
+ else
+ flavors = (char **) xmalloc (sizeof (char *));
+ flavors [n_flavors-1] = (char *) name;
+ flavors_len += strlen (name);
+}
+
/* Test whether a pathname, after canonicalization, is the same or a
sub-directory of the sysroot directory. */
@@ -304,6 +338,7 @@
const char *lib;
const char *suffix;
{
+ char *flavor_dir = (char *) alloca (flavors_len + n_flavors + 1);
search_dirs_type *search;
/* If this is not an archive, try to open it in the current
@@ -337,6 +372,7 @@
search = search->next)
{
char *string;
+ int i, count;
if (entry->dynamic && ! link_info.relocateable)
{
@@ -347,6 +383,7 @@
}
}
+#if 0
string = (char *) xmalloc (strlen (search->name)
+ strlen (slash)
+ strlen (lib)
@@ -369,6 +406,41 @@
}
free (string);
+#else
+ for (count=n_flavors; count>=0; count--) {
+
+ *flavor_dir = '\0';
+ for (i=0; i<count; i++) {
+ strcat (flavor_dir, flavors[i]);
+ strcat (flavor_dir, slash);
+ }
+ string = (char *) xmalloc (strlen (search->name)
+ + strlen (slash)
+ + strlen (flavor_dir)
+ + strlen (lib)
+ + strlen (entry->filename)
+ + strlen (arch)
+ + strlen (suffix)
+ + 1);
+
+ if (entry->is_archive)
+ sprintf (string, "%s%s%s%s%s%s%s", search->name, slash, flavor_dir,
+ lib, entry->filename, arch, suffix);
+ else if (entry->filename[0] == '/' || entry->filename[0] == '.')
+ strcpy (string, entry->filename);
+ else
+ sprintf (string, "%s%s%s%s", search->name, slash, flavor_dir,
+ entry->filename);
+
+ if (ldfile_try_open_bfd (string, entry))
+ {
+ entry->filename = string;
+ return TRUE;
+ }
+
+ free (string);
+ }
+#endif
}
return FALSE;