Upgrade to Pro — share decks privately, control downloads, hide ads and more …

swiftcのmanglingとsubstitution

 swiftcのmanglingとsubstitution

omochimetaru

June 22, 2018
Tweet

More Decks by omochimetaru

Other Decks in Programming

Transcript

  1. manglingͱܕ৘ใ ؔ਺ͷγϯϘϧ໊ʹ͸ϥϕϧ໊΋͍͍ͭͯΔ func hogehoge(aaa: Int, bbb: Float) -> String $S1c8hogehoge3aaa3bbbSSSi_SftF

    3aaa: "aaa" 3bbb: "bbb" SS: ฦΓ஋͸String Si: ୈ1Ҿ਺͸Int _: Ϧετ͕ଓ͘ Sf: ୈ2Ҿ਺͸Float t: Ϧετ͸ऴΘΓ 8
  2. -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
  3. manglingͱSubstitution struct Water {} struct Stone { func hogehoge(aaa: Stone,

    bbb: Water, ccc: Stone) -> Water { fatalError() } } $S1c5StoneV8hogehoge3aaa3bbb3cccAA5WaterVAC_AiCtF 13
  4. ʁ 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
  5. Substitutionͷྫ AA A: ஔ׵։࢝ A: [0]൪ʹஔ׵, ஔ׵ऴྃ(େจࣈ) AiC i: [8]൪ʹஔ׵

    C: [2]൪ʹஔ׵, ஔ׵ऴྃ(େจࣈ) A2C 2: ࣍ͷஔ׵Λ2ճ܁Γฦ͢ C: [2]൪ʹஔ׵, ஔ׵ऴྃ(େจࣈ) 16
  6. 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