Patchwork [v6,02/14] provide support for default implementations using weak symbols

login
register
mail settings
Submitter =?utf-8?Q?Llu=C3=ADs?=
Date Aug. 25, 2011, 3:51 p.m.
Message ID <20110825155143.19177.99563.stgit@ginnungagap.bsc.es>
Download mbox | patch
Permalink /patch/111604/
State New
Headers show

Comments

=?utf-8?Q?Llu=C3=ADs?= - Aug. 25, 2011, 3:51 p.m.
Routines using the QEMU_WEAK attribute can have a default implementation that
can be later overriden just by re-implementing it.

Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
---
 compiler.h |   13 ++++++++++++-
 1 files changed, 12 insertions(+), 1 deletions(-)
Blue Swirl - Aug. 25, 2011, 5:40 p.m.
On Thu, Aug 25, 2011 at 3:51 PM, Lluís <xscript@gmx.net> wrote:
> Routines using the QEMU_WEAK attribute can have a default implementation that
> can be later overriden just by re-implementing it.

Nack: weak attributes are only available for ELF and a.out.

> Signed-off-by: Lluís Vilanova <vilanova@ac.upc.edu>
> ---
>  compiler.h |   13 ++++++++++++-
>  1 files changed, 12 insertions(+), 1 deletions(-)
>
> diff --git a/compiler.h b/compiler.h
> index 9af5dc6..bc06760 100644
> --- a/compiler.h
> +++ b/compiler.h
> @@ -12,7 +12,7 @@
>  #define QEMU_WARN_UNUSED_RESULT
>  #endif
>
> -#define QEMU_BUILD_BUG_ON(x) \
> +#define QEMU_BUILD_BUG_ON(x)                                    \
>     typedef char qemu_build_bug_on__##__LINE__[(x)?-1:1];
>
>  #if defined __GNUC__
> @@ -31,4 +31,15 @@
>  #define GCC_FMT_ATTR(n, m)
>  #endif
>
> +/* Routine attribute to provide default (overridable) implementations.
> + *
> + * The code providing the default implementation must define QEMU_WEAK_DEFAULT
> + * before including this file.
> + */
> +#if !defined(QEMU_WEAK_DEFAULT)
> +#define QEMU_WEAK
> +#else
> +#define QEMU_WEAK __attribute__((weak))
> +#endif
> +
>  #endif /* COMPILER_H */
>
>
>
=?utf-8?Q?Llu=C3=ADs?= - Aug. 25, 2011, 6:27 p.m.
Blue Swirl writes:

> On Thu, Aug 25, 2011 at 3:51 PM, Lluís <xscript@gmx.net> wrote:
>> Routines using the QEMU_WEAK attribute can have a default implementation that
>> can be later overriden just by re-implementing it.

> Nack: weak attributes are only available for ELF and a.out.

Right, sorry. It was too good to be true.

I'll fall back to implementing these on each backend.


Lluis

Patch

diff --git a/compiler.h b/compiler.h
index 9af5dc6..bc06760 100644
--- a/compiler.h
+++ b/compiler.h
@@ -12,7 +12,7 @@ 
 #define QEMU_WARN_UNUSED_RESULT
 #endif
 
-#define QEMU_BUILD_BUG_ON(x) \
+#define QEMU_BUILD_BUG_ON(x)                                    \
     typedef char qemu_build_bug_on__##__LINE__[(x)?-1:1];
 
 #if defined __GNUC__
@@ -31,4 +31,15 @@ 
 #define GCC_FMT_ATTR(n, m)
 #endif
 
+/* Routine attribute to provide default (overridable) implementations.
+ *
+ * The code providing the default implementation must define QEMU_WEAK_DEFAULT
+ * before including this file.
+ */
+#if !defined(QEMU_WEAK_DEFAULT)
+#define QEMU_WEAK
+#else
+#define QEMU_WEAK __attribute__((weak))
+#endif
+
 #endif /* COMPILER_H */