Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GCCのプラグインを作る / I Made a GCC Plugin
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
chapati
October 25, 2024
Programming
1
260
GCCのプラグインを作る / I Made a GCC Plugin
GCCのプラグインを作ったのでLTで話しました
chapati
October 25, 2024
Tweet
Share
More Decks by chapati
See All by chapati
D言語に入門した話 / Introduction to D language
shouth
0
400
Other Decks in Programming
See All in Programming
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
280
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
4
440
Linux Kernelの1文字のミスで 権限昇格ができた話
rqda
0
1.9k
AWS×クラウドネイティブソフトウェア設計 / AWS x Cloud-Native Software Design
nrslib
16
3.3k
へんな働き方
yusukebe
5
2.7k
メタプログラミングで実現する「コードを仕様にする」仕組み/nikkei-tech-talk43
nikkei_engineer_recruiting
0
200
AI時代のシステム設計:ドメインモデルで変更しやすさを守る設計戦略
masuda220
PRO
6
1.1k
Java 21/25 Virtual Threads 소개
debop
0
100
Understanding Apache Lucene - More than just full-text search
spinscale
0
130
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
220
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
670
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
520
Featured
See All Featured
AI: The stuff that nobody shows you
jnunemaker
PRO
3
450
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
230
Become a Pro
speakerdeck
PRO
31
5.9k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
770
SEO for Brand Visibility & Recognition
aleyda
0
4.4k
YesSQL, Process and Tooling at Scale
rocio
174
15k
Test your architecture with Archunit
thirion
1
2.2k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.7k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
14k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
310
Transcript
GCCのプラグインを作る 茶葉亭
自己紹介 • 半値:茶葉亭 • 元2023年度あくあたん工房代表 • C++がとくい • 言語処理系がだいすき •
最近はWebAssemblyに興味がある ◦ プラグインシステムを WASMで作るの ロマンがある https://github.com/shouth
GCCって知ってる? • GNU Compiler Collectionの略 • コードをコンパイルしてプログラムを作るために使われるソフトウェア • gcc example.c
-o example
GCCのプラグインってなんぞや • 通常触れる機会はない ◦ なんなら発表者も最近まで知らなかった • 字義通りコンパイラに組み込まれるプラグインのこと ◦ 「プラグイン」を知らんくてもマイクラの modとかは知ってるやろ あれと同じようなもん
なんでGCCのプラグインを作るのか? • 普通にプログラムをコンパイルする用途では必要にならない • デカいソースコードを書いている人たちは必要とすることがある ◦ コンパイラの挙動を知りたいがパッチをあててビルドするのはダルい ◦ コンパイラがソースコードをどのように解釈しているのかを知りたい ◦
コンパイラに機能を組み込んでどこにバグが隠れているか炙り出したい ◦ プログラミング言語を独自に拡張したい ◦ コンパイルされたプログラムのセキュリティを強化したい ◦ コンパイルに時間がかかりすぎている原因を知りたい • 著名なOSSだとLinuxとかがGCCのプラグインを使ってる ◦ https://github.com/torvalds/linux/tree/master/scripts/gcc-plugins
環境構築 Ubuntuの場合 • gcc -v • apt install gcc-<major version>-plugin-dev
具体例 • gcc -v ◦ gcc version 13.2.0 (Ubuntu 13.2.0-23ubuntu4) • apt install gcc-13-plugin-dev
ミニマルなGCCプラグイン g++ -I`g++ -print-file-name=plugin`/include -shared -fPIC <plugin-name>.cpp -o <shared-object>.so みたいな感じでビルドする
ミニマルなGCCプラグイン g++ -fplugin=<shared-object>.so … みたいな感じで使う
ミニマルなGCCプラグイン この例ではコンパイル時に「executing plugin_init」が表示されるだけ
GCCプラグインを使ってできること • GCCの内部状態を好き放題いじることができる! ◦ GCC自体のソースコードに含まれるヘッダがプラグイン向けにも公開されているため ◦ GENERICとかGIMPLEとかRTLとかの中間表現を自由にいじれます ◦ cpp_callbacksやopt_passを操作してコンパイル時に好きな処理を実行させることができます
ドキュメントとか • GNU Compiler Collecion (GCC) Internals ◦ https://gcc.gnu.org/onlinedocs/gccint/ ◦
GCCの内部状態に関しておおよそ全てが記載されている ◦ プラグインを作る時は Plugin API のページを最初に読もう ◦ 読んでも挙動がよくわからない? 大丈夫!GCCのソースコードはGPLv3の下に公開されているよ!!!!!! ▪ ここを読んでもろて … https://github.com/gcc-mirror/gcc/tree/master/gcc
というわけでプラグインを作ってみました • コンパイルする時にどういう処理に時間がかかっているのかを調べるためのプラグ インを作りました • 実演します
みなさまもプラグインを使ってよきコンパイルライフを!