スキップしてメイン コンテンツに移動

Zephyr build (7)

この記事で関係するターゲット

linker.cmd ターゲット

[zephyr_base]/Makefile
linker.cmd: $(zephyr-deps)
        $(Q)$(CC) -x assembler-with-cpp -nostdinc -undef -E -P \
        $(LDFLAG_LINKERCMD) $(LD_TOOLCHAIN) -I$(srctree)/include \
        -I$(objtree)/include/generated $(EXTRA_LINKER_CMD_OPT) $(KBUILD_LDS) -o $@

$(zephyr-deps)

TODO

$(Q)

[zephyr_base]/Makefile
ifeq ("$(origin V)", "command line")
  KBUILD_VERBOSE = $(V)
endif
ifndef KBUILD_VERBOSE
  KBUILD_VERBOSE = 0
endif

ifeq ($(KBUILD_VERBOSE),1)
  quiet =
  Q =
else
  quiet=quiet_
  Q = @
endif
...
export quiet Q KBUILD_VERBOSE
make V=1 などとすると、環境変数 Q は"" となる(or 未定義?)。それ以外では、Q は @ となる。
$(Q)$(CC) が gcc となる場合、実行する gcc ... というコマンドが表示されるが、@gcc となる場合、コマンドは表示されない。
5.2 Recipe Echoing 参照。

$(CC)

前の記事 参照。

$(LDFLAG_LINKERCMD)

未定義

$(LD_TOOLCHAIN)

[zephyr_base]/Makefile
LD_TOOLCHAIN ?= -D__GCC_LINKER_CMD__
LD_TOOLCHAIN が未定義の場合、-D__GCC_LINKER_CMD__ とする。

$(srctree)

[zephyr_base]/Makefile
ifeq ($(KBUILD_SRC),)
        # building in the source tree
        srctree := .
else
        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
                # building in a subdirectory of the source tree
                srctree := ..
        else
                srctree := $(KBUILD_SRC)
        endif
endif
objtree  := .
(省略)
export srctree objtree VPATH
TODO 後で検討
KBUILD_SRC は、[zephyr_base] (sub-makeターゲット時にセットされる)。
srctree は [zephyr_base]となる。
objtree は . (カレントディレクトリ)となる。

$(objtree)

上記参照

$(EXTRA_LINKER_CMD_OPT)

未定義

$(KBUILD_LDS)

[zephyr_base]/Makefile
ifdef CONFIG_HAVE_CUSTOM_LINKER_SCRIPT
KBUILD_LDS         := $(subst $(DQUOTE),,$(CONFIG_CUSTOM_LINKER_SCRIPT))
else
# Try a board specific linker file
KBUILD_LDS := $(srctree)/boards/$(BOARD_NAME)/linker.ld

# If not available, try an SoC specific linker file
ifeq ($(wildcard $(KBUILD_LDS)),)
KBUILD_LDS         := $(srctree)/arch/$(ARCH)/soc/$(SOC_PATH)/linker.ld
endif
endif

export LD_TOOLCHAIN KBUILD_LDS
KBUILD_LDS は [zephyr_base]/arch/x86/soc/ia32/linker.ld -o linker.cmd となる。

BOARD_NAME は qemu_x86。
[zephyr_base]/Makefile
BOARD_NAME = $(subst $(DQUOTE),,$(CONFIG_BOARD))
[zephyr_base]/samples/hello_world/microkernel/outdir/.config
CONFIG_BOARD="qemu_x86"

SOC_PATH は ia32。
[zephyr_base]/Makefile
SOC_NAME = $(subst $(DQUOTE),,$(CONFIG_SOC))
SOC_SERIES = $(subst $(DQUOTE),,$(CONFIG_SOC_SERIES))
(省略)
ifeq ($(SOC_SERIES),)
SOC_PATH = $(SOC_NAME)
else
SOC_PATH = $(SOC_FAMILY)/$(SOC_SERIES)
endif
[zephyr_base]/samples/hello_world/microkernel/outdir/.config
CONFIG_SOC="ia32"
CONFIG_SOC_SERIES は未定義。
[zephyr_base]/samples/hello_world/microkernel/outdir/.config
# CONFIG_HAVE_CUSTOM_LINKER_SCRIPT is not set

$(Q)$(CC) -x assembler-with-cpp -nostdinc -undef -E -P $(LDFLAG_LINKERCMD) $(LD_TOOLCHAIN) -I$(srctree)/include -I$(objtree)/include/generated $(EXTRA_LINKER_CMD_OPT) $(KBUILD_LDS) -o $@

/Volumes/CrossToolNG/x-tools/i586-pc-elf/bin/i586-pc-elf-gcc -x assembler-with-cpp -nostdinc -undef -E -P \
        -D__GCC_LINKER_CMD__ -I[zephyr_base]/include \
        -I./include/generated  [zephyr_base]/arch/x86/soc/ia32/linker.ld -o linker.cmd
-x assembler-with-cpp
3.2 Options Controlling the Kind of Output
-x language
Specify explicitly the language for the following input files (rather than letting the compiler choose a default based on the file name suffix). This option applies to all following input files until the next -x option. Possible values for language are:
          c  c-header  cpp-output
          c++  c++-header  c++-cpp-output
          objective-c  objective-c-header  objective-c-cpp-output
          objective-c++ objective-c++-header objective-c++-cpp-output
          assembler  assembler-with-cpp
          ada
          f77  f77-cpp-input f95  f95-cpp-input
          go
          java
-nostdinc
2.3 Search Path
You can prevent GCC from searching any of the default directories with
the -nostdinc option. This is useful when you are compiling an
operating system kernel or some other program that does not use the
standard C library facilities, or the standard C library itself. -I
options are not ignored as described above when -nostdinc is in
effect.
-undef
3.12 Options Controlling the Preprocessor
-undef
Do not predefine any system-specific or GCC-specific macros. The standard predefined macros remain defined. 
-E
3.2 Options Controlling the Kind of Output
-E

  Stop after the preprocessing stage; do not run the compiler
  proper. The output is in the form of preprocessed source code, which
  is sent to the standard output.  Input files that don't require
  preprocessing are ignored.
3.14 Options for Linking
-c
-S
-E

  If any of these options is used, then the linker is not run, and
  object file names should not be used as arguments.
-P
3.12 Options Controlling the Preprocessor
-P

  Inhibit generation of linemarkers in the output from the
  preprocessor. This might be useful when running the preprocessor on
  something that is not C code, and will be sent to a program which
  might be confused by the linemarkers.
-D__GCC_LINKER_CMD__
3.12 Options Controlling the Preprocessor
-D name

  Predefine name as a macro, with definition 1. 
-I[zephyr_base]/include
3.15 Options for Directory Search
-Idir

  Add the directory dir to the head of the list of directories to be
  searched for header files. This can be used to override a system
  header file, substituting your own version, since these directories
  are searched before the system header file directories. However, you
  should not use this option to add directories that contain
  vendor-supplied system header files (use -isystem for that). If you
  use more than one -I option, the directories are scanned in
  left-to-right order; the standard system directories come after.
-I./include/generated
同上 see above
[zephyr_base]/arch/x86/soc/ia32/linker.ld
プロプロセス元のファイル。
(略)
MEMORY
    {
#ifdef CONFIG_XIP
    ROM (rx)        : ORIGIN = PHYS_LOAD_ADDR, LENGTH = CONFIG_ROM_SIZE*1K
    RAM (wx)        : ORIGIN = PHYS_RAM_ADDR, LENGTH = CONFIG_RAM_SIZE*1K
#else  /* !CONFIG_XIP */
    RAM (wx)        : ORIGIN = PHYS_LOAD_ADDR, LENGTH = CONFIG_RAM_SIZE*1K
#endif /* CONFIG_XIP */
(略)
-o linker.cmd
linker.ld をプリプロセスした結果を出力するファイル。
[zephyr_base]/samples/hello_world/microkernel/outdir に生成される。
(略)
MEMORY
    {
    RAM (wx) : ORIGIN = 0x00100000, LENGTH = 192*1K
(略)
Invocation
-o file

  Write output to file. This is the same as specifying file as the
  second non-option argument to cpp. gcc has a different
  interpretation of a second non-option argument, so you must use -o
  to specify the output file.

コメント

このブログの人気の投稿

Zephyr build (5)

この記事で関係するターゲット 前の記事 参照 linker.cmd [zephyr_base]/samples/hello_world/microkernel/outdir/linker.cmd MEMORY { RAM (wx) : ORIGIN = 0x00100000, LENGTH = 192*1K IDT_LIST : ORIGIN = 2K, LENGTH = 2K } OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386") OUTPUT_ARCH(i386) SECTIONS { _image_rom_start = 0x00100000; _image_text_start = 0x00100000; text () : { *(.text_start) *(".text_start.*") *(.text) *(".text.*") *(.gnu.linkonce.t.*) *(.eh_frame) *(.init) *(.fini) *(.eini) } > RAM _image_text_end = .; devconfig () : { __devconfig_start = .; *(".devconfig.*") KEEP(*(SORT(".devconfig*"))) __devconfig_end = .; } > RAM gpio_compat () : { __gpio_compat_start = .; *(".gpio_compat.*") KEEP(*(SORT(".gpio_compat*"))) __gpio_compat_end = .; } > RAM rodata () : { *(.rodata) *(".rodata.*") *(.gnu.linkonce.r.*) . = ALIGN(8); _id

Initial run-length encoding@bzip2を読んでみた

Wikipediaのbzip2圧縮アルゴリズムの一部を読んだので意訳して紹介します。 参考にしたソースコードは bzip2-1.0.6 です。 Wikipedia https://en.wikipedia.org/wiki/Bzip2#Initial_run-length_encoding bzip2 ソースコード https://github.com/junkawa/bzip2/tree/master/bzip2-1.0.6 概要 bzip2では、入力データを読み込んだ時( copy_input_until_stop()@bzlib.c → ADD_CHAR_TO_BLOCK() → add_pair_to_block() ) に ランレングス符号化 を行う。 Wikipedia Any sequence of 4 to 255 consecutive duplicate symbols is replaced by the first four symbols and a repeat length between 0 and 251.   4〜255回、同じシンボルが連続した場合、「最初の4シンボル+残りの繰り返し回数」に置き換わる。 Thus the sequence "AAAAAAABBBBCCCD" is replaced with "AAAA\3BBBB\0CCCD", where "\3" and "\0" represent byte values 3 and 0 respectively.  "AAAAAAABBBBCCCD"は、"AAAA\3BBBB\0CCCD"に置き換わる。 AAAAAAA (Aが7回)は、最初の4シンボル(AAAA) + 残りの繰り返し回数(3)となる。 BBBB (Bが4回)は、最初の4シンボル(BBBB) + 残りの繰り返し回数(0)となる。 C,Dは連続回数が4回に達しないのでそのままとなる。 ここでは分かりやすさのため、A,B,Cというシンボルを使っているが、実際のbzip2では1シンボルは1バイト(0〜255の値)。 したがって、シンボル7

Zephyr build (6)

この記事で関係するターゲット 前の記事 参照 zephyr.lnk [zephyr_base]/Makefile -nostartfiles -nodefaultlibs -nostdlib -static -Wl,-X -Wl,-N -Wl,--gc-sections -Wl,--build-id=none -Wl,-Map=[zephyr_base]/samples/hello_world/microkernel/outdir/zephyr.map -L ./include/generated -u _OffsetAbsSyms -u _ConfigAbsSyms -e __start -Wl,--start-group -Wl,--whole-archive -Wl,--no-whole-archive drivers/built-in.o ./samples/hello_world/microkernel/src/built-in.o lib/built-in.o kernel/built-in.o misc/built-in.o net/built-in.o boards/built-in.o arch/built-in.o ext/built-in.o ./arch/x86/core/offsets/offsets.o -Wl,--end-group -L /Volumes/CrossToolNG/x-tools/i586-pc-elf/lib/gcc/i586-pc-elf/5.2.0/ -lgcc -nostartfiles 3.14 Options for Linking Do not use the standard system startup files when linking. The standard system libraries are used normally, unless -nostdlib or -nodefaultlibs is used. スタートアップファイル(crt*.oなど)をリンクしない。 -nodefaultlibs 3.14 Options for Linking Do not use the standard system