This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix dlls for non underscored targets.


On Wed, Sep 20, 2006 at 11:56:26PM +0100, Pedro Alves wrote:
>Danny Smith escreveu:
>> Pedro Alves
>>  
>>>Hi all,
>>>
>>>The attached patch fixes dll generation / import lib usage
>>>for non underscored targets.
>>>    
>>
>>It breaks dll generation on mingw32, specifically export of data
>>symbols, eg,  
>>generating dll from testsuite/ld-auto-import/dll.c
>>  
>Thanks for taking a look.
>
>That test only runs on native configurations (*),
>so I missed some obvious mistakes I made.
>
>Here is an updated patch, tested on cross to arm-wince-pe,
>and native i686-pc-cygwin.
>
>(*) Can see why. It only compiles and links. It doesn't run the
>built executables.
>
>Please review and commit.
>
>2006-09-20  Pedro Alves  <pedro_alves@portugalmail.pt>
>
>ld/ChangeLog
>
>  * pe-dll.c : Fix typo.
>  (auto-export) : Check against __imp_ on non underscored targets.
>  (process_def_file) : Use __imp_ on non underscored targets too.
>  Only skip underscore on underscored targets.
>  (make_one) : Use __imp_ on non underscored targets too.
>  (pe_create_runtime_relocator_reference) : Only underscore
>  _pei386_runtime_relocator on underscored targets.
>  (pe_process_import_defs) : Use __imp_ on non underscored targets too.
>  * pe.em (U) : New macro.
>  (set_pe_subsystem) : Remove underscore from WinMainCRTStartup
>  on wince subsystem case.
>  (pe_find_data_imports) : Use U on "_head_".
>

>Index: pe-dll.c
>===================================================================
>RCS file: /cvs/src/src/ld/pe-dll.c,v
>retrieving revision 1.89
>diff -u -p -r1.89 pe-dll.c
>--- pe-dll.c	20 Sep 2006 11:35:09 -0000	1.89
>+++ pe-dll.c	20 Sep 2006 22:22:16 -0000
>@@ -123,7 +123,7 @@
>     (so, DLL name is referenced by multiple entries), and pointer to symbol
>     name thunk. Symbol name thunk is singleton vector (__nm_th_<symbol>)
>     pointing to IMAGE_IMPORT_BY_NAME structure (__nm_<symbol>) directly
>-    containing imported name. Here comes that "om the edge" problem mentioned
>+    containing imported name. Here comes that "on the edge" problem mentioned
>     above: PE specification rambles that name vector (OriginalFirstThunk)
>     should run in parallel with addresses vector (FirstThunk), i.e. that they
>     should have same number of elements and terminated with zero. We violate
>@@ -460,7 +460,9 @@ auto_export (bfd *abfd, def_file *d, con
>     libname = lbasename (abfd->my_archive->filename);
> 
>   /* We should not re-export imported stuff.  */
>-  if (CONST_STRNEQ (n, "_imp_"))
>+  if (pe_details->underscored
>+	    ? CONST_STRNEQ (n, "_imp_")
>+	    : CONST_STRNEQ (n, "__imp_"))
>     return 0;
> 
>   for (i = 0; i < d->num_exports; i++)
>@@ -617,8 +619,8 @@ process_def_file (bfd *abfd ATTRIBUTE_UN
> 
> 		  /* We should not re-export imported stuff.  */
> 		  {
>-		    char *name = xmalloc (strlen (sn) + 2 + 6);
>-		    sprintf (name, "%s%s", U("_imp_"), sn);
>+		    char *name = xmalloc (sizeof ("__imp_") - 1 + strlen (sn) + 1);

Wouldn't it be better to just get rid of the "- 1 ... + 1" above?

I'm also wondering if it would make sense to just put the "__imp_"/"_imp_" string in a
variable somewhere and just use that.

>+		    sprintf (name, "%s%s", "__imp_", sn);
> 
> 		    blhe = bfd_link_hash_lookup (info->hash, name,
> 						 FALSE, FALSE, FALSE);
>@@ -628,7 +630,7 @@ process_def_file (bfd *abfd ATTRIBUTE_UN
> 		      continue;
> 		  }
> 
>-		  if (*sn == '_')
>+		  if (pe_details->underscored && *sn == '_')
> 		    sn++;
> 
> 		  if (auto_export (b, pe_def_file, sn))
>@@ -1918,7 +1920,7 @@ make_one (def_file_export *exp, bfd *par
> 		    BSF_GLOBAL, 0);
>       if (! exp->flag_data)
> 	quick_symbol (abfd, "", exp->internal_name, "", tx, BSF_GLOBAL, 0);
>-      quick_symbol (abfd, U ("_imp_"), exp->internal_name, "", id5,
>+      quick_symbol (abfd, "__imp_", exp->internal_name, "", id5,
> 		    BSF_GLOBAL, 0);
>       /* Fastcall applies only to functions,
> 	 so no need for auto-import symbol.  */
>@@ -1930,12 +1932,12 @@ make_one (def_file_export *exp, bfd *par
>       if (! exp->flag_data)
> 	quick_symbol (abfd, U (""), exp->internal_name, "", tx,
> 		      BSF_GLOBAL, 0);
>-      quick_symbol (abfd, U ("_imp__"), exp->internal_name, "", id5,
>+      quick_symbol (abfd, "__imp_", U (""), exp->internal_name, id5,
> 		    BSF_GLOBAL, 0);
>       /* Symbol to reference ord/name of imported
> 	 data symbol, used to implement auto-import.  */
>       if (exp->flag_data)
>-	quick_symbol (abfd, U("_nm__"), exp->internal_name, "", id6,
>+	quick_symbol (abfd, U ("_nm_"), U (""), exp->internal_name, id6,
> 		      BSF_GLOBAL,0);
>     }
>   if (pe_dll_compat_implib)
>@@ -2259,7 +2261,7 @@ pe_create_runtime_relocator_reference (b
>   symtab = xmalloc (2 * sizeof (asymbol *));
>   extern_rt_rel = quick_section (abfd, ".rdata", SEC_HAS_CONTENTS, 2);
> 
>-  quick_symbol (abfd, "", "__pei386_runtime_relocator", "", UNDSEC,
>+  quick_symbol (abfd, "", U ("_pei386_runtime_relocator"), "", UNDSEC,
> 		BSF_NO_FLAGS, 0);
> 
>   bfd_set_section_size (abfd, extern_rt_rel, 4);
>@@ -2460,7 +2462,7 @@ pe_process_import_defs (bfd *output_bfd,
> 	    char *name = xmalloc (len + 2 + 6);
> 
>  	    if (lead_at)
>-	      sprintf (name, "%s%s", "",
>+	      sprintf (name, "%s",
> 		       pe_def_file->imports[i].internal_name);
> 	    else
> 	      sprintf (name, "%s%s",U (""),
>@@ -2472,10 +2474,10 @@ pe_process_import_defs (bfd *output_bfd,
> 	    if (!blhe || (blhe && blhe->type != bfd_link_hash_undefined))
> 	      {
> 		if (lead_at)
>-		  sprintf (name, "%s%s", U ("_imp_"),
>+		  sprintf (name, "%s%s", "__imp_", 
> 			   pe_def_file->imports[i].internal_name);
> 		else
>-		  sprintf (name, "%s%s", U ("_imp__"),
>+		  sprintf (name, "%s%s%s", "__imp_", U (""),
> 			   pe_def_file->imports[i].internal_name);
> 
> 		blhe = bfd_link_hash_lookup (link_info->hash, name,
>Index: emultempl/pe.em
>===================================================================
>RCS file: /cvs/src/src/ld/emultempl/pe.em,v
>retrieving revision 1.120
>diff -u -p -r1.120 pe.em
>--- emultempl/pe.em	16 Sep 2006 18:12:16 -0000	1.120
>+++ emultempl/pe.em	20 Sep 2006 22:22:38 -0000
>@@ -115,6 +115,7 @@ cat >>e${EMULATION_NAME}.c <<EOF
> #define PE_DEF_FILE_ALIGNMENT		0x00000200
> #endif
> 
>+#define U(S) ${INITIAL_SYMBOL_CHAR} S
> 
> static struct internal_extra_pe_aouthdr pe;
> static int dll;
>@@ -400,7 +401,7 @@ set_pe_subsystem (void)
>       { "windows", 2, "WinMainCRTStartup" },
>       { "console", 3, "mainCRTStartup" },
>       { "posix",   7, "__PosixProcessStartup"},
>-      { "wince",   9, "_WinMainCRTStartup" },
>+      { "wince",   9, "WinMainCRTStartup" },
>       { "xbox",   14, "mainCRTStartup" },
>       { NULL, 0, NULL }
>     };
>@@ -925,14 +926,14 @@ pe_find_data_imports (void)
> 
> 	      for (i = 0; i < nsyms; i++)
> 		{
>-		  if (! CONST_STRNEQ (symbols[i]->name, "__head_"))
>+		  if (! CONST_STRNEQ (symbols[i]->name, U ("_head_")))
> 		    continue;
> 
> 		  if (pe_dll_extra_pe_debug)
> 		    printf ("->%s\n", symbols[i]->name);
> 
> 		  pe_data_import_dll = (char*) (symbols[i]->name +
>-						sizeof ("__head_") - 1);
>+						sizeof (U ("_head_")) - 1);
> 		  break;
> 		}

I am not at a place where I can check the source code right now but I'm not
clear on why you remove the U ("_head_") in some cases and add it in others.

cgf 


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