diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-08-13 17:29:30 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-08-13 17:29:30 +0000 |
commit | 9bc65db1ccf92991a4cd1aa19559c501fadba963 (patch) | |
tree | 5151de01751b24d690444de42bb0d59e3a3d0764 /gcc/collect2.c | |
parent | 3acec327002ee8f76d9e705cd483ee42879b879c (diff) | |
download | gcc-9bc65db1ccf92991a4cd1aa19559c501fadba963.tar.gz |
* tree.h: De-conditionalize init_priority code.
* mips.h (NM_FLAGS): Change from -Bp to -Bn.
* collect2.c (NM_FLAGS): Change from -p to -n.
* configure.in: Turn on collect2 for mipstx39-elf.
Handle use_collect2=no properly.
* c-common.c: De-conditionalize init_priority code.
* collect2.c (extract_init_priority, sort_ids): New fns.
(main): Call sort_ids.
Move sequence_number to file scope.
* configure.in: Handle --enable-init-priority.
* c-common.c (attrs): Add A_INIT_PRIORITY.
(init_attributes, decl_attributes): Likewise.
* tree.h (DEFAULT_INIT_PRIORITY, MAX_INIT_PRIORITY): New macros.
* tree.c (get_file_function_name_long): Split out...
(get_file_function_name): ...from here.
cp/:
* lang-options.h: Add -finit-priority.
* decl2.c: Likewise. Check flag_init_priority instead of
USE_INIT_PRIORITY.
* decl2.c (setup_initp): New fn.
(start_objects, finish_objects, do_ctors): Handle init_priority.
(do_dtors, finish_file): Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@21701 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/collect2.c')
-rw-r--r-- | gcc/collect2.c | 72 |
1 files changed, 70 insertions, 2 deletions
diff --git a/gcc/collect2.c b/gcc/collect2.c index 539e088472f..c9b471d4ba8 100644 --- a/gcc/collect2.c +++ b/gcc/collect2.c @@ -137,7 +137,7 @@ extern char *make_temp_file PROTO ((char *)); /* Default flags to pass to nm. */ #ifndef NM_FLAGS -#define NM_FLAGS "-p" +#define NM_FLAGS "-n" #endif #endif /* OBJECT_FORMAT_NONE */ @@ -280,6 +280,8 @@ static void do_wait PROTO((char *)); static void fork_execute PROTO((char *, char **)); static void maybe_unlink PROTO((char *)); static void add_to_list PROTO((struct head *, char *)); +static int extract_init_priority PROTO((char *)); +static void sort_ids PROTO((struct head *)); static void write_list PROTO((FILE *, char *, struct id *)); #ifdef COLLECT_EXPORT_LIST static void dump_list PROTO((FILE *, char *, struct id *)); @@ -1483,6 +1485,10 @@ main (argc, argv) return 0; } + /* Sort ctor and dtor lists by priority. */ + sort_ids (&constructors); + sort_ids (&destructors); + maybe_unlink(output_file); outf = fopen (c_file, "w"); if (outf == (FILE *) 0) @@ -1697,6 +1703,8 @@ maybe_unlink (file) } +static long sequence_number = 0; + /* Add a name to a linked list. */ static void @@ -1707,7 +1715,6 @@ add_to_list (head_ptr, name) struct id *newid = (struct id *) xcalloc (sizeof (struct id) + strlen (name), 1); struct id *p; - static long sequence_number = 0; strcpy (newid->name, name); if (head_ptr->first) @@ -1732,6 +1739,67 @@ add_to_list (head_ptr, name) head_ptr->number++; } +/* Grab the init priority number from an init function name that + looks like "_GLOBAL_.I.12345.foo". */ + +static int +extract_init_priority (name) + char *name; +{ + int pos = 0; + + while (name[pos] == '_') + ++pos; + pos += 10; /* strlen ("GLOBAL__X_") */ + + /* Extract init_p number from ctor/dtor name. */ + return strtoul(name + pos, NULL, 10); +} + +/* Insertion sort the ids from ctor/dtor list HEAD_PTR in descending order. + ctors will be run from right to left, dtors from left to right. */ + +static void +sort_ids (head_ptr) + struct head *head_ptr; +{ + /* id holds the current element to insert. id_next holds the next + element to insert. id_ptr iterates through the already sorted elements + looking for the place to insert id. */ + struct id *id, *id_next, **id_ptr; + int i; + + id = head_ptr->first; + + /* We don't have any sorted elements yet. */ + head_ptr->first = NULL; + + for (; id; id = id_next) + { + id_next = id->next; + id->sequence = extract_init_priority (id->name); + + for (id_ptr = &(head_ptr->first); ; id_ptr = &((*id_ptr)->next)) + if (*id_ptr == NULL + /* If the sequence numbers are the same, we put the id from the + file later on the command line later in the list. */ + || id->sequence > (*id_ptr)->sequence + /* Hack: do lexical compare, too. + || (id->sequence == (*id_ptr)->sequence + && strcmp (id->name, (*id_ptr)->name) > 0) */ + ) + { + id->next = *id_ptr; + *id_ptr = id; + break; + } + } + + /* Now set the sequence numbers properly so write_c_file works. */ + for (id = head_ptr->first; id; id = id->next) + id->sequence = ++sequence_number; +} + /* Write: `prefix', the names on list LIST, `suffix'. */ static void |