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
swiftcのmanglingとsubstitution
Search
omochimetaru
June 22, 2018
Programming
230
4
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
swiftcのmanglingとsubstitution
omochimetaru
June 22, 2018
More Decks by omochimetaru
See All by omochimetaru
Swift Concurrency 年表クイズ
omochi
3
320
型推論のちょっと深い話
omochi
1
550
Swiftの型推論を学ぼう | Let's Learn About Type Inference in Swift
omochi
4
11k
[スクリプト] Swiftの型推論を学ぼう
omochi
2
540
Swift6のprotocol
omochi
6
1.4k
SwiftSyntaxをうまく使おう
omochi
2
430
今から使えるSwiftとC++の新しいinterop手法
omochi
0
520
CSFixとラベルマッチ
omochi
0
480
Swiftのmodifyアクセサとコルーチン
omochi
0
930
Other Decks in Programming
See All in Programming
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
590
自動化したのに回らないテスト運用の壁ーAI時代の品質責任と生産性
mfunaki
0
130
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.9k
Laravelで学ぶ Webアプリケーションチューニング入門/web_application_tuning_101
hanhan1978
4
1.7k
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
160
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
490
使いながら育てる Claude Code — 開発フローの1コマンド化 × 繰り返し指摘の自動仕組み化
shiki_kakaku
0
1.7k
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
480
Apache Hive: そしてCloud Native Lakehouseへ
okumin
1
210
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
180
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.5k
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
670
Featured
See All Featured
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
How Software Deployment tools have changed in the past 20 years
geshan
1
34k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
Writing Fast Ruby
sferik
630
63k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.8k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Designing for Performance
lara
611
70k
GraphQLとの向き合い方2022年版
quramy
50
15k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
460
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.2k
AI: The stuff that nobody shows you
jnunemaker
PRO
9
890
Balancing Empowerment & Direction
lara
6
1.2k
Transcript
swiftcͷmanglingͱ Substitution Θ͍Θ͍swiftc #3, 2018/06/22 omochimetaru @ 1
mangling ϓϩάϥϜΛίϯύΠϧͯ͠LLVMόΠφϦʹͳΔͱ͖ɺ ఆؔͳͲͷ໊લ͕ม͞ΕΔɻ ͜ΕΛγϯϘϧ໊ͱݺͿɻ // c.swift func hogehoge() -> Void
{ ... } ; c.ll define hidden swiftcc void @"$S1c8hogehogeyyF"() #0 { ... } 2
γϯϘϧ໊ γϯϘϧ໊ίϯύΠϧ͞ΕͨόΠφϦͷதͰͷ໊લɻ ͱͱͷݴޠͷ໊લ͚ͩͰͳ͘ɺ ༷ʑͳใಉ࣌ʹຒΊࠐ·ΕΔɻ ͜ͷมΛmanglingͱ͍͏ɻ 3
manglingͱSwift γϯϘϧ໊ʹSwiftͷγϯϘϧͰ͋Δ͜ͱΛࣔ͢ϔομ͕ ͘ɻ $S1c8hogehogeyyF $S: SwiftͷγϯϘϧ 4
manglingͱϞδϡʔϧ໊ γϯϘϧ໊ʹϞδϡʔϧؚ໊͕·ΕΔɻ ͜ΕʹΑΓɺผϞδϡʔϧͷಉ໊ΤϯςΟςΟͱিಥ͠ͳ͍ɻ $S1c8hogehogeyyF 1c: "c" ͷ 8hogehoge: "hogehoge" ͜͜ͰϞδϡʔϧ໊
c ࣈΩʔϫʔυͷ͞ϔομ 5
manglingͱΤϯςΟςΟͷछྨ γϯϘϧ໊ʹΤϯςΟςΟͷछྨ͕͍͍ͭͯΔ $S1c8hogehogeyyF F: ؔ ΤϯςΟςΟͷྫ WV: value witness table
fC: allocating init fc: non-allocating init s: property setter g: property getter 6
manglingͱܕใ ؔͷγϯϘϧ໊ʹҾฦΓͷܕ͕͍͍ͭͯΔ $S1c8hogehogeyyF y: ฦΓVoid y: Ҿແ͠ ܕͷྫ Si: Swift.Int
Sf: Swift.Float SS: Swift.String 7
manglingͱܕใ ؔͷγϯϘϧ໊ʹϥϕϧ໊͍͍ͭͯΔ func hogehoge(aaa: Int, bbb: Float) -> String $S1c8hogehoge3aaa3bbbSSSi_SftF
3aaa: "aaa" 3bbb: "bbb" SS: ฦΓString Si: ୈ1ҾInt _: Ϧετ͕ଓ͘ Sf: ୈ2ҾFloat t: ϦετऴΘΓ 8
manglingͱϢʔβఆٛܕ struct Stone { func hogehoge() {} } $S1c5StoneV8hogehogeyyF 1c:
"c" 5Stone: "Stone" V: struct 8hogehoge: "hogehoge" 9
Swift demangle γϯϘϧ໊͔ΒٯมΛͯ͠ɺຒΊࠐ·ΕͨใΛಡΊΔɻ $ swift demangle '$S1c5StoneV8hogehogeyyF' $S1c5StoneV8hogehogeyyF ---> c.Stone.hogehoge()
-> () 10
-expandΦϓγϣϯ͕͓͢͢Ί $ swift demangle -expand '$S1c5StoneV8hogehogeyyF' Demangling for $S1c5StoneV8hogehogeyyF kind=Global
kind=Function kind=Structure kind=Module, text="c" kind=Identifier, text="Stone" kind=Identifier, text="hogehoge" kind=Type kind=FunctionType kind=ArgumentTuple, index=0 kind=Type kind=Tuple kind=ReturnType kind=Type kind=Tuple $S1c5StoneV8hogehogeyyF ---> c.Stone.hogehoge() -> () 11
Substitution 12
manglingͱSubstitution struct Water {} struct Stone { func hogehoge(aaa: Stone,
bbb: Water, ccc: Stone) -> Water { fatalError() } } $S1c5StoneV8hogehoge3aaa3bbb3cccAA5WaterVAC_AiCtF 13
ʁ expect $S1c5StoneV8hogehoge3aaa3bbb3ccc1c5WaterV1c5StoneV_1c5WaterV1c5StoneVtF 1c5WaterV: struct c.Water 1c5StoneV: struct c.Stone 1c5WaterV:
struct c.Water 1c5StoneV: struct c.Stone actual $S1c5StoneV8hogehoge3aaa3bbb3cccAA5WaterVAC_AiCtF AA: ?? 5WaterV: struct Water AC: ?? AiC: ?? 14
Substitution ManglingͷաఔͰग़ݱͨ͠จࣈྻܕ͕ྻʹอଘ͞ΕΔɻ 2Ҏ߱ͷग़ݱ࣌ʹͦͷྻͷΠϯσοΫεͱͯ͠Τϯίʔ υ͞Εɺ σίʔυ࣌ʹͦͷྻͷཁૉʹஔ͞ΕΔɻ ͜ͷػೳΛSubstitution(ஔ)ͱ͍͏ɻ 15
Substitutionͷྫ AA A: ஔ։࢝ A: [0]൪ʹஔ, ஔऴྃ(େจࣈ) AiC i: [8]൪ʹஔ
C: [2]൪ʹஔ, ஔऴྃ(େจࣈ) A2C 2: ࣍ͷஔΛ2ճ܁Γฦ͢ C: [2]൪ʹஔ, ஔऴྃ(େจࣈ) 16
Substitutionͷྫ $S1c5StoneV8hogehoge3aaa3bbb3cccAA5WaterVAC_AiCtF 1c: [0] = "c" 5Stone: [1] = "Stone"
V: [2] = struct c.Stone 8hogehoge: [3] = "hogehoge" 3aaa: [4] = "aaa" 3bbb: [5] = "bbb" 3ccc: [6] = "ccc" AA: "c" from [0] 5Water: [7] = "Water" V: [8] = struct c.Water AC: struct c.Stone from [2] Ai: struct c.Water from [8] C: struct c.Stone from [2] 17
ࢿྉ Mangling https://github.com/apple/swift/blob/master/docs/ABI/ Mangling.rst 18
·ͱΊ • mangling໘ന͍ • swift demangle ศར • substitution͍͢͝ 19
͓ΘΓ 20