Skip to content

Commit 7e155aa

Browse files
committed
Centralize glibc/gcc attributes
Make a common header file that collects up all used attributes. Switch a couple places to use it. NOTE: the ones that are in the shipped API cannot use gcc-attributes or we have to ship it, too.
1 parent 69c08ef commit 7e155aa

File tree

4 files changed

+53
-25
lines changed

4 files changed

+53
-25
lines changed

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ EXTRA_DIST = ChangeLog AUTHORS NEWS README.md INSTALL \
3333
contrib/libauplugin/Makefile \
3434
contrib/libauplugin/auplugin-example.c \
3535
contrib/libauplugin/auplugin-example.conf
36+
noinst_HEADERS = gcc-attributes.h
3637

3738
CONFIG_CLEAN_FILES = debug*.list config/*
3839

auparse/interpret.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "dso.h"
2929
#include "rnode.h"
3030
#include <time.h>
31+
#include "gcc-attributes.h"
3132

3233
#define NEVER_LOADED 0xFFFF
3334

common/common.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,7 @@
2929
#endif
3030
#include <sys/types.h>
3131
#include "dso.h"
32-
// These macros originate in sys/cdefs.h
33-
#ifndef __attr_access
34-
# define __attr_access(x)
35-
#endif
36-
#ifndef __attribute_malloc__
37-
# define __attribute_malloc__
38-
#endif
39-
#ifndef __attr_dealloc
40-
# define __attr_dealloc(dealloc, argno)
41-
#endif
42-
#ifndef __wur
43-
# define __wur
44-
#endif
45-
#ifndef __has_attribute
46-
# define __has_attribute(x) 0
47-
#endif
48-
#ifndef __attribute_const__
49-
# define __attribute_const__
50-
#endif
51-
#ifndef __attribute_pure__
52-
# define __attribute_pure__
53-
#endif
54-
#ifndef __nonnull
55-
# define __nonnull(params)
56-
#endif
32+
#include "gcc-attributes.h"
5733

5834
/* Wrapper macros for optional atomics
5935
* Note: ATOMIC_INT and ATOMIC_UNSIGNED are defined in config.h */

gcc-attributes.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* gcc-attributes.h -- compatibility wrappers for GCC function attributes
2+
* Copyright 2025 Red Hat Inc.
3+
* All Rights Reserved.
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
*/
19+
20+
#ifndef AUDIT_GCC_ATTRIBUTES_H
21+
#define AUDIT_GCC_ATTRIBUTES_H
22+
23+
/* These macros originate in sys/cdefs.h but may be missing on some libc
24+
* implementations (e.g. musl). Provide fallbacks when they are undefined.
25+
*/
26+
#ifndef __has_attribute
27+
# define __has_attribute(x) 0
28+
#endif
29+
30+
#ifndef __attr_access
31+
# define __attr_access(x)
32+
#endif
33+
34+
#ifndef __attribute_malloc__
35+
# define __attribute_malloc__
36+
#endif
37+
38+
#ifndef __attr_dealloc
39+
# define __attr_dealloc(dealloc, argno)
40+
#endif
41+
42+
#ifndef __attr_dealloc_free
43+
# define __attr_dealloc_free
44+
#endif
45+
46+
#ifndef __wur
47+
# define __wur
48+
#endif
49+
50+
#endif /* AUDIT_GCC_ATTRIBUTES_H */

0 commit comments

Comments
 (0)