This is the mail archive of the gas2@sourceware.cygnus.com mailing list for the gas2 project.


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

coff weak symbol patches


Hi Ian,
Attached are the diffs for coff weak symbols. One problem area to 
note is weak undefined symbols probably don't work properly.

I've sent off the form you sent and the e-mail too.

Here's the changelog I came up with:

Include Changes:
* internal.h: Defined C_WEAKEXT.
* pe.h: Redefined C_WEAKEXT to C_NT_WEAK if 
COFF_WITH_PE defined.

BFD changes:
* obj-coff.c: Added obj_coff_weak to handle the ".weak" directive.
* coffcode.h
    (coff_slurp_symbol_table): Add case for C_WEAKEXT to handle 
weak symbols. Set BSF_WEAK for weak symbols.
* coffgen.c (coff_write_symbol): Make sure symbol has 
C_WEAKEXT storage class when BSF_WEAK is set.
    (coff_write_alien_symbol): Same
    (coff_print_symbol): Show if symbol is weak when printing all 
symbol information.
* cofflink.c
    (coff_link_check_ar_symbols): Include C_WEAKEXT type 
symbols in check.
    (coff_link_add_symbols): Same. Also make sure symbol 
remains weak when undefined.
    (_bfd_coff_link_input_bfd): Add C_WEAKEXT to skip test.

AS change:
* config/tc-i386.h: Added definition of LOCAL_LABEL for when 
TE_GO32 defined


-- 
Mark E. snowball3@usa.net
http://members.xoom.com/snowball3/

*** bfd/coffcode.~h	Thu Oct  1 04:17:04 1998
--- bfd/coffcode.h	Mon Oct  5 08:49:06 1998
***************
*** 3486,3494 ****
  #ifdef COFF_WITH_PE
              /* PE uses storage class 0x68 to denote a section symbol */
              case C_SECTION:
- 	    /* PE uses storage class 0x69 for a weak external symbol.  */
- 	    case C_NT_WEAK:
  #endif
  	      if ((src->u.syment.n_scnum) == 0)
  		{
  		  if ((src->u.syment.n_value) == 0)
--- 3486,3493 ----
  #ifdef COFF_WITH_PE
              /* PE uses storage class 0x68 to denote a section symbol */
              case C_SECTION:
  #endif
+             case C_WEAKEXT:       /* Weak external symbol */
  	      if ((src->u.syment.n_scnum) == 0)
  		{
  		  if ((src->u.syment.n_value) == 0)
***************
*** 3518,3523 ****
--- 3517,3525 ----
  				       - dst->symbol.section->vma);
  #endif
  
+                   if (src->u.syment.n_sclass == C_WEAKEXT)
+                     dst->symbol.flags = BSF_WEAK;
+ 
  		  if (ISFCN ((src->u.syment.n_type)))
  		    {
  		      /* A function ext does not go at the end of a
***************
*** 3533,3543 ****
  	      /* A symbol with a csect entry should not go at the end.  */
  	      if (src->u.syment.n_numaux > 0)
  		dst->symbol.flags |= BSF_NOT_AT_END;
- #endif
- 
- #ifdef COFF_WITH_PE
- 	      if (src->u.syment.n_sclass == C_NT_WEAK)
- 		dst->symbol.flags = BSF_WEAK;
  #endif
  
  	      break;
--- 3535,3540 ----
*** bfd/coffgen.~c	Thu Oct  1 04:13:08 1998
--- bfd/coffgen.c	Mon Oct  5 08:43:42 1998
***************
*** 929,934 ****
--- 929,938 ----
  	symbol->section->output_section->target_index;
      }
  
+ /* Translate 'weak' flag to storage type */
+   if (symbol->flags & BSF_WEAK)
+     native->u.syment.n_sclass = C_WEAKEXT;
+ 
    coff_fix_symbol_name (abfd, symbol, native, string_size_p,
  			debug_string_section_p, debug_string_size_p);
  
***************
*** 1032,1037 ****
--- 1036,1043 ----
    native->u.syment.n_type = 0;
    if (symbol->flags & BSF_LOCAL)
      native->u.syment.n_sclass = C_STAT;
+   else if (symbol->flags & BSF_WEAK)
+     native->u.syment.n_sclass = C_WEAKEXT;
    else
      native->u.syment.n_sclass = C_EXT;
    native->u.syment.n_numaux = 0;
***************
*** 1981,1989 ****
--- 1987,1998 ----
  	{
  	  unsigned long val;
  	  unsigned int aux;
+           char weak[] = " (w)";
  	  combined_entry_type *combined = coffsymbol (symbol)->native;
  	  combined_entry_type *root = obj_raw_syments (abfd);
  	  struct lineno_cache_entry *l = coffsymbol (symbol)->lineno;
+           if (combined->u.syment.n_type != C_WEAKEXT)
+             weak[0] = '\0';
  
  	  fprintf (file, "[%3ld]", (long) (combined - root));
  
***************
*** 1995,2008 ****
  		    - root));
  
  	  fprintf (file,
! 		   "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x%08lx %s",
  		   combined->u.syment.n_scnum,
  		   combined->u.syment.n_flags,
  		   combined->u.syment.n_type,
  		   combined->u.syment.n_sclass,
  		   combined->u.syment.n_numaux,
  		   val,
! 		   symbol->name);
  
  	  for (aux = 0; aux < combined->u.syment.n_numaux; aux++)
  	    {
--- 2004,2018 ----
  		    - root));
  
  	  fprintf (file,
!                    "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x%08lx %s %s",
  		   combined->u.syment.n_scnum,
  		   combined->u.syment.n_flags,
  		   combined->u.syment.n_type,
  		   combined->u.syment.n_sclass,
  		   combined->u.syment.n_numaux,
  		   val,
!                    symbol->name,
!                    weak);
  
  	  for (aux = 0; aux < combined->u.syment.n_numaux; aux++)
  	    {
*** bfd/cofflink.~c	Thu Oct  1 04:13:08 1998
--- bfd/cofflink.c	Tue Oct  6 11:00:44 1998
***************
*** 244,249 ****
--- 244,250 ----
        bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &sym);
  
        if ((sym.n_sclass == C_EXT
+            || sym.n_sclass == C_WEAKEXT
  #ifdef C_SYSTEM
  	   || sym.n_sclass == C_SYSTEM
  #endif
***************
*** 266,279 ****
  	     undefined.  If a symbol is currently known to be common,
  	     COFF linkers do not bring in an object file which defines
  	     it.  */
! 	  if (h != (struct bfd_link_hash_entry *) NULL
! 	      && h->type == bfd_link_hash_undefined)
! 	    {
  	      if (! (*info->callbacks->add_archive_element) (info, abfd, name))
  		return false;
  	      *pneeded = true;
  	      return true;
! 	    }
  	}
  
        esym += (sym.n_numaux + 1) * symesz;
--- 267,280 ----
  	     undefined.  If a symbol is currently known to be common,
  	     COFF linkers do not bring in an object file which defines
  	     it.  */
!         if (h != (struct bfd_link_hash_entry *) NULL
!             && h->type == bfd_link_hash_undefined)
!           {
  	      if (! (*info->callbacks->add_archive_element) (info, abfd, name))
  		return false;
  	      *pneeded = true;
  	      return true;
!           }
  	}
  
        esym += (sym.n_numaux + 1) * symesz;
***************
*** 337,342 ****
--- 338,344 ----
        bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &sym);
  
        if (sym.n_sclass == C_EXT
+         || sym.n_sclass == C_WEAKEXT
  #ifdef C_SYSTEM
  	  || sym.n_sclass == C_SYSTEM
  #endif
***************
*** 367,373 ****
  	    {
  	      if (value == 0)
  		{
! 		  flags = 0;
  		  section = bfd_und_section_ptr;
  		}
  	      else
--- 369,375 ----
  	    {
  	      if (value == 0)
  		{
!                   flags = 0;
  		  section = bfd_und_section_ptr;
  		}
  	      else
***************
*** 375,380 ****
--- 377,386 ----
  		  flags = BSF_GLOBAL;
  		  section = bfd_com_section_ptr;
  		}
+ 
+               /* Reset weak flag if storage is C_WEAKEXT */
+               if (sym.n_sclass == C_WEAKEXT)
+                 flags = BSF_WEAK;
  	    }
  	  else
  	    {
***************
*** 1329,1334 ****
--- 1335,1341 ----
        if (! skip)
  	{
  	  if (isym.n_sclass == C_EXT
+               || isym.n_sclass == C_WEAKEXT
  #ifdef C_SYSTEM
  	      || isym.n_sclass == C_SYSTEM
  #endif
***************
*** 1648,1654 ****
  	  /* If doing task linking, convert normal global function symbols to
  	     static functions. */
  
! 	  if (finfo->info->task_link && isym.n_sclass == C_EXT)
  	    isym.n_sclass = C_STAT;
  
  	  /* Output the symbol.  */
--- 1655,1661 ----
  	  /* If doing task linking, convert normal global function symbols to
  	     static functions. */
  
!           if (finfo->info->task_link && ((isym.n_sclass == C_EXT) || (isym.n_sclass == C_WEAKEXT)))
  	    isym.n_sclass = C_STAT;
  
  	  /* Output the symbol.  */
***************
*** 2276,2283 ****
        abort ();
        return false;
  
-     case bfd_link_hash_undefined:
      case bfd_link_hash_undefweak:
        isym.n_scnum = N_UNDEF;
        isym.n_value = 0;
        break;
--- 2283,2290 ----
        abort ();
        return false;
  
      case bfd_link_hash_undefweak:
+     case bfd_link_hash_undefined:
        isym.n_scnum = N_UNDEF;
        isym.n_value = 0;
        break;
***************
*** 2342,2348 ****
       just ignore it and it will be output during a later pass. */
    if (finfo->global_to_static)
      {
!       if (isym.n_sclass != C_EXT)
  	{
  	  return true;
  	}
--- 2349,2355 ----
       just ignore it and it will be output during a later pass. */
    if (finfo->global_to_static)
      {
!       if ((isym.n_sclass != C_EXT) && (isym.n_sclass != C_WEAKEXT))
  	{
  	  return true;
  	}
*** include/coff/internal.~h	Thu Oct  1 04:24:14 1998
--- include/coff/internal.h	Mon Oct  5 08:01:28 1998
***************
*** 215,221 ****
  #define C_ALIAS	 	105	/* duplicate tag		*/
  #define C_HIDDEN	106	/* ext symbol in dmert public lib */
  
- 
  /* New storage classes for WINDOWS_NT   */
  #define C_SECTION       104     /* section name */
  #define C_NT_WEAK	105	/* weak external */
--- 215,220 ----
***************
*** 265,270 ****
--- 264,274 ----
  #define C_THUMBLABEL    (128 + C_LABEL)		/* 134 */
  #define C_THUMBEXTFUNC  (C_THUMBEXT  + 20)	/* 150 */
  #define C_THUMBSTATFUNC (C_THUMBSTAT + 20)	/* 151 */
+ 
+ #ifndef C_WEAKEXT
+ /* Extension storage class for binutils not used by any platform*/
+ #define C_WEAKEXT       127     /* weak external symbol */
+ #endif
  
  /********************** SECTION HEADER **********************/
  
*** gas/config/obj-coff.~c	Mon Oct  5 15:25:14 1998
--- gas/config/obj-coff.c	Mon Oct  5 15:54:06 1998
***************
*** 179,184 ****
--- 179,231 ----
      s_lcomm (0);
  }
  
+ void
+ obj_coff_weak (ignore)
+      int ignore;
+ {
+   char *name;
+   int c;
+   symbolS *symbolP;
+   expressionS exp;
+ 
+   name = input_line_pointer;
+   c = get_symbol_end ();
+   symbolP = symbol_find_or_make (name);
+   *input_line_pointer = c;
+ 
+   SKIP_WHITESPACE ();
+ 
+   if (*input_line_pointer == ',')
+     {
+       if (S_IS_DEFINED (symbolP))
+ 	{
+ 	  as_bad (_("Ignoring attempt to redefine symbol `%s'."),
+ 		  S_GET_NAME (symbolP));
+ 	  ignore_rest_of_line ();
+ 	  return;
+ 	}
+ 
+       ++input_line_pointer;
+       SKIP_WHITESPACE ();
+       if (! is_end_of_line[(unsigned char) *input_line_pointer])
+ 	{
+ 	  expression (&exp);
+ 	  if (exp.X_op != O_symbol)
+ 	    {
+ 	      as_bad (_("bad .weak directive"));
+ 	      ignore_rest_of_line();
+ 	      return;
+ 	    }
+ 	  symbolP->sy_value = exp;
+ 	}
+     }
+ 
+   S_SET_WEAK (symbolP);
+   S_SET_STORAGE_CLASS (symbolP, C_WEAKEXT);
+ 
+   demand_empty_rest_of_line ();
+ }
+ 
  #ifdef BFD_ASSEMBLER
  
  static void SA_SET_SYM_TAGNDX PARAMS ((symbolS *, symbolS *));
***************
*** 577,582 ****
--- 624,630 ----
        break;
  
      case C_EXT:
+     case C_WEAKEXT:
      case C_STAT:
      case C_LABEL:
        /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
***************
*** 929,935 ****
    if (!block_stack)
      block_stack = stack_init (512, sizeof (symbolS*));
  
!   if (!S_IS_DEFINED (symp) && S_GET_STORAGE_CLASS (symp) != C_STAT)
      S_SET_STORAGE_CLASS (symp, C_EXT);
  
    if (!SF_GET_DEBUG (symp))
--- 977,988 ----
    if (!block_stack)
      block_stack = stack_init (512, sizeof (symbolS*));
  
!   if (S_IS_WEAK (symp))
!     S_SET_STORAGE_CLASS (symp, C_WEAKEXT);
! 
!   if (!S_IS_DEFINED (symp) &&
!       S_GET_STORAGE_CLASS (symp) != C_STAT &&
!       S_GET_STORAGE_CLASS (symp) != C_WEAKEXT )
      S_SET_STORAGE_CLASS (symp, C_EXT);
  
    if (!SF_GET_DEBUG (symp))
***************
*** 2227,2232 ****
--- 2280,2286 ----
        break;
  
      case C_EXT:
+     case C_WEAKEXT:
      case C_STAT:
      case C_LABEL:
        /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
***************
*** 2632,2637 ****
--- 2686,2692 ----
      {
        if (symbolP->sy_mri_common)
  	{
+           /* FIXME: C_WEAKEXT too? */
  	  if (S_GET_STORAGE_CLASS (symbolP) == C_EXT)
  	    as_bad (_("%s: global symbols not supported in common sections"),
  		    S_GET_NAME (symbolP));
***************
*** 2818,2825 ****
        else if (!S_IS_DEFINED (symbolP)
  	       && !S_IS_DEBUG (symbolP)
  	       && !SF_GET_STATICS (symbolP) &&
! 	       S_GET_STORAGE_CLASS (symbolP) == C_EXT)
! 	{			/* C_EXT && !SF_GET_FUNCTION(symbolP))  */
  	  /* if external, Remove from the list */
  	  symbolS *hold = symbol_previous (symbolP);
  
--- 2873,2881 ----
        else if (!S_IS_DEFINED (symbolP)
  	       && !S_IS_DEBUG (symbolP)
  	       && !SF_GET_STATICS (symbolP) &&
!                (S_GET_STORAGE_CLASS (symbolP) == C_EXT ||
!                 S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT))
!         {                       /* (C_EXT || C_WEAKEXT) && !SF_GET_FUNCTION(symbolP))  */
  	  /* if external, Remove from the list */
  	  symbolS *hold = symbol_previous (symbolP);
  
***************
*** 2831,2837 ****
        else if (! S_IS_DEBUG (symbolP)
  	       && ! SF_GET_STATICS (symbolP)
  	       && ! SF_GET_FUNCTION (symbolP)
! 	       && S_GET_STORAGE_CLASS (symbolP) == C_EXT)
  	{
  	  symbolS *hold = symbol_previous (symbolP);
  
--- 2887,2894 ----
        else if (! S_IS_DEBUG (symbolP)
  	       && ! SF_GET_STATICS (symbolP)
  	       && ! SF_GET_FUNCTION (symbolP)
!                && (S_GET_STORAGE_CLASS (symbolP) == C_EXT
!                    || S_GET_STORAGE_CLASS (symbolP) == C_WEAKEXT)
  	{
  	  symbolS *hold = symbol_previous (symbolP);
  
***************
*** 4326,4331 ****
--- 4383,4389 ----
    /* We accept the .bss directive for backward compatibility with
       earlier versions of gas.  */
    {"bss", obj_coff_bss, 0},
+   {"weak", obj_coff_weak, 0},
  #ifndef BFD_ASSEMBLER
    {"use", obj_coff_section, 0},
    {"text", obj_coff_text, 0},
*** include/coff/pe.~h	Mon Oct  5 08:06:02 1998
--- include/coff/pe.h	Mon Oct  5 08:06:34 1998
***************
*** 164,169 ****
--- 164,174 ----
  #undef  E_FILNMLEN
  #define E_FILNMLEN	18	/* # characters in a file name		*/
  
+ #ifdef COFF_WITH_PE
+ #undef C_WEAKEXT
+ #define C_WEAKEXT 105 /* make same as C_NT_WEAK */
+ #endif
+ 
  #endif
  
  
*** gas/config/tc-i386.~h	Thu Oct  1 04:10:42 1998
--- gas/config/tc-i386.h	Tue Oct  6 08:33:52 1998
***************
*** 146,160 ****
  #define tc_coff_symbol_emit_hook(a)	;	/* not used */
  
  #ifndef BFD_ASSEMBLER
  #ifndef OBJ_AOUT
  #ifndef TE_PE
! #ifndef TE_GO32
  /* Local labels starts with .L */
  #define LOCAL_LABEL(name) (name[0] == '.' \
  		 && (name[1] == 'L' || name[1] == 'X' || name[1] == '.'))
  #endif
  #endif
! #endif
  #endif
  
  #define LOCAL_LABELS_FB 1
--- 146,166 ----
  #define tc_coff_symbol_emit_hook(a)	;	/* not used */
  
  #ifndef BFD_ASSEMBLER
+ 
+ #if defined(TE_GO32)
+ #define LOCAL_LABEL(name) (name[0] == 'L')
+ #endif
+ 
  #ifndef OBJ_AOUT
  #ifndef TE_PE
! #ifndef LOCAL_LABEL
  /* Local labels starts with .L */
  #define LOCAL_LABEL(name) (name[0] == '.' \
  		 && (name[1] == 'L' || name[1] == 'X' || name[1] == '.'))
  #endif
  #endif
! 
! #endif /* BFD_ASSEMBLER */
  #endif
  
  #define LOCAL_LABELS_FB 1