[PUSHED] Fix testcases using __attribute__((noclone)) with Clang

Gary Benson gbenson@redhat.com
Mon Nov 2 12:13:29 GMT 2020


Hi Pedro,

Sorry for the random email I just sent, git-send-email fired it off
before I was ready!

What it *should* have said was:
Thank you for the review.  I've updated my patch with your suggestion.
Also, I interpreted your "I think this would work" to mean you hadn't
tested it, so I dug out a copy of GCC 4.8 and checked the preprocessor
conditionals were doing the right thing (they were).

Cheers,
Gary

Pedro Alves wrote:
> On 9/16/20 5:06 PM, Gary Benson via Gdb-patches wrote:
> > Clang fails to compile a number of files with the following warning:
> > unknown attribute 'noclone' ignored [-Wunknown-attributes].  This
> > commit adds a new header, lib/noclone.h, which defines the macro
> > ATTRIBUTE_NOCLONE accordingly, and updates the relevant testcases
> > to use it.
> 
> > diff --git a/gdb/testsuite/lib/noclone.h b/gdb/testsuite/lib/noclone.h
> > new file mode 100644
> > index 0000000..b6a4aa7
> > --- /dev/null
> > +++ b/gdb/testsuite/lib/noclone.h
> 
> I'd think that if you need to handle one attribute,
> you'll soon enough need to handle other attributes.
> Thus, I'd call this header something more generic like attributes.h.
> 
> > +
> > +/* Compatibility macro for __attribute__((noclone)).  */
> > +
> > +#ifndef NOCLONE_H
> > +#define NOCLONE_H
> > +
> > +#ifdef __cplusplus
> > +extern "C" {
> > +#endif
> > +
> > +#if __has_attribute(noclone)
> 
> __has_attribute isn't universally available.  For GCC, it was
> only added on GCC 5:
> 
>   https://gcc.gnu.org/gcc-5/changes.html
> 
> We support building GDB with GCC 4.8.  And the set of compilers the
> testsuite can be run against is larger than the set of compilers GDB
> builds with -- consider cross compilers for embedded targets,
> for example.
> 
> So we need to handle __has_attribute not being defined.  I think
> this would work:
> 
> #ifdef __has_attribute
> # if !__has_attribute (noclone)
> #  define ATTRIBUTE_NOCLONE
> # endif
> #endif
> #ifndef ATTRIBUTE_NOCLONE
> # define ATTRIBUTE_NOCLONE __attribute__((noclone))
> #endif
> 
> > +# define ATTRIBUTE_NOCLONE __attribute__((noclone))
> > +#else
> > +# define ATTRIBUTE_NOCLONE
> > +#endif
> > +
> > +#ifdef __cplusplus
> > +}
> > +#endif
> > +



More information about the Gdb-patches mailing list