[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: EXTERN doesn't work as -u
From: |
Alan Modra |
Subject: |
Re: EXTERN doesn't work as -u |
Date: |
Wed, 20 Mar 2002 18:19:08 +1030 |
User-agent: |
Mutt/1.3.25i |
On Thu, Mar 14, 2002 at 12:07:53PM +0100, Marcus Brinkmann wrote:
> ulysses:/tmp# make
> echo 'main() {};' > foo.c
> cc -c -o foo.o foo.c
> echo 'bar() { return 0; }' > bar.c
> cc -c -o bar.o bar.c
> ar cru libbar.a bar.o
> ranlib libbar.a
> gcc -static -o foo1 foo.o -u bar libbar.a
> echo 'EXTERN(bar);' > libbar-script.a
> gcc -static -o foo2 foo.o libbar-script.a libbar.a
> objdump --syms foo1 | grep bar && echo BAR defined in foo1 || echo BAR
> undefined in foo1
> 00000000 l df *ABS* 00000000 bar.c
> 080481d0 g F .text 00000009 bar
> BAR defined in foo1
> objdump --syms foo2 | grep bar && echo BAR defined in foo2 || echo BAR
> undefined in foo2
> BAR undefined in foo2
>
> I would expect that foo2 also contains the symbol bar.
Fixed like this.
ld/ChangeLog
* ldlang.c (ldlang_add_undef): If the output bfd has been opened,
add the symbol to the linker hash table immediately.
(lang_place_undefineds): Split symbol creation out..
(insert_undefined): ..to here.
--
Alan Modra
IBM OzLabs - Linux Technology Centre
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.78
diff -u -p -r1.78 ldlang.c
--- ldlang.c 2002/03/18 02:55:51 1.78
+++ ldlang.c 2002/03/20 07:46:26
@@ -92,6 +92,7 @@ static bfd *open_output PARAMS ((const c
static void ldlang_open_output PARAMS ((lang_statement_union_type *));
static void open_input_bfds PARAMS ((lang_statement_union_type *, boolean));
static void lang_reasonable_defaults PARAMS ((void));
+static void insert_undefined PARAMS ((const char *));
static void lang_place_undefineds PARAMS ((void));
static void map_input_to_output_sections
PARAMS ((lang_statement_union_type *, const char *,
@@ -2010,7 +2011,11 @@ lang_reasonable_defaults ()
}
/* Add the supplied name to the symbol table as an undefined reference.
- Remove items from the chain as we open input bfds. */
+ This is a two step process as the symbol table doesn't even exist at
+ the time the ld command line is processed. First we put the name
+ on a list, then, once the output file has been opened, transfer the
+ name to the symbol table. */
+
typedef struct ldlang_undef_chain_list
{
struct ldlang_undef_chain_list *next;
@@ -2031,6 +2036,28 @@ ldlang_add_undef (name)
ldlang_undef_chain_list_head = new;
new->name = xstrdup (name);
+
+ if (output_bfd != NULL)
+ insert_undefined (new->name);
+}
+
+/* Insert NAME as undefined in the symbol table. */
+
+static void
+insert_undefined (name)
+ const char *name;
+{
+ struct bfd_link_hash_entry *h;
+
+ h = bfd_link_hash_lookup (link_info.hash, name, true, false, true);
+ if (h == (struct bfd_link_hash_entry *) NULL)
+ einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
+ if (h->type == bfd_link_hash_new)
+ {
+ h->type = bfd_link_hash_undefined;
+ h->u.undef.abfd = NULL;
+ bfd_link_add_undef (link_info.hash, h);
+ }
}
/* Run through the list of undefineds created above and place them
@@ -2046,17 +2073,7 @@ lang_place_undefineds ()
ptr != (ldlang_undef_chain_list_type *) NULL;
ptr = ptr->next)
{
- struct bfd_link_hash_entry *h;
-
- h = bfd_link_hash_lookup (link_info.hash, ptr->name, true, false, true);
- if (h == (struct bfd_link_hash_entry *) NULL)
- einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
- if (h->type == bfd_link_hash_new)
- {
- h->type = bfd_link_hash_undefined;
- h->u.undef.abfd = NULL;
- bfd_link_add_undef (link_info.hash, h);
- }
+ insert_undefined (ptr->name);
}
}