* [dpdk-dev] [PATCH] eal/x86: fix clang build with -O0
@ 2016-06-03 8:15 Thomas Monjalon
2016-06-03 8:16 ` Olivier MATZ
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Monjalon @ 2016-06-03 8:15 UTC (permalink / raw)
To: dev; +Cc: Damjan Marion
From: Damjan Marion <damarion@cisco.com>
Clang seems to have a bug with asm inside inline function rte_xabort():
rte_rtm.h:56:15: error: invalid operand for inline asm constraint 'i'
asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory");
^
It is seen only when building with EXTRA_CFLAGS=-O0.
The workaround is to replace the inline function by a macro.
Fixes: ba7468997ea6 ("spinlock: add HTM lock elision for x86")
Signed-off-by: Damjan Marion <damarion@cisco.com>
Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
---
lib/librte_eal/common/include/arch/x86/rte_rtm.h | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/lib/librte_eal/common/include/arch/x86/rte_rtm.h b/lib/librte_eal/common/include/arch/x86/rte_rtm.h
index d935641..0649f79 100644
--- a/lib/librte_eal/common/include/arch/x86/rte_rtm.h
+++ b/lib/librte_eal/common/include/arch/x86/rte_rtm.h
@@ -50,11 +50,10 @@ void rte_xend(void)
asm volatile(".byte 0x0f,0x01,0xd5" ::: "memory");
}
-static __attribute__((__always_inline__)) inline
-void rte_xabort(const unsigned int status)
-{
- asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory");
-}
+/* not an inline function to workaround a clang bug with -O0 */
+#define rte_xabort(status) do { \
+ asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory"); \
+} while (0)
static __attribute__((__always_inline__)) inline
int rte_xtest(void)
--
2.7.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/x86: fix clang build with -O0
2016-06-03 8:15 [dpdk-dev] [PATCH] eal/x86: fix clang build with -O0 Thomas Monjalon
@ 2016-06-03 8:16 ` Olivier MATZ
2016-06-03 8:46 ` Thomas Monjalon
0 siblings, 1 reply; 3+ messages in thread
From: Olivier MATZ @ 2016-06-03 8:16 UTC (permalink / raw)
To: Thomas Monjalon, dev; +Cc: Damjan Marion
Hi Thomas,
On 06/03/2016 10:15 AM, Thomas Monjalon wrote:
> From: Damjan Marion <damarion@cisco.com>
>
> Clang seems to have a bug with asm inside inline function rte_xabort():
>
> rte_rtm.h:56:15: error: invalid operand for inline asm constraint 'i'
> asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory");
> ^
>
> It is seen only when building with EXTRA_CFLAGS=-O0.
>
> The workaround is to replace the inline function by a macro.
>
> Fixes: ba7468997ea6 ("spinlock: add HTM lock elision for x86")
>
> Signed-off-by: Damjan Marion <damarion@cisco.com>
> Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
> ---
> lib/librte_eal/common/include/arch/x86/rte_rtm.h | 9 ++++-----
> 1 file changed, 4 insertions(+), 5 deletions(-)
>
> diff --git a/lib/librte_eal/common/include/arch/x86/rte_rtm.h b/lib/librte_eal/common/include/arch/x86/rte_rtm.h
> index d935641..0649f79 100644
> --- a/lib/librte_eal/common/include/arch/x86/rte_rtm.h
> +++ b/lib/librte_eal/common/include/arch/x86/rte_rtm.h
> @@ -50,11 +50,10 @@ void rte_xend(void)
> asm volatile(".byte 0x0f,0x01,0xd5" ::: "memory");
> }
>
> -static __attribute__((__always_inline__)) inline
> -void rte_xabort(const unsigned int status)
> -{
> - asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory");
> -}
> +/* not an inline function to workaround a clang bug with -O0 */
> +#define rte_xabort(status) do { \
> + asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory"); \
> +} while (0)
>
> static __attribute__((__always_inline__)) inline
> int rte_xtest(void)
>
Generally speaking, it's not a good idea to replace a static inline by a
macro because it relaxes type checking. Looks ok in that case to
workaround the clang issue.
Acked-by: Olivier Matz <olivier.matz@6wind.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [dpdk-dev] [PATCH] eal/x86: fix clang build with -O0
2016-06-03 8:16 ` Olivier MATZ
@ 2016-06-03 8:46 ` Thomas Monjalon
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Monjalon @ 2016-06-03 8:46 UTC (permalink / raw)
To: dev; +Cc: Olivier MATZ, Damjan Marion
2016-06-03 10:16, Olivier MATZ:
> On 06/03/2016 10:15 AM, Thomas Monjalon wrote:
> > From: Damjan Marion <damarion@cisco.com>
> >
> > Clang seems to have a bug with asm inside inline function rte_xabort():
> >
> > rte_rtm.h:56:15: error: invalid operand for inline asm constraint 'i'
> > asm volatile(".byte 0xc6,0xf8,%P0" :: "i" (status) : "memory");
> > ^
> >
> > It is seen only when building with EXTRA_CFLAGS=-O0.
> >
> > The workaround is to replace the inline function by a macro.
> >
> > Fixes: ba7468997ea6 ("spinlock: add HTM lock elision for x86")
> >
> > Signed-off-by: Damjan Marion <damarion@cisco.com>
> > Signed-off-by: Thomas Monjalon <thomas.monjalon@6wind.com>
>
> Generally speaking, it's not a good idea to replace a static inline by a
> macro because it relaxes type checking. Looks ok in that case to
> workaround the clang issue.
>
> Acked-by: Olivier Matz <olivier.matz@6wind.com>
Thanks,
This patch has been appplied very quickly for the purpose of a live demo
at a VPP event: https://wiki.fd.io/view/Events
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-06-03 8:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03 8:15 [dpdk-dev] [PATCH] eal/x86: fix clang build with -O0 Thomas Monjalon
2016-06-03 8:16 ` Olivier MATZ
2016-06-03 8:46 ` Thomas Monjalon
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).