[PATCH] Fix dlls for non underscored targets.

Pedro Alves pedro_alves@portugalmail.pt
Thu Sep 21 05:25:00 GMT 2006


Christopher Faylor escreveu:
>>> Pedro Alves wrote:
>>> That test only runs on native configurations (*),
>>> so I missed some obvious mistakes I made.
>>>       
>>> (*) Can see why. It only compiles and links. It doesn't run the
>>> built executables.
>>>       
s/Can/Can't/


>>   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?
>
>   
Well, I left it for clarity. The first is because sizeof ("string") returns
the length+1 and the last is for the terminating '\0' of the full built
'char *name'.
It think it is clearer this way than how it was.

(While doing this sizeof ("string") - 1for the nth time, I wonder if a
#define LIT_STR_LENGTH(STR) (sizeof (STR "") - 1)
shouldn't be added to bfd-in.h ...)

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

Humm, not sure what you mean? With this patch it is __imp_
everywhere, except one place (auto_export) that expects a symbol name 
stripped from the underscore.
Maybe you meant a define?

>>     
>
> 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.
>
>   

Where?
It was already U ("_head_") in pe-dll.c, only in pe.em it missed the U.

You meant _nm_? Where you confused by this?:

       if (exp->flag_data)
-	quick_symbol (abfd, U("_nm__"), exp->internal_name, "", id6,
+	quick_symbol (abfd, U ("_nm_"), U (""), exp->internal_name, id6,

I'm not removing the U here. What happens is that the rightmost
underscore in _nm__ is the underscore to add to exp->internal name
for underscored targets. It makes no sense to add it to non underscored
targets, so 'U ("_nm_"), U ("")' takes care of that.
It maps to __nm_ + _$(SYMBOL) on underscored targets (like it was
before), and to
_nm_ + $(SYMBOL) on non underscored ones.

---

To back this __imp_ everywhere thing, on WinCE SDK import libs, you will
find stuff like this:

coredll.lib (...) __imp_printf

Notice there is only one underscore between the '__imp' and 'printf'.

Cheers,
Pedro Alves





More information about the Binutils mailing list