Skip to contentSkip to conversation

disable lock annotation with clang 3.4.2

PATCH Applied David Marchand 5 participants 5 messages Feb 13, 2023 – Feb 14, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 disable lock annotation with clang 3.4.2

Venerable RHEL7 clang 3.4.2 has (at least) two issues with lock annotations.

A first one with regards to the attribute position:
../lib/vhost/vhost.h:518:2: error: GCC does not allow

	assert_exclusive_lock attribute in this position on a
	function definition [-Werror,-Wgcc-compat]
        __rte_assert_exclusive_lock(&vq->access_lock)
        ^
../lib/eal/include/rte_lock_annotations.h:29:38: note: expanded
	from macro '__rte_assert_exclusive_lock'
        __attribute__((assert_exclusive_lock(__VA_ARGS__)))
                                            ^

This can be worked around by splitting and having the allocation on the function declaration.

But on the other hand, clang 3.4.2 does not seem to propagate those annotations in presence of a __builtin_expect (i.e. unlikely()), like for example when calling if (unlikely(rte_spinlock_trylock() == 0)).

Those annotations were only working with clang in any case, so restrict to clang versions newer than 3.5.0.

Fixes 657a98f38940 ("eal: annotate spinlock, rwlock and seqlock")
---
 drivers/meson.build | 2 +-
 lib/meson.build     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/meson.build +1 -1
index bddc4a6cc4..0618c31a69 100644
@@ -168,7 +168,7 @@ foreach subpath:subdirs
         enabled_drivers += name
         lib_name = '_'.join(['rte', class, name])
         cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=' + '.'.join([log_prefix, name])
-        if annotate_locks and cc.has_argument('-Wthread-safety')
+        if annotate_locks and cc.get_id() == 'clang' and cc.version().version_compare('>=3.5.0')
             cflags += '-DRTE_ANNOTATE_LOCKS'
             cflags += '-Wthread-safety'
         endif
lib/meson.build +1 -1
index 450c061d2b..2bc0932ad5 100644
@@ -203,7 +203,7 @@ foreach l:libraries
         cflags += '-DRTE_USE_FUNCTION_VERSIONING'
     endif
     cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=lib.' + l
-    if annotate_locks and cc.has_argument('-Wthread-safety')
+    if annotate_locks and cc.get_id() == 'clang' and cc.version().version_compare('>=3.5.0')
         cflags += '-DRTE_ANNOTATE_LOCKS'
         cflags += '-Wthread-safety'
     endif
Signature · 1 line
2.39.1
#1 lore raw
Quoted 37 lines · David Marchand

Venerable RHEL7 clang 3.4.2 has (at least) two issues with lock annotations.

A first one with regards to the attribute position:
../lib/vhost/vhost.h:518:2: error: GCC does not allow

	assert_exclusive_lock attribute in this position on a
	function definition [-Werror,-Wgcc-compat]
        __rte_assert_exclusive_lock(&vq->access_lock)
        ^
../lib/eal/include/rte_lock_annotations.h:29:38: note: expanded
	from macro '__rte_assert_exclusive_lock'
        __attribute__((assert_exclusive_lock(__VA_ARGS__)))
                                            ^

This can be worked around by splitting and having the allocation on the function declaration.

But on the other hand, clang 3.4.2 does not seem to propagate those annotations in presence of a __builtin_expect (i.e. unlikely()), like for example when calling if (unlikely(rte_spinlock_trylock() == 0)).

Those annotations were only working with clang in any case, so restrict to clang versions newer than 3.5.0.

Fixes 657a98f38940 ("eal: annotate spinlock, rwlock and seqlock")
---
 drivers/meson.build | 2 +-
 lib/meson.build     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/meson.build +0 -0
index bddc4a6cc4..0618c31a69 100644

drivers/meson.build foreach subpath:subdirs · line 174

Quoted 8 lines
drivers/meson.build +1 -1
@@ -168,7 +168,7 @@ foreach subpath:subdirs
         enabled_drivers += name
         lib_name = '_'.join(['rte', class, name])
         cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=' + '.'.join([log_prefix, name])
-        if annotate_locks and cc.has_argument('-Wthread-safety')
+        if annotate_locks and cc.get_id() == 'clang' and cc.version().version_compare('>=3.5.0')
             cflags += '-DRTE_ANNOTATE_LOCKS'
             cflags += '-Wthread-safety'
         endif

Are we likely to see any issues with this with any other compilers? Should we look to do a built-test in meson to determine feature support rather than checking clang versions explicitly?

On the plus side, checking clang version like this makes it clear when we can drop the conditional.

/Bruce

#2 lore raw
Quoted 54 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 13 February 2023 15.55

Quoted 14 lines · David Marchand

Venerable RHEL7 clang 3.4.2 has (at least) two issues with lock annotations.

A first one with regards to the attribute position:
../lib/vhost/vhost.h:518:2: error: GCC does not allow

	assert_exclusive_lock attribute in this position on a
	function definition [-Werror,-Wgcc-compat]
        __rte_assert_exclusive_lock(&vq->access_lock)
        ^
../lib/eal/include/rte_lock_annotations.h:29:38: note: expanded
	from macro '__rte_assert_exclusive_lock'
        __attribute__((assert_exclusive_lock(__VA_ARGS__)))
                                            ^
Quoted 1 line

This can be worked around by splitting and having the allocation on

the

Quoted 7 lines

function declaration.

But on the other hand, clang 3.4.2 does not seem to propagate those annotations in presence of a __builtin_expect (i.e. unlikely()), like for example when calling if (unlikely(rte_spinlock_trylock() == 0)).

Those annotations were only working with clang in any case, so

restrict

Quoted 15 lines

to clang versions newer than 3.5.0.

Fixes 657a98f38940 ("eal: annotate spinlock, rwlock and seqlock")
---
 drivers/meson.build | 2 +-
 lib/meson.build     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/meson.build +0 -0
index bddc4a6cc4..0618c31a69 100644

drivers/meson.build foreach subpath:subdirs · line 170

Quoted 3 lines
drivers/meson.build +0 -0
@@ -168,7 +168,7 @@ foreach subpath:subdirs
         enabled_drivers += name
         lib_name = '_'.join(['rte', class, name])
         cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=' +

'.'.join([log_prefix, name])

drivers/meson.build foreach subpath:subdirs · line 171

Quoted 2 lines
drivers/meson.build +1 -1
-        if annotate_locks and cc.has_argument('-Wthread-safety')
+        if annotate_locks and cc.get_id() == 'clang' and

cc.version().version_compare('>=3.5.0')

drivers/meson.build foreach subpath:subdirs · line 174

Quoted 3 lines
drivers/meson.build +0 -0
             cflags += '-DRTE_ANNOTATE_LOCKS'
             cflags += '-Wthread-safety'
         endif
Quoted 8 lines

Are we likely to see any issues with this with any other compilers? Should
we look to do a built-test in meson to determine feature support rather than checking clang versions explicitly?

On the plus side, checking clang version like this makes it clear when we
can drop the conditional.

I prefer this over auto-detection in meson, for the reason mentioned by Bruce.

Furthermore, different compilers may use different syntax in the code, so it is impossible to detect generically; the auto-detection would be per compiler anyway.

#3 lore raw
Quoted 75 lines

-----Original Message-----
From: Morten Brørup <[email protected]>
Sent: Monday, February 13, 2023 6:09 PM
To: Bruce Richardson <[email protected]>; David Marchand <[email protected]>
Cc: [email protected]; NBU-Contact-Thomas Monjalon (EXTERNAL) <[email protected]>; Raslan Darawsheh <[email protected]>; Chenbo Xia <[email protected]>; Maxime Coquelin <[email protected]>
Subject: RE: [PATCH] disable lock annotation with clang 3.4.2

Quoted 54 lines

From: Bruce Richardson [mailto:[email protected]]
Sent: Monday, 13 February 2023 15.55

Quoted 14 lines · David Marchand

Venerable RHEL7 clang 3.4.2 has (at least) two issues with lock annotations.

A first one with regards to the attribute position:
../lib/vhost/vhost.h:518:2: error: GCC does not allow

	assert_exclusive_lock attribute in this position on a
	function definition [-Werror,-Wgcc-compat]
        __rte_assert_exclusive_lock(&vq->access_lock)
        ^
../lib/eal/include/rte_lock_annotations.h:29:38: note: expanded
	from macro '__rte_assert_exclusive_lock'
        __attribute__((assert_exclusive_lock(__VA_ARGS__)))
                                            ^
Quoted 1 line

This can be worked around by splitting and having the allocation on

the

Quoted 7 lines

function declaration.

But on the other hand, clang 3.4.2 does not seem to propagate those annotations in presence of a __builtin_expect (i.e. unlikely()), like for example when calling if (unlikely(rte_spinlock_trylock() == 0)).

Those annotations were only working with clang in any case, so

restrict

Quoted 15 lines

to clang versions newer than 3.5.0.

Fixes 657a98f38940 ("eal: annotate spinlock, rwlock and seqlock")
---
 drivers/meson.build | 2 +-
 lib/meson.build     | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/meson.build +0 -0
index bddc4a6cc4..0618c31a69 100644

drivers/meson.build foreach subpath:subdirs · line 170

Quoted 3 lines
drivers/meson.build +0 -0
@@ -168,7 +168,7 @@ foreach subpath:subdirs
         enabled_drivers += name
         lib_name = '_'.join(['rte', class, name])
         cflags += '-DRTE_LOG_DEFAULT_LOGTYPE=' +

'.'.join([log_prefix, name])

drivers/meson.build foreach subpath:subdirs · line 171

Quoted 2 lines
drivers/meson.build +1 -1
-        if annotate_locks and cc.has_argument('-Wthread-safety')
+        if annotate_locks and cc.get_id() == 'clang' and

cc.version().version_compare('>=3.5.0')

drivers/meson.build foreach subpath:subdirs · line 174

Quoted 3 lines
drivers/meson.build +0 -0
             cflags += '-DRTE_ANNOTATE_LOCKS'
             cflags += '-Wthread-safety'
         endif
Quoted 8 lines

Are we likely to see any issues with this with any other compilers? Should
we look to do a built-test in meson to determine feature support rather than checking clang versions explicitly?

On the plus side, checking clang version like this makes it clear when we
can drop the conditional.

Quoted 8 lines

I prefer this over auto-detection in meson, for the reason mentioned by Bruce.

Furthermore, different compilers may use different syntax in the code, so it is impossible to detect generically; the auto-detection would be per compiler anyway.

Kindest regards,
Raslan Darawsheh

#4 lore raw

13/02/2023 17:36, Raslan Darawsheh:

Quoted 32 lines

From: Morten Brørup <[email protected]>

Quoted 31 lines

From: Bruce Richardson [mailto:[email protected]]

Quoted 30 lines · David Marchand
Quoted 14 lines

Venerable RHEL7 clang 3.4.2 has (at least) two issues with lock annotations.

A first one with regards to the attribute position:
../lib/vhost/vhost.h:518:2: error: GCC does not allow

	assert_exclusive_lock attribute in this position on a
	function definition [-Werror,-Wgcc-compat]
        __rte_assert_exclusive_lock(&vq->access_lock)
        ^
../lib/eal/include/rte_lock_annotations.h:29:38: note: expanded
	from macro '__rte_assert_exclusive_lock'
        __attribute__((assert_exclusive_lock(__VA_ARGS__)))
                                            ^
Quoted 1 line

This can be worked around by splitting and having the allocation on

the

Quoted 7 lines

function declaration.

But on the other hand, clang 3.4.2 does not seem to propagate those annotations in presence of a __builtin_expect (i.e. unlikely()), like for example when calling if (unlikely(rte_spinlock_trylock() == 0)).

Those annotations were only working with clang in any case, so

restrict

Quoted 5 lines

to clang versions newer than 3.5.0.

Fixes 657a98f38940 ("eal: annotate spinlock, rwlock and seqlock")

[...]

Quoted 12 lines
Quoted 12 lines
Quoted 8 lines

Are we likely to see any issues with this with any other compilers? Should
we look to do a built-test in meson to determine feature support rather than checking clang versions explicitly?

On the plus side, checking clang version like this makes it clear when we
can drop the conditional.

I prefer this over auto-detection in meson, for the reason mentioned by Bruce.

Quoted 6 lines
Quoted 5 lines

Furthermore, different compilers may use different syntax in the code, so it is impossible to detect generically; the auto-detection would be per compiler anyway.

Applied, thanks.