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

Jan Beulich jbeulich@suse.com
Tue Mar 11 07:53:26 GMT 2025


On 10.03.2025 19:25, 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"),
> +			      false, false, true);

I understand the same is used when looking up _tls_used, yet it feels wrong
to assume that bfd_get_symbol_leading_char() can only ever return nil or '_'.
Nevertheless, because of the pre-existing similar code, I'm not going to
insist that this be corrected right here.

> +  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);
> +	  else
> +	    {
> +	      _bfd_error_handler
> +		(_("%pB: unable to fill in DataDictionary[10] because the size can't be read"),
> +		 abfd);
> +	      result = false;
> +	    }
> +	}
> +      else
> +	{
> +	  _bfd_error_handler
> +	    (_("%pB: unable to fill in DataDictionary[10] because __load_config_used is missing"),
> +	     abfd);

Message text here suggests this is rather (or also?) meant to be in the outer
if()'s "else", i.e.

> +	  result = false;
> +	}
> +    }

... here. Perhaps things want adjusting such that the message is issued in
both cases, e.g.

  h1 = coff_link_hash_lookup (coff_hash_table (info),
			      (bfd_get_symbol_leading_char (abfd) != 0
			       ? "__load_config_used" : "_load_config_used"),
			      false, false, true);
  if (h1 != NULL
      && ((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))
    h1 = NULL;
  if (h1 != NULL)
    {
      ...

?

Jan


More information about the Binutils mailing list