[PATCH v2 2/3] bfd/PE: don't write an OptionalHeader to object files

Tobias Deiminger tobias.deiminger@linutronix.de
Mon Nov 30 14:39:52 GMT 2026


Hi Jan,

Am Freitag, 27. November 2026, 11:36:19 Mitteleuropäische Normalzeit schrieb Jan Beulich:
> [..]
> However, again I wonder if we can't get away with less churn ...
> 
> > --- a/bfd/coffcode.h
> > +++ b/bfd/coffcode.h
> > @@ -378,8 +378,10 @@ extern const bfd_target TARGET_SYM_BIG;
> >  
> >  #if defined(COFF_WITH_PE) && !defined(COFF_IMAGE_WITH_PE)
> >  # define COFF_DEFAULT_MAX_NSCNS (IMAGE_SYM_SECTION_MAX + 1)
> > +# define COFF_EXEC_P 0
> >  #else
> >  # define COFF_DEFAULT_MAX_NSCNS 32768
> > +# define COFF_EXEC_P EXEC_P
> >  #endif
> >  
> >  #if defined (COFF_LONG_SECTION_NAMES)
> > @@ -3055,10 +3057,17 @@ coff_compute_section_file_positions (bfd * abfd)
> >      }
> >  #endif
> >  
> > -  if (bfd_get_start_address (abfd))
> > -    /*  A start address may have been added to the original file. In this
> > -	case it will need an optional header to record it.  */
> > -    abfd->flags |= EXEC_P;
> > +  if (bfd_applicable_file_flags (abfd) & EXEC_P)
> > +    {
> > +      /* A start address may have been added to the original file.  In this
> > +	 case it will need an optional header to record it.  */
> > +      if (bfd_get_start_address (abfd))
> > +	abfd->flags |= EXEC_P;
> > +    }
> > +  else
> > +    /* ld may have requested the executable flag even if not supported by
> > +       the target format.  */
> > +    abfd->flags &= ~EXEC_P;
> 
> ... here:
> 
>   if (!(bfd_applicable_file_flags (abfd) & EXEC_P))
>     /* ld may have requested the executable flag even if not supported by
>        the target format.  */
>     abfd->flags &= ~EXEC_P;
>   else if (bfd_get_start_address (abfd))
>     /*  A start address may have been added to the original file. In this
> 	case it will need an optional header to record it.  */
>     abfd->flags |= EXEC_P;

again, yours is equivalent and looks nicer. Feel free to edit on merge.

Tobias
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <https://sourceware.org/pipermail/binutils/attachments/20261130/520741fa/attachment.sig>


More information about the Binutils mailing list