Errors in Linux sources?
<p>I am trying to write a kernel module for an external system. To do this, I used the .config file for that kernel and rebuilt the sources on my development computer. Then I wrote a makefile which uses the following lines:</p>

<pre><code>CC=arm-xilinx-linux-gnueabi-gcc
make -C /home/osboxes/Documents/linux-xcomm_zynq/ M=$(PWD) modules
</code></pre>

<p>in order to build the module for the target. My kernel source is nothing except an include to module.h and kernel.h, and an init_module and cleanup_module with a printk in each. I successfully built it for my development computer, so I know there is not an error in that.</p>

<p>When I tried building for my target, I got several errors. Could there be a mistake being made when generating the Linux sources? I have not made any modifications to the Linux source directory after running make.</p>

<p>Here is the output from my attempt at building the kernel:</p>

<pre><code>CC=arm-xilinx-linux-gnueabi-gcc
make -C /home/osboxes/Documents/linux-xcomm_zynq/ M=/home/osboxes/Documents/kernel_modules/DRFM modules
make[1]: Entering directory '/home/osboxes/Documents/linux-xcomm_zynq'
  CC [M]  /home/osboxes/Documents/kernel_modules/DRFM/testmod.o
In file included from ./arch/x86/include/asm/bitops.h:16:0,
                 from include/linux/bitops.h:36,
                 from include/linux/kernel.h:10,
                 from include/linux/list.h:8,
                 from include/linux/module.h:9,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/arch_hweight.h: In function ‘__arch_hweight64’:
./arch/x86/include/asm/arch_hweight.h:56:42: error: expected ‘:’ or ‘)’ before ‘POPCNT64’
  asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
                                          ^
./arch/x86/include/asm/alternative.h:131:28: note: in definition of macro ‘ALTINSTR_REPLACEMENT’
  b_replacement(num)":\n\t" newinstr "\n" e_replacement(num) ":\n\t"
                            ^
./arch/x86/include/asm/arch_hweight.h:56:7: note: in expansion of macro ‘ALTERNATIVE’
  asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
       ^
In file included from ./arch/x86/include/asm/pgtable_types.h:250:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:52,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
include/asm-generic/pgtable-nopud.h: At top level:
include/asm-generic/pgtable-nopud.h:15:0: warning: "PUD_SHIFT" redefined
 #define PUD_SHIFT PGDIR_SHIFT
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:205:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:52,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/pgtable_64_types.h:33:0: note: this is the location of the previous definition
 #define PUD_SHIFT 30
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:250:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:52,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
include/asm-generic/pgtable-nopud.h:16:0: warning: "PTRS_PER_PUD" redefined
 #define PTRS_PER_PUD 1
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:205:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:52,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
         from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/processor.h:172:0: warning: "cache_line_size" redefined
 #define cache_line_size() (boot_cpu_data.x86_cache_alignment)
 ^
In file included from include/linux/printk.h:8:0,
                 from include/linux/kernel.h:13,
                 from include/linux/list.h:8,
                 from include/linux/module.h:9,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
include/linux/cache.h:64:0: note: this is the location of the previous definition
 #define cache_line_size() L1_CACHE_BYTES
 ^
In file included from ./arch/x86/include/asm/segment.h:155:0,
                 from ./arch/x86/include/asm/ptrace.h:4,
                 from ./arch/x86/include/asm/alternative.h:8,
                 from ./arch/x86/include/asm/bitops.h:16,
                 from include/linux/bitops.h:36,
                 from include/linux/kernel.h:10,
                 from include/linux/list.h:8,
                 from include/linux/module.h:9,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/cache.h:7:25: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
                         ^
./arch/x86/include/asm/cache.h:8:30: note: in expansion of macro ‘L1_CACHE_SHIFT’
 #define L1_CACHE_BYTES (1 &lt;&lt; L1_CACHE_SHIFT)
                              ^
include/linux/cache.h:12:25: note: in expansion of macro ‘L1_CACHE_BYTES’
 #define SMP_CACHE_BYTES L1_CACHE_BYTES
                         ^
include/linux/cache.h:20:58: note: in expansion of macro ‘SMP_CACHE_BYTES’
 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
                                                          ^
./arch/x86/include/asm/processor.h:275:27: note: in expansion of macro ‘____cacheline_aligned’
 } __attribute__((packed)) ____cacheline_aligned;
                           ^
In file included from ./arch/x86/include/asm/thread_info.h:52:0,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/processor.h:275:1: error: requested alignment is not an integer constant
 } __attribute__((packed)) ____cacheline_aligned;
 ^
./arch/x86/include/asm/processor.h:306:1: error: requested alignment is not an integer constant
 } ____cacheline_aligned;
 ^
In file included from include/asm-generic/percpu.h:6:0,
                 from ./arch/x86/include/asm/percpu.h:551,
                 from ./arch/x86/include/asm/preempt.h:5,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/processor.h:308:39: error: requested alignment is not an integer constant
 DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss);
                                       ^
include/linux/percpu-defs.h:101:38: note: in definition of macro ‘DECLARE_PER_CPU_SECTION’
  extern __PCPU_ATTRS(sec) __typeof__(type) name
                                      ^
./arch/x86/include/asm/processor.h:308:1: note: in expansion of macro ‘DECLARE_PER_CPU_SHARED_ALIGNED’
 DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, cpu_tss);
 ^
In file included from ./arch/x86/include/asm/preempt.h:5:0,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/processor.h: In function ‘current_top_of_stack’:
./arch/x86/include/asm/processor.h:466:30: error: ‘cpu_current_top_of_stack’ undeclared (first use in this function)
  return this_cpu_read_stable(cpu_current_top_of_stack);
                              ^
./arch/x86/include/asm/percpu.h:213:9: note: in definition of macro ‘percpu_stable_op’
  typeof(var) pfo_ret__;    \
         ^
./arch/x86/include/asm/processor.h:466:9: note: in expansion of macro ‘this_cpu_read_stable’
  return this_cpu_read_stable(cpu_current_top_of_stack);
         ^
./arch/x86/include/asm/processor.h:466:30: note: each undeclared identifier is reported only once for each function it appears in
  return this_cpu_read_stable(cpu_current_top_of_stack);
                              ^
./arch/x86/include/asm/percpu.h:213:9: note: in definition of macro ‘percpu_stable_op’
  typeof(var) pfo_ret__;    \
         ^
./arch/x86/include/asm/processor.h:466:9: note: in expansion of macro ‘this_cpu_read_stable’
  return this_cpu_read_stable(cpu_current_top_of_stack);
         ^
In file included from ./arch/x86/include/asm/atomic.h:240:0,
                 from include/linux/atomic.h:4,
                 from ./arch/x86/include/asm/thread_info.h:53,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/atomic64_64.h: At top level:
./arch/x86/include/asm/atomic64_64.h:19:40: error: unknown type name ‘atomic64_t’
 static inline long atomic64_read(const atomic64_t *v)
                                        ^
In file included from include/uapi/linux/stddef.h:1:0,
                 from include/linux/stddef.h:4,
                 from ./include/uapi/linux/posix_types.h:4,
                 from include/uapi/linux/types.h:13,
                 from include/linux/types.h:5,
                 from include/linux/list.h:4,
                 from include/linux/module.h:9,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/atomic64_64.h: In function ‘atomic64_read’:
./arch/x86/include/asm/atomic64_64.h:21:22: error: request for member ‘counter’ in something not a structure or union
  return READ_ONCE((v)-&gt;counter);
                      ^
include/linux/compiler.h:279:17: note: in definition of macro ‘__READ_ONCE’
  union { typeof(x) __val; char __c[1]; } __u;   \
                 ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘READ_ONCE’
  return READ_ONCE((v)-&gt;counter);
         ^
./arch/x86/include/asm/atomic64_64.h:21:22: error: request for member ‘counter’ in something not a structure or union
  return READ_ONCE((v)-&gt;counter);
                      ^
include/linux/compiler.h:281:22: note: in definition of macro ‘__READ_ONCE’
   __read_once_size(&amp;(x), __u.__c, sizeof(x));  \
                      ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘READ_ONCE’
  return READ_ONCE((v)-&gt;counter);
         ^
./arch/x86/include/asm/atomic64_64.h:21:22: error: request for member ‘counter’ in something not a structure or union
  return READ_ONCE((v)-&gt;counter);
                      ^
include/linux/compiler.h:281:42: note: in definition of macro ‘__READ_ONCE’
   __read_once_size(&amp;(x), __u.__c, sizeof(x));  \
                                          ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘READ_ONCE’
  return READ_ONCE((v)-&gt;counter);
         ^
./arch/x86/include/asm/atomic64_64.h:21:22: error: request for member ‘counter’ in something not a structure or union
  return READ_ONCE((v)-&gt;counter);
                      ^
include/linux/compiler.h:283:30: note: in definition of macro ‘__READ_ONCE’
   __read_once_size_nocheck(&amp;(x), __u.__c, sizeof(x)); \
                              ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘READ_ONCE’
  return READ_ONCE((v)-&gt;counter);
         ^
./arch/x86/include/asm/atomic64_64.h:21:22: error: request for member ‘counter’ in something not a structure or union
  return READ_ONCE((v)-&gt;counter);
                      ^
include/linux/compiler.h:283:50: note: in definition of macro ‘__READ_ONCE’
   __read_once_size_nocheck(&amp;(x), __u.__c, sizeof(x)); \
                                                  ^
./arch/x86/include/asm/atomic64_64.h:21:9: note: in expansion of macro ‘READ_ONCE’
  return READ_ONCE((v)-&gt;counter);
         ^
In file included from ./arch/x86/include/asm/atomic.h:240:0,
                 from include/linux/atomic.h:4,
                 from ./arch/x86/include/asm/thread_info.h:53,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:59,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/linux/stat.h:18,
                 from include/linux/module.h:10,
                 from /home/osboxes/Documents/kernel_modules/DRFM/testmod.c:1:
./arch/x86/include/asm/atomic64_64.h: At top level:
./arch/x86/include/asm/atomic64_64.h:31:33: error: unknown type name ‘atomic64_t’
 static inline void atomic64_set(atomic64_t *v, long i)
                                 ^
./arch/x86/include/asm/atomic64_64.h:43:50: error: unknown type name ‘atomic64_t’
 static __always_inline void atomic64_add(long i, atomic64_t *v)
                                                  ^
./arch/x86/include/asm/atomic64_64.h:57:41: error: unknown type name ‘atomic64_t’
 static inline void atomic64_sub(long i, atomic64_t *v)
                                         ^
./arch/x86/include/asm/atomic64_64.h:73:49: error: unknown type name ‘atomic64_t’
 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
                                                 ^
./arch/x86/include/asm/atomic64_64.h:84:42: error: unknown type name ‘atomic64_t’
 static __always_inline void atomic64_inc(atomic64_t *v)
                                          ^
./arch/x86/include/asm/atomic64_64.h:97:42: error: unknown type name ‘atomic64_t’
 static __always_inline void atomic64_dec(atomic64_t *v)
                                          ^
./arch/x86/include/asm/atomic64_64.h:112:41: error: unknown type name ‘atomic64_t’
 static inline int atomic64_dec_and_test(atomic64_t *v)
                                         ^
./arch/x86/include/asm/atomic64_64.h:125:41: error: unknown type name ‘atomic64_t’
 static inline int atomic64_inc_and_test(atomic64_t *v)
                                         ^
./arch/x86/include/asm/atomic64_64.h:139:49: error: unknown type name ‘atomic64_t’
 static inline int atomic64_add_negative(long i, atomic64_t *v)
                                                 ^
./arch/x86/include/asm/atomic64_64.h:151:57: error: unknown type name ‘atomic64_t’
 static __always_inline long atomic64_add_return(long i, atomic64_t *v)
</code></pre>

<p>I hit the character limit, so I can't post the whole thing, but this is most of it.</p>

<p>I should mention: My target system is an ARM processor, I am building on an x86 64 bit VM with Debian. I have set the CROSS_COMPILER and the PATH to reference the arm-xilinx-linux-gnueabi-gcc compiler I am trying to use.</p>

<p>After it being pointed out that the above is pulling from the x86 sources in my source directory, I tried adding ARCH=arm into the make command, which gave the following errors:</p>

<pre><code>CC=arm-xilinx-linux-gnueabi-gcc
make ARCH=arm -C /home/osboxes/Documents/linux-xcomm_zynq/ M=/home/osboxes/Documents/kernel_modules/DRFM modules
make[1]: Entering directory '/home/osboxes/Documents/linux-xcomm_zynq'
  CC [M]  /home/osboxes/Documents/kernel_modules/DRFM/testmod.o
gcc: error: unrecognized argument in option ‘-mabi=aapcs-linux’
gcc: note: valid arguments to ‘-mabi=’ are: ms sysv
gcc: error: unrecognized command line option ‘-mlittle-endian’
gcc: error: unrecognized command line option ‘-mno-thumb-interwork’
gcc: error: unrecognized command line option ‘-mfpu=vfp’
scripts/Makefile.build:264: recipe for target '/home/osboxes/Documents/kernel_modules/DRFM/testmod.o' failed
make[2]: *** [/home/osboxes/Documents/kernel_modules/DRFM/testmod.o] Error 1
Makefile:1384: recipe for target '_module_/home/osboxes/Documents/kernel_modules/DRFM' failed
make[1]: *** [_module_/home/osboxes/Documents/kernel_modules/DRFM] Error 2
make[1]: Leaving directory '/home/osboxes/Documents/linux-xcomm_zynq'
Makefile:7: recipe for target 'cross' failed
make: *** [cross] Error 2
</code></pre>

<p>In some other questions I searched for, I saw answers saying that a "error: unrecognized command" might mean I'm using the wrong compiler, but I specified that arm-xilinx-linux-gnueabi-gcc should be used, which should be an appropriate ARM compiler, to my knowledge.</p>