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
chapati
October 25, 2024
Programming
280
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
GCCのプラグインを作る / I Made a GCC Plugin
GCCのプラグインを作ったのでLTで話しました
chapati
October 25, 2024
More Decks by chapati
See All by chapati
D言語に入門した話 / Introduction to D language
shouth
0
430
Other Decks in Programming
See All in Programming
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
3
390
AIエージェント時代のコードレビューを設計する
nogu66
6
2.5k
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
130
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
2
1.5k
不幸な GC
chencmd
0
890
思考垂れ流し開発 ~音声入力 × AIエージェント × 開発ハーネスによる試行錯誤~
npostring
0
900
アクセシビリティから考える情報設計
high_g_engineer
0
280
型解析で実現する Go の言語内 DSL / Conference に Go! タイムテーブルの歩き方 for Gophers
mazrean
0
130
What We Talk About When We Talk About XP
m_seki
2
390
Vibes Containers 〜AIで変わるコンテナ設計と運用〜
tkikuc
2
500
自分的「カンファレンスの楽しみ方」
syumai
0
190
Go 1.27からのGODEBUG / Go 1.27 リリースパーティ #go127party
mazrean
0
320
Featured
See All Featured
WENDY [Excerpt]
tessaabrams
12
39k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
440
Six Lessons from altMBA
skipperchong
29
4.5k
Paper Plane (Part 1)
katiecoart
PRO
1
11k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.6k
Bootstrapping a Software Product
garrettdimon
PRO
306
120k
What's in a price? How to price your products and services
michaelherold
247
13k
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
310
Building Adaptive Systems
keathley
44
3.2k
Building Applications with DynamoDB
mza
96
7.2k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
2.1k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.7k
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
というわけでプラグインを作ってみました • コンパイルする時にどういう処理に時間がかかっているのかを調べるためのプラグ インを作りました • 実演します
みなさまもプラグインを使ってよきコンパイルライフを!