Output section type (READONLY)

Fangrui Song i@maskray.me
Mon Feb 21 23:30:45 GMT 2022


Thanks!

On Mon, Feb 21, 2022, 15:04 Alan Modra <amodra@gmail.com> wrote:

> On Wed, Feb 16, 2022 at 06:12:19PM -0800, Fangrui Song wrote:
> > On 2022-02-16, Nick Clifton wrote:
> > > Hi Guys,
> > >
> > >  I have gone ahead and applied an update form of Fanguri's patch
> (attached).
> >
> > Thanks, this enables a proper way to set the section type in the future.
> > Hope someone implements this for gold as well since it does not
> > recognize .note* as SHT_NOTE, either.
>
> "DO NOT EDIT!" says the comment at the top of bfd-in2.h.  Move the new
> type field where it belongs.
>
>         PR ld/28841
>         * section.c (struct bfd_section): Add type.  Formatting.
>         (BFD_FAKE_SECTION): Formatting.
>         * bfd-in2.h: Regenerate.
>
> diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
> index 78a0a1dea42..db41e7eb7fe 100644
> --- a/bfd/bfd-in2.h
> +++ b/bfd/bfd-in2.h
> @@ -1166,11 +1166,13 @@ typedef struct bfd_section
>      struct bfd_section *s;
>      const char *linked_to_symbol_name;
>    } map_head, map_tail;
> - /* Points to the output section this section is already assigned to, if
> any.
> -    This is used when support for non-contiguous memory regions is
> enabled.  */
> - struct bfd_section *already_assigned;
>
> -  /* Explicitly specified section type, if non-zero. */
> +  /* Points to the output section this section is already assigned to,
> +     if any.  This is used when support for non-contiguous memory
> +     regions is enabled.  */
> +  struct bfd_section *already_assigned;
> +
> +  /* Explicitly specified section type, if non-zero.  */
>    unsigned int type;
>
>  } asection;
> @@ -1356,7 +1358,7 @@ discarded_section (const asection *sec)
>       (struct bfd_symbol *) SYM, &SEC.symbol,                           \
>                                                                         \
>    /* map_head, map_tail, already_assigned, type                     */ \
> -     { NULL }, { NULL }, NULL, 0                                       \
> +     { NULL }, { NULL }, NULL,             0                           \
>                                                                         \
>      }
>
> diff --git a/bfd/section.c b/bfd/section.c
> index 2de7dbf661a..9a1071454f5 100644
> --- a/bfd/section.c
> +++ b/bfd/section.c
> @@ -551,9 +551,14 @@ CODE_FRAGMENT
>  .    struct bfd_section *s;
>  .    const char *linked_to_symbol_name;
>  .  } map_head, map_tail;
> -. {* Points to the output section this section is already assigned to, if
> any.
> -.    This is used when support for non-contiguous memory regions is
> enabled.  *}
> -. struct bfd_section *already_assigned;
> +.
> +.  {* Points to the output section this section is already assigned to,
> +.     if any.  This is used when support for non-contiguous memory
> +.     regions is enabled.  *}
> +.  struct bfd_section *already_assigned;
> +.
> +.  {* Explicitly specified section type, if non-zero.  *}
> +.  unsigned int type;
>  .
>  .} asection;
>  .
> @@ -738,7 +743,7 @@ CODE_FRAGMENT
>  .     (struct bfd_symbol *) SYM, &SEC.symbol,                          \
>  .                                                                      \
>  .  {* map_head, map_tail, already_assigned, type                     *}
>       \
> -.     { NULL }, { NULL }, NULL, 0
>       \
> +.     { NULL }, { NULL }, NULL,             0                          \
>  .                                                                      \
>  .    }
>  .
>
> --
> Alan Modra
> Australia Development Lab, IBM
>


More information about the Binutils mailing list