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

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 libraries when linking. Only the
  libraries you specify are passed to the linker, and options specifying
  linkage of the system libraries, such as -static-libgcc or
  -shared-libgcc, are ignored. The standard startup files are used
  normally, unless -nostartfiles is used.
標準システムライブラリ(libcなど)をリンクしない。

-nostdlib

3.14 Options for Linking
  Do not use the standard system startup files or libraries when
  linking. No startup files and only the libraries you specify are
  passed to the linker, and options specifying linkage of the system
  libraries, such as -static-libgcc or -shared-libgcc, are ignored.
オプションで指定したライブラリだけをリンクする。

-static

3.14 Options for Linking
  On systems that support dynamic linking, this prevents linking with
  the shared libraries. On other systems, this option has no effect.
共有ライブリラリ(*.so)をリンクしない。

-Wl,-X

2.1 Command Line Options
--discard-locals
  
  Delete all temporary local symbols. (These symbols start with
  system-specific local label prefixes, typically `.L' for ELF systems
  or `L' for traditional a.out systems.)
一時的(=記憶領域が割り当てられていない?)なローカル(=オブジェクトファイルスコープ?)なシンボル(ELFではLで始まる)を全て削除する。

-Wl,-N

2.1 Command Line Options
--omagic
  Set the text and data sections to be readable and writable. Also, do
  not page-align the data segment, and disable linking against shared
  libraries. If the output format supports Unix style magic numbers,
  mark the output as OMAGIC. Note: Although a writable text section is
  allowed for PE-COFF targets, it does not conform to the format
  specification published by Microsoft.
textとdataセクションを読み書き可能にする。dataセグメントのページアライメントを行わない。共有ライブリラリとのリンクを禁止する。

-Wl,--gc-sections

2.1 Command Line Options
  Enable garbage collection of unused input sections. It is ignored on
  targets that do not support this option. The default behaviour (of not
  performing this garbage collection) can be restored by specifying
  `--no-gc-sections' on the command line. Note that garbage collection
  for COFF and PE format targets is supported, but the implementation is
  currently considered to be experimental.  `--gc-sections' decides
  which input sections are used by examining symbols and
  relocations. The section containing the entry symbol and all sections
  containing symbols undefined on the command-line will be kept, as will
  sections containing symbols referenced by dynamic objects. Note that
  when building shared libraries, the linker must assume that any
  visible symbol is referenced. Once this initial set of sections has
  been determined, the linker recursively marks as used any section
  referenced by their relocations. See `--entry' and `--undefined'.

  This option can be set when doing a partial link (enabled with option
  `-r'). In this case the root of symbols kept must be explicitly
  specified either by an `--entry' or `--undefined' option or by a ENTRY
  command in the linker script.
未使用の入力セクションに対するガベージコレクションを有効にする。

-Wl,--build-id=none

2.1 Command Line Options
--build-id
--build-id=style

  Request the creation of a .note.gnu.build-id ELF note section or a
  .buildid COFF section. The contents of the note are unique bits
  identifying this linked file. style can be uuid to use 128 random
  bits, sha1 to use a 160-bit SHA1 hash on the normative parts of the
  output contents, md5 to use a 128-bit MD5 hash on the normative parts
  of the output contents, or 0xhexstring to use a chosen bit string
  specified as an even number of hexadecimal digits (- and : characters
  between digit pairs are ignored). If style is omitted, sha1 is used.
  The md5 and sha1 styles produces an identifier that is always the same
  in an identical output file, but will be unique among all nonidentical
  output files. It is not intended to be compared as a checksum for the
  file's contents. A linked file may be changed later by other tools,
  but the build ID bit string identifying the original linked file does
  not change.

  Passing none for style disables the setting from any --build-id
  options earlier on the command line.
.note.gnu.build-id セクションを作成しない。

-Wl,-Map=[zephyr_base]/samples/hello_world/microkernel/outdir/zephyr.map

2.1 Command Line Options
  Print a link map to the file mapfile. See the description of the -M
  option, above.

-M
--print-map
Print a link map to the standard output. A link map provides
information about the link, including the following:

    ・Where object files are mapped into memory.
    ・How common symbols are allocated.
    ・All archive members included in the link, with a mention of the
      symbol which caused the archive member to be brought in.
    ・The values assigned to symbols.

Note - symbols whose values are computed by an expression which
involves a reference to a previous value of the same symbol may not
have correct result displayed in the link map. This is because the
linker discards intermediate results and only retains the final value
of an expression. Under such circumstances the linker will display the
final value enclosed by square brackets. Thus for example a linker
script containing:

                  foo = 1
                  foo = foo * 4
                  foo = foo + 8
          
will produce the following output in the link map if the -M option is used:

                  0x00000001                foo = 0x1
                  [0x0000000c]                foo = (foo * 0x4)
                  [0x0000000c]                foo = (foo + 0x8)
          
See Expressions for more information about expressions in linker scripts.
リンクマップファイル(シンボルとアドレスのマップ?)を生成する。

-L ./include/generated

3.14 Options for Linking
  The directories searched include several standard system directories
  plus any that you specify with -L.
ライブラリサーチパスに./include/generatedを追加する。

-u _OffsetAbsSyms -u _ConfigAbsSyms

3.14 Options for Linking
  Pretend the symbol symbol is undefined, to force linking of library
  modules to define it. You can use -u multiple times with different
  symbols to force loading of additional library modules.
シンボル(_OffsetAbsSyms,_ConfigAbsSyms)を定義するライブラリと強制的にリンクするために、シンボルを未定義として扱う?。

-e __start

2.1 Command Line Options
--entry=entry
  Use entry as the explicit symbol for beginning execution of your
  program, rather than the default entry point. If there is no symbol
  named entry, the linker will try to parse entry as a number, and use
  that as the entry address (the number will be interpreted in base 10;
  you may use a leading `0x' for base 16, or a leading `0' for base
  8). See Entry Point, for a discussion of defaults and other ways of
  specifying the entry point.
最初に実行されるエントリポイントとして__startを指定する。

-Wl,--start-group ... -Wl,--end-group

2.1 Command Line Options
--start-group archives --end-group
  The archives should be a list of archive files. They may be either
  explicit file names, or `-l' options.  The specified archives are
  searched repeatedly until no new undefined references are
  created. Normally, an archive is searched only once in the order that
  it is specified on the command line. If a symbol in that archive is
  needed to resolve an undefined symbol referred to by an object in an
  archive that appears later on the command line, the linker would not
  be able to resolve that reference. By grouping the archives, they all
  be searched repeatedly until all possible references are resolved.

  Using this option has a significant performance cost. It is best to
  use it only when there are unavoidable circular references between two
  or more archives.
-Wl,--start-group と -Wl,--end-group の間にアーカイブファイル(*.a、*.o)のリストを記述する。
リストに含まれるアーカイブファイル(オブジェクトファイル)は、未定義のシンボルがなくなるまで(リスト中のファイルを横断して)探索を繰り返す。
通常は、オブジェクトファイルの指定順番はシンボルの解決順にする必要がある。(通常はファイル間で一方向の参照のみ?)
オブジェクトファイルがお互いのシンボルを参照する場合には、通常の方法では解決できないので、-Wl,--start-group と -Wl,--end-group を使う必要がある。
-Wl,--start-group
 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
今回は、上記のオブジェクトファイルのシンボルを互いに繰り返し探索する。

-Wl,--whole-archive ... -Wl,--no-whole-archive

2.1 Command Line Options
-Wl,--whole-archive
  For each archive mentioned on the command line after the
  --whole-archive option, include every object file in the archive in
  the link, rather than searching the archive for the required object
  files. This is normally used to turn an archive file into a shared
  library, forcing every object to be included in the resulting shared
  library. This option may be used more than once.  Two notes when using
  this option from gcc: First, gcc doesn't know about this option, so
  you have to use -Wl,-whole-archive. Second, don't forget to use
  -Wl,-no-whole-archive after your list of archives, because gcc will
  add its own list of archives to your link and you may not want this
  flag to affect those as well.
-Wl,--no-whole-archive
  Turn off the effect of the --whole-archive option for subsequent archive files.
-Wl,--whole-archive と -Wl,--no-whole-archive の間に含まれるアーカイブ中のオブジェクトを強制的にリンクする?。

-L /Volumes/CrossToolNG/x-tools/i586-pc-elf/lib/gcc/i586-pc-elf/5.2.0/

2.1 Command Line Options
  The directories searched include several standard system directories
  plus any that you specify with -L.
ライブラリサーチパスに/Volumes/CrossToolNG/x-tools/i586-pc-elf/lib/gcc/i586-pc-elf/5.2.0/を追加する。

-lgcc

3.14 Options for Linking
  In other words, when you specify -nostdlib or -nodefaultlibs you
  should usually specify -lgcc as well. This ensures that you have no
  unresolved references to internal GCC library subroutines. (An example
  of such an internal subroutine is __main, used to ensure C++
  constructors are called; see collect2.)
gccの内部ライブラリが未定義エラーを出さないようにするために、これが必要。

コメント

このブログの人気の投稿

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