* [PATCH] compiler.h adjustments
@ 2012-10-25 11:51 Jan Beulich
2012-10-25 12:17 ` Keir Fraser
0 siblings, 1 reply; 2+ messages in thread
From: Jan Beulich @ 2012-10-25 11:51 UTC (permalink / raw)
To: xen-devel
[-- Attachment #1: Type: text/plain, Size: 3487 bytes --]
- replace __attribute_used__ with just __used
- add __maybe_unused and explain the difference between the two
- remove gcc 3.x specifics (as we don't support building with it
anymore; really for quite some time we didn't even support building
with the checked for minor versions)
- remove left over __setup() from init.h (rather than adjusting it)
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -41,7 +41,7 @@
#include <asm/early_printk.h>
#include "gic.h"
-static __attribute_used__ void init_done(void)
+static __used void init_done(void)
{
free_init_memory();
startup_cpu_idle_loop();
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -1,7 +1,7 @@
#ifndef __LINUX_COMPILER_H
#define __LINUX_COMPILER_H
-#if !defined(__GNUC__) || (__GNUC__ < 3)
+#if !defined(__GNUC__) || (__GNUC__ < 4)
#error Sorry, your compiler is too old/not recognized.
#endif
@@ -17,11 +17,11 @@
#ifdef __clang__
/* Clang can replace some vars with new automatic ones that go in .data;
* mark all explicit-segment vars 'used' to prevent that. */
-#define __section(s) __attribute_used__ __attribute__((__section__(s)))
+#define __section(s) __used __attribute__((__section__(s)))
#else
#define __section(s) __attribute__((__section__(s)))
#endif
-#define __used_section(s) __attribute_used__ __attribute__((__section__(s)))
+#define __used_section(s) __used __attribute__((__section__(s)))
#define __text_section(s) __attribute__((__section__(s)))
#ifdef INIT_SECTIONS_ONLY
@@ -36,23 +36,23 @@
#define __attribute_pure__ __attribute__((pure))
#define __attribute_const__ __attribute__((__const__))
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
-#define __attribute_used__ __attribute__((__used__))
-#else
-#define __attribute_used__ __attribute__((__unused__))
-#endif
+/*
+ * The difference between the following two attributes is that __used is
+ * intended to be used in cases where a reference to an identifier may be
+ * invisible to the compiler (e.g. an inline assembly operand not listed
+ * in the asm()'s operands), preventing the compiler from eliminating the
+ * variable or function.
+ * __maybe_unused otoh is to be used to merely prevent warnings (e.g. when
+ * an identifier is used only inside a preprocessor conditional, yet putting
+ * its declaration/definition inside another conditional would harm code
+ * readability).
+ */
+#define __used __attribute__((__used__))
+#define __maybe_unused __attribute__((__unused__))
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#define __must_check __attribute__((warn_unused_result))
-#else
-#define __must_check
-#endif
-#if __GNUC__ > 3
#define offsetof(a,b) __builtin_offsetof(a,b)
-#else
-#define offsetof(a,b) ((unsigned long)&(((a *)0)->b))
-#endif
/* &a[0] degrades to a pointer: a different type from an array */
#define __must_be_array(a) \
--- a/xen/include/xen/init.h
+++ b/xen/include/xen/init.h
@@ -114,9 +114,6 @@ extern struct kernel_param __setup_start
__kparam __setup_##_var = \
{ __setup_str_##_var, OPT_STR, &_var, sizeof(_var) }
-/* Make sure obsolete cmdline params don't break the build. */
-#define __setup(_name, _fn) static void * __attribute_used__ _dummy_##_fn = _fn
-
#endif /* __ASSEMBLY__ */
#ifdef CONFIG_HOTPLUG
[-- Attachment #2: attrib-used-unused.patch --]
[-- Type: text/plain, Size: 3507 bytes --]
compiler.h adjustments
- replace __attribute_used__ with just __used
- add __maybe_unused and explain the difference between the two
- remove gcc 3.x specifics (as we don't support building with it
anymore; really for quite some time we didn't even support building
with the checked for minor versions)
- remove left over __setup() from init.h (rather than adjusting it)
Signed-off-by: Jan Beulich <jbeulich@suse.com>
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -41,7 +41,7 @@
#include <asm/early_printk.h>
#include "gic.h"
-static __attribute_used__ void init_done(void)
+static __used void init_done(void)
{
free_init_memory();
startup_cpu_idle_loop();
--- a/xen/include/xen/compiler.h
+++ b/xen/include/xen/compiler.h
@@ -1,7 +1,7 @@
#ifndef __LINUX_COMPILER_H
#define __LINUX_COMPILER_H
-#if !defined(__GNUC__) || (__GNUC__ < 3)
+#if !defined(__GNUC__) || (__GNUC__ < 4)
#error Sorry, your compiler is too old/not recognized.
#endif
@@ -17,11 +17,11 @@
#ifdef __clang__
/* Clang can replace some vars with new automatic ones that go in .data;
* mark all explicit-segment vars 'used' to prevent that. */
-#define __section(s) __attribute_used__ __attribute__((__section__(s)))
+#define __section(s) __used __attribute__((__section__(s)))
#else
#define __section(s) __attribute__((__section__(s)))
#endif
-#define __used_section(s) __attribute_used__ __attribute__((__section__(s)))
+#define __used_section(s) __used __attribute__((__section__(s)))
#define __text_section(s) __attribute__((__section__(s)))
#ifdef INIT_SECTIONS_ONLY
@@ -36,23 +36,23 @@
#define __attribute_pure__ __attribute__((pure))
#define __attribute_const__ __attribute__((__const__))
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
-#define __attribute_used__ __attribute__((__used__))
-#else
-#define __attribute_used__ __attribute__((__unused__))
-#endif
+/*
+ * The difference between the following two attributes is that __used is
+ * intended to be used in cases where a reference to an identifier may be
+ * invisible to the compiler (e.g. an inline assembly operand not listed
+ * in the asm()'s operands), preventing the compiler from eliminating the
+ * variable or function.
+ * __maybe_unused otoh is to be used to merely prevent warnings (e.g. when
+ * an identifier is used only inside a preprocessor conditional, yet putting
+ * its declaration/definition inside another conditional would harm code
+ * readability).
+ */
+#define __used __attribute__((__used__))
+#define __maybe_unused __attribute__((__unused__))
-#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#define __must_check __attribute__((warn_unused_result))
-#else
-#define __must_check
-#endif
-#if __GNUC__ > 3
#define offsetof(a,b) __builtin_offsetof(a,b)
-#else
-#define offsetof(a,b) ((unsigned long)&(((a *)0)->b))
-#endif
/* &a[0] degrades to a pointer: a different type from an array */
#define __must_be_array(a) \
--- a/xen/include/xen/init.h
+++ b/xen/include/xen/init.h
@@ -114,9 +114,6 @@ extern struct kernel_param __setup_start
__kparam __setup_##_var = \
{ __setup_str_##_var, OPT_STR, &_var, sizeof(_var) }
-/* Make sure obsolete cmdline params don't break the build. */
-#define __setup(_name, _fn) static void * __attribute_used__ _dummy_##_fn = _fn
-
#endif /* __ASSEMBLY__ */
#ifdef CONFIG_HOTPLUG
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] compiler.h adjustments
2012-10-25 11:51 [PATCH] compiler.h adjustments Jan Beulich
@ 2012-10-25 12:17 ` Keir Fraser
0 siblings, 0 replies; 2+ messages in thread
From: Keir Fraser @ 2012-10-25 12:17 UTC (permalink / raw)
To: Jan Beulich, xen-devel
On 25/10/2012 04:51, "Jan Beulich" <JBeulich@suse.com> wrote:
> - replace __attribute_used__ with just __used
> - add __maybe_unused and explain the difference between the two
> - remove gcc 3.x specifics (as we don't support building with it
> anymore; really for quite some time we didn't even support building
> with the checked for minor versions)
> - remove left over __setup() from init.h (rather than adjusting it)
>
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
> --- a/xen/arch/arm/setup.c
> +++ b/xen/arch/arm/setup.c
> @@ -41,7 +41,7 @@
> #include <asm/early_printk.h>
> #include "gic.h"
>
> -static __attribute_used__ void init_done(void)
> +static __used void init_done(void)
> {
> free_init_memory();
> startup_cpu_idle_loop();
> --- a/xen/include/xen/compiler.h
> +++ b/xen/include/xen/compiler.h
> @@ -1,7 +1,7 @@
> #ifndef __LINUX_COMPILER_H
> #define __LINUX_COMPILER_H
>
> -#if !defined(__GNUC__) || (__GNUC__ < 3)
> +#if !defined(__GNUC__) || (__GNUC__ < 4)
> #error Sorry, your compiler is too old/not recognized.
> #endif
>
> @@ -17,11 +17,11 @@
> #ifdef __clang__
> /* Clang can replace some vars with new automatic ones that go in .data;
> * mark all explicit-segment vars 'used' to prevent that. */
> -#define __section(s) __attribute_used__ __attribute__((__section__(s)))
> +#define __section(s) __used __attribute__((__section__(s)))
> #else
> #define __section(s) __attribute__((__section__(s)))
> #endif
> -#define __used_section(s) __attribute_used__ __attribute__((__section__(s)))
> +#define __used_section(s) __used __attribute__((__section__(s)))
> #define __text_section(s) __attribute__((__section__(s)))
>
> #ifdef INIT_SECTIONS_ONLY
> @@ -36,23 +36,23 @@
> #define __attribute_pure__ __attribute__((pure))
> #define __attribute_const__ __attribute__((__const__))
>
> -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
> -#define __attribute_used__ __attribute__((__used__))
> -#else
> -#define __attribute_used__ __attribute__((__unused__))
> -#endif
> +/*
> + * The difference between the following two attributes is that __used is
> + * intended to be used in cases where a reference to an identifier may be
> + * invisible to the compiler (e.g. an inline assembly operand not listed
> + * in the asm()'s operands), preventing the compiler from eliminating the
> + * variable or function.
> + * __maybe_unused otoh is to be used to merely prevent warnings (e.g. when
> + * an identifier is used only inside a preprocessor conditional, yet putting
> + * its declaration/definition inside another conditional would harm code
> + * readability).
> + */
> +#define __used __attribute__((__used__))
> +#define __maybe_unused __attribute__((__unused__))
>
> -#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
> #define __must_check __attribute__((warn_unused_result))
> -#else
> -#define __must_check
> -#endif
>
> -#if __GNUC__ > 3
> #define offsetof(a,b) __builtin_offsetof(a,b)
> -#else
> -#define offsetof(a,b) ((unsigned long)&(((a *)0)->b))
> -#endif
>
> /* &a[0] degrades to a pointer: a different type from an array */
> #define __must_be_array(a) \
> --- a/xen/include/xen/init.h
> +++ b/xen/include/xen/init.h
> @@ -114,9 +114,6 @@ extern struct kernel_param __setup_start
> __kparam __setup_##_var = \
> { __setup_str_##_var, OPT_STR, &_var, sizeof(_var) }
>
> -/* Make sure obsolete cmdline params don't break the build. */
> -#define __setup(_name, _fn) static void * __attribute_used__ _dummy_##_fn =
> _fn
> -
> #endif /* __ASSEMBLY__ */
>
> #ifdef CONFIG_HOTPLUG
>
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xen.org
> http://lists.xen.org/xen-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-10-25 12:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-25 11:51 [PATCH] compiler.h adjustments Jan Beulich
2012-10-25 12:17 ` Keir Fraser
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).