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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
390
Other Decks in Programming
See All in Programming
AIによる高速開発をどう制御するか? ガードレール設置で開発速度と品質を両立させたチームの事例
tonkotsuboy_com
7
2.3k
例外処理とどう使い分ける?Result型を使ったエラー設計 #burikaigi
kajitack
16
6.1k
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
130
CSC307 Lecture 08
javiergs
PRO
0
670
izumin5210のプロポーザルのネタ探し #tskaigi_msup
izumin5210
1
120
0→1 フロントエンド開発 Tips🚀 #レバテックMeetup
bengo4com
0
570
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
Best-Practices-for-Cortex-Analyst-and-AI-Agent
ryotaroikeda
1
110
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
170
Grafana:建立系統全知視角的捷徑
blueswen
0
330
Automatic Grammar Agreementと Markdown Extended Attributes について
kishikawakatsumi
0
190
2026年 エンジニアリング自己学習法
yumechi
0
130
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
200
Six Lessons from altMBA
skipperchong
29
4.1k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
0
260
BBQ
matthewcrist
89
10k
Optimizing for Happiness
mojombo
379
71k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
What's in a price? How to price your products and services
michaelherold
247
13k
[SF Ruby Conf 2025] Rails X
palkan
1
750
The Illustrated Children's Guide to Kubernetes
chrisshort
51
51k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
66
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
というわけでプラグインを作ってみました • コンパイルする時にどういう処理に時間がかかっているのかを調べるためのプラグ インを作りました • 実演します
みなさまもプラグインを使ってよきコンパイルライフを!