AVR Libc Home Page | ![]() |
AVR Libc Development Pages | ||
Main Page | FAQ | Library Reference | Additional Documentation | Example Projects |
これはGNUツールのAVR独自の部分の簡単なサマリーです。通常、これらのツールのドキュメントは大変大きく、texinfo形式で管理されています。コマンドラインオプションについてはマニュアルページで詳しく解説されています。
以下の機種依存オプションがCコンパイラフロントエンドに認識されます。
-mmcu=
architecture architectureに対応するようコードをコンパイルします。現在の所知られているアーキテクチャは以下のようなものがあります。
avr1 | Simple CPU core, only assembler support |
avr2 | "Classic" CPU core, up to 8 KB of ROM |
avr3 | "Classic" CPU core, more than 8 KB of ROM |
avr4 | "Enhanced" CPU core, up to 8 KB of ROM |
avr5 | "Enhanced" CPU core, more than 8 KB of ROM |
デフォルトでは、avr2アーキテクチャ用のコードが生成されます。
-mmcu=
architecture オプションだけを指定し、-mmcu=
MCU type オプションを指定しなかった場合、どのデバイス定義を選ぶべきは判断できないため、ファイル<avr/io.h>
のインクルード作業は正常に行われません。
-mmcu=
MCU type MCU types 部には、avr-gccが把握しているデバイス名が入ります。この表は対応するavr-gcc アーキテクチャ名と-mmcuオプションで宣言されるプリプロセッサシンボルの一覧です。
Architecture | MCU name | Macro |
avr1 | at90s1200 | __AVR_AT90S1200__ |
avr1 | attiny11 | __AVR_ATtiny11__ |
avr1 | attiny12 | __AVR_ATtiny12__ |
avr1 | attiny15 | __AVR_ATtiny15__ |
avr1 | attiny28 | __AVR_ATtiny28__ |
avr2 | at90s2313 | __AVR_AT90S2313__ |
avr2 | at90s2323 | __AVR_AT90S2323__ |
avr2 | at90s2333 | __AVR_AT90S2333__ |
avr2 | at90s2343 | __AVR_AT90S2343__ |
avr2 | attiny22 | __AVR_ATtiny22__ |
avr2 | attiny24 | __AVR_ATtiny24__ |
avr2 | attiny25 | __AVR_ATtiny25__ |
avr2 | attiny26 | __AVR_ATtiny26__ |
avr2 | attiny261 | __AVR_ATtiny261__ |
avr2 | attiny44 | __AVR_ATtiny44__ |
avr2 | attiny45 | __AVR_ATtiny45__ |
avr2 | attiny461 | __AVR_ATtiny461__ |
avr2 | attiny84 | __AVR_ATtiny84__ |
avr2 | attiny85 | __AVR_ATtiny85__ |
avr2 | attiny861 | __AVR_ATtiny861__ |
avr2 | at90s4414 | __AVR_AT90S4414__ |
avr2 | at90s4433 | __AVR_AT90S4433__ |
avr2 | at90s4434 | __AVR_AT90S4434__ |
avr2 | at90s8515 | __AVR_AT90S8515__ |
avr2 | at90c8534 | __AVR_AT90C8534__ |
avr2 | at90s8535 | __AVR_AT90S8535__ |
avr2 | at86rf401 | __AVR_AT86RF401__ |
avr2 | attiny13 | __AVR_ATtiny13__ |
avr2 | attiny2313 | __AVR_ATtiny2313__ |
avr3 | atmega103 | __AVR_ATmega103__ |
avr3 | atmega603 | __AVR_ATmega603__ |
avr3 | at43usb320 | __AVR_AT43USB320__ |
avr3 | at43usb355 | __AVR_AT43USB355__ |
avr3 | at76c711 | __AVR_AT76C711__ |
avr4 | atmega48 | __AVR_ATmega48__ |
avr4 | atmega8 | __AVR_ATmega8__ |
avr4 | atmega8515 | __AVR_ATmega8515__ |
avr4 | atmega8535 | __AVR_ATmega8535__ |
avr4 | atmega88 | __AVR_ATmega88__ |
avr4 | at90pwm2 | __AVR_AT90PWM2__ |
avr4 | at90pwm3 | __AVR_AT90PWM3__ |
avr5 | at90can32 | __AVR_AT90CAN32__ |
avr5 | at90can64 | __AVR_AT90CAN64__ |
avr5 | at90can128 | __AVR_AT90CAN128__ |
avr5 | atmega128 | __AVR_ATmega128__ |
avr5 | atmega1280 | __AVR_ATmega1280__ |
avr5 | atmega1281 | __AVR_ATmega1281__ |
avr5 | atmega16 | __AVR_ATmega16__ |
avr5 | atmega161 | __AVR_ATmega161__ |
avr5 | atmega162 | __AVR_ATmega162__ |
avr5 | atmega163 | __AVR_ATmega163__ |
avr5 | atmega164 | __AVR_ATmega164__ |
avr5 | atmega165 | __AVR_ATmega165__ |
avr5 | atmega168 | __AVR_ATmega168__ |
avr5 | atmega169 | __AVR_ATmega169__ |
avr5 | atmega32 | __AVR_ATmega32__ |
avr5 | atmega323 | __AVR_ATmega323__ |
avr5 | atmega324 | __AVR_ATmega324__ |
avr5 | atmega325 | __AVR_ATmega325__ |
avr5 | atmega3250 | __AVR_ATmega3250__ |
avr5 | atmega329 | __AVR_ATmega329__ |
avr5 | atmega3290 | __AVR_ATmega3290__ |
avr5 | atmega64 | __AVR_ATmega64__ |
avr5 | atmega640 | __AVR_ATmega640__ |
avr5 | atmega644 | __AVR_ATmega644__ |
avr5 | atmega645 | __AVR_ATmega645__ |
avr5 | atmega6450 | __AVR_ATmega6450__ |
avr5 | atmega649 | __AVR_ATmega649__ |
avr5 | atmega6490 | __AVR_ATmega6490__ |
avr5 | at94k | __AVR_AT94K__ |
-morder1
-morder2
レジスタ割り当ての順番を指定します。デフォルトは、
r24, r25,
r18, r19, r20, r21, r22, r23,
r30, r31,
r26, r27, r28, r29,
r17, r16,
r15, r14, r13, r12, r11, r10, r9, r8, r7, r6, r5, r4, r3, r2, r0, r1
Order 1 は以下の割り当てを使います。
r18, r19, r20, r21, r22, r23, r24, r25 ,
r30, r31,
r26, r27, r28, r29,
r17, r16,
r15, r14, r13, r12, r11, r10, r9, r8, r7, r6, r5, r4, r3, r2, r0, r1
Order 2 は以下の割り当てを使います。
r25, r24, r23, r22, r21, r20, r19, r18,
r30, r31,
r26, r27, r28, r29,
r17, r16,
r15, r14, r13, r12, r11, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0
-mint8
intを8bit整数にします。これは実際には
avr-libc
でサポートされていないので、通常は使用できません。デフォルトでは16-bit整数値を使います。
-mno-interrupts
割り込みを禁止しないでスタックポインタを書き換えるコードを生成します。通常は、ステータスレジスタ SREG がテンポラリレジスタに保存され、スタックポインタ変更中割り込みは禁止され、最後にSREGが復帰されます(割り込み許可・禁止状態も元に戻されます)。
-mcall-prologues
関数のprologue/epilogue(入口・出口処理)にサブルーチンを使います。たくさんのレジスタ(関数の入口・出口で退避復帰を要する)を使う複雑な関数では、このオプションによって実行速度と引き替えにいくらかのコード量の節約ができます。
-minit-stack=
nnnn 初期のスタックポインタを nnnn に設定します。デフォルトでは、スタックポインタはランタイム初期化コードでRAMENDに設定される
symbol __stack
に設定されます。
-mtiny-stack
スタックポインタの下位8bitだけを変更するようにします。※スタックが0x100以降に配置されないなら利用可能
-mno-tablejump
テーブルジャンプ命令を生成しない。デフォルトでは、switch文を最適化するためにジャンプテーブルが使われます。このオプションによりテーブルジャンプを禁止すると、比較命令の羅列が生成されます。通常はジャンプ命令の方がより高速ですが、ほとんどのジャンプがデフォルトラベルに飛ぶような状況では、フラッシュメモリを無駄にしてしまいます。
-mshort-calls
ROMが8Kを越えるデバイスでもrjmp/rcall
(ジャンプ範囲が限られている)を使う。avr2/avr4アーキテクチャ(ROMが8KB未満)では常にこの状況です。avr3/avr5アーキテクチャでは、現在の関数の外へのジャンプには全アドレス空間をカバーできるjmp/call命令を使いますが、これはコードサイズを大きくして実行速度も低下させます。
-mrtl
"RTL"と呼ばれる内部コンパイル結果をダンプして、generated assemblerコードのコメントに書き込みます。これはavr-gccをデバッグする時に使われます。
-msize
各行の アドレス、サイズ、相対的コストをgenerated assemblerコードのコメントに書き込みます。これはavr-gccをデバッグする時に使われます。
-mdeb
たくさんのデバッグ情報をstderr
に書き出すようにします。
以下の一般的なgccオプションはAVRユーザーにはいくらか興味深いものでしょう。
-O
n 最適化レベル n 。n の値が大きいとより最適化されることを意味し、最適化レベル0は全く最適化を行わない(-O
オプションがない場合のデフォルト)ことを意味します。特別なオプション
-Os
は、コードサイズを増加させない最適化だけをONにすることを意味します。
-O3
指定では、gccはすべての単純な関数をインラインに展開することに注意してください。AVRターゲットでは、これはコードサイズ増大により大変な悲惨化(※)を招きます。-O3
と併用するとよい他の最適化としては、唯一-frename-registers
が上げられますが、これはむしろ(ソース内で)手動で設定されるものでしょう。
※原文ではoptimizeとoptimistを掛けているのか、optimizeの反対語としてpessimizationと書かれています:-)
単なる-O
オプションは-O1
と等価です。
すべての最適化を切ると、最適化の時だけに行われるコード解析ステップに関連するウォーニングが出るのを防ぎます。 (実行されないコードや、使用されない変数などへの警告)
FAQ entry 最適化されたコードに関する項目も参照ください。
-Wa,
assembler-options-Wl,
linker-options アセンブラやリンカにオプションリストを渡します。
-g
avr-gdbで使用されるデバッグ情報を生成します。
-ffreestanding
"freestanding" 実行環境を前提とする。これは自動的に組み込まれる関数をOFFにする。(though they can still be reached by prepending
__builtin_
to the actual function name) これは、コンパイラはmain()
がvoidを返値として宣言されても警告を発しないというマイクロコントローラにはいくらかしっくり来る性質をもたらします。(アプリケーションは意味のあるリターン値を環境に返せないし、ほとんどの場合、main()
はどこにも帰りようがない)
しかしながら、これは確かな名前で知られていて、当然スタンダードとして解説されているとおりの動作を行うとされている関数数類に関する最適化も全部オフにしてしまいます。たとえば、関数 strlen() をリテラル文字列("ABC"のような形)に対して使うとコンパイラはすぐにその文字列の実際の長さを調べて、その値を返すコードに差し替えますが、-ffreestanding
をつけると、常に strlen() をランタイムで呼ぶようになります。
-funsigned-char
符号有無が定義づけられていない char型を unsigned charと見なす。このオプションがない場合は、デフォルトはsigned charとなります。
-funsigned-bitfields
符号有無が定義づけられていない ビットフィールド型を unsigned と見なす。デフォルトはsigned.
-fshort-enums
enum型に対して、とりうる値の範囲を表現するのに最低限のバイトしか割り当てない。つまり、enum型はそれを収容するのに充分な部屋(bit数)を持つ最小の整数型となります。
-fpack-struct
構造体のメンバを隙間を空けずに詰め込む
※uint8_t型とuint16_t型があれば、アドレスを偶数になんて考えずにくっつけて配置するってことかな?
-mmcu=
architecture-mmcu=
MCU name
avr-as understands the same -mmcu=
options as avr-gcc. By default, avr2 is assumed, but this can be altered by using the appropriate .arch pseudo-instruction inside the assembler source file.
-mall-opcodes
Turns off opcode checking for the actual MCU type, and allows any possible AVR opcode to be assembled.
-mno-skip-bug
Don't emit a warning when trying to skip a 2-word instruction with a CPSE/SBIC/SBIS/SBRC/SBRS
instruction. Early AVR devices suffered from a hardware bug where these instructions could not be properly skipped.
-mno-wrap
For RJMP/RCALL
instructions, don't allow the target address to wrap around for devices that have more than 8 KB of memory.
--gstabs
Generate .stabs debugging symbols for assembler source lines. This enables avr-gdb to trace through assembler source files. This option must not be used when assembling sources that have been generated by the C compiler; these files already contain the appropriate line number information from the C source files.
-a[cdhlmns=
file]
Turn on the assembler listing. The sub-options are:
c
omit false conditionals d
omit debugging directives h
include high-level source l
include assembly m
include macro expansions n
omit forms processing s
include symbols =
file set the name of the listing file
The various sub-options can be combined into a single -a
option list; =file must be the last one in that case.
-Wa
(see above), so in order to include the C source code into the assembler listing in file foo.lst
, when compiling foo.c
, the following compiler command-line can be used:
$ avr-gcc -c -O foo.c -o foo.o -Wa,-ahls=foo.lst
In order to pass an assembler file through the C preprocessor first, and have the assembler generate line number debugging information for it, the following command can be used:
$ avr-gcc -c -x assembler-with-cpp -o foo.o foo.S -Wa,--gstabs
Note that on Unix systems that have case-distinguishing file systems, specifying a file name with the suffix .S (upper-case letter S) will make the compiler automatically assume
-x assembler-with-cpp
, while using .s would pass the file directly to the assembler (no preprocessing done).
-l
name
Locate the archive library named lib
name.a
, and use it to resolve currently unresolved symbols from it. The library is searched along a path that consists of builtin pathname entries that have been specified at compile time (e. g. /usr/local/avr/lib
on Unix systems), possibly extended by pathname entries as specified by -L
options (that must precede the -l
options on the command-line).
-L
path
Additional location to look for archive libraries requested by -l
options.
--defsym
symbol=expr Define a global symbol symbol using expr as the value.
-M
Print a linker map to stdout
.
-Map
mapfile Print a linker map to mapfile.
--cref
Output a cross reference table to the map file (in case -Map
is also present), or to stdout
.
--section-start
sectionname=org Start section sectionname at absolute address org.
-Tbss
org-Tdata
org-Ttext
org
Start the bss
, data
, or text
section at org, respectively.
-T
scriptfile
Use scriptfile as the linker script, replacing the default linker script. Default linker scripts are stored in a system-specific location (e. g. under /usr/local/avr/lib/ldscripts
on Unix systems), and consist of the AVR architecture name (avr2 through avr5) with the suffix .x appended. They describe how the various memory sections will be linked together.
.o (object files) and
.a (object libraries) are provided to the linker.
System libraries are usually not passed by their explicit filename but rather using the -l
option which uses an abbreviated form of the archive filename (see above). avr-libc ships two system libraries, libc.a
, and libm.a
. While the standard library libc.a
will always be searched for unresolved references when the linker is started using the C compiler frontend (i. e., there's always at least one implied -lc
option), the mathematics library libm.a
needs to be explicitly requested using -lm
. See also the entry in the FAQ explaining this.
Conventionally, Makefiles use the make
macro LDLIBS
to keep track of -l
(and possibly -L
) options that should only be appended to the C compiler command-line when linking the final binary. In contrast, the macro LDFLAGS
is used to store other command-line options to the C compiler that should be passed as options during the linking stage. The difference is that options are placed early on the command-line, while libraries are put at the end since they are to be used to resolve global symbols that are still unresolved at this point.
Specific linker flags can be passed from the C compiler command-line using the -Wl
compiler option, see above. This option requires that there be no spaces in the appended linker option, while some of the linker options above (like -Map
or --defsym
) would require a space. In these situations, the space can be replaced by an equal sign as well. For example, the following command-line can be used to compile foo.c
into an executable, and also produce a link map that contains a cross-reference list in the file foo.map:
$ avr-gcc -O -o foo.out -Wl,-Map=foo.map -Wl,--cref foo.c
Alternatively, a comma as a placeholder will be replaced by a space before passing the option to the linker. So for a device with external SRAM, the following command-line would cause the linker to place the data segment at address 0x2000 in the SRAM:
$ avr-gcc -mmcu=atmega128 -o foo.out -Wl,-Tdata,0x802000
See the explanation of the data section for why 0x800000 needs to be added to the actual value. Note that unless a -minit-stack
option has been given when compiling the C source file that contains the function main()
, the stack will still remain in internal RAM, through the symbol __stack
that is provided by the run-time startup code. This is probably a good idea anyway (since internal RAM access is faster), and even required for some early devices that had hardware bugs preventing them from using a stack in external RAM. Note also that the heap for malloc()
will still be placed after all the variables in the data section, so in this situation, no stack/heap collision can occur.