Fix compilation with kernel headers < 3.4
Subsystems (2)
PATCH 1/1 Fix compilation with kernel headers < 3.4
Since commit 596b1c94aa38e21b7a8c8562e8b61ccb744255d2, iproute2 uses types __kernel_long_t and __kernel_ulong_t but does not provide internal definitions for it.
This means that compilation using kernel headers that are older than 3.4 (where these types were added) will fail. This situation may be uncommon for native compilation, but not uncommon for cross compilation where the toolchains may be a bit older.
Provide the necessary types internally if not provided by the kernel headers to fix compilation in such cases.
--- include/linux/sysinfo.h | 14 ++++++++++++++ misc/ss.c | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/linux/sysinfo.h
include/linux/sysinfo.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _SYSINFO_COMPAT_H +#define _SYSINFO_COMPAT_H + +/* In case the kernel header asm/posix_types.h is too old (< 3.4) to provide +* __kernel_long_t, provide it here +*/ +#ifndef __kernel_long_t +typedef long __kernel_long_t ; +typedef unsigned long __kernel_ulong_t ; +#endif + +#include_next <linux/sysinfo.h> + +#endif /* _SYSINFO_COMPAT_H */
misc/ss.c +10 -0
@@ -46,6 +46,16 @@#include <linux/sctp.h> #include <linux/vm_sockets_diag.h> +#ifndef AF_VSOCK +#define AF_VSOCK 40 +#if defined(AF_MAX ) &&AF_MAX <41 +#undef AF_MAX +#endif +#ifndef AF_MAX +#define AF_MAX 41 +#endif /* AF_MAX */ +#endif /* AF_VSOCK */ +#define MAGIC_SEQ 123456#define BUF_CHUNK (1024 * 1024)#define LEN_ALIGN (x) (((x) + 1) & ~1)
Signature · 1 line
1.7.10.4
Quoted 12 lines · Serhey Popovych
Since commit
596b1c94aa38e21b7a8c8562e8b61ccb744255d2, iproute2 uses types__kernel_long_tand__kernel_ulong_tbut does not provide internal definitions for it.This means that compilation using kernel headers that are older than 3.4 (where these types were added) will fail. This situation may be uncommon for native compilation, but not uncommon for cross compilation where the toolchains may be a bit older.
Provide the necessary types internally if not provided by the kernel headers to fix compilation in such cases.
Quoted 8 lines
Co-Developed-by Serhii Popovych <[email protected]>Signed-off-by Thomas De Schampheleire <[email protected]>Signed-off-by Serhey Popovych <[email protected]>--- include/linux/sysinfo.h | 14 ++++++++++++++ misc/ss.c | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/linux/sysinfo.h
Oops, forgot to mention in subject: this is RFC one.
Quoted 43 lines
include/linux/sysinfo.h new file +14
-0@@ -0,0 +1,14 @@ +#ifndef _SYSINFO_COMPAT_H +#define _SYSINFO_COMPAT_H + +/* In case the kernel header asm/posix_types.h is too old (< 3.4) to provide +* __kernel_long_t, provide it here +*/ +#ifndef __kernel_long_t +typedef long __kernel_long_t ; +typedef unsigned long __kernel_ulong_t ; +#endif + +#include_next <linux/sysinfo.h> + +#endif /* _SYSINFO_COMPAT_H */ misc/ss.c +10
-0@@ -46,6 +46,16 @@#include <linux/sctp.h> #include <linux/vm_sockets_diag.h> +#ifndef AF_VSOCK +#define AF_VSOCK 40 +#if defined(AF_MAX ) &&AF_MAX <41 +#undef AF_MAX +#endif +#ifndef AF_MAX +#define AF_MAX 41 +#endif /* AF_MAX */ +#endif /* AF_VSOCK */ +#define MAGIC_SEQ 123456#define BUF_CHUNK (1024 * 1024)#define LEN_ALIGN (x) (((x) + 1) & ~1)
Quoted 52 lines · Serhey Popovych
Since commit
596b1c94aa38e21b7a8c8562e8b61ccb744255d2, iproute2 uses types__kernel_long_tand__kernel_ulong_tbut does not provide internal definitions for it.This means that compilation using kernel headers that are older than 3.4 (where these types were added) will fail. This situation may be uncommon for native compilation, but not uncommon for cross compilation where the toolchains may be a bit older.
Provide the necessary types internally if not provided by the kernel headers to fix compilation in such cases.
Co-Developed-by Serhii Popovych <[email protected]>Signed-off-by Thomas De Schampheleire <[email protected]>Signed-off-by Serhey Popovych <[email protected]>--- include/linux/sysinfo.h | 14 ++++++++++++++ misc/ss.c | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/linux/sysinfo.hinclude/linux/sysinfo.h new file +14
-0@@ -0,0 +1,14 @@ +#ifndef _SYSINFO_COMPAT_H +#define _SYSINFO_COMPAT_H + +/* In case the kernel header asm/posix_types.h is too old (< 3.4) to provide +* __kernel_long_t, provide it here +*/ +#ifndef __kernel_long_t +typedef long __kernel_long_t ; +typedef unsigned long __kernel_ulong_t ; +#endif + +#include_next <linux/sysinfo.h> + +#endif /* _SYSINFO_COMPAT_H */ misc/ss.c +3
-0@@ -46,6 +46,16 @@#include <linux/sctp.h> #include <linux/vm_sockets_diag.h> +#ifndef AF_VSOCK +#define AF_VSOCK 40 +#if defined(AF_MAX ) &&AF_MAX <41
misc/ss.c line 61
Quoted 10 lines
misc/ss.c +7
-0+#undef AF_MAX +#endif +#ifndef AF_MAX +#define AF_MAX 41 +#endif /* AF_MAX */ +#endif /* AF_VSOCK */ +#define MAGIC_SEQ 123456#define BUF_CHUNK (1024 * 1024)#define LEN_ALIGN (x) (((x) + 1) & ~1)
Thanks, this patch works fine in my use case too.
I can't judge the changes in ss.c. I did not see such problems, but my toolchain is based on 3.3 kernel headers.
Best regards,
Thomas
Quoted 66 lines · Thomas De Schampheleire
Quoted 52 lines · Serhey Popovych
Since commit
596b1c94aa38e21b7a8c8562e8b61ccb744255d2, iproute2 uses types__kernel_long_tand__kernel_ulong_tbut does not provide internal definitions for it.This means that compilation using kernel headers that are older than 3.4 (where these types were added) will fail. This situation may be uncommon for native compilation, but not uncommon for cross compilation where the toolchains may be a bit older.
Provide the necessary types internally if not provided by the kernel headers to fix compilation in such cases.
Co-Developed-by Serhii Popovych <[email protected]>Signed-off-by Thomas De Schampheleire <[email protected]>Signed-off-by Serhey Popovych <[email protected]>--- include/linux/sysinfo.h | 14 ++++++++++++++ misc/ss.c | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/linux/sysinfo.hinclude/linux/sysinfo.h new file +14
-0@@ -0,0 +1,14 @@ +#ifndef _SYSINFO_COMPAT_H +#define _SYSINFO_COMPAT_H + +/* In case the kernel header asm/posix_types.h is too old (< 3.4) to provide +* __kernel_long_t, provide it here +*/ +#ifndef __kernel_long_t +typedef long __kernel_long_t ; +typedef unsigned long __kernel_ulong_t ; +#endif + +#include_next <linux/sysinfo.h> + +#endif /* _SYSINFO_COMPAT_H */ misc/ss.c +3
-0@@ -46,6 +46,16 @@#include <linux/sctp.h> #include <linux/vm_sockets_diag.h> +#ifndef AF_VSOCK +#define AF_VSOCK 40 +#if defined(AF_MAX ) &&AF_MAX <41 misc/ss.c line 61
Quoted 10 lines
misc/ss.c +7
-0+#undef AF_MAX +#endif +#ifndef AF_MAX +#define AF_MAX 41 +#endif /* AF_MAX */ +#endif /* AF_VSOCK */ +#define MAGIC_SEQ 123456#define BUF_CHUNK (1024 * 1024)#define LEN_ALIGN (x) (((x) + 1) & ~1)Thanks, this patch works fine in my use case too.
Quoted 2 lines
I can't judge the changes in
ss.c. I did not see such problems, but my toolchain is based on 3.3 kernel headers.
Well, I tested this with 3.2 kernels (oldest supported) in Debian 7 (Wheezy) environment:
ss.c:294:15: error: 'AF_VSOCK' undeclared here (not in a function) ss.c:323:2: error: array index in initializer not of integer type ss.c:323:2: error: (near initialization for 'default_afs') make[1]: *** [ss.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2
Look at your 3.3 headers, probably they provide some redefine for AF_VSOCK. In stock linux-stable/linux-3.3.y I see no AF_VSOCK, so probably I will get same error as above (however not checked yet).
Quoted 4 lines
Best regards,
Thomas
Quoted 31 lines · Serhey Popovych
Since commit
596b1c94aa38e21b7a8c8562e8b61ccb744255d2, iproute2 uses types__kernel_long_tand__kernel_ulong_tbut does not provide internal definitions for it.This means that compilation using kernel headers that are older than 3.4 (where these types were added) will fail. This situation may be uncommon for native compilation, but not uncommon for cross compilation where the toolchains may be a bit older.
Provide the necessary types internally if not provided by the kernel headers to fix compilation in such cases.
Co-Developed-by Serhii Popovych <[email protected]>Signed-off-by Thomas De Schampheleire <[email protected]>Signed-off-by Serhey Popovych <[email protected]>--- include/linux/sysinfo.h | 14 ++++++++++++++ misc/ss.c | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/linux/sysinfo.hinclude/linux/sysinfo.h new file +4
-0@@ -0,0 +1,14 @@ +#ifndef _SYSINFO_COMPAT_H +#define _SYSINFO_COMPAT_H + +/* In case the kernel header asm/posix_types.h is too old (< 3.4) to provide
include/linux/sysinfo.h line 14
Quoted 10 lines
include/linux/sysinfo.h new file +10
-0+* __kernel_long_t, provide it here +*/ +#ifndef __kernel_long_t +typedef long __kernel_long_t ; +typedef unsigned long __kernel_ulong_t ; +#endif + +#include_next <linux/sysinfo.h> + +#endif /* _SYSINFO_COMPAT_H */
Actually, I now wonder: instead of applying this trick with #include_next on sysinfo.h, why not do it on linux/types.h ? That would be more correct and more robust for the future, no?
/Thomas
Quoted 38 lines · Thomas De Schampheleire
Quoted 37 lines · Serhey Popovych
Since commit
596b1c94aa38e21b7a8c8562e8b61ccb744255d2, iproute2 uses types__kernel_long_tand__kernel_ulong_tbut does not provide internal definitions for it.This means that compilation using kernel headers that are older than 3.4 (where these types were added) will fail. This situation may be uncommon for native compilation, but not uncommon for cross compilation where the toolchains may be a bit older.
Provide the necessary types internally if not provided by the kernel headers to fix compilation in such cases.
Co-Developed-by Serhii Popovych <[email protected]>Signed-off-by Thomas De Schampheleire <[email protected]>Signed-off-by Serhey Popovych <[email protected]>--- include/linux/sysinfo.h | 14 ++++++++++++++ misc/ss.c | 10 ++++++++++ 2 files changed, 24 insertions(+) create mode 100644 include/linux/sysinfo.hinclude/linux/sysinfo.h new file +10
-0@@ -0,0 +1,14 @@ +#ifndef _SYSINFO_COMPAT_H +#define _SYSINFO_COMPAT_H + +/* In case the kernel header asm/posix_types.h is too old (< 3.4) to provide +* __kernel_long_t, provide it here +*/ +#ifndef __kernel_long_t +typedef long __kernel_long_t ; +typedef unsigned long __kernel_ulong_t ; +#endif
Quoted 8 lines
include/linux/sysinfo.h line 14
Quoted 4 lines
include/linux/sysinfo.h new file +4
-0+ +#include_next <linux/sysinfo.h> + +#endif /* _SYSINFO_COMPAT_H */ Actually, I now wonder: instead of applying this trick with #include_next on
sysinfo.h, why not do it onlinux/types.h? That would be more correct and more robust for the future, no?
No. Headers in include/uapi updated automatically from newer kernel versions. If we do any hacks in iproute2 uapi directory updating headers automatically would be problematic.
As for me using #include_next presents better approach.
Better to provide means for compatibility and that I propose to do with series "ip: Provide compatibility bits to build with old glibc/kernel headers".
Quoted 3 lines
/Thomas