SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Downloaden Sie, um offline zu lesen
1
Tricky implementation
Of Go ARM soft float
Tetsuyuki Kobayashi
2015.2.14 Kernel/VM 探検隊
2015.2.22 YAPF
2
 The latest version of this slide will
be available from here
 http://www.slideshare.net/tetsu.koba/presentati
ons
3
Who am I?
 20+ years involved in embedded systems
 10 years in real time OS, such as iTRON
 10 years in embedded Java Virtual Machine
 Now GCC, Linux, QEMU, Android, …
 Blogs
 http://d.hatena.ne.jp/embedded/
 http://kobablog.wordpress.com/(English)
 Twitter
 @tetsu_koba
4
Golang for ARM Linux
 ツールチェインのビルド
 ソースコードを入手して
$ cd go/src
$ GOOS=linux GOARCH=arm GOARM=5 ./make.bash
 実行型のビルド
 Go コマンドに PATH を通して
$ GOOS=linux GOARCH=arm GOARM=5 go build hello.go
5
GOARM
 GOARM=5
 For armv5, no FPU, soft float
 GOARM=6
 (Default)
 For armv6, VFPv1
 GOARM=7
 For armv7, VFPv3
6
以上。
7
間違えなければ
どうということはない。
8
しかし、
9
間違いから理解が
深まることもある。
10
ツールチェインのビルドミス
$ GOOS=linux GOARCH=arm GOARM=5 ./make.bash
 GOARM を指定しないときは GOARM=6
これを忘れた!
11
ARM$ ./hello
Illegal Instruction
 できた実行ファイルを実機 (armv5, no
FPU) に持って行って実行すると
$ GOOS=linux GOARCH=arm GOARM=5 go build hello.go
12
FPU 命令が混じってた
vldr d2, [r3]
 gdb で illegal instruction を起こした命令を
調べると
ランタイムライブラリが GOARM=6 で
ビルドされているからか!
13
やり直し
$ GOOS=linux GOARCH=arm GOARM=5 ./make.bash
$ GOOS=linux GOARCH=arm GOARM=5 go build hello.go
14
念のために逆アセンブル
$ arm-linux-gnueabi-objdump -d hello
...
bl <_sfloat>
vldr d2, [r3]
fcpyd d4, d2
...
  FPU 命令がまだある?!
15
Go1.4 は armv5 サポート
無くなった?
 git で go1.3, go1.2, go1.1 のそれぞれ
のタグをチェックアウトして調べた
 全て同じだった
16
Soft float emulation
 ARM の Linux kernel には soft float
emulation があった
 kernel を再ビルド
CONFIG_OABI_COMAT=y
CONFIG_FPE_NWFPE=y
 これで動いた!
ARM$ ./hello
Hello, Go
17
しかし
 Go ARM がカーネルコンフィグに依
存するとはどこにも書いてない?
 しかも
 ARM の soft float emulation は
Deprecated
 最近のカーネルではすでに削除されて
いる
18
実は
 soft float emulation を有効にしていな
いカーネルでも hello は動いた
 カーネルのコンフィグは無関係

 ( 本当はツールチェインのビルドを間
違っただけ )
19
謎の関数 _sfloat
...
bl <_sfloat>
vldr d2, [r3]
fcpyd d4, d2
...
フロート演算のコードに共通するパターンを発見。
...
bl <_sfloat>
vldr d2, [r0]
fcmped d3, d2
fmstat
bvs 117fc
...
  FPU 命令の前に必ず
_sfloat を呼び出す
20
_sfloat のソースコードを追跡
 _sfloat in go/src/runtime/vlop_arm.s
 → runtime ・ _sfloat2
 _sfloat2 in go/src/runtime/softfloat_arm.c
 → sfloat2
21
static void sfloat2(void)
{
…
while (skip = stepflt(pc, (uint32*)&regs->r0)){
:
:
pc += skip
}
g->m->ptarg[0] = pc;
}
Soft float emulation inside golang
Comment is source code:
stepflt returns number of words that the fp instruction is occupying,
0 if next instruction isn't float
FPU 命令のインタープリタ
22
// returns number of words that the fp instruction
// is occupying, 0 if next instruction isn't float.
static uint32
stepflt(uint32 *pc, uint32 *regs)
{
...
switch(i & 0xffff0ff0) {
default:
goto done;
case 0xeeb00a40: // F[regd] = F[regm] (MOVF)
m->freglo[regd] = m->freglo[regm];
if(trace)
runtime·printf("*** F[%d] = F[%d] %xn",
regd, regm, m->freglo[regd]);
break;
case 0xeeb00b40: // D[regd] = D[regm] (MOVD)
stepflt は FPU 命令のインタープリタ
23
FPU 命令は CPU で実行されていない
FPU 命令が混じっていても
illegal instruction にならない
...
bl <_sfloat>
vldr d2, [r0]
fcmped d3, d2
fmstat
bvs 117fc
...
_sfloat から戻ってきた後に
この命令から実行再開
24
GOARM=5 と 6 の生成コードの違い
 どちらも FPU 命令を生成する
 GOARM=5 の場合は FPU 命令の塊の前に
_sfloat への呼び出しが挿入される。
( リンカーがこれを行っている )
 生成された FPU 命令は同じ。
 コンパイラは soft float のための命令を生成し
ないので実装がラク。
25
結論
 Golang は自前で soft float emulation する
仕組みを持っている。
 カーネルの soft float emulation は不要。
 正しくビルドすれば普通に動く。
 ついでにわかったこと
 ARM Linux の soft float emulation は
deprecated
26
Q & A
@tetsu_koba
Thank you for listening!

Weitere ähnliche Inhalte

Was ist angesagt?

UEFI時代のブートローダ
UEFI時代のブートローダUEFI時代のブートローダ
UEFI時代のブートローダTakuya ASADA
 
A_road_to_AMBER_simulations_ver_1.0
A_road_to_AMBER_simulations_ver_1.0A_road_to_AMBER_simulations_ver_1.0
A_road_to_AMBER_simulations_ver_1.0Satoshi Kume
 
野良ビルドから見たGentoo
野良ビルドから見たGentoo野良ビルドから見たGentoo
野良ビルドから見たGentooNaohiro Aota
 
20分で理解するdisplaysystem
20分で理解するdisplaysystem20分で理解するdisplaysystem
20分で理解するdisplaysystemmagoroku Yamamoto
 
WebOS Open Source Edition を試してみた
WebOS Open Source Edition を試してみたWebOS Open Source Edition を試してみた
WebOS Open Source Edition を試してみたTetsuyuki Kobayashi
 
WSL2+docker+JupyterとVS Codeリモート環境の構築
WSL2+docker+JupyterとVS Codeリモート環境の構築WSL2+docker+JupyterとVS Codeリモート環境の構築
WSL2+docker+JupyterとVS Codeリモート環境の構築Saito5656
 
Introduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutIntroduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutTaisuke Yamada
 
とある帽子の大蛇料理Ⅱ
とある帽子の大蛇料理Ⅱとある帽子の大蛇料理Ⅱ
とある帽子の大蛇料理ⅡMasami Ichikawa
 
BHyVeってなんや
BHyVeってなんやBHyVeってなんや
BHyVeってなんやTakuya ASADA
 
Bhyve code reading
Bhyve code readingBhyve code reading
Bhyve code readingTakuya ASADA
 
Lagopus, raw socket build
Lagopus, raw socket buildLagopus, raw socket build
Lagopus, raw socket buildMasaru Oki
 
組み込みLinuxでのGolangのススメ
組み込みLinuxでのGolangのススメ組み込みLinuxでのGolangのススメ
組み込みLinuxでのGolangのススメTetsuyuki Kobayashi
 
Linuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くLinuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くTetsuyuki Kobayashi
 

Was ist angesagt? (20)

UEFI時代のブートローダ
UEFI時代のブートローダUEFI時代のブートローダ
UEFI時代のブートローダ
 
Mincs 日本語版
Mincs 日本語版Mincs 日本語版
Mincs 日本語版
 
ZynqMP勉強会
ZynqMP勉強会ZynqMP勉強会
ZynqMP勉強会
 
A_road_to_AMBER_simulations_ver_1.0
A_road_to_AMBER_simulations_ver_1.0A_road_to_AMBER_simulations_ver_1.0
A_road_to_AMBER_simulations_ver_1.0
 
野良ビルドから見たGentoo
野良ビルドから見たGentoo野良ビルドから見たGentoo
野良ビルドから見たGentoo
 
Patch101
Patch101Patch101
Patch101
 
20分で理解するdisplaysystem
20分で理解するdisplaysystem20分で理解するdisplaysystem
20分で理解するdisplaysystem
 
WebOS Open Source Edition を試してみた
WebOS Open Source Edition を試してみたWebOS Open Source Edition を試してみた
WebOS Open Source Edition を試してみた
 
WSL2+docker+JupyterとVS Codeリモート環境の構築
WSL2+docker+JupyterとVS Codeリモート環境の構築WSL2+docker+JupyterとVS Codeリモート環境の構築
WSL2+docker+JupyterとVS Codeリモート環境の構築
 
Vsubuntu
VsubuntuVsubuntu
Vsubuntu
 
initramfsについて
initramfsについてinitramfsについて
initramfsについて
 
Introduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and DracutIntroduction to Initramfs - Initramfs-tools and Dracut
Introduction to Initramfs - Initramfs-tools and Dracut
 
とある帽子の大蛇料理Ⅱ
とある帽子の大蛇料理Ⅱとある帽子の大蛇料理Ⅱ
とある帽子の大蛇料理Ⅱ
 
Rust-DPDK
Rust-DPDKRust-DPDK
Rust-DPDK
 
BHyVeってなんや
BHyVeってなんやBHyVeってなんや
BHyVeってなんや
 
Bhyve code reading
Bhyve code readingBhyve code reading
Bhyve code reading
 
Lagopus, raw socket build
Lagopus, raw socket buildLagopus, raw socket build
Lagopus, raw socket build
 
SystemV IPC
SystemV IPCSystemV IPC
SystemV IPC
 
組み込みLinuxでのGolangのススメ
組み込みLinuxでのGolangのススメ組み込みLinuxでのGolangのススメ
組み込みLinuxでのGolangのススメ
 
Linuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書くLinuxのユーザーランドをinitから全てまるごとgolangで書く
Linuxのユーザーランドをinitから全てまるごとgolangで書く
 

Andere mochten auch

Using QEMU for cross development
Using QEMU for cross developmentUsing QEMU for cross development
Using QEMU for cross developmentTetsuyuki Kobayashi
 
Basic of virtual memory of Linux
Basic of virtual memory of LinuxBasic of virtual memory of Linux
Basic of virtual memory of LinuxTetsuyuki Kobayashi
 
ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?Tetsuyuki Kobayashi
 
Simple and efficient way to get the last log using MMAP
Simple and efficient way to get the last log using MMAPSimple and efficient way to get the last log using MMAP
Simple and efficient way to get the last log using MMAPTetsuyuki Kobayashi
 
Reusing your existing software on Android
Reusing your existing software on AndroidReusing your existing software on Android
Reusing your existing software on AndroidTetsuyuki Kobayashi
 
Linux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringLinux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringGeorg Schönberger
 
Android Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersAndroid Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersReto Meier
 
Android HAL Introduction: libhardware and its legacy
Android HAL Introduction: libhardware and its legacyAndroid HAL Introduction: libhardware and its legacy
Android HAL Introduction: libhardware and its legacyJollen Chen
 
ABA TECHSHOW 2016 - Common Grounds: 60 Android and iOS Apps for Lawyers
ABA TECHSHOW 2016 - Common Grounds: 60 Android and iOS Apps for LawyersABA TECHSHOW 2016 - Common Grounds: 60 Android and iOS Apps for Lawyers
ABA TECHSHOW 2016 - Common Grounds: 60 Android and iOS Apps for LawyersBrian Focht
 
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Joemarie Amparo
 

Andere mochten auch (20)

ARM 64bit has come!
ARM 64bit has come!ARM 64bit has come!
ARM 64bit has come!
 
Tips of Malloc & Free
Tips of Malloc & FreeTips of Malloc & Free
Tips of Malloc & Free
 
Using QEMU for cross development
Using QEMU for cross developmentUsing QEMU for cross development
Using QEMU for cross development
 
Basic of virtual memory of Linux
Basic of virtual memory of LinuxBasic of virtual memory of Linux
Basic of virtual memory of Linux
 
Android ipm 20110409
Android ipm 20110409Android ipm 20110409
Android ipm 20110409
 
ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?ADB(Android Debug Bridge): How it works?
ADB(Android Debug Bridge): How it works?
 
Simple and efficient way to get the last log using MMAP
Simple and efficient way to get the last log using MMAPSimple and efficient way to get the last log using MMAP
Simple and efficient way to get the last log using MMAP
 
QEMU in Cross building
QEMU in Cross buildingQEMU in Cross building
QEMU in Cross building
 
Android On Ubuntu for developer
Android On Ubuntu for developerAndroid On Ubuntu for developer
Android On Ubuntu for developer
 
Logging system of Android
Logging system of AndroidLogging system of Android
Logging system of Android
 
Reusing your existing software on Android
Reusing your existing software on AndroidReusing your existing software on Android
Reusing your existing software on Android
 
Logging system of Android
Logging system of AndroidLogging system of Android
Logging system of Android
 
Linux Performance Profiling and Monitoring
Linux Performance Profiling and MonitoringLinux Performance Profiling and Monitoring
Linux Performance Profiling and Monitoring
 
Android Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App DevelopersAndroid Protips: Advanced Topics for Expert Android App Developers
Android Protips: Advanced Topics for Expert Android App Developers
 
Android HAL Introduction: libhardware and its legacy
Android HAL Introduction: libhardware and its legacyAndroid HAL Introduction: libhardware and its legacy
Android HAL Introduction: libhardware and its legacy
 
ABA TECHSHOW 2016 - Common Grounds: 60 Android and iOS Apps for Lawyers
ABA TECHSHOW 2016 - Common Grounds: 60 Android and iOS Apps for LawyersABA TECHSHOW 2016 - Common Grounds: 60 Android and iOS Apps for Lawyers
ABA TECHSHOW 2016 - Common Grounds: 60 Android and iOS Apps for Lawyers
 
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
Efficient Android Threading
Efficient Android ThreadingEfficient Android Threading
Efficient Android Threading
 
Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1Android Development for Beginners with Sample Project - Day 1
Android Development for Beginners with Sample Project - Day 1
 

Ähnlich wie Tricky implementation of Go ARM soft float

Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Tetsuyuki Kobayashi
 
組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ(Go con版)組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ(Go con版)Tetsuyuki Kobayashi
 
Programming camp Codereading
Programming camp CodereadingProgramming camp Codereading
Programming camp CodereadingHiro Yoshioka
 
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】Masahito Zembutsu
 
今だからこそ知りたい Docker Compose/Swarm 入門
今だからこそ知りたい Docker Compose/Swarm 入門今だからこそ知りたい Docker Compose/Swarm 入門
今だからこそ知りたい Docker Compose/Swarm 入門Masahito Zembutsu
 
コンテナ情報交換会2
コンテナ情報交換会2コンテナ情報交換会2
コンテナ情報交換会2Masahide Yamamoto
 
ラズパイ2で動く Docker PaaS
ラズパイ2で動く Docker PaaSラズパイ2で動く Docker PaaS
ラズパイ2で動く Docker PaaSnpsg
 
スタート低レイヤー #0
スタート低レイヤー #0スタート低レイヤー #0
スタート低レイヤー #0Kiwamu Okabe
 
Flutterを体験してみませんか
Flutterを体験してみませんかFlutterを体験してみませんか
Flutterを体験してみませんかcch-robo
 
Rubyで創るOpenFlowネットワーク - LLまつり
Rubyで創るOpenFlowネットワーク - LLまつりRubyで創るOpenFlowネットワーク - LLまつり
Rubyで創るOpenFlowネットワーク - LLまつりYuya Rin
 
Docker調査20150704
Docker調査20150704Docker調査20150704
Docker調査20150704HommasSlide
 
勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る
勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る
勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作るKenichiro MATOHARA
 
2014 dart flight school in Tokyo
2014 dart flight school in Tokyo2014 dart flight school in Tokyo
2014 dart flight school in Tokyonothingcosmos
 
ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)
ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)
ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)inaz2
 
Vim の開発環境
Vim の開発環境Vim の開発環境
Vim の開発環境eagletmt
 
ホームディレクトリに埋もれた便利なコードをさがせ!
ホームディレクトリに埋もれた便利なコードをさがせ!ホームディレクトリに埋もれた便利なコードをさがせ!
ホームディレクトリに埋もれた便利なコードをさがせ!Yohei Fushii
 

Ähnlich wie Tricky implementation of Go ARM soft float (20)

Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
Raspberry Pi Zero とカメラモジュールで作るライブ配信実験機
 
組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ(Go con版)組み込みLinuxでのGolangのススメ(Go con版)
組み込みLinuxでのGolangのススメ(Go con版)
 
Programming camp Codereading
Programming camp CodereadingProgramming camp Codereading
Programming camp Codereading
 
about DakotagUI
about DakotagUIabout DakotagUI
about DakotagUI
 
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
Docker入門-基礎編 いまから始めるDocker管理【2nd Edition】
 
今だからこそ知りたい Docker Compose/Swarm 入門
今だからこそ知りたい Docker Compose/Swarm 入門今だからこそ知りたい Docker Compose/Swarm 入門
今だからこそ知りたい Docker Compose/Swarm 入門
 
カーネルモジュールプログラミング超入門 #1(仮)
カーネルモジュールプログラミング超入門 #1(仮)カーネルモジュールプログラミング超入門 #1(仮)
カーネルモジュールプログラミング超入門 #1(仮)
 
コンテナ情報交換会2
コンテナ情報交換会2コンテナ情報交換会2
コンテナ情報交換会2
 
Pdp11 on-fpga
Pdp11 on-fpgaPdp11 on-fpga
Pdp11 on-fpga
 
ラズパイ2で動く Docker PaaS
ラズパイ2で動く Docker PaaSラズパイ2で動く Docker PaaS
ラズパイ2で動く Docker PaaS
 
Hudson using Groovy #jggug
Hudson using Groovy  #jggugHudson using Groovy  #jggug
Hudson using Groovy #jggug
 
スタート低レイヤー #0
スタート低レイヤー #0スタート低レイヤー #0
スタート低レイヤー #0
 
Flutterを体験してみませんか
Flutterを体験してみませんかFlutterを体験してみませんか
Flutterを体験してみませんか
 
Rubyで創るOpenFlowネットワーク - LLまつり
Rubyで創るOpenFlowネットワーク - LLまつりRubyで創るOpenFlowネットワーク - LLまつり
Rubyで創るOpenFlowネットワーク - LLまつり
 
Docker調査20150704
Docker調査20150704Docker調査20150704
Docker調査20150704
 
勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る
勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る
勉強会向けサーバを作ってみる2 / Rasbian jessieを試す/ Google Authenticatorのパスコードを作る
 
2014 dart flight school in Tokyo
2014 dart flight school in Tokyo2014 dart flight school in Tokyo
2014 dart flight school in Tokyo
 
ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)
ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)
ROP Illmatic: Exploring Universal ROP on glibc x86-64 (ja)
 
Vim の開発環境
Vim の開発環境Vim の開発環境
Vim の開発環境
 
ホームディレクトリに埋もれた便利なコードをさがせ!
ホームディレクトリに埋もれた便利なコードをさがせ!ホームディレクトリに埋もれた便利なコードをさがせ!
ホームディレクトリに埋もれた便利なコードをさがせ!
 

Mehr von Tetsuyuki Kobayashi

Mehr von Tetsuyuki Kobayashi (11)

some topic of ffmpeg
some topic of ffmpeg some topic of ffmpeg
some topic of ffmpeg
 
New VIdeo CODEC AV1
New VIdeo CODEC AV1 New VIdeo CODEC AV1
New VIdeo CODEC AV1
 
Try new transport protocol SRT (ver. 2)
Try new transport protocol SRT  (ver. 2)Try new transport protocol SRT  (ver. 2)
Try new transport protocol SRT (ver. 2)
 
Try new transport protocol SRT
Try new transport protocol SRTTry new transport protocol SRT
Try new transport protocol SRT
 
Virtual memory 20070222-en
Virtual memory 20070222-enVirtual memory 20070222-en
Virtual memory 20070222-en
 
Tweaking Google TV emulator
Tweaking Google TV emulatorTweaking Google TV emulator
Tweaking Google TV emulator
 
Inter-process communication of Android
Inter-process communication of AndroidInter-process communication of Android
Inter-process communication of Android
 
Android is NOT just 'Java on Linux'
Android is NOT just 'Java on Linux'Android is NOT just 'Java on Linux'
Android is NOT just 'Java on Linux'
 
Init of Android
Init of AndroidInit of Android
Init of Android
 
Let's play with Goldfish
Let's play with GoldfishLet's play with Goldfish
Let's play with Goldfish
 
Opensource Android
Opensource AndroidOpensource Android
Opensource Android
 

Kürzlich hochgeladen

20240412_HCCJP での Windows Server 2025 Active Directory
20240412_HCCJP での Windows Server 2025 Active Directory20240412_HCCJP での Windows Server 2025 Active Directory
20240412_HCCJP での Windows Server 2025 Active Directoryosamut
 
IoT in the era of generative AI, Thanks IoT ALGYAN.pptx
IoT in the era of generative AI, Thanks IoT ALGYAN.pptxIoT in the era of generative AI, Thanks IoT ALGYAN.pptx
IoT in the era of generative AI, Thanks IoT ALGYAN.pptxAtomu Hidaka
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
PHP-Conference-Odawara-2024-04-000000000
PHP-Conference-Odawara-2024-04-000000000PHP-Conference-Odawara-2024-04-000000000
PHP-Conference-Odawara-2024-04-000000000Shota Ito
 
新人研修のまとめ 2024/04/12の勉強会で発表されたものです。
新人研修のまとめ       2024/04/12の勉強会で発表されたものです。新人研修のまとめ       2024/04/12の勉強会で発表されたものです。
新人研修のまとめ 2024/04/12の勉強会で発表されたものです。iPride Co., Ltd.
 
UPWARD_share_company_information_20240415.pdf
UPWARD_share_company_information_20240415.pdfUPWARD_share_company_information_20240415.pdf
UPWARD_share_company_information_20240415.pdffurutsuka
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。iPride Co., Ltd.
 

Kürzlich hochgeladen (9)

20240412_HCCJP での Windows Server 2025 Active Directory
20240412_HCCJP での Windows Server 2025 Active Directory20240412_HCCJP での Windows Server 2025 Active Directory
20240412_HCCJP での Windows Server 2025 Active Directory
 
IoT in the era of generative AI, Thanks IoT ALGYAN.pptx
IoT in the era of generative AI, Thanks IoT ALGYAN.pptxIoT in the era of generative AI, Thanks IoT ALGYAN.pptx
IoT in the era of generative AI, Thanks IoT ALGYAN.pptx
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
PHP-Conference-Odawara-2024-04-000000000
PHP-Conference-Odawara-2024-04-000000000PHP-Conference-Odawara-2024-04-000000000
PHP-Conference-Odawara-2024-04-000000000
 
新人研修のまとめ 2024/04/12の勉強会で発表されたものです。
新人研修のまとめ       2024/04/12の勉強会で発表されたものです。新人研修のまとめ       2024/04/12の勉強会で発表されたものです。
新人研修のまとめ 2024/04/12の勉強会で発表されたものです。
 
UPWARD_share_company_information_20240415.pdf
UPWARD_share_company_information_20240415.pdfUPWARD_share_company_information_20240415.pdf
UPWARD_share_company_information_20240415.pdf
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
 

Tricky implementation of Go ARM soft float

  • 1. 1 Tricky implementation Of Go ARM soft float Tetsuyuki Kobayashi 2015.2.14 Kernel/VM 探検隊 2015.2.22 YAPF
  • 2. 2  The latest version of this slide will be available from here  http://www.slideshare.net/tetsu.koba/presentati ons
  • 3. 3 Who am I?  20+ years involved in embedded systems  10 years in real time OS, such as iTRON  10 years in embedded Java Virtual Machine  Now GCC, Linux, QEMU, Android, …  Blogs  http://d.hatena.ne.jp/embedded/  http://kobablog.wordpress.com/(English)  Twitter  @tetsu_koba
  • 4. 4 Golang for ARM Linux  ツールチェインのビルド  ソースコードを入手して $ cd go/src $ GOOS=linux GOARCH=arm GOARM=5 ./make.bash  実行型のビルド  Go コマンドに PATH を通して $ GOOS=linux GOARCH=arm GOARM=5 go build hello.go
  • 5. 5 GOARM  GOARM=5  For armv5, no FPU, soft float  GOARM=6  (Default)  For armv6, VFPv1  GOARM=7  For armv7, VFPv3
  • 10. 10 ツールチェインのビルドミス $ GOOS=linux GOARCH=arm GOARM=5 ./make.bash  GOARM を指定しないときは GOARM=6 これを忘れた!
  • 11. 11 ARM$ ./hello Illegal Instruction  できた実行ファイルを実機 (armv5, no FPU) に持って行って実行すると $ GOOS=linux GOARCH=arm GOARM=5 go build hello.go
  • 12. 12 FPU 命令が混じってた vldr d2, [r3]  gdb で illegal instruction を起こした命令を 調べると ランタイムライブラリが GOARM=6 で ビルドされているからか!
  • 13. 13 やり直し $ GOOS=linux GOARCH=arm GOARM=5 ./make.bash $ GOOS=linux GOARCH=arm GOARM=5 go build hello.go
  • 14. 14 念のために逆アセンブル $ arm-linux-gnueabi-objdump -d hello ... bl <_sfloat> vldr d2, [r3] fcpyd d4, d2 ...   FPU 命令がまだある?!
  • 15. 15 Go1.4 は armv5 サポート 無くなった?  git で go1.3, go1.2, go1.1 のそれぞれ のタグをチェックアウトして調べた  全て同じだった
  • 16. 16 Soft float emulation  ARM の Linux kernel には soft float emulation があった  kernel を再ビルド CONFIG_OABI_COMAT=y CONFIG_FPE_NWFPE=y  これで動いた! ARM$ ./hello Hello, Go
  • 17. 17 しかし  Go ARM がカーネルコンフィグに依 存するとはどこにも書いてない?  しかも  ARM の soft float emulation は Deprecated  最近のカーネルではすでに削除されて いる
  • 18. 18 実は  soft float emulation を有効にしていな いカーネルでも hello は動いた  カーネルのコンフィグは無関係   ( 本当はツールチェインのビルドを間 違っただけ )
  • 19. 19 謎の関数 _sfloat ... bl <_sfloat> vldr d2, [r3] fcpyd d4, d2 ... フロート演算のコードに共通するパターンを発見。 ... bl <_sfloat> vldr d2, [r0] fcmped d3, d2 fmstat bvs 117fc ...   FPU 命令の前に必ず _sfloat を呼び出す
  • 20. 20 _sfloat のソースコードを追跡  _sfloat in go/src/runtime/vlop_arm.s  → runtime ・ _sfloat2  _sfloat2 in go/src/runtime/softfloat_arm.c  → sfloat2
  • 21. 21 static void sfloat2(void) { … while (skip = stepflt(pc, (uint32*)&regs->r0)){ : : pc += skip } g->m->ptarg[0] = pc; } Soft float emulation inside golang Comment is source code: stepflt returns number of words that the fp instruction is occupying, 0 if next instruction isn't float FPU 命令のインタープリタ
  • 22. 22 // returns number of words that the fp instruction // is occupying, 0 if next instruction isn't float. static uint32 stepflt(uint32 *pc, uint32 *regs) { ... switch(i & 0xffff0ff0) { default: goto done; case 0xeeb00a40: // F[regd] = F[regm] (MOVF) m->freglo[regd] = m->freglo[regm]; if(trace) runtime·printf("*** F[%d] = F[%d] %xn", regd, regm, m->freglo[regd]); break; case 0xeeb00b40: // D[regd] = D[regm] (MOVD) stepflt は FPU 命令のインタープリタ
  • 23. 23 FPU 命令は CPU で実行されていない FPU 命令が混じっていても illegal instruction にならない ... bl <_sfloat> vldr d2, [r0] fcmped d3, d2 fmstat bvs 117fc ... _sfloat から戻ってきた後に この命令から実行再開
  • 24. 24 GOARM=5 と 6 の生成コードの違い  どちらも FPU 命令を生成する  GOARM=5 の場合は FPU 命令の塊の前に _sfloat への呼び出しが挿入される。 ( リンカーがこれを行っている )  生成された FPU 命令は同じ。  コンパイラは soft float のための命令を生成し ないので実装がラク。
  • 25. 25 結論  Golang は自前で soft float emulation する 仕組みを持っている。  カーネルの soft float emulation は不要。  正しくビルドすれば普通に動く。  ついでにわかったこと  ARM Linux の soft float emulation は deprecated
  • 26. 26 Q & A @tetsu_koba Thank you for listening!