diff -r -N -c binutils-2.12.90.0.3.orig/bfd/nlmcode.h binutils-2.12.90.0.3/bfd/nlmcode.h
*** binutils-2.12.90.0.3.orig/bfd/nlmcode.h	Tue Oct  2 00:25:21 2001
--- binutils-2.12.90.0.3/bfd/nlmcode.h	Thu Mar 28 22:55:56 2002
***************
*** 718,723 ****
--- 718,749 ----
  	  != sizeof (thdr))
  	return false;
      }
+     
+   /* Swapped the order of the MeSsAgEs and CoPyRiGhT tag to make the
+      NW4.x and NW5.x loaders happy. Still works on NW3.x. Thanks for
+      Rostislav Letos from Novell and Gunter Knauf for hints and testing. */
+     
+   /* Write out the copyright header if there is one.  */
+   if (find_nonzero ((PTR) nlm_copyright_header (abfd),
+ 		    sizeof (Nlm_Internal_Copyright_Header)))
+     {
+       Nlm_External_Copyright_Header thdr;
+ 
+       memcpy (thdr.stamp, "CoPyRiGhT=", 10);
+       amt = sizeof (thdr.stamp);
+       if (bfd_bwrite ((PTR) thdr.stamp, amt, abfd) != amt)
+ 	return false;
+       thdr.copyrightMessageLength[0] =
+ 	nlm_copyright_header (abfd)->copyrightMessageLength;
+       amt = 1;
+       if (bfd_bwrite ((PTR) thdr.copyrightMessageLength, amt, abfd) != amt)
+ 	return false;
+       /* The copyright message is a variable length string.  */
+       amt = nlm_copyright_header (abfd)->copyrightMessageLength + 1;
+       if (bfd_bwrite ((PTR) nlm_copyright_header (abfd)->copyrightMessage,
+ 		     amt, abfd) != amt)
+ 	return false;
+     }
  
    /* Write out the extended header if there is one.  */
    if (find_nonzero ((PTR) nlm_extended_header (abfd),
***************
*** 818,845 ****
  	return false;
      }
  
-   /* Write out the copyright header if there is one.  */
-   if (find_nonzero ((PTR) nlm_copyright_header (abfd),
- 		    sizeof (Nlm_Internal_Copyright_Header)))
-     {
-       Nlm_External_Copyright_Header thdr;
- 
-       memcpy (thdr.stamp, "CoPyRiGhT=", 10);
-       amt = sizeof (thdr.stamp);
-       if (bfd_bwrite ((PTR) thdr.stamp, amt, abfd) != amt)
- 	return false;
-       thdr.copyrightMessageLength[0] =
- 	nlm_copyright_header (abfd)->copyrightMessageLength;
-       amt = 1;
-       if (bfd_bwrite ((PTR) thdr.copyrightMessageLength, amt, abfd) != amt)
- 	return false;
-       /* The copyright message is a variable length string.  */
-       amt = nlm_copyright_header (abfd)->copyrightMessageLength + 1;
-       if (bfd_bwrite ((PTR) nlm_copyright_header (abfd)->copyrightMessage,
- 		     amt, abfd) != amt)
- 	return false;
-     }
- 
    /* Write out the custom header if there is one.   */
    if (find_nonzero ((PTR) nlm_custom_header (abfd),
  		    sizeof (Nlm_Internal_Custom_Header)))
--- 844,849 ----
diff -r -N -c binutils-2.12.90.0.3.orig/binutils/nlmconv.c binutils-2.12.90.0.3/binutils/nlmconv.c
*** binutils-2.12.90.0.3.orig/binutils/nlmconv.c	Thu Mar  7 20:52:37 2002
--- binutils-2.12.90.0.3/binutils/nlmconv.c	Fri Mar 29 16:48:24 2002
***************
*** 466,471 ****
--- 466,515 ----
    newsyms = (asymbol **) xmalloc (newsymalloc * sizeof (asymbol *));
    newsymcount = 0;
    endsym = NULL;
+ 
+   /* Validate all export symbols. */
+   if (export_symbols != NULL)
+     {
+       struct string_list *e;
+       for (e = export_symbols; e != NULL; e = e->next)
+         {
+           int valid = false;
+           for (i = 0; i < symcount; i++)	    
+             {
+               register asymbol *sym = symbols[i];
+               if (strcmp (e->string, bfd_asymbol_name (sym)) == 0)
+                 {
+                   const char *sn = bfd_get_section (sym)->name;
+                   if ((strcmp (sn, NLM_INITIALIZED_DATA_NAME) == 0)
+ 		    || (strcmp (sn, NLM_CODE_NAME) == 0)) valid = true;
+                   else
+                     /* If any symbol referencing to an unitialized variable is
+ 		       exported, created NLM becomes corrupted because this
+ 		       reference is pointing beyond data section boundaries.
+ 		       It should be resolved by moving of this variable into
+ 		       data section.
+ 		          With all uninitialized variables optionally 
+ 		       moved into data section, it would also solve the problem
+ 		       with uninitialized variables in general, so they would
+ 		       be zeroed by default.  */
+                     if (bfd_is_com_section (bfd_get_section (sym)))
+                       {
+ 		        non_fatal (_("warning: symbol %s exported"
+ 		          " but it is an uninitialized variable,"
+ 			  " created NLM will be corrupted!"), e->string);
+                         /* treat as valid even if it should be fatal,
+ 			   NLM is corrupted in this case */
+                         valid = true;
+                       }
+                   break;
+                 } 
+             }  
+           if (!valid)
+ 	    non_fatal (_("warning: symbol %s exported"
+       	                 " but not defined anywhere"), e->string);
+         }
+     }
+ 
    for (i = 0; i < symcount; i++)
      {
        register asymbol *sym;
***************
*** 2119,2125 ****
--- 2163,2173 ----
        p = program_name + strlen (program_name);
        while (p != program_name)
  	{
+ #ifdef WIN32
+ 	  if (p[-1] == '\\')
+ #else
  	  if (p[-1] == '/')
+ #endif
  	    {
  	      ld = (char *) xmalloc (p - program_name + strlen (LD_NAME) + 1);
  	      memcpy (ld, program_name, p - program_name);
***************
*** 2137,2146 ****
--- 2185,2203 ----
    unlink_on_exit = make_temp_file (".O");
  
    argv[0] = ld;
+ #ifdef WIN32
+   argv[1] = (char *) "-m";
+   argv[2] = (char *) "i386nw";
+   argv[3] = (char *) "-Ur";
+   argv[4] = (char *) "-o";
+   argv[5] = unlink_on_exit;
+   i = 6;
+ #else
    argv[1] = (char *) "-Ur";
    argv[2] = (char *) "-o";
    argv[3] = unlink_on_exit;
    i = 4;
+ #endif
    for (q = inputs; q != NULL; q = q->next, i++)
      argv[i] = q->string;
    argv[i] = NULL;
