Skip to content

Commit

Permalink
Work around fragile #include in binutils
Browse files Browse the repository at this point in the history
The `bfd.h` header file that is included in `binutils` has the line
`#include "ansidecl.h"`, which is fragile because it prefers Cygwin's
`include/ansidecl.h` (as opposed to `#include <ansidecl.h>`, which would
only look in the system include paths).

This matters because as of v2.42, `bfd.h` also makes use of the
`ATTRIBUTE_WARN_UNUSED_RESULT` macro.

So let's just copy that macro (and while at it, the other `ATTRIBUTE_*`
macros) from binutils' `ansidecl.h` file, to avoid compile errors while
compiling `dumper.o` that look like this:

  /usr/include/bfd.h:2770:1: error: expected initializer before ‘ATTRIBUTE_WARN_UNUSED_RESULT’
   2770 | ATTRIBUTE_WARN_UNUSED_RESULT;
        | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed Feb 2, 2024
1 parent 980b652 commit de45537
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions include/ansidecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,49 @@ So instead we use the macro below and test it against specific values. */
# endif /* GNUC >= 4.9 */
#endif /* ATTRIBUTE_NO_SANITIZE_UNDEFINED */

/* Attribute 'nonstring' was valid as of gcc 8. */
#ifndef ATTRIBUTE_NONSTRING
# if GCC_VERSION >= 8000
# define ATTRIBUTE_NONSTRING __attribute__ ((__nonstring__))
# else
# define ATTRIBUTE_NONSTRING
# endif
#endif

/* Attribute `alloc_size' was valid as of gcc 4.3. */
#ifndef ATTRIBUTE_RESULT_SIZE_1
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_1 __attribute__ ((alloc_size (1)))
# else
# define ATTRIBUTE_RESULT_SIZE_1
#endif
#endif

#ifndef ATTRIBUTE_RESULT_SIZE_2
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_2 __attribute__ ((alloc_size (2)))
# else
# define ATTRIBUTE_RESULT_SIZE_2
#endif
#endif

#ifndef ATTRIBUTE_RESULT_SIZE_1_2
# if (GCC_VERSION >= 4003)
# define ATTRIBUTE_RESULT_SIZE_1_2 __attribute__ ((alloc_size (1, 2)))
# else
# define ATTRIBUTE_RESULT_SIZE_1_2
#endif
#endif

/* Attribute `warn_unused_result' was valid as of gcc 3.3. */
#ifndef ATTRIBUTE_WARN_UNUSED_RESULT
# if GCC_VERSION >= 3003
# define ATTRIBUTE_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__))
# else
# define ATTRIBUTE_WARN_UNUSED_RESULT
# endif
#endif

/* We use __extension__ in some places to suppress -pedantic warnings
about GCC extensions. This feature didn't work properly before
gcc 2.8. */
Expand Down

0 comments on commit de45537

Please sign in to comment.