public inbox for gas2@sourceware.org
 help / color / mirror / Atom feed
From: hjl@lucon.org (H.J. Lu)
To: ian@cygnus.com (Ian Lance Taylor)
Cc: gas2@cygnus.com, libc-hacker@gnu.org (GNU C Library)
Subject: An ELF linker patch
Date: Thu, 30 Apr 1998 11:54:00 -0000	[thread overview]
Message-ID: <m0yUySx-000268C@ocean.lucon.org> (raw)

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

             reply	other threads:[~1998-04-30 11:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-30 11:54 H.J. Lu [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m0yUySx-000268C@ocean.lucon.org \
    --to=hjl@lucon.org \
    --cc=gas2@cygnus.com \
    --cc=ian@cygnus.com \
    --cc=libc-hacker@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).