Skip to contentSkip to conversation

locking/qspinlock: Fix build for anonymous union in older gcc compilers

PATCH In review Steven Rostedt 4 participants 4 messages Jun 22, 2018 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 locking/qspinlock: Fix build for anonymous union in older gcc compilers

From: Steven Rostedt (VMware) <[email protected]>

One of my tests compiles the kernel with gcc 4.5.3, and I hit the following build error:

/work/git/linux-trace.git/include/linux/semaphore.h: In function 'sema_init':
/work/git/linux-trace.git/include/linux/semaphore.h:35:17: error: unknown field 'val' specified in initializer /work/git/linux-trace.git/include/linux/semaphore.h:35:17: warning: missing braces around initializer /work/git/linux-trace.git/include/linux/semaphore.h:35:17: warning: (near initialization for '(anonymous).raw_lock.<anonymous>.val') In file included from /work/git/linux-trace.git/include/linux/sched/user.h:7:0,

                 from /work/git/linux-trace.git/include/linux/cred.h:22,
                 from /work/git/linux-trace.git/include/linux/seq_file.h:12,
                 from /work/git/linux-trace.git/include/linux/cgroup.h:18,
                 from /work/git/linux-trace.git/include/linux/memcontrol.h:22,
                 from /work/git/linux-trace.git/include/linux/swap.h:9,
                 from /work/git/linux-trace.git/include/linux/suspend.h:5,
                 from /work/git/linux-trace.git/arch/x86/kernel/asm-offsets.c:13:

I bisected it down to the introduction of the commit that makes qspinlock have an anonymous union, which makes initializing it special for older compilers. By adding strategic brackets, it makes the build happy again.

Fixes 625e88be1f41 ("locking/qspinlock: Merge 'struct __qspinlock' into 'struct qspinlock'")

---

include/asm-generic/qspinlock_types.h +1 -1
index 0763f065b975..d10f1e7d6ba8 100644
@@ -63,7 +63,7 @@ typedef struct qspinlock {
 /*
  * Initializier
  */
-#define	__ARCH_SPIN_LOCK_UNLOCKED	{ .val = ATOMIC_INIT(0) }
+#define	__ARCH_SPIN_LOCK_UNLOCKED	{ { .val = ATOMIC_INIT(0) } }
 
 /*
  * Bitfields in the atomic value:
Acked-by on v1 1/1
#1 lore raw
Quoted 32 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

One of my tests compiles the kernel with gcc 4.5.3, and I hit the following build error:

/work/git/linux-trace.git/include/linux/semaphore.h: In function 'sema_init':
/work/git/linux-trace.git/include/linux/semaphore.h:35:17: error: unknown field 'val' specified in initializer /work/git/linux-trace.git/include/linux/semaphore.h:35:17: warning: missing braces around initializer /work/git/linux-trace.git/include/linux/semaphore.h:35:17: warning: (near initialization for '(anonymous).raw_lock.<anonymous>.val') In file included from /work/git/linux-trace.git/include/linux/sched/user.h:7:0,

                 from /work/git/linux-trace.git/include/linux/cred.h:22,
                 from /work/git/linux-trace.git/include/linux/seq_file.h:12,
                 from /work/git/linux-trace.git/include/linux/cgroup.h:18,
                 from /work/git/linux-trace.git/include/linux/memcontrol.h:22,
                 from /work/git/linux-trace.git/include/linux/swap.h:9,
                 from /work/git/linux-trace.git/include/linux/suspend.h:5,
                 from /work/git/linux-trace.git/arch/x86/kernel/asm-offsets.c:13:

I bisected it down to the introduction of the commit that makes qspinlock have an anonymous union, which makes initializing it special for older compilers. By adding strategic brackets, it makes the build happy again.

Fixes 625e88be1f41 ("locking/qspinlock: Merge 'struct __qspinlock' into 'struct qspinlock'")

---

include/asm-generic/qspinlock_types.h +0 -0
index 0763f065b975..d10f1e7d6ba8 100644

include/asm-generic/qspinlock_types.h typedef struct qspinlock { · line 69

Quoted 8 lines
include/asm-generic/qspinlock_types.h +1 -1
@@ -63,7 +63,7 @@ typedef struct qspinlock {
 /*
  * Initializier
  */
-#define	__ARCH_SPIN_LOCK_UNLOCKED	{ .val = ATOMIC_INIT(0) }
+#define	__ARCH_SPIN_LOCK_UNLOCKED	{ { .val = ATOMIC_INIT(0) } }
 
 /*
  * Bitfields in the atomic value:
#2 lore raw

[tip:locking/urgent] locking/qspinlock: Fix build for anonymous union in older GCC compilers

In reply to Steven Rostedt
locking/qspinlock: Fix build for anonymous union in older GCC compilers
Commit-ID:  6cc65be4f6f2a7186af8f3e09900787c7912dad2
Gitweb:     https://git.kernel.org/tip/6cc65be4f6f2a7186af8f3e09900787c7912dad2
Author:     Steven Rostedt (VMware) <[email protected]>
AuthorDate: Thu, 21 Jun 2018 20:35:26 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 22 Jun 2018 04:19:16 +0200

locking/qspinlock: Fix build for anonymous union in older GCC compilers

One of my tests compiles the kernel with gcc 4.5.3, and I hit the following build error:

include/linux/semaphore.h: In function 'sema_init':
include/linux/semaphore.h:35:17: error: unknown field 'val' specified in initializer include/linux/semaphore.h:35:17: warning: missing braces around initializer include/linux/semaphore.h:35:17: warning: (near initialization for '(anonymous).raw_lock.<anonymous>.val')

I bisected it down to:

625e88be1f41 ("locking/qspinlock: Merge 'struct __qspinlock' into 'struct qspinlock'")

... which makes qspinlock have an anonymous union, which makes initializing it special for older compilers. By adding strategic brackets, it makes the build happy again.

Cc Andrew Morton <[email protected]>
Cc Boqun Feng <[email protected]>
Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra (Intel) <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Will Deacon <[email protected]>
Fixes 625e88be1f41 ("locking/qspinlock: Merge 'struct __qspinlock' into 'struct qspinlock'")
---
 include/asm-generic/qspinlock_types.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/asm-generic/qspinlock_types.h +1 -1
index 0763f065b975..d10f1e7d6ba8 100644
@@ -63,7 +63,7 @@ typedef struct qspinlock {
 /*
  * Initializier
  */
-#define	__ARCH_SPIN_LOCK_UNLOCKED	{ .val = ATOMIC_INIT(0) }
+#define	__ARCH_SPIN_LOCK_UNLOCKED	{ { .val = ATOMIC_INIT(0) } }
 
 /*
  * Bitfields in the atomic value:
Acked-by on v1 1/1
#3 lore raw
In reply to Steven Rostedt

Hi Steve,

Quoted 19 lines · Steven Rostedt

From: Steven Rostedt (VMware) <[email protected]>

One of my tests compiles the kernel with gcc 4.5.3, and I hit the following build error:

/work/git/linux-trace.git/include/linux/semaphore.h: In function 'sema_init':
/work/git/linux-trace.git/include/linux/semaphore.h:35:17: error: unknown field 'val' specified in initializer /work/git/linux-trace.git/include/linux/semaphore.h:35:17: warning: missing braces around initializer /work/git/linux-trace.git/include/linux/semaphore.h:35:17: warning: (near initialization for '(anonymous).raw_lock.<anonymous>.val') In file included from /work/git/linux-trace.git/include/linux/sched/user.h:7:0,

                 from /work/git/linux-trace.git/include/linux/cred.h:22,
                 from /work/git/linux-trace.git/include/linux/seq_file.h:12,
                 from /work/git/linux-trace.git/include/linux/cgroup.h:18,
                 from /work/git/linux-trace.git/include/linux/memcontrol.h:22,
                 from /work/git/linux-trace.git/include/linux/swap.h:9,
                 from /work/git/linux-trace.git/include/linux/suspend.h:5,
                 from /work/git/linux-trace.git/arch/x86/kernel/asm-offsets.c:13:
Quoted 8 lines

I bisected it down to the introduction of the commit that makes qspinlock have an anonymous union, which makes initializing it special for older compilers. By adding strategic brackets, it makes the build happy again.

Fixes 625e88be1f41 ("locking/qspinlock: Merge 'struct __qspinlock' into 'struct qspinlock'")

---

Cheers for spotting this and fixing it up! I know it's already in -tip, but anyway:

Will