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
310
型推論のちょっと深い話
omochi
1
540
Swiftの型推論を学ぼう | Let's Learn About Type Inference in Swift
omochi
4
11k
[スクリプト] Swiftの型推論を学ぼう
omochi
2
530
Swift6のprotocol
omochi
6
1.4k
SwiftSyntaxをうまく使おう
omochi
2
420
今から使えるSwiftとC++の新しいinterop手法
omochi
0
520
CSFixとラベルマッチ
omochi
0
470
Swiftのmodifyアクセサとコルーチン
omochi
0
930
Other Decks in Programming
See All in Programming
Oxcを導入して開発体験が向上した話
yug1224
4
320
Agentic UI
manfredsteyer
PRO
0
180
Contextとはなにか
chiroruxx
1
330
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
710
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
6
1.4k
RTSPクライアントを自作してみた話
simotin13
0
620
OSもどきOS
arkw
0
570
エージェンティックRAGにAWSで入門しよう!
har1101
8
1.7k
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
190
ふつうのFeature Flag実践入門
irof
8
4.1k
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
800
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
260
Featured
See All Featured
Side Projects
sachag
455
43k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
370
Statistics for Hackers
jakevdp
799
230k
How to build a perfect <img>
jonoalderson
1
5.7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Rails Girls Zürich Keynote
gr2m
96
14k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
Technical Leadership for Architectural Decision Making
baasie
3
420
Skip the Path - Find Your Career Trail
mkilby
1
150
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
200
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
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