2004-07-04 Aaron W. LaFramboise <aaron98wiridge9@aaronwl.com>
authorChristopher Faylor <me+cygwin@cgf.cx>
Sat, 3 Jul 2004 16:07:51 +0000 (16:07 +0000)
committerChristopher Faylor <me+cygwin@cgf.cx>
Sat, 3 Jul 2004 16:07:51 +0000 (16:07 +0000)
* bfd/cofflink.c (_bfd_coff_generic_relocate_section): Resolve PE weak
externals properly.
* src/gas/config/obj-coff.c (obj_coff_weak): New .weak syntax for PE weak
externals.
* binutils/doc/binutils.texi (nm): Clarify weak symbol description.
* gas/config/tc-i386.c (tc_gen_reloc): Use addend for weak symbols in TE_PE.
* gas/doc/as.texinfo (Weak): Document PE weak symbols.
* ld/ld.texinfo (WIN32): Document PE weak symbols.

bfd/ChangeLog
bfd/cofflink.c
binutils/ChangeLog
binutils/doc/binutils.texi
gas/ChangeLog
gas/config/obj-coff.c
gas/config/tc-i386.c
gas/doc/as.texinfo
ld/ChangeLog
ld/ld.texinfo

index e8e452f976c2d3e66b20aa9bc447c5faa145067b..198494653e9e6199fcf44fe88776b555477692d5 100644 (file)
@@ -1,3 +1,8 @@
+2004-07-03  Aaron W. LaFramboise  <aaron98wiridge9@aaronwl.com>
+
+       * cofflink.c (_bfd_coff_generic_relocate_section): Resolve PE weak
+       externals properly.
+
 2004-07-02  Martin Schwidefsky  <schwidefsky@de.ibm.com>
 
        * config.bfd: Add want64 to configuration target s390-*-linux*.
index 1af86abaec9d43548ee4a0a0e1ea8164214eec00..af6dd3d699684fac1a77e32159223cf6b56825f2 100644 (file)
@@ -2923,16 +2923,41 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
          if (h->root.type == bfd_link_hash_defined
              || h->root.type == bfd_link_hash_defweak)
            {
+             /* Defined weak symbols are a GNU extension. */
              asection *sec;
 
              sec = h->root.u.def.section;
              val = (h->root.u.def.value
                     + sec->output_section->vma
                     + sec->output_offset);
-             }
+           }
 
          else if (h->root.type == bfd_link_hash_undefweak)
-           val = 0;
+           {
+              if (h->class == C_NT_WEAK && h->numaux == 1)
+               {
+                 /* See _Microsoft Portable Executable and Common Object
+                   * File Format Specification_, section 5.5.3.
+                  * Note that weak symbols without aux records are a GNU
+                  * extension.
+                  * FIXME: All weak externals are treated as having
+                  * characteristics IMAGE_WEAK_EXTERN_SEARCH_LIBRARY (2).
+                  * There are no known uses of the other two types of
+                  * weak externals.
+                  */
+                 asection *sec;
+                 struct coff_link_hash_entry *h2 =
+                   input_bfd->tdata.coff_obj_data->sym_hashes[
+                   h->aux->x_sym.x_tagndx.l];
+
+                 sec = h2->root.u.def.section;
+                 val = h2->root.u.def.value + sec->output_section->vma
+                   + sec->output_offset;
+               }
+             else
+                /* This is a GNU extension. */
+               val = 0;
+           }
 
          else if (! info->relocatable)
            {
index 6cb1f691a4a97f083fb62483ccba3fe371e5eab0..8ea599b12c36dbb5607a3e4857b28939df568ecd 100644 (file)
@@ -1,3 +1,7 @@
+2004-07-03  Aaron W. LaFramboise  <aaron98wiridge9@aaronwl.com>
+
+       * doc/binutils.texi (nm): Clarify weak symbol description.
+
 2004-06-24  Ben Elliston  <bje@au.ibm.com>
 
        * readelf.c (get_segment_type): Display "GNU_STACK", not just
index 2e787202985c546dd3b6feafcb4ef0666da3ee60..c27c627094a360978b4c68c7026af18911366fa4 100644 (file)
@@ -748,7 +748,8 @@ The symbol is a weak symbol that has not been specifically tagged as a
 weak object symbol.  When a weak defined symbol is linked with a normal
 defined symbol, the normal defined symbol is used with no error.
 When a weak undefined symbol is linked and the symbol is not defined,
-the value of the weak symbol becomes zero with no error.
+the value of the symbol is determined in a system-specific manner without
+error.  Uppercase indicates that a default value has been specified.
 
 @item -
 The symbol is a stabs symbol in an a.out object file.  In this case, the
index 50a3ac42deba10d8c2108ce7d0ae7ed9a986d4b3..f02d2a816d2f7f7387f76633c7e7736a23f78aa4 100644 (file)
@@ -1,3 +1,9 @@
+2004-07-03  Aaron W. LaFramboise  <aaron98wiridge9@aaronwl.com>
+
+       * config/obj-coff.c (obj_coff_weak): New .weak syntax for PE weak
+       externals.
+       * doc/as.texinfo (Weak): Document PE weak symbols.
+
 2004-07-03  Richard Sandiford  <rsandifo@redhat.com>
 
        * config/tc-mips.c (HAVE_IN_PLACE_ADDENDS): New macro.
index 8ead485253ee21e795f69fb2976492e56d5061d4..0239b76f88e613acf5354e30cde2fb0088d4bb80 100644 (file)
@@ -212,47 +212,6 @@ obj_coff_bss (ignore)
     s_lcomm (0);
 }
 
-/* Handle .weak.  This is a GNU extension.  */
-
-static void
-obj_coff_weak (ignore)
-     int ignore ATTRIBUTE_UNUSED;
-{
-  char *name;
-  int c;
-  symbolS *symbolP;
-
-  do
-    {
-      name = input_line_pointer;
-      c = get_symbol_end ();
-      symbolP = symbol_find_or_make (name);
-      *input_line_pointer = c;
-      SKIP_WHITESPACE ();
-
-#if defined BFD_ASSEMBLER || defined S_SET_WEAK
-      S_SET_WEAK (symbolP);
-#endif
-
-#ifdef TE_PE
-      S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
-#else
-      S_SET_STORAGE_CLASS (symbolP, C_WEAKEXT);
-#endif
-
-      if (c == ',')
-       {
-         input_line_pointer++;
-         SKIP_WHITESPACE ();
-         if (*input_line_pointer == '\n')
-           c = '\n';
-       }
-    }
-  while (c == ',');
-
-  demand_empty_rest_of_line ();
-}
-
 #ifdef BFD_ASSEMBLER
 
 static segT fetch_coff_debug_section PARAMS ((void));
@@ -1135,6 +1094,86 @@ obj_coff_val (ignore)
   demand_empty_rest_of_line ();
 }
 
+/* Handle .weak.  This is a GNU extension in formats other than PE. */
+static void
+obj_coff_weak (ignore)
+     int ignore ATTRIBUTE_UNUSED;
+{
+  char *name;
+  int c;
+  symbolS *symbolP;
+
+  do
+    {
+      name = input_line_pointer;
+      c = get_symbol_end ();
+      if (*name == 0)
+       {
+         as_warn (_("badly formed .weak directive ignored"));
+         ignore_rest_of_line ();
+         return;
+       }
+      symbolP = symbol_find_or_make (name);
+      *input_line_pointer = c;
+      SKIP_WHITESPACE ();
+
+#if defined BFD_ASSEMBLER || defined S_SET_WEAK
+      S_SET_WEAK (symbolP);
+#endif
+
+#ifdef TE_PE
+      /* See _Microsoft Portable Executable and Common Object
+       * File Format Specification_, section 5.5.3.
+       * Note that weak symbols without aux records are a GNU
+       * extension.
+       */
+      S_SET_STORAGE_CLASS (symbolP, C_NT_WEAK);
+
+      if (c == '=')
+       {
+         symbolS *alternateP;
+         long characteristics = 2;
+         ++input_line_pointer;
+         if (*input_line_pointer == '=')
+           {
+             characteristics = 1;
+             ++input_line_pointer;
+           }
+
+         SKIP_WHITESPACE();
+         name = input_line_pointer;
+         c = get_symbol_end();
+         if (*name == 0)
+           {
+             as_warn (_("alternate name missing in .weak directive"));
+             ignore_rest_of_line ();
+             return;
+           }
+         alternateP = symbol_find_or_make (name);
+         *input_line_pointer = c;
+
+         S_SET_NUMBER_AUXILIARY (symbolP, 1);
+         SA_SET_SYM_TAGNDX (symbolP, alternateP);
+         SA_SET_SYM_FSIZE (symbolP, characteristics);
+       }
+#else  /* TE_PE */
+      S_SET_STORAGE_CLASS (symbolP, C_WEAKEXT);
+#endif  /* TE_PE */
+
+      if (c == ',')
+       {
+         input_line_pointer++;
+         SKIP_WHITESPACE ();
+         if (*input_line_pointer == '\n')
+           c = '\n';
+       }
+
+    }
+  while (c == ',');
+
+  demand_empty_rest_of_line ();
+}
+
 void
 coff_obj_read_begin_hook ()
 {
index 823435f110120c30a3cd2ca55765a1f862b7eb29..cc95843662f8b6ef6e41c2ad197768acf11aa4d5 100644 (file)
@@ -5280,6 +5280,12 @@ tc_gen_reloc (section, fixp)
   *rel->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
 
   rel->address = fixp->fx_frag->fr_address + fixp->fx_where;
+
+#ifdef TE_PE
+  if (S_IS_WEAK (fixp->fx_addsy))
+    rel->addend = rel->address - (*rel->sym_ptr_ptr)->value + 4;
+  else
+#endif
   if (!use_rela_relocations)
     {
       /* HACK: Since i386 ELF uses Rel instead of Rela, encode the
index 056fa6db357b31adf74e234b7ccc1f7ed62344ae..29605b3f1e2eda7500fc9d666f2cedf7aff5625c 100644 (file)
@@ -3400,8 +3400,8 @@ respectively, with @code{.val} and @code{.type}.
 
 @cindex auxiliary attributes, COFF symbols
 The @command{@value{AS}} directives @code{.dim}, @code{.line}, @code{.scl},
-@code{.size}, and @code{.tag} can generate auxiliary symbol table
-information for COFF.
+@code{.size}, @code{.tag}, and @code{.weak} can generate auxiliary symbol
+table information for COFF.
 @end ifset
 
 @ifset SOM
@@ -3823,9 +3823,9 @@ Some machine configurations provide additional directives.
 * Version::                     @code{.version "@var{string}"}
 * VTableEntry::                 @code{.vtable_entry @var{table}, @var{offset}}
 * VTableInherit::               @code{.vtable_inherit @var{child}, @var{parent}}
-* Weak::                        @code{.weak @var{names}}
 @end ifset
 
+* Weak::                        @code{.weak @var{names}}
 * Word::                        @code{.word @var{expressions}}
 * Deprecated::                  Deprecated Directives
 @end menu
@@ -5808,14 +5808,31 @@ parent whose addend is the value of the child symbol.  As a special case the
 parent name of @code{0} is treated as refering the @code{*ABS*} section.
 @end ifset
 
-@ifset ELF
 @node Weak
 @section @code{.weak @var{names}}
 
 @cindex @code{weak} directive
 This directive sets the weak attribute on the comma separated list of symbol
 @code{names}.  If the symbols do not already exist, they will be created.
-@end ifset
+
+Weak symbols are supported in COFF as a GNU extension.  This directive
+sets the weak attribute on the comma separated list of symbol
+@code{names}.  If the symbols do not already exist, they will be created.
+
+@smallexample
+@code{.weak @var{name} [ < = | == > @var{alternate}] [, ...]}
+@end smallexample
+
+On the PE target, weak aliases are supported natively.  Weak aliases
+(usually called "weak externals" in PE) are created when an alternate
+name is specified.  When a weak symbol is linked and the symbol is not
+defined, the weak symbol becomes an alias for the alternate symbol.  If
+one equal sign is used, the linker searches for defined symbols within
+other objects and libraries.  This is the usual mode, historically
+called "lazy externals."  Otherwise, when two equal signs are used,
+the linker searches for defined symbols only within other objects.
+
+Non-alias weak symbols are supported on PE as a GNU extension.
 
 @node Word
 @section @code{.word @var{expressions}}
index 8aad6330be35813b4dfb47bbdd997fd9a4f2ee9a..c957555ab9dd6f0e95d51d306d247a7607a69949 100644 (file)
@@ -1,3 +1,7 @@
+2004-07-03  Aaron W. LaFramboise  <aaron98wiridge9@aaronwl.com>
+
+       * ld.texinfo (WIN32): Document PE weak symbols.
+
 2004-07-02  Kaz Kojima  <kkojima@rr.iij4u.or.jp>
 
        * emulparams/shlelf32_linux.sh (COMMONPAGESIZE): Set to 4KB.
index c6002da1f9d50a1f4ec677b5350b702f732d337e..2b77260b60bbcc31abaadb51b1e6b3427266da07 100644 (file)
@@ -5292,6 +5292,24 @@ to handle the other symbols, then the both the new names @emph{and}
 the original names for the renamed symbols will be exported.  
 In effect, you'd be aliasing those symbols, not renaming them, 
 which is probably not what you wanted.
+
+@cindex weak externals
+@item weak externals
+The Windows object format, PE, specifies a form of weak symbols called
+weak externals.  When a weak symbol is linked and the symbol is not
+defined, the weak symbol becomes an alias for some other symbol.  There
+are three variants of weak externals:
+@itemize
+@item Definition is searched for in objects and libraries, historically
+called lazy externals.
+@item Definition is searched for only in other objects, not in libraries.
+This form is not presently implemented.
+@item No search; the symbol is an alias.  This form is not presently
+implemented.
+@end itemize
+As a GNU extension, weak symbols that do not specify an alternate symbol
+are supported.  If the symbol is undefined when linking, the symbol
+uses a default value.
 @end table
 
 @ifclear GENERIC
This page took 0.039938 seconds and 4 git commands to generate.