__linux__ and cross-compile
Subsystems (5)
PATCH 1/1 __linux__ and cross-compile
Hi there,
The following patch fixes compilation/miscompilation problems, which may happend iwtg variuos cross compile configuration, wherte the compiler used to compile the kernel does not necessarily define __linux__. The patch replaces __linux__ with __KERNEL__, using __KERNEL_ as an indication that the source is compiled as a part of linux. Sources, which can be compiled in userspace as well, are changed to use #if defined(__linux__) || defined(__KERNEL__).
Regards,
-velco
===== arch/alpha/kernel/entry.S 1.1 vs edited =====
arch/alpha/kernel/entry.S +0 -3
@@ -121,9 +121,6 @@ .text .set noat -#if defined(__linux__) && !defined(__ELF__) - .set singlegp -#endif .align 3 .globl entInt
===== drivers/char/drm/drm.h 1.2 vs edited =====
drivers/char/drm/drm.h +1 -1
@@ -35,7 +35,7 @@#ifndef _DRM_H_#define _DRM_H_ -#if defined(__linux__) +#if defined(__linux__) || defined(__KERNEL__)#include <linux/config.h> #include <asm/ioctl.h> /* For _IO* macros */ #define DRM_IOCTL_NR (n) _IOC_NR(n)
===== drivers/char/drm-4.0/drm.h 1.1 vs edited =====
drivers/char/drm-4.0/drm.h +1 -1
@@ -36,7 +36,7 @@#define _DRM_H_#include <linux/config.h> -#if defined(__linux__) +#if defined(__linux__) || defined(__KERNEL__)#include <asm/ioctl.h> /* For _IO* macros */ #define DRM_IOCTL_NR (n) _IOC_NR(n)#elif defined(__FreeBSD__)
===== drivers/scsi/aic7xxx/aic7xxx.c 1.1 vs edited =====
drivers/scsi/aic7xxx/aic7xxx.c +5 -5
@@ -3653,7 +3653,7 @@case 2 :ahc_dma_tag_destroy (ahc, ahc->shared_data_dmat);case 1 : -#ifndef __linux__ +#ifndef __KERNEL__ahc_dma_tag_destroy (ahc, ahc->buffer_dmat);#endif break ;
@@ -3661,7 +3661,7 @@break ; } -#ifndef __linux__ +#ifndef __KERNEL__ahc_dma_tag_destroy (ahc, ahc->parent_dmat);#endif ahc_platform_free (ahc);
@@ -4121,7 +4121,7 @@ newcount =MIN (newcount, (AHC_SCB_MAX_ALLOC - scb_data->numscbs));for (i =0 ; i < newcount; i++) {struct scb_platform_data *pdata; -#ifndef __linux__ +#ifndef __KERNEL__int error;#endif pdata = (struct scb_platform_data *)malloc(sizeof(*pdata),
@@ -4138,7 +4138,7 @@ next_scb->sg_list_phys = physaddr +sizeof (struct ahc_dma_seg ); next_scb->ahc_softc = ahc; next_scb->flags =SCB_FREE ; -#ifndef __linux__ +#ifndef __KERNEL__ error =ahc_dmamap_create (ahc, ahc->buffer_dmat,/*flags*/ 0 , &next_scb->dmamap);if (error !=0 )
@@ -4254,7 +4254,7 @@if ((AHC_TMODE_ENABLE & (0x1 << ahc->unit)) ==0 ) ahc->features &= ~AHC_TARGETMODE ; -#ifndef __linux__ +#ifndef __KERNEL__/* DMA tag for mapping buffers into device visible space. */ if (ahc_dma_tag_create(ahc, ahc->parent_dmat, /*alignment*/1, /*boundary*/BUS_SPACE_MAXADDR_32BIT + 1,
===== drivers/scsi/aic7xxx/aic7xxx.h 1.1 vs edited =====
drivers/scsi/aic7xxx/aic7xxx.h +2 -2
@@ -547,7 +547,7 @@ahc_io_ctx_t io_ctx;struct ahc_softc *ahc_softc;scb_flag flags; -#ifndef __linux__ +#ifndef __KERNEL__bus_dmamap_t dmamap;#endif struct scb_platform_data *platform_data;
@@ -870,7 +870,7 @@struct ahc_softc {bus_space_tag_t tag;bus_space_handle_t bsh; -#ifndef __linux__ +#ifndef __KERNEL__bus_dma_tag_t buffer_dmat;/* dmat for buffer I/O */ #endif struct scb_data *scb_data;
===== drivers/scsi/dpt/osd_defs.h 1.1 vs edited =====
drivers/scsi/dpt/osd_defs.h +1 -1
@@ -52,7 +52,7 @@/*Definitions - Defines & Constants ----------------------------------------- */ /* Define the operating system */ -#if (defined(__linux__)) +#if defined(__linux__) || defined(__KERNEL__)# define _DPT_LINUX#elif (defined(__bsdi__))# define _DPT_BSDI
===== include/asm-mips/sgidefs.h 1.1 vs edited =====
include/asm-mips/sgidefs.h +0 -8
@@ -11,14 +11,6 @@#define __ASM_SGIDEFS_H/* -* Using a Linux compiler for building Linux seems logic but not to -* everybody. -*/ -#ifndef __linux__ -#error Use a Linux compiler or give up. -#endif - -/* * Definitions for the ISA levels * * With the introduction of MIPS32 / MIPS64 instruction sets definitions
===== include/asm-mips64/sgidefs.h 1.1 vs edited =====
include/asm-mips64/sgidefs.h +0 -8
@@ -11,14 +11,6 @@#define __ASM_SGIDEFS_H/* -* Using a Linux compiler for building Linux seems logic but not to -* everybody. -*/ -#ifndef __linux__ -#error Use a Linux compiler or give up. -#endif - -/* * Definitions for the ISA levels * * With the introduction of MIPS32 / MIPS64 instruction sets definitions
===== include/linux/coda.h 1.1 vs edited =====
include/linux/coda.h +2 -2
@@ -98,7 +98,7 @@#endif /* !DJGPP */ -#if defined(__linux__) +#if defined(__linux__) || defined(__KERNEL__)#define cdev_t u_quad_t#ifndef __KERNEL__#if !defined(_UQUAD_T_) && (!defined(__GLIBC__) || __GLIBC__ <2 )
@@ -211,8 +211,8 @@#endif /* VICEFID */ -#ifdef __linux__ +#if defined(__linux__) || defined(__KERNEL__)static __inline__ino_t coda_f2i (struct ViceFid *fid) {if ( ! fid )
Quoted 6 lines · Momchil Velikov
Hi there,
The following patch fixes compilation/miscompilation problems, which may happend iwtg variuos cross compile configuration, wherte the compiler used to compile the kernel does not necessarily define
__linux__. The patch replaces__linux__with__KERNEL__, using
Isn't this a compiler bug?
Quoted 2 lines
__KERNEL_as an indication that the source is compiled as a part of
...
This is definitely wrong in files that are not Linux-specific and that are used on FreeBSD (and BSDI) as well (you would know that if you'd looked at the files your patch changes)...
cu
Adrian
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Adrian" == Adrian Bunk <[email protected]> writes:
Quoted 6 lines · Momchil Velikov
Quoted 6 lines
Hi there,
The following patch fixes compilation/miscompilation problems, which may happend iwtg variuos cross compile configuration, wherte the compiler used to compile the kernel does not necessarily define
__linux__. The patch replaces__linux__with__KERNEL__, using
Adrian> Isn't this a compiler bug?
Why would it be ? I may want to cross-compile from, e.g., NetBSD with the host compiler, or I may want compile from GNU/Linux, but with a compiler like arm-elf-gcc, that is, generic arm cross compiler, used for other kernels too.
Quoted 2 lines
Quoted 2 lines
__KERNEL_as an indication that the source is compiled as a part of
...
Adrian> This is definitely wrong in files that are not Linux-specific and that are Adrian> used on FreeBSD (and BSDI) as well (you would know that if you'd looked at Adrian> the files your patch changes)...
*BSD define _KERNEL, don't they ?
Regards,
-velco
Quoted 10 lines · Momchil Velikov
Quoted 4 lines
Quoted 4 lines
The following patch fixes compilation/miscompilation problems, which may happend iwtg variuos cross compile configuration, wherte the compiler used to compile the kernel does not necessarily define
__linux__. The patch replaces__linux__with__KERNEL__, usingAdrian> Isn't this a compiler bug?
Why would it be ? I may want to cross-compile from, e.g., NetBSD with the host compiler, or I may want compile from GNU/Linux, but with a
...
If your compiler is configured as a cross-compiler everything should work as expected. If you are trying to compile a Linux kernel with a gcc that is configured to build binaries for NetBSD this sounds evil.
Quoted 8 lines
Quoted 2 lines
Quoted 2 lines
__KERNEL_as an indication that the source is compiled as a part of
...Adrian> This is definitely wrong in files that are not Linux-specific and that are Adrian> used on FreeBSD (and BSDI) as well (you would know that if you'd looked at Adrian> the files your patch changes)...
*BSD define
_KERNEL, don't they ?
I don't know (I never tried to compile a *BSD kernel).
But if yes please consider what the following parts of your patch change:
-#ifndef __linux__
+#ifndef __KERNEL__
Quoted 2 lines
Regards,
-velco
cu
Adrian
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Adrian" == Adrian Bunk <[email protected]> writes:
Adrian> If your compiler is configured as a cross-compiler everything should work Adrian> as expected. If you are trying to compile a Linux kernel with a gcc that Adrian> is configured to build binaries for NetBSD this sounds evil.
Could you elaborate why ? I think people do it all the time, compiling linux (which is not a _linux_ binary, but a i386, alpha, etc. binary) with a compiler configured to compile linux binaries.
Quoted 3 lines
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines
__KERNEL_as an indication that the source is compiled as a part of
...
Adrian> This is definitely wrong in files that are not Linux-specific and that are Adrian> used on FreeBSD (and BSDI) as well (you would know that if you'd looked at Adrian> the files your patch changes)...
Quoted 2 lines
Quoted 2 lines
*BSD define
_KERNEL, don't they ?
Adrian> I don't know (I never tried to compile a *BSD kernel). Adrian> But if yes please consider what the following parts of your patch change:
Adrian> -#ifndef __linux__
Adrian> +#ifndef __KERNEL__
I have. Have you ?
Regards,
-velco
Quoted 3 lines · [email protected] said:
If your compiler is configured as a cross-compiler everything should
work as expected. If you are trying to compile a Linux kernel with a gcc that is configured to build binaries for NetBSD this sounds evil.
What if he's trying to build UML to run on NetBSD? What if the best QA'd cross-gcc he has available is a generic arm-elf-gcc and he doesn't want to rebuild and do a full test and release cycle on it just because a handful of the kernel header files assume __linux__ will be defined?
Quoted 1 line
I don't know (I never tried to compile a *BSD kernel).
If you don't know, who was it that typed 'This is definitely wrong' in your first mail? Your cat?
Review
Quoted 3 lines
But if yes please consider what the following parts of your patch change:
(quoted diff) +1
-1-#ifndef __linux__ +#ifndef __KERNEL__
Well, if he hadn't explicitly mentioned that he made header files which could be included by userspace use defined(__KERNEL__)||defined(__linux__) then I'd understand what you meant. As it is, I don't. Please explain.
--
dwmw2
Quoted 8 lines · David Woodhouse
...
Review
Quoted 3 lines
But if yes please consider what the following parts of your patch change:
(quoted diff) +1
-1-#ifndef __linux__ +#ifndef __KERNEL__Well, if he hadn't explicitly mentioned that he made header files which could be included by userspace use defined(__KERNEL__)||defined(__linux__) then I'd understand what you meant. As it is, I don't. Please explain.
This is part of his patch to drivers/scsi/aic7xxx/aic7xxx.c
It's clear that code that is part of an "#ifndef __linux__" will never be included on any other OS than Linux. Is this also garuanteed for "#ifndef __KERNEL__"?
Quoted 1 line
dwmw2
cu
Adrian
Quoted 2 lines · [email protected] said:
It's clear that code that is part of an "#ifndef
__linux__" will
never be included on any other OS than Linux.
True. But unfortunately that's not a useful guarantee. This code doesn't (normally) run _on_ Linux. It is _in_ Linux, and it's still possible that the offending code won't get included when it should.
Quoted 1 line
Is this also garuanteed for "#ifndef
__KERNEL__"?
We think *BSD uses _KERNEL, and don't know of anything else which defines __KERNEL__ other than Linux. So he's switching from something that's known broken to something which we _believe_ will be reliable.
--
dwmw2