Use __unused0 instead of __unused for user visible struct member names
Subsystems (10)
PATCH 1/1 Use __unused0 instead of __unused for user visible struct member names
On BSD systems __unused has traditionally been defined to mean the equivalent of gcc's __attribute__((__unused__)), some parts of the Linux tree use that convention too (e.g. perf). The problem comes when defining such macro while trying to build unmodified source code with BSD origins on systems with Linux headers.
Rename the user visible struct members from __unused to __unused0 to not cause compilation failures due to that macro, which should not be a problem as those members are supposed to be private anyway.
--- arch/alpha/include/asm/stat.h | 2 +- arch/arm/include/asm/ucontext.h | 2 +- arch/ia64/include/asm/stat.h | 2 +- arch/mips/include/asm/compat.h | 2 +- arch/powerpc/include/asm/ucontext.h | 2 +- arch/s390/include/asm/stat.h | 2 +- arch/sparc/include/asm/compat.h | 4 ++-- arch/sparc/include/asm/elf_32.h | 2 +- arch/sparc/include/asm/elf_64.h | 2 +- arch/sparc/include/asm/fcntl.h | 4 ++-- arch/sparc/include/asm/stat.h | 2 +- arch/tile/include/asm/compat.h | 2 +- arch/x86/include/asm/stat.h | 2 +- include/linux/icmp.h | 2 +- include/linux/sysctl.h | 2 +- 15 files changed, 17 insertions(+), 17 deletions(-)
arch/alpha/include/asm/stat.h +1 -1
@@ -42,7 +42,7 @@ struct stat64 {unsigned long st_mtime_nsec;unsigned long st_ctime;unsigned long st_ctime_nsec; - long __unused[3]; + long __unused0[3]; };#endif
arch/arm/include/asm/ucontext.h +1 -1
@@ -20,7 +20,7 @@ struct ucontext {struct sigcontext uc_mcontext;sigset_t uc_sigmask;/* Allow for uc_sigmask growth. Glibc uses a 1024-bit sigset_t. */ -int __unused[32 - (sizeof (sigset_t) /sizeof (int ))]; +int __unused0[32 - (sizeof (sigset_t) /sizeof (int ))];/* Last for extensibility. Eight byte aligned because some coprocessors require eight byte alignment. */ unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
arch/ia64/include/asm/stat.h +1 -1
@@ -24,7 +24,7 @@ struct stat {unsigned long st_ctime_nsec;unsigned long st_blksize;long st_blocks; -unsigned long __unused[3 ]; +unsigned long __unused0[3 ]; };#define STAT_HAVE_NSEC 1
arch/mips/include/asm/compat.h +1 -1
@@ -84,7 +84,7 @@ struct compat_flock {compat_off_t l_len;s32 l_sysid;compat_pid_t l_pid; -short __unused; +short __unused0;s32 pad[4 ]; };
arch/powerpc/include/asm/ucontext.h +1 -1
@@ -28,7 +28,7 @@ struct ucontext {sigset_t uc_sigmask;/* glibc has 1024-bit signal masks, ours are 64-bit */ #ifdef __powerpc64__ -sigset_t __unused[15 ];/* Allow for uc_sigmask growth */ +sigset_t __unused0[15 ];/* Allow for uc_sigmask growth */ struct sigcontext uc_mcontext;/* last for extensibility */ #else int uc_maskext[30 ];
arch/s390/include/asm/stat.h +1 -1
@@ -95,7 +95,7 @@ struct stat {unsigned long st_ctime_nsec;unsigned long st_blksize;long st_blocks; - unsigned long __unused[3]; + unsigned long __unused0[3]; };#endif /* __s390x__ */
arch/sparc/include/asm/compat.h +2 -2
@@ -107,7 +107,7 @@ struct compat_flock {compat_off_t l_start;compat_off_t l_len;compat_pid_t l_pid; -short __unused; +short __unused0; };#define F_GETLK64 12
@@ -120,7 +120,7 @@ struct compat_flock64 {compat_loff_t l_start;compat_loff_t l_len;compat_pid_t l_pid; -short __unused; +short __unused0; };struct compat_statfs {
arch/sparc/include/asm/elf_32.h +1 -1
@@ -82,7 +82,7 @@ typedef struct {unsigned long pr_regs[32 ];double pr_dregs[16 ]; } pr_fr; -unsigned long __unused; +unsigned long __unused0;unsigned long pr_fsr;unsigned char pr_qcnt;unsigned char pr_q_entrysize;
arch/sparc/include/asm/elf_64.h +1 -1
@@ -133,7 +133,7 @@ typedef struct {unsigned int pr_regs[32 ];unsigned long pr_dregs[16 ]; } pr_fr; -unsigned int __unused; +unsigned int __unused0;unsigned int pr_fsr;unsigned char pr_qcnt;unsigned char pr_q_entrysize;
arch/sparc/include/asm/fcntl.h +2 -2
@@ -47,8 +47,8 @@#define F_WRLCK 2#define F_UNLCK 3 -#define __ARCH_FLOCK_PAD short __unused; -#define __ARCH_FLOCK64_PAD short __unused; +#define __ARCH_FLOCK_PAD short __unused0; +#define __ARCH_FLOCK64_PAD short __unused0;#include <asm-generic/fcntl.h>
arch/sparc/include/asm/stat.h +1 -1
@@ -43,7 +43,7 @@ struct stat64 {unsigned long st_mtime_nsec;unsigned long st_ctime;unsigned long st_ctime_nsec; - long __unused[3]; + long __unused0[3]; };#else
arch/tile/include/asm/compat.h +1 -1
@@ -80,7 +80,7 @@ struct compat_sysctl {unsigned int oldlenp;unsigned int newval;unsigned int newlen; -unsigned int __unused[4 ]; +unsigned int __unused0[4 ]; };
arch/x86/include/asm/stat.h +1 -1
@@ -85,7 +85,7 @@ struct stat {unsigned long st_mtime_nsec;unsigned long st_ctime;unsigned long st_ctime_nsec; - long __unused[3]; + long __unused0[3]; };#endif
include/linux/icmp.h +1 -1
@@ -76,7 +76,7 @@ struct icmphdr { } echo;__be32 gateway;struct { -__be16 __unused; +__be16 __unused0;__be16 mtu; } frag; } un;
include/linux/sysctl.h +1 -1
@@ -40,7 +40,7 @@ struct __sysctl_args {size_t __user *oldlenp;void __user *newval;size_t newlen; -unsigned long __unused[4 ]; +unsigned long __unused0[4 ]; };/* Define sysctl names first */
Signature · 1 line
1.7.7.3
(+cc: some possible relevant people)
Hi,
Quoted 9 lines · Guillem Jover
On BSD systems
__unusedhas traditionally been defined to mean the equivalent of gcc's __attribute__((__unused__)), some parts of the Linux tree use that convention too (e.g. perf). The problem comes when defining such macro while trying to build unmodified source code with BSD origins on systems with Linux headers.Rename the user visible struct members from
__unusedto__unused0to not cause compilation failures due to that macro, which should not be a problem as those members are supposed to be private anyway.
Thanks, sounds like a good idea.
It would be nice to document one detail: why do these struct members have a double-underscore before "unused" in the first place? I understand that libc has (and hence installed kernel headers have) a limited namespace to work with and they have to be on guard against applications doing something crazy like
#define unused 0
but aren't there other identifiers in that namespace that work just as well?
That's not actually an objection --- I'm just curious. __unused1 like is already used in e.g. asm-generic/stat.h seems fine to me.
Some examples:
Quoted 2 lines
Signed-off-by Guillem Jover <[email protected]>---
[...]
arch/alpha/include/asm/stat.h struct stat64 { · line 46
Quoted 11 lines
arch/alpha/include/asm/stat.h +1
-1@@ -42,7 +42,7 @@ struct stat64 {unsigned long st_mtime_nsec;unsigned long st_ctime;unsigned long st_ctime_nsec; -long __unused[3 ]; +long __unused0[3 ]; };
This could be
long st_unused[3];
or
long st_padding[3];
Quoted 6 lines
arch/alpha/include/asm/stat.h +0
-0#endif arch/arm/include/asm/ucontext.h +0
-0
arch/arm/include/asm/ucontext.h struct ucontext { · line 26
Quoted 8 lines
arch/arm/include/asm/ucontext.h +1
-1@@ -20,7 +20,7 @@ struct ucontext {struct sigcontext uc_mcontext;sigset_t uc_sigmask;/* Allow for uc_sigmask growth. Glibc uses a 1024-bit sigset_t. */ -int __unused[32 - (sizeof (sigset_t) /sizeof (int ))]; +int __unused0[32 - (sizeof (sigset_t) /sizeof (int ))];/* Last for extensibility. Eight byte aligned because some coprocessors require eight byte alignment. */ unsigned long uc_regspace[128] __attribute__((__aligned__(8)));
Likewise, this could be something like
int uc_sigmask_padding[32 - ...];
Remainder left unsnipped for convenience of people cc-ed. If the general idea looks sensible, what would be the best way to usher it into mainline? Should it be split up into patches for the various arch-specific trees, or should acks from relevant people be collected some other way?
Thanks,
Jonathan
Quoted 184 lines
arch/ia64/include/asm/stat.h +1
-1@@ -24,7 +24,7 @@ struct stat {unsigned long st_ctime_nsec;unsigned long st_blksize;long st_blocks; -unsigned long __unused[3 ]; +unsigned long __unused0[3 ]; };#define STAT_HAVE_NSEC 1arch/mips/include/asm/compat.h +1
-1@@ -84,7 +84,7 @@ struct compat_flock {compat_off_t l_len;s32 l_sysid;compat_pid_t l_pid; -short __unused; +short __unused0;s32 pad[4 ]; };arch/powerpc/include/asm/ucontext.h +1
-1@@ -28,7 +28,7 @@ struct ucontext {sigset_t uc_sigmask;/* glibc has 1024-bit signal masks, ours are 64-bit */ #ifdef __powerpc64__ -sigset_t __unused[15 ];/* Allow for uc_sigmask growth */ +sigset_t __unused0[15 ];/* Allow for uc_sigmask growth */ struct sigcontext uc_mcontext;/* last for extensibility */ #else int uc_maskext[30 ];arch/s390/include/asm/stat.h +1
-1@@ -95,7 +95,7 @@ struct stat {unsigned long st_ctime_nsec;unsigned long st_blksize;long st_blocks; - unsigned long __unused[3]; + unsigned long __unused0[3]; };#endif /* __s390x__ */ arch/sparc/include/asm/compat.h +2
-2@@ -107,7 +107,7 @@ struct compat_flock {compat_off_t l_start;compat_off_t l_len;compat_pid_t l_pid; -short __unused; +short __unused0; };#define F_GETLK64 12@@ -120,7 +120,7 @@ struct compat_flock64 {compat_loff_t l_start;compat_loff_t l_len;compat_pid_t l_pid; -short __unused; +short __unused0; };struct compat_statfs {arch/sparc/include/asm/elf_32.h +1
-1@@ -82,7 +82,7 @@ typedef struct {unsigned long pr_regs[32 ];double pr_dregs[16 ]; } pr_fr; -unsigned long __unused; +unsigned long __unused0;unsigned long pr_fsr;unsigned char pr_qcnt;unsigned char pr_q_entrysize;arch/sparc/include/asm/elf_64.h +1
-1@@ -133,7 +133,7 @@ typedef struct {unsigned int pr_regs[32 ];unsigned long pr_dregs[16 ]; } pr_fr; -unsigned int __unused; +unsigned int __unused0;unsigned int pr_fsr;unsigned char pr_qcnt;unsigned char pr_q_entrysize;arch/sparc/include/asm/fcntl.h +2
-2@@ -47,8 +47,8 @@#define F_WRLCK 2#define F_UNLCK 3 -#define __ARCH_FLOCK_PAD short __unused; -#define __ARCH_FLOCK64_PAD short __unused; +#define __ARCH_FLOCK_PAD short __unused0; +#define __ARCH_FLOCK64_PAD short __unused0;#include <asm-generic/fcntl.h> arch/sparc/include/asm/stat.h +1
-1@@ -43,7 +43,7 @@ struct stat64 {unsigned long st_mtime_nsec;unsigned long st_ctime;unsigned long st_ctime_nsec; - long __unused[3]; + long __unused0[3]; };#else arch/tile/include/asm/compat.h +1
-1@@ -80,7 +80,7 @@ struct compat_sysctl {unsigned int oldlenp;unsigned int newval;unsigned int newlen; -unsigned int __unused[4 ]; +unsigned int __unused0[4 ]; };arch/x86/include/asm/stat.h +1
-1@@ -85,7 +85,7 @@ struct stat {unsigned long st_mtime_nsec;unsigned long st_ctime;unsigned long st_ctime_nsec; - long __unused[3]; + long __unused0[3]; };#endif include/linux/icmp.h +1
-1@@ -76,7 +76,7 @@ struct icmphdr { } echo;__be32 gateway;struct { -__be16 __unused; +__be16 __unused0;__be16 mtu; } frag; } un;include/linux/sysctl.h +1
-1@@ -40,7 +40,7 @@ struct __sysctl_args {size_t __user *oldlenp;void __user *newval;size_t newlen; -unsigned long __unused[4 ]; +unsigned long __unused0[4 ]; };/* Define sysctl names first */ Signature · 1 line
1.7.7.3
Quoted 14 lines · Jonathan Nieder
(+cc: some possible relevant people)
Hi,Quoted 9 lines · Guillem Jover
On BSD systems
__unusedhas traditionally been defined to mean the equivalent of gcc's __attribute__((__unused__)), some parts of the Linux tree use that convention too (e.g. perf). The problem comes when defining such macro while trying to build unmodified source code with BSD origins on systems with Linux headers.Rename the user visible struct members from
__unusedto__unused0to not cause compilation failures due to that macro, which should not be a problem as those members are supposed to be private anyway.
^__ is reserved for libc internal stuff and there is no reason to name the unused/padding members "__unused".
So one or a set of patches that rename them all to something more sensible would be fine.
Sam
Quoted 8 lines · Sam Ravnborg
Quoted 7 lines · Jonathan Nieder
Quoted 6 lines · Guillem Jover
On BSD systems
__unusedhas traditionally been defined to mean the equivalent of gcc's __attribute__((__unused__)), some parts of the Linux tree use that convention too (e.g. perf). The problem comes when defining such macro while trying to build unmodified source code with BSD origins on systems with Linux headers.
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Rename the user visible struct members from
__unusedto__unused0to not cause compilation failures due to that macro, which should not be a problem as those members are supposed to be private anyway.^__ is reserved for libc internal stuff and there is no reason to name the unused/padding members "
__unused".
So one or a set of patches that rename them all to something more sensible would be fine.
On a quick glance, I've found other functionally similar struct member names present on the tree:
__unused __unusedN __reserved __reservedN __reserved_N __resN __pad __padN __flr_pad __ifi_pad __tcpm_padN __tcpct_padN
Do you mean you'd like to see patch(es) to rename all those? I'd not mind providing them, although my immediate concern right now is just regarding __unused.
There's also __buf in linux/sem.h and __data in linux/socket.h, but I'd rather not thouch those, as I'd expect to be users for them?
thanks,
guillem
Quoted 21 lines · Guillem Jover
Quoted 8 lines · Sam Ravnborg
Quoted 7 lines · Jonathan Nieder
Quoted 6 lines · Guillem Jover
On BSD systems
__unusedhas traditionally been defined to mean the equivalent of gcc's __attribute__((__unused__)), some parts of the Linux tree use that convention too (e.g. perf). The problem comes when defining such macro while trying to build unmodified source code with BSD origins on systems with Linux headers.Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Rename the user visible struct members from
__unusedto__unused0to not cause compilation failures due to that macro, which should not be a problem as those members are supposed to be private anyway.^__ is reserved for libc internal stuff and there is no reason to name the unused/padding members "
__unused".
So one or a set of patches that rename them all to something more sensible would be fine.On a quick glance, I've found other functionally similar struct member names present on the tree:
Quoted 6 lines
__unused__unusedN__reserved__reservedN__reserved_N__resN__pad__padN__flr_pad__ifi_pad__tcpm_padN__tcpct_padNDo you mean you'd like to see patch(es) to rename all those? I'd not mind providing them, although my immediate concern right now is just regarding
__unused.
__.* and _[A-Z].* are reserved for the implementation. Unfortunately, both the kernel userspace headers and the libc are part of the implementation, so there needs to be some common sense applied to avoid clashes. IMO renaming __unused to __unused0 on the basis that some headers define __unused to __attribute__((__unused__)) makes sense, but blindly renaming any occurence of double underscore helps little.
Just my $0.02.
Michal
Quoted 29 lines · Michal Marek
Quoted 21 lines · Guillem Jover
Quoted 8 lines · Sam Ravnborg
Quoted 7 lines · Jonathan Nieder
Quoted 6 lines · Guillem Jover
On BSD systems
__unusedhas traditionally been defined to mean the equivalent of gcc's __attribute__((__unused__)), some parts of the Linux tree use that convention too (e.g. perf). The problem comes when defining such macro while trying to build unmodified source code with BSD origins on systems with Linux headers.Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Rename the user visible struct members from
__unusedto__unused0to not cause compilation failures due to that macro, which should not be a problem as those members are supposed to be private anyway.^__ is reserved for libc internal stuff and there is no reason to name the unused/padding members "
__unused".
So one or a set of patches that rename them all to something more sensible would be fine.On a quick glance, I've found other functionally similar struct member names present on the tree:
Quoted 6 lines
__unused__unusedN__reserved__reservedN__reserved_N__resN__pad__padN__flr_pad__ifi_pad__tcpm_padN__tcpct_padNDo you mean you'd like to see patch(es) to rename all those? I'd not mind providing them, although my immediate concern right now is just regarding
__unused.
Quoted 6 lines
__.* and _[A-Z].* are reserved for the implementation. Unfortunately, both the kernel userspace headers and the libc are part of the implementation, so there needs to be some common sense applied to avoid clashes. IMO renaming
__unusedto__unused0on the basis that some headers define__unusedto __attribute__((__unused__)) makes sense, but blindly renaming any occurence of double underscore helps little.
Agree on Michael on this.
Sam
Sam Ravnborg dixit:
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines · Guillem Jover
On BSD systems
__unusedhas traditionally been defined to mean the equivalent of gcc's __attribute__((__unused__)), some parts of the
[…]
Quoted 2 lines
^__ is reserved for libc internal stuff and there is no reason to name the unused/padding members "
__unused".
Considering that glibc has seen the light¹ now too, can we please do something about these now? The BSD tools (not just NetBSD®) have been using this for far longer after all…
Currently (git pull --ff torvalds master), we have:
• 2 occurrences of files *inside* the Linux kernel defining __unused to² __attribute__((unused)) themselves
• 68 struct members and function arguments called __unused
Quoted 2 lines
So one or a set of patches that rename them all to something more sensible would be fine.
I think __unused0 is okay as it matches current __unused[0-9] in use by other parts of the Linux kernel – although glibc now uses __glibc_reserved[0-9], I think this doesn’t look like the Linux kernel should use it ☻☺
① http://thread.gmane.org/gmane.comp.lib.glibc.alpha/36439
② I’ve recently come to the belief that this should be
__attribute__((__unused__)) in all cases, i.e. all those attribute namings need double underscores before and after, as some software likes to #define printf to something else, lighttpd does #define bounded something else, so there’s probably software out there containing #define unused foo.
Sam Ravnborg dixit:
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines · Guillem Jover
On BSD systems
__unusedhas traditionally been defined to mean the equivalent of gcc's __attribute__((__unused__)), some parts of the
[…]
Quoted 2 lines
^__ is reserved for libc internal stuff and there is no reason to name the unused/padding members "
__unused".
Considering that glibc has seen the light¹ now too, can we please do something about these now? The BSD tools (not just NetBSD®) have been using this for far longer after all…
Currently (git pull --ff torvalds master), we have:
• 2 occurrences of files *inside* the Linux kernel defining __unused to² __attribute__((unused)) themselves
• 68 struct members and function arguments called __unused
Quoted 2 lines
So one or a set of patches that rename them all to something more sensible would be fine.
I think __unused0 is okay as it matches current __unused[0-9] in use by other parts of the Linux kernel – although glibc now uses __glibc_reserved[0-9], I think this doesn’t look like the Linux kernel should use it ☻☺
① http://thread.gmane.org/gmane.comp.lib.glibc.alpha/36439
② I’ve recently come to the belief that this should be
__attribute__((__unused__)) in all cases, i.e. all those attribute namings need double underscores before and after, as some software likes to #define printf to something else, lighttpd does #define bounded something else, so there’s probably software out there containing #define unused foo.