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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
510
CSFixとラベルマッチ
omochi
0
470
Swiftのmodifyアクセサとコルーチン
omochi
0
930
Other Decks in Programming
See All in Programming
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
620
ふつうのFeature Flag実践入門
irof
7
3.9k
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.9k
さぁV100、メモリをお食べ・・・
nilpe
0
140
Mujeres en SEO Summit 2026 - Greatest Disaster Hits en Web Performance
guaca
0
170
PHPで使える日時の表現と、その知り方 #frontend_phpcon_do
o0h
PRO
0
230
A2UI という光を覗いてみる
satohjohn
1
130
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
750
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
160
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
7
4.3k
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
5.7k
Featured
See All Featured
Exploring anti-patterns in Rails
aemeredith
3
410
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
330
[SF Ruby Conf 2025] Rails X
palkan
2
1.1k
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
420
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.6k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
310
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Git: the NoSQL Database
bkeepers
PRO
432
67k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
The SEO identity crisis: Don't let AI make you average
varn
0
490
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
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