Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.3. No stdlib #121

Merged
merged 4 commits into from
Mar 28, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 54 additions & 40 deletions 1.6/ja/book/no-stdlib.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,51 @@
% No stdlib

Rust’s standard library provides a lot of useful functionality, but assumes
support for various features of its host system: threads, networking, heap
allocation, and others. There are systems that do not have these features,
however, and Rust can work with those too! To do so, we tell Rust that we
don’t want to use the standard library via an attribute: `#![no_std]`.

> Note: This feature is technically stable, but there are some caveats. For
> one, you can build a `#![no_std]` _library_ on stable, but not a _binary_.
> For details on libraries without the standard library, see [the chapter on
> `#![no_std]`](using-rust-without-the-standard-library.html)

Obviously there's more to life than just libraries: one can use
`#[no_std]` with an executable, controlling the entry point is
possible in two ways: the `#[start]` attribute, or overriding the
default shim for the C `main` function with your own.

The function marked `#[start]` is passed the command line parameters
in the same format as C:
%No stdlib
<!-- % No stdlib -->

<!-- Rust’s standard library provides a lot of useful functionality, but assumes -->
<!-- support for various features of its host system: threads, networking, heap -->
<!-- allocation, and others. There are systems that do not have these features, -->
<!-- however, and Rust can work with those too! To do so, we tell Rust that we -->
<!-- don’t want to use the standard library via an attribute: `#![no_std]`. -->
Rustの標準ライブラリはたくさんの有用な機能を提供していますが、スレッド、ネットワーク、ヒープ割り当てなど、さまざまな機能についてホストシステムのサポートがあることを前提としています。しかし、それらの機能を持たないシステムは存在しますし、Rustはそういったシステム上でも動作します。そのためには、 `#![no_std]` アトリビュートを使って標準ライブラリを使用しないことを示します。

<!-- > Note: This feature is technically stable, but there are some caveats. For -->
<!-- > one, you can build a `#![no_std]` _library_ on stable, but not a _binary_. -->
<!-- > For details on libraries without the standard library, see [the chapter on -->
<!-- > `#![no_std]`](using-rust-without-the-standard-library.html) -->
> 注記: このフィーチャは技術的には安定していますが、いくつかの注意点があります。例えば、 `#![no_std]` を含んだ _ライブラリ_ は安定版でビルドできますが、 _バイナリ_ はそうではありません。標準ライブラリを使用しないライブラリについての詳細は [`#![no_std]` についてのドキュメント](using-rust-without-the-standard-library.html) を参照してください。

<!-- Obviously there's more to life than just libraries: one can use -->
<!-- `#[no_std]` with an executable, controlling the entry point is -->
<!-- possible in two ways: the `#[start]` attribute, or overriding the -->
<!-- default shim for the C `main` function with your own. -->
当然のことですが、ライブラリだけが全てではなく、実行可能形式においても `#[no_std]` は使用できます。このときエントリポイントを指定する方法には2種類あり、1つは `#[start]` アトリビュート、もう1つはCの `main` 関数の上書きです。

<!-- The function marked `#[start]` is passed the command line parameters -->
<!-- in the same format as C: -->
`#[start]` のついた関数へはCと同じフォーマットでコマンドライン引数が渡されます。

```rust
# #![feature(libc)]
#![feature(lang_items)]
#![feature(start)]
#![no_std]

// Pull in the system libc library for what crt0.o likely requires
# //// Pull in the system libc library for what crt0.o likely requires
// crt0.oが必要としていると思われるもののためにシステムのlibcライブラリを参照します。
extern crate libc;

// Entry point for this program
# //// Entry point for this program
// このプログラムのエントリポイントです
#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
0
}

// These functions and traits are used by the compiler, but not
// for a bare-bones hello world. These are normally
// provided by libstd.
# //// These functions and traits are used by the compiler, but not
# //// for a bare-bones hello world. These are normally
# //// provided by libstd.
// これらの関数とトレイトは必要最小限のhello worldのようなプログラムが
// 使うのではなく、コンパイラが使います。通常これらはlibstdにより提供されます。
#[lang = "eh_personality"] extern fn eh_personality() {}
#[lang = "panic_fmt"] fn panic_fmt() -> ! { loop {} }
# #[lang = "eh_unwind_resume"] extern fn rust_eh_unwind_resume() {}
Expand All @@ -45,10 +54,11 @@ fn start(_argc: isize, _argv: *const *const u8) -> isize {
# // fn main() {} tricked you, rustdoc!
```

To override the compiler-inserted `main` shim, one has to disable it
with `#![no_main]` and then create the appropriate symbol with the
correct ABI and the correct name, which requires overriding the
compiler's name mangling too:
<!-- To override the compiler-inserted `main` shim, one has to disable it -->
<!-- with `#![no_main]` and then create the appropriate symbol with the -->
<!-- correct ABI and the correct name, which requires overriding the -->
<!-- compiler's name mangling too: -->
コンパイラによって挿入される `main` を上書きするには、まず `#![no_main]` によってコンパイラによる挿入を無効にします。その上で、正しいABIと正しい名前を備えたシンボルを作成します。これにはコンパイラの名前マングリングを上書きする必要もあります。

```rust
# #![feature(libc)]
Expand All @@ -59,7 +69,9 @@ compiler's name mangling too:

extern crate libc;

#[no_mangle] // ensure that this symbol is called `main` in the output
# //#[no_mangle] // ensure that this symbol is called `main` in the output
#[no_mangle] // 出力結果においてこのシンボル名が `main` になることを保証します。

pub extern fn main(argc: i32, argv: *const *const u8) -> i32 {
0
}
Expand All @@ -73,14 +85,16 @@ pub extern fn main(argc: i32, argv: *const *const u8) -> i32 {
```


The compiler currently makes a few assumptions about symbols which are available
in the executable to call. Normally these functions are provided by the standard
library, but without it you must define your own.
<!-- The compiler currently makes a few assumptions about symbols which are available -->
<!-- in the executable to call. Normally these functions are provided by the standard -->
<!-- library, but without it you must define your own. -->
今のところ、コンパイラは実行可能形式においていくつかのシンボルが呼び出し可能であるという前提を置いています。通常、これらの関数は標準ライブラリが提供しますが、それを使わない場合自分で定義しなければなりません。

The first of these two functions, `eh_personality`, is used by the
failure mechanisms of the compiler. This is often mapped to GCC's
personality function (see the
[libstd implementation](../std/rt/unwind/index.html) for more
information), but crates which do not trigger a panic can be assured
that this function is never called. The second function, `panic_fmt`, is
also used by the failure mechanisms of the compiler.
<!-- The first of these two functions, `eh_personality`, is used by the -->
<!-- failure mechanisms of the compiler. This is often mapped to GCC's -->
<!-- personality function (see the -->
<!-- [libstd implementation](../std/rt/unwind/index.html) for more -->
<!-- information), but crates which do not trigger a panic can be assured -->
<!-- that this function is never called. The second function, `panic_fmt`, is -->
<!-- also used by the failure mechanisms of the compiler. -->
2つある関数のうち1つ目は `eh_personality` で、コンパイラの失敗メカニズムに使われます。これはしばしばGCCのpersonality関数に割り当てられますが(詳細は[libstd実装](../std/rt/unwind/index.html)を参照してください)、パニックを発生させないクレートではこの関数は呼ばれないことが保証されています。2つ目の関数は `panic_fmt` で、こちらもコンパイラの失敗メカニズムのために使われます。
3 changes: 3 additions & 0 deletions TranslationTable.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
| coercion | 型強制
| combinator | コンビネータ
| comma | カンマ
| command line | コマンドライン
| compile-time error | コンパイル時エラー
| compiler | コンパイラ
| composable | 合成可能
Expand Down Expand Up @@ -63,11 +64,13 @@
| early return | 早期リターン
| empty tuple | 空タプル
| encode | エンコード
| entry point | エントリポイント
| enum | 列挙型
| equality | 等値性
| ergonomic | エルゴノミック(人間にとって扱いやすいもの)
| error | エラー
| error handling | エラーハンドリング
| executable | 実行可能形式
| existentially quantified type | 存在量型
| expression statement | 式文
| exterior | 外側の
Expand Down