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: [gold patch] Fix problem with placement of .tbss with scripts


Cary Coutant <ccoutant@google.com> writes:

>         * script-sections.cc (Sort_output_sections::operator()): Sort TLS
>         sections before NOBITS sections.
>
>
> diff --git a/gold/script-sections.cc b/gold/script-sections.cc
> index 7bcf91c..fd1ae72 100644
> --- a/gold/script-sections.cc
> +++ b/gold/script-sections.cc
> @@ -3586,17 +3586,13 @@ Sort_output_sections::operator()(const
> Output_section* os1,
>    if (os1->address() != os2->address())
>      return os1->address() < os2->address();
>
> -  // Sort TLS sections to the end.
> +  // Sort PROGBITS < TLS < TLS NOBITS < NOBITS.
> +  bool nobits1 = os1->type() == elfcpp::SHT_NOBITS;
> +  bool nobits2 = os2->type() == elfcpp::SHT_NOBITS;
>    bool tls1 = (os1->flags() & elfcpp::SHF_TLS) != 0;
>    bool tls2 = (os2->flags() & elfcpp::SHF_TLS) != 0;
> -  if (tls1 != tls2)
> -    return tls2;
> -
> -  // Sort PROGBITS before NOBITS.
> -  if (os1->type() == elfcpp::SHT_PROGBITS && os2->type() == elfcpp::SHT_NOBITS)
> -    return true;
> -  if (os1->type() == elfcpp::SHT_NOBITS && os2->type() == elfcpp::SHT_PROGBITS)
> -    return false;
> +  if (nobits1 != nobits2 || tls1 != tls2)
> +    return (!nobits1 && nobits2) || (!nobits1 && tls2) || (tls1 && nobits2);
>
>    // Sort non-NOLOAD before NOLOAD.
>    if (os1->is_noload() && !os2->is_noload())


Thanks for spotting this.

I think we can get the same results with code that is slightly simpler
to understand by writing it like this:

  // Sort PROGBITS before NOBITS.
  if (os1->type() == elfcpp::SHT_PROGBITS && os2->type() == elfcpp::SHT_NOBITS)
    return true;
  if (os1->type() == elfcpp::SHT_NOBITS && os2->type() == elfcpp::SHT_PROGBITS)
    return false;

  // Sort PROGBITS TLS sections to the end, NOBITS TLS sections to the
  // beginning.
  bool tls1 = (os1->flags() & elfcpp::SHF_TLS) != 0;
  bool tls2 = (os2->flags() & elfcpp::SHF_TLS) != 0;
  if (tls1 != tls2)
    return os1->type() == elfcpp::SHT_PROGBITS ? tls2 : tls1;

Either way is fine with me.

Thanks.

Ian


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