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]: ld crash on i386/pe when linking with a dll that has no exports


On Nov 27, 2009, at 5:54 AM, Dave Korn wrote:

> Christopher Faylor wrote:
> 
>>> The patch is OK, thank you Tristan :)
>> 
>> Actually, Tristan, please don't check this in as-is.
>> 
>> Having two comments which say "No exports" is confusing.  The comment should
>> probably be something like:
>> 
>> /* Null export table - nothing to export */
>> 
>> And, maybe the previous comment should say /* No imports or exports */.
> 
>  Yep, it would certainly make sense to clarify the two comments, I'd suggest
> that the one you refer to just above there should directly mention "number of
> data directory entries" or similar, in order to make explicit that these are
> on different levels of indirection, but I'm not picky; anything that you guys
> concur with is good enough for me, you both know what you're doing.

Ok, here is what I am checking.  I think that comments are clarified.

(Note: I think that the number of directory entries is always 16.  But the check is harmless).

Tristan.

ld/
2009-11-27  Tristan Gingold  <gingold@adacore.com>

	* pe-dll.c (pe_implied_import_dll): Return early if there is no
	export entries.

*** pe-dll.c	15 Nov 2009 07:52:42 -0000	1.123
--- pe-dll.c	27 Nov 2009 08:52:25 -0000
***************
*** 2981,2987 ****
        return FALSE;
      }
  
!   /* Get pe_header, optional header and numbers of export entries.  */
    pe_header_offset = pe_get32 (dll, 0x3c);
    opthdr_ofs = pe_header_offset + 4 + 20;
  #ifdef pe_use_x86_64
--- 2981,2987 ----
        return FALSE;
      }
  
!   /* Get pe_header, optional header and numbers of directory entries.  */
    pe_header_offset = pe_get32 (dll, 0x3c);
    opthdr_ofs = pe_header_offset + 4 + 20;
  #ifdef pe_use_x86_64
***************
*** 2990,2996 ****
    num_entries = pe_get32 (dll, opthdr_ofs + 92);
  #endif
  
!   if (num_entries < 1) /* No exports.  */
      return FALSE;
  
  #ifdef pe_use_x86_64
--- 2990,2997 ----
    num_entries = pe_get32 (dll, opthdr_ofs + 92);
  #endif
  
!   /* No import or export directory entry.  */
!   if (num_entries < 1)
      return FALSE;
  
  #ifdef pe_use_x86_64
***************
*** 3001,3006 ****
--- 3002,3011 ----
    export_size = pe_get32 (dll, opthdr_ofs + 100);
  #endif
  
+   /* No export table - nothing to export.  */
+   if (export_size == 0)
+     return FALSE;
+ 
    nsections = pe_get16 (dll, pe_header_offset + 4 + 2);
    secptr = (pe_header_offset + 4 + 20 +
  	    pe_get16 (dll, pe_header_offset + 4 + 16));


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