Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/gnu/usr.bin/ld/ld Fix two problems:



details:   https://anonhg.NetBSD.org/src/rev/2fe6aa1b8866
branches:  trunk
changeset: 480251:2fe6aa1b8866
user:      mycroft <mycroft%NetBSD.org@localhost>
date:      Fri Jan 07 20:23:41 2000 +0000

description:
Fix two problems:
* On other systems, `-Bsymbolic' does not affect undefined (external)
  symbols at all.  We were generating invalid PLT slots in this case.
* Do not prebind GOT and PLT slots when `-r' is used; only do so if
  -Bsymbolic is used {or if we're in RRS_PARTIAL mode, but I'm not
  sure that's correct}.  Otherwise, we could inadvertantly prebind
  symbols when using `-r' with PIC files; when the resulting .o file
  is then linked into a shared library, the library would not permit
  an executable to override its symbols as it's supposed to.

diffstat:

 gnu/usr.bin/ld/ld/ld.1  |  11 +++++------
 gnu/usr.bin/ld/ld/rrs.c |  33 ++++++++++++---------------------
 2 files changed, 17 insertions(+), 27 deletions(-)

diffs (114 lines):

diff -r e3184977170a -r 2fe6aa1b8866 gnu/usr.bin/ld/ld/ld.1
--- a/gnu/usr.bin/ld/ld/ld.1    Fri Jan 07 15:19:12 2000 +0000
+++ b/gnu/usr.bin/ld/ld/ld.1    Fri Jan 07 20:23:41 2000 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: ld.1,v 1.20 1999/03/22 18:51:52 garbled Exp $
+.\"    $NetBSD: ld.1,v 1.21 2000/01/07 20:23:41 mycroft Exp $
 .\"
 .\" Copyright (c) 1998 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -107,11 +107,10 @@
 Instructs the linker to build a shared object from the object files rather
 than a normal executable image.
 .It Fl B Ns Ar symbolic
-This option causes all symbolic references in the output to be resolved in
-this link-edit session. The only remaining run-time relocation requirements are
-.Em base-relative
-relocations, ie. translation with respect to the load address. Failure to
-resolve any symbolic reference causes an error to be reported.
+Causes symbolic references to symbols within the object to be resolved and
+changed to base-relative references.  This can be used, e.g., to make a shared
+library use an internal symbol when the executable that loads it has its own
+definition.  References to undefined symbols are not affected by this flag.
 .It Fl B Ns Ar forcearchive
 Force all members of archives to be loaded, whether or not such members
 contribute a definition to any plain object files. Useful for making a
diff -r e3184977170a -r 2fe6aa1b8866 gnu/usr.bin/ld/ld/rrs.c
--- a/gnu/usr.bin/ld/ld/rrs.c   Fri Jan 07 15:19:12 2000 +0000
+++ b/gnu/usr.bin/ld/ld/rrs.c   Fri Jan 07 20:23:41 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rrs.c,v 1.29 1999/02/27 03:31:12 tv Exp $      */
+/*     $NetBSD: rrs.c,v 1.30 2000/01/07 20:23:41 mycroft Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -318,10 +318,7 @@
        r->r_address = rp->r_address;
        r->r_symbolnum = sp->rrs_symbolnum;
 
-       if (link_mode & SYMBOLIC) {
-               if (!sp->defined)
-                       warnx("Cannot reduce symbol \"%s\" in %s",
-                               sp->name, get_file_name(entry));
+       if (sp->defined && (link_mode & SYMBOLIC)) {
                RELOC_EXTERN_P(r) = 0;
                *relocation += sp->value;
                (void) md_make_reloc(rp, r, RELTYPE_RELATIVE);
@@ -362,11 +359,8 @@
        sp->name, sp->rrs_symbolnum, sp->jmpslot_offset);
 #endif
 
-       if ((link_mode & SYMBOLIC) || rrs_section_type == RRS_PARTIAL) {
-               if (!sp->defined)
-                       warnx("Cannot reduce symbol \"%s\" in %s",
-                               sp->name, get_file_name(entry));
-
+       if (sp->defined &&
+           ((link_mode & SYMBOLIC) || rrs_section_type == RRS_PARTIAL)) {
                md_fix_jmpslot( rrs_plt + sp->jmpslot_offset/sizeof(jmpslot_t),
                                rrs_sdt.sdt_plt + sp->jmpslot_offset,
                                sp->value, 0);
@@ -375,6 +369,9 @@
                        discarded_rrs_relocs++;
                        return rrs_sdt.sdt_plt + sp->jmpslot_offset;
                }
+       } else if (rrs_section_type == RRS_PARTIAL) {
+               warnx("Cannot reduce symbol \"%s\" in %s",
+                     sp->name, get_file_name(entry));
        } else {
                md_make_jmpslot(rrs_plt + sp->jmpslot_offset/sizeof(jmpslot_t),
                                sp->jmpslot_offset,
@@ -390,7 +387,7 @@
 
        r->r_address = (long)rrs_sdt.sdt_plt + sp->jmpslot_offset;
 
-       if (link_mode & SYMBOLIC) {
+       if (sp->defined && (link_mode & SYMBOLIC)) {
                RELOC_EXTERN_P(r) = 0;
                md_make_jmpreloc(rp, r, RELTYPE_RELATIVE);
        } else {
@@ -432,8 +429,8 @@
        if (sp->gotslot_offset != -1) {
 #ifdef DIAGNOSTIC
                if (*GOTP(sp->gotslot_offset) != addend +
-                   ((!(link_mode & SHAREABLE) || (link_mode & SYMBOLIC))
-                      ? sp->value : 0))
+                   (((link_mode & SYMBOLIC) || rrs_section_type == RRS_PARTIAL)
+                      && sp->defined ? sp->value : 0))
                        errx(1, "%s: %s: gotslot at %#x is multiple valued, "
                                "*got = %#x, addend = %#x, sp->value = %#x",
                                get_file_name(entry), sp->name,
@@ -461,8 +458,7 @@
 #endif
 
        if (sp->defined &&
-           (!(link_mode & SHAREABLE) || (link_mode & SYMBOLIC))) {
-
+           ((link_mode & SYMBOLIC) || rrs_section_type == RRS_PARTIAL)) {
                /*
                 * Reduce to just a base-relative translation.
                 */
@@ -473,12 +469,7 @@
 #endif
                reloc_type = RELTYPE_RELATIVE;
 
-       } else if ((link_mode & SYMBOLIC) || rrs_section_type == RRS_PARTIAL) {
-               /*
-                * SYMBOLIC: all symbols must be known.
-                * RRS_PARTIAL: we don't link against shared objects,
-                * so again all symbols must be known.
-                */
+       } else if (rrs_section_type == RRS_PARTIAL) {
                warnx("Cannot reduce symbol \"%s\" in %s",
                      sp->name, get_file_name(entry));
 



Home | Main Index | Thread Index | Old Index