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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
chapati
October 25, 2024
Programming
290
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
440
Other Decks in Programming
See All in Programming
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
570
R8 の設定見直しでアプリサイズ削減
andpad
0
190
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
140
The Rails Doctrine Decade
koic
2
550
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
280
dotNET_vulnclicker_intro.pdf
deka_morita
0
130
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.5k
contenteditable と日本語入力に向き合う
colorful12
0
180
phperだってパンチカードでコーディングしたい
o0h
PRO
0
260
外から家のPCの電源入れたい!をPHPで解決する
kawashimo0
1
130
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
600
技術的負債の返済は、AI時代の複利で効く投資 — 経営としての意思決定とその遂行
curekoshimizu
1
2.3k
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
400
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.5k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
370
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
560
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
560
Paper Plane (Part 1)
katiecoart
PRO
2
11k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
540
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
570
YesSQL, Process and Tooling at Scale
rocio
174
15k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
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
というわけでプラグインを作ってみました • コンパイルする時にどういう処理に時間がかかっているのかを調べるためのプラグ インを作りました • 実演します
みなさまもプラグインを使ってよきコンパイルライフを!