Question on commit a48931cc2df9f87596d93b31

Sonja Schofield sonja.tideman@oracle.com
Fri Apr 17 19:13:03 GMT 2020


Hello Nick,

----- nickc@redhat.com wrote:

> 
> The reason for this is explained in the commit message for this
> change:
> 
>   "This one exposed a bug in tic6x gas, found with inline function
>   parameter type checking." [...]
> 
> Ie, using inline functions rather than macros allows for extra
> checking by the compiler, which in turn leads to more robust code.
>

Yes, I understand most of the other changes, it was just the is_const_section change I was curious about.
 
> > It also changed the bfd_is_const_section macro from considering
> abs_section_ptr, und_section_ptr, com_section_ptr, and ind_section_ptr
> as const to an inline function that just considers abs_section_ptr and
> ind_section_ptr as const.
> 
> Ah no, that is not what happened.  The macro was changed from this:
> 
>  #define bfd_is_const_section(SEC)              \
>   (   ((SEC) == bfd_abs_section_ptr)            \
>    || ((SEC) == bfd_und_section_ptr)            \
>    || ((SEC) == bfd_com_section_ptr)            \
>    || ((SEC) == bfd_ind_section_ptr))
> 
> to this:
> 
>  static inline bfd_boolean
>  bfd_is_const_section (const asection *sec)
>  {
>    return sec >= bfd_abs_section_ptr && sec <= bfd_ind_section_ptr;
>  }
> 
> Note the use of >= and <=.  The function makes use of the fact that
> these section pointers are known to be allocated in sequence and 
> adjacent to each other, so that a couple of redundant pointer checks
> can be eliminated.

Except the code defines the relevant pointers as:

> /* Pointer to the common section.  */
> #define bfd_com_section_ptr (&_bfd_std_section[0])
> /* Pointer to the undefined section.  */
> #define bfd_und_section_ptr (&_bfd_std_section[1])
> /* Pointer to the absolute section.  */
> #define bfd_abs_section_ptr (&_bfd_std_section[2])
> /* Pointer to the indirect section.  */
> #define bfd_ind_section_ptr (&_bfd_std_section[3])

which means the "sec >= bfd_abs_section_ptr && sec <= bfd_ind_section_ptr" would only cover abs_section_ptr and ind_section_ptr.  If the first >= was to the com_section_ptr it would do as you describe, unless there is something I am missing?


Thanks,
Sonja


More information about the Binutils mailing list