最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Cygwin下交叉编译Linux内核make zImage时出错:scripts/mod/modpost.h:119:2: error: unknown type name ‘Elf32_Section’

Cygwin crifan 4274浏览 0评论

【问题】

折腾:

【记录】Cygwin下交叉编译Linux内核在配置后去make编译

期间,交叉编译出错:

CLi@PC-CLI-1 ~/develop/kernel/linux-2.6.19.1
$ make ARCH=arm CROSS_COMPILE=arm-xscale-linux-gnueabi- zImage
  HOSTCC  scripts/basic/fixdep
scripts/basic/fixdep.c: In function ‘parse_config_file’:
scripts/basic/fixdep.c:242:4: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/fixdep.c: In function ‘parse_dep_file’:
scripts/basic/fixdep.c:319:4: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/fixdep.c: In function ‘traps’:
scripts/basic/fixdep.c:371:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
scripts/basic/fixdep.c:373:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  HOSTCC  scripts/basic/docproc
scripts/basic/docproc.c: In function ‘find_export_symbols’:
scripts/basic/docproc.c:188:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:191:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:197:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:200:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c: In function ‘singfunc’:
scripts/basic/docproc.c:267:17: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c: In function ‘parse_file’:
scripts/basic/docproc.c:300:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:305:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:310:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:316:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:319:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  HOSTLD  scripts/kconfig/conf
scripts/kconfig/conf -s arch/arm/Kconfig
  CHK     include/linux/version.h
  UPD     include/linux/version.h
  SYMLINK include/asm-arm/arch -> include/asm-arm/arch-pxa
  Generating include/asm-arm/mach-types.h
  CHK     include/linux/utsrelease.h
  UPD     include/linux/utsrelease.h
  SYMLINK include/asm -> include/asm-arm
  HOSTCC  scripts/basic/fixdep
scripts/basic/fixdep.c: In function ‘parse_config_file’:
scripts/basic/fixdep.c:242:4: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/fixdep.c: In function ‘parse_dep_file’:
scripts/basic/fixdep.c:319:4: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/fixdep.c: In function ‘traps’:
scripts/basic/fixdep.c:371:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
scripts/basic/fixdep.c:373:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  HOSTCC  scripts/basic/docproc
scripts/basic/docproc.c: In function ‘find_export_symbols’:
scripts/basic/docproc.c:188:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:191:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:197:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:200:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c: In function ‘singfunc’:
scripts/basic/docproc.c:267:17: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c: In function ‘parse_file’:
scripts/basic/docproc.c:300:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:305:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:310:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:316:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:319:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  CC      arch/arm/kernel/asm-offsets.s
  GEN     include/asm-arm/asm-offsets.h
  CC      scripts/mod/empty.o
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/file2alias.o
In file included from scripts/mod/file2alias.c:13:0:
scripts/mod/modpost.h:21:0: warning: "ELF_ST_BIND" redefined [enabled by default]
In file included from /usr/include/machine/elf.h:45:0,
                 from /usr/include/elf.h:37,
                 from scripts/mod/modpost.h:10,
                 from scripts/mod/file2alias.c:13:
/usr/include/sys/elf_generic.h:84:0: note: this is the location of the previous definition
In file included from scripts/mod/file2alias.c:13:0:
scripts/mod/modpost.h:22:0: warning: "ELF_ST_TYPE" redefined [enabled by default]
In file included from /usr/include/machine/elf.h:45:0,
                 from /usr/include/elf.h:37,
                 from scripts/mod/modpost.h:10,
                 from scripts/mod/file2alias.c:13:
/usr/include/sys/elf_generic.h:85:0: note: this is the location of the previous definition
In file included from scripts/mod/file2alias.c:13:0:
scripts/mod/modpost.h:26:0: warning: "ELF_R_SYM" redefined [enabled by default]
In file included from /usr/include/machine/elf.h:45:0,
                 from /usr/include/elf.h:37,
                 from scripts/mod/modpost.h:10,
                 from scripts/mod/file2alias.c:13:
/usr/include/sys/elf_generic.h:81:0: note: this is the location of the previous definition
In file included from scripts/mod/file2alias.c:13:0:
scripts/mod/modpost.h:27:0: warning: "ELF_R_TYPE" redefined [enabled by default]
In file included from /usr/include/machine/elf.h:45:0,
                 from /usr/include/elf.h:37,
                 from scripts/mod/modpost.h:10,
                 from scripts/mod/file2alias.c:13:
/usr/include/sys/elf_generic.h:82:0: note: this is the location of the previous definition
In file included from scripts/mod/file2alias.c:13:0:
scripts/mod/modpost.h:119:2: error: unknown type name ‘Elf32_Section’
scripts/mod/modpost.h:120:2: error: unknown type name ‘Elf32_Section’
scripts/mod/modpost.h:121:2: error: unknown type name ‘Elf32_Section’
scripts/mod/modpost.h:122:2: error: unknown type name ‘Elf32_Section’
scripts/mod/modpost.h:123:2: error: unknown type name ‘Elf32_Section’
scripts/mod/file2alias.c: In function ‘do_of_entry’:
scripts/mod/file2alias.c:365:9: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/mod/file2alias.c: In function ‘do_vio_entry’:
scripts/mod/file2alias.c:381:3: warning: array subscript has type ‘char’ [-Wchar-subscripts]
make[2]: *** [scripts/mod/file2alias.o] Error 1
make[1]: *** [scripts/mod] Error 2
make: *** [scripts] Error 2

CLi@PC-CLI-1 ~/develop/kernel/linux-2.6.19.1
$

如图:

scripts mod modpost h error unknown type name Elf32_Section

即:

scripts/mod/modpost.h:119:2: error: unknown type name ‘Elf32_Section’

【解决过程】

1.结果搜:

unknown type name ‘Elf32_Section’

之类的内容,完全都搜不到有人遇到类似问题。

2.后来搜:

cygwin scripts/mod/modpost.h

而找到:

Re: [PATCH 2.6.21.3] kbuild: fix build for cygwin

Build Linux Kernel in Cygwin

然后去修改

linux-2.6.19.1\scripts\mod\modpost.h

改为:

#include <unistd.h>
#include <elf.h>
 
#ifdef __CYGWIN__
#define uint16_t __uint16_t
#define uint32_t __uint32_t
typedef uint16_t Elf32_Section;
typedef uint16_t Elf64_Section;
#endif

#include "elfconfig.h"

#if KERNEL_ELFCLASS == ELFCLASS32

#define Elf_Ehdr    Elf32_Ehdr
#define Elf_Shdr    Elf32_Shdr
#define Elf_Sym     Elf32_Sym
#define Elf_Addr    Elf32_Addr
#define Elf_Section Elf32_Section

#ifndef __CYGWIN__
#define ELF_ST_BIND ELF32_ST_BIND
#define ELF_ST_TYPE ELF32_ST_TYPE
#endif

#define Elf_Rel     Elf32_Rel
#define Elf_Rela    Elf32_Rela
#define ELF_R_SYM   ELF32_R_SYM
#define ELF_R_TYPE  ELF32_R_TYPE
#else

#define Elf_Ehdr    Elf64_Ehdr
#define Elf_Shdr    Elf64_Shdr
#define Elf_Sym     Elf64_Sym
#define Elf_Addr    Elf64_Addr
#define Elf_Section Elf64_Section
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_ST_TYPE ELF64_ST_TYPE

#define Elf_Rel     Elf64_Rel
#define Elf_Rela    Elf64_Rela
#define ELF_R_SYM   ELF64_R_SYM
#define ELF_R_TYPE  ELF64_R_TYPE
#endif

/* copy from linux-2.6.24includeasm-x86 */
#define R_386_32       1
#define R_386_PC32     2
/* copy from linux-2.6.24includeasm-arm */
#define R_ARM_PC24     1
#define R_ARM_ABS32    2
/* copy from linux-2.6.24includeasm-mips */
#define R_MIPS_32      2
#define R_MIPS_26      4
#define R_MIPS_HI16    5
#define R_MIPS_LO16    6

/* The 64-bit MIPS ELF ABI uses an unusual reloc format. */
typedef struct

另外,也注意到:

Re: [PATCH 2.6.21.3] kbuild: fix build for cygwin

中也提到了:

make:

HOST_LOADLIBES="-lcurses -lintl"

的事情。

3.然后再去编译试试,然后(虽然有其他警告,但是也)可以继续编译了:

CLi@PC-CLI-1 ~/develop/kernel/linux-2.6.19.1
$ make ARCH=arm CROSS_COMPILE=arm-xscale-linux-gnueabi- zImage
  CHK     include/linux/version.h
make[1]: `include/asm-arm/mach-types.h' is up to date.
  CHK     include/linux/utsrelease.h
  HOSTCC  scripts/basic/fixdep
scripts/basic/fixdep.c: In function ‘parse_config_file’:
scripts/basic/fixdep.c:242:4: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/fixdep.c: In function ‘parse_dep_file’:
scripts/basic/fixdep.c:319:4: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/fixdep.c: In function ‘traps’:
scripts/basic/fixdep.c:371:2: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
scripts/basic/fixdep.c:373:4: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
  HOSTCC  scripts/basic/docproc
scripts/basic/docproc.c: In function ‘find_export_symbols’:
scripts/basic/docproc.c:188:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:191:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:197:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:200:5: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c: In function ‘singfunc’:
scripts/basic/docproc.c:267:17: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c: In function ‘parse_file’:
scripts/basic/docproc.c:300:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:305:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:310:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:316:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/basic/docproc.c:319:6: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  HOSTCC  scripts/mod/mk_elfconfig
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/file2alias.o
In file included from scripts/mod/file2alias.c:13:0:
scripts/mod/modpost.h:36:0: warning: "ELF_R_SYM" redefined [enabled by default]
In file included from /usr/include/machine/elf.h:45:0,
                 from /usr/include/elf.h:37,
                 from scripts/mod/modpost.h:10,
                 from scripts/mod/file2alias.c:13:
/usr/include/sys/elf_generic.h:81:0: note: this is the location of the previous definition
In file included from scripts/mod/file2alias.c:13:0:
scripts/mod/modpost.h:37:0: warning: "ELF_R_TYPE" redefined [enabled by default]
In file included from /usr/include/machine/elf.h:45:0,
                 from /usr/include/elf.h:37,
                 from scripts/mod/modpost.h:10,
                 from scripts/mod/file2alias.c:13:
/usr/include/sys/elf_generic.h:82:0: note: this is the location of the previous definition
scripts/mod/file2alias.c: In function ‘do_of_entry’:
scripts/mod/file2alias.c:365:9: warning: array subscript has type ‘char’ [-Wchar-subscripts]
scripts/mod/file2alias.c: In function ‘do_vio_entry’:
scripts/mod/file2alias.c:381:3: warning: array subscript has type ‘char’ [-Wchar-subscripts]
  HOSTCC  scripts/mod/modpost.o

如图:

HOSTCC scripts mod file2alias o done

【总结】

Cygwin下交叉编译Linux内核,make出现:

scripts/mod/modpost.h:119:2: error: unknown type name ‘Elf32_Section’

的错误,的原因是:

Cygwin中的typedefs和Linux不一样,导致在Linux中可以正常编译的内核源码,此处在Cygwin中无法编译。

解决办法是:

修改:

linux-2.6.19.1\scripts\mod\modpost.h

变为:

#include <unistd.h>
#include <elf.h>
 
#ifdef __CYGWIN__
#define uint16_t __uint16_t
#define uint32_t __uint32_t
typedef uint16_t Elf32_Section;
typedef uint16_t Elf64_Section;
#endif

#include "elfconfig.h"

#if KERNEL_ELFCLASS == ELFCLASS32

#define Elf_Ehdr    Elf32_Ehdr
#define Elf_Shdr    Elf32_Shdr
#define Elf_Sym     Elf32_Sym
#define Elf_Addr    Elf32_Addr
#define Elf_Section Elf32_Section

#ifndef __CYGWIN__
#define ELF_ST_BIND ELF32_ST_BIND
#define ELF_ST_TYPE ELF32_ST_TYPE
#endif

#define Elf_Rel     Elf32_Rel
#define Elf_Rela    Elf32_Rela
#define ELF_R_SYM   ELF32_R_SYM
#define ELF_R_TYPE  ELF32_R_TYPE
#else

#define Elf_Ehdr    Elf64_Ehdr
#define Elf_Shdr    Elf64_Shdr
#define Elf_Sym     Elf64_Sym
#define Elf_Addr    Elf64_Addr
#define Elf_Section Elf64_Section
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_ST_TYPE ELF64_ST_TYPE

#define Elf_Rel     Elf64_Rel
#define Elf_Rela    Elf64_Rela
#define ELF_R_SYM   ELF64_R_SYM
#define ELF_R_TYPE  ELF64_R_TYPE
#endif

/* copy from linux-2.6.24includeasm-x86 */
#define R_386_32       1
#define R_386_PC32     2
/* copy from linux-2.6.24includeasm-arm */
#define R_ARM_PC24     1
#define R_ARM_ABS32    2
/* copy from linux-2.6.24includeasm-mips */
#define R_MIPS_32      2
#define R_MIPS_26      4
#define R_MIPS_HI16    5
#define R_MIPS_LO16    6

/* The 64-bit MIPS ELF ABI uses an unusual reloc format. */
typedef struct

即可。

转载请注明:在路上 » 【已解决】Cygwin下交叉编译Linux内核make zImage时出错:scripts/mod/modpost.h:119:2: error: unknown type name ‘Elf32_Section’

与本文相关的文章

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.201 seconds, using 22.40MB memory