[PATCH v3] bfd: fill in PE load config directory entry.

Jan Beulich jbeulich@suse.com
Thu Mar 20 11:31:32 GMT 2025


On 13.03.2025 18:14, Jeremy Drake wrote:
> @@ -4573,6 +4575,48 @@ _bfd_XXi_final_link_postscript (bfd * abfd, struct coff_final_link_info *pfinfo)
>  #endif
>      }
> 
> +  h1 = coff_link_hash_lookup (coff_hash_table (info),
> +			      (bfd_get_symbol_leading_char (abfd) != 0
> +			       ? "__load_config_used" : "_load_config_used"),

Still assuming bfd_get_symbol_leading_char() can only ever return nil or '_'?

> +			      false, false, true);
> +  if (h1 != NULL)
> +    {
> +      char data[4];
> +      if ((h1->root.type == bfd_link_hash_defined
> +	   || h1->root.type == bfd_link_hash_defweak)
> +	  && h1->root.u.def.section != NULL
> +	  && h1->root.u.def.section->output_section != NULL)
> +	{
> +	  pe_data (abfd)->pe_opthdr.DataDirectory[PE_LOAD_CONFIG_TABLE].VirtualAddress =
> +	    (h1->root.u.def.value
> +	     + h1->root.u.def.section->output_section->vma
> +	     + h1->root.u.def.section->output_offset
> +	     - pe_data (abfd)->pe_opthdr.ImageBase);
> +
> +	  /* the size is stored as the first 4 bytes at _load_config_used */
> +	  if (bfd_get_section_contents (abfd,
> +		h1->root.u.def.section->output_section, data,
> +		h1->root.u.def.section->output_offset + h1->root.u.def.value,
> +		4))
> +	    pe_data (abfd)->pe_opthdr.DataDirectory[PE_LOAD_CONFIG_TABLE].Size =
> +	      bfd_get_32 (abfd, data);

I wonder if we can indeed blindly use that value, with no sanity checking
whatsoever.

Furthermore, having checked two random executables each from two random VC
installations, I find that the size in the data directory and the value at
the start of the referenced RVA aren't the same: In all four cases the data
directory says 0x40 while the 32-bit item at the indicated RVA is 0x48.

Jan


More information about the Binutils mailing list