[m-dev.] promoted ROTDs

Peter Wang novalazy at gmail.com
Wed Jul 25 14:01:30 AEST 2018


On Wed, 25 Jul 2018 05:30:01 +0200 (CEST), "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> 
> 
> On Wed, 25 Jul 2018 11:08:27 +1000, Peter Wang <novalazy at gmail.com> wrote:
> > On Wed, 25 Jul 2018 02:47:22 +0200 (CEST), "Zoltan Somogyi" <zoltan.somogyi at runbox.com> wrote:
> > > I added -Werror to the .mgnuc_copts file in all the directories
> > > (runtime, library, compiler etc) and got a clean bootcheck in hlc.gc.
> > > However, the bootcheck in asm_fast.gc was anything but clean.
> > > First, you get errors (originally warnings) in mercury_context.c
> > > for its use of the system-provided FD_SET macro. After several layers,
> > > it expands to a conditional expression that contains a call to a function
> > > with a __warnattr. The call should never be made (the condition *should*
> > > prevent it), but gcc either doesn't know this or doesn't care. I have found
> > > no way to shut this off.
> > 
> > What is the warning?
> 
> mercury_context.c: In function ‘MR_check_pending_contexts.constprop.0’:
> mercury_context.c:1632:13: warning: call to ‘__fdelt_warn’ declared with attribute warning: bit outside of fd_set selected [enabled by default]
> mercury_context.c:1638:13: warning: call to ‘__fdelt_warn’ declared with attribute warning: bit outside of fd_set selected [enabled by default]
> mercury_context.c:1644:13: warning: call to ‘__fdelt_warn’ declared with attribute warning: bit outside of fd_set selected [enabled by default]
> mercury_context.c:1680:20: warning: call to ‘__fdelt_warn’ declared with attribute warning: bit outside of fd_set selected [enabled by default]
> mercury_context.c:1682:20: warning: call to ‘__fdelt_warn’ declared with attribute warning: bit outside of fd_set selected [enabled by default]
> mercury_context.c:1684:20: warning: call to ‘__fdelt_warn’ declared with attribute warning: bit outside of fd_set selected [enabled by default]
> 
> The calls to FD_SET and FD_ISSET expand to __FD_ELT(d) in /usr/include/bits/select2.h,
> which on my laptop looks like this:
> 
> /* Helper functions to issue warnings and errors when needed.  */
> extern long int __fdelt_chk (long int __d);
> extern long int __fdelt_warn (long int __d)
>   __warnattr ("bit outside of fd_set selected");
> #undef __FD_ELT
> #define __FD_ELT(d) \
>   __extension__                                                             \
>   ({ long int __d = (d);                                                    \
>      (__builtin_constant_p (__d)                                            \
>       ? (0 <= __d && __d < __FD_SETSIZE                                     \
>          ? (__d / __NFDBITS)                                                \
>          : __fdelt_warn (__d))                                              \
>       : __fdelt_chk (__d)); })

Looks like your version of gcc somehow thinks the argument to FD_SET is
constant.

Nonetheless, it does indicate a potential problem in mercury_context.c,
if the pending I/O stuff were actually to be used ;)
The select() interface cannot handle file descriptors above FD_SETSIZE-1
but on some systems (e.g. Linux) the file descriptor limit can be raised
higher, then the calls to FD_* macros could read/write memory outside of
their respective fd_sets. I'll add a comment.

Peter


More information about the developers mailing list