This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

An ELF linker patch


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 ();


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]