public inbox for gas2@sourceware.org
 help / color / mirror / Atom feed
* An ELF linker patch
@ 1998-04-30 11:54 H.J. Lu
  1998-04-30 12:07 ` Ian Lance Taylor
  1998-05-04  1:51 ` Andreas Schwab
  0 siblings, 2 replies; 6+ messages in thread
From: H.J. Lu @ 1998-04-30 11:54 UTC (permalink / raw)
  To: Ian Lance Taylor; +Cc: gas2, GNU C Library

Hi,

This patch fixes the bug with

# gcc -O -g -o sharedstatic main.c libfoo.so -Wl,-rpath,. -Wl,-Bstatic

under glibc 2.1. The problem is there are some data symbols defined in
both the dynamic linker as well as libc.a under glibc 2.1. When
-Wl,-Bstatic is added at the end, the dynamic linker and libc.a are
used for the final link. As the result, those data symbols are defined
in the dynamic executable. But when it runs, the dynamic linker will
be invoked by the kernel to load the dynamic executable. During the
loading, the data symbol definitions in the dynamic linker are used.
But after switching to the executable, the definitions in the executable
are used. It doesn't work very well since the dynamic linker depends on
those data symbols very much.

This patch seems to fix the problem by loading the dynamic linker first
before anything else such that the definitions in libc.a are not used
if the dynamic linker presents.

Thanks.


-- 
H.J. Lu (hjl@gnu.org)
---
Thu Apr 30 08:17:47 1998  H.J. Lu  (hjl@gnu.org)

	* ldlang.c (lang_load_interpreter): LNew function to load the
	dynamic linker.
	(lang_process): Call lang_load_interpreter () before
	open_input_bfds ().

Index: ldlang.c
===================================================================
RCS file: /home/work/cvs/gnu/binutils/ld/ldlang.c,v
retrieving revision 1.32
diff -u -p -r1.32 ldlang.c
--- ldlang.c	1998/03/31 22:25:42	1.32
+++ ldlang.c	1998/04/30 18:36:42
@@ -3219,6 +3219,39 @@ reset_memory_regions ()
     }
 }
 
+static void lang_load_interpreter PARAMS ((CONST char *));
+
+static void
+lang_load_interpreter (interpreter)
+     CONST char *interpreter;
+{
+  if (interpreter != NULL)
+    {
+      lang_input_statement_type *interp = (lang_input_statement_type *)
+	stat_alloc (sizeof (lang_input_statement_type));
+
+      interp->header.next = NULL;
+      interp->header.type = lang_input_statement_enum;
+      interp->target = NULL;
+      interp->filename = interpreter;
+      interp->is_archive = false;
+      interp->real = true;
+      interp->local_sym_name = interpreter;
+      interp->just_syms_flag = false;
+      interp->search_dirs_flag = false;
+      interp->the_bfd = (bfd *) NULL;
+      interp->asymbols = (asymbol **) NULL;
+      interp->next_real_file = (lang_statement_union_type *) NULL;
+      interp->next = (lang_statement_union_type *) NULL;
+      interp->symbol_count = 0;
+      interp->dynamic = config.dynamic_link;
+      interp->whole_archive = whole_archive;
+      interp->loaded = false;
+
+      open_input_bfds ((lang_statement_union_type *) interp, false);
+    }
+}
+
 void
 lang_process ()
 {
@@ -3234,6 +3267,19 @@ lang_process ()
 
   /* Create a bfd for each input file */
   current_target = default_target;
+
+  /* FIXME: Should it go into a new emulation function,
+	    ldemul_before_open ()? For ELF,
+
+     1. Make sure we are creating a dynamic executable in the final
+	link.
+     2. If command_line.interpreter is NULL, get the default
+	interpreter name from the backend. We may need a new function
+	from each ELF backend to return the default interpreter name.
+     3. Call lang_load_interpreter () with the interpreter name.
+   */
+  lang_load_interpreter (command_line.interpreter); 
+
   open_input_bfds (statement_list.head, false);
 
   ldemul_after_open ();

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1998-05-04 16:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-30 11:54 An ELF linker patch H.J. Lu
1998-04-30 12:07 ` Ian Lance Taylor
1998-05-04  1:51 ` Andreas Schwab
1998-05-04  9:21   ` Ulrich Drepper
1998-05-04 15:53     ` Thomas Bushnell, n/BSG
1998-05-04 16:37       ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).