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
540
Swift6のprotocol
omochi
6
1.4k
SwiftSyntaxをうまく使おう
omochi
2
430
今から使えるSwiftとC++の新しいinterop手法
omochi
0
520
CSFixとラベルマッチ
omochi
0
470
Swiftのmodifyアクセサとコルーチン
omochi
0
930
Other Decks in Programming
See All in Programming
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
14
6.7k
はてなアカウント基盤 State of the Union
cockscomb
1
1.3k
ローカルLLMでどこまでコードが書けるか -縮小版 / How much code can be written on a local LLM Shortened
kishida
2
180
LLM本来の能力を解き放つサンドボックス技術とAI民主化への適用
yukukotani
3
4.9k
20260623_Loop Engineeringで自分の分身の問い合わせBotを作る
ryugen04
0
170
例外の正しい扱い方 そのエラー try-catchして大丈夫?
jinwatanabe
0
340
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
570
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
200
Vue × Nuxt × Oxc どこまで使える?実運用の現在地
andpad
0
360
Strategic Design in the Frontend: Moduliths & Micro Frontends @DDDEurope
manfredsteyer
PRO
0
140
OSINT for SRE: 学術論文とポストモーテムから探る システム障害の共通パターン / SRE NEXT 2026
tomoyk
1
2.5k
OS アップデート対応の取り組み方がもっと共有されてほしい
andpad
0
110
Featured
See All Featured
Docker and Python
trallard
47
3.9k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
440
Ethics towards AI in product and experience design
skipperchong
2
320
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
180
Testing 201, or: Great Expectations
jmmastey
46
8.2k
WENDY [Excerpt]
tessaabrams
11
38k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Building Adaptive Systems
keathley
44
3.1k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
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