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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
1
1.2k
AIエージェントで 変わるAndroid開発環境
takahirom
2
760
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
260
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
580
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
150
その節約、円になってますか?
isamumumu
1
650
そこに3びきプロダクトがいるじゃろう——生成AI時代における“価値が届かない理由”の構造
kosuket
0
380
霧の中の代数的エフェクト
funnyycat
1
450
yield再入門 #phpcon
o0h
PRO
0
870
数百円から始めるRuby電子工作
tarosay
0
120
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
17k
Terraform標準の組織で AWS CDKをどう使うか
mu7889yoon
1
450
Featured
See All Featured
How to Align SEO within the Product Triangle To Get Buy-In & Support - #RIMC
aleyda
2
1.7k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
360
エンジニアに許された特別な時間の終わり
watany
108
250k
The SEO identity crisis: Don't let AI make you average
varn
0
520
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
600
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
340
A Soul's Torment
seathinner
6
3.1k
KATA
mclloyd
PRO
35
15k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Mobile First: as difficult as doing things right
swwweet
225
10k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
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