Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
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
GKE で Pod の見方を変えたら、スケールアウト時の挙動を真に捉えられた話
stkk
0
120
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
110
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
130
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
240
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
620
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
110
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
0
450
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
410
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
220
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
100
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
170
Heart of Swift Concurrency
koher
0
760
Featured
See All Featured
Color Theory Basics | Prateek | Gurzu
gurzu
1
470
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.3k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
880
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
sira's awesome portfolio website redesign presentation
elsirapls
0
410
Writing Fast Ruby
sferik
630
63k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
520
Dealing with People You Can't Stand - Big Design 2015
cassininazir
368
27k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Making Projects Easy
brettharned
120
6.8k
The Curse of the Amulet
leimatthew05
3
14k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
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
というわけでプラグインを作ってみました • コンパイルする時にどういう処理に時間がかかっているのかを調べるためのプラグ インを作りました • 実演します
みなさまもプラグインを使ってよきコンパイルライフを!