Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Modifying il2cpp generated code before binary build step

Discussion in 'Scripting' started by JustAnotherName, Jun 21, 2020.

  1. JustAnotherName

    JustAnotherName

    Joined:
    Sep 27, 2017
    Posts:
    11
    I'm interested in injecting a .h header #include as well as some C++ macro signatures into the generated C++ code for il2cpp builds. Does Unity currently support subscribing to build steps to enable this kind of automated code modification? If not; is it possible to run a manual build from il2cppOutput for GameAssembly.dll?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,773
    No neither is supported by IL2CPP. Can you elaborate on your use case though? Maybe we can help in another way.
     
    JustAnotherName likes this.
  3. JustAnotherName

    JustAnotherName

    Joined:
    Sep 27, 2017
    Posts:
    11
    For most software virtualization products, we require the ability to insert C++ macros and a header file to emit opcodes in the PE which the protection toolchain can pick up for virtualization of methods. Naturally being able to hook into an il2cpp build right after the .cpp files are generated, but before the executable is compiled, for proprietary code modification is useful. I'm aware of being able to generate a visual studio solution which would solve this issue for Windows builds but I don't know how that would work for macos. I see https://docs.unity3d.com/ScriptReference/Build.IIl2CppProcessor.html but unfortunately only a binding for before .cpp generation and not after .cpp generation.

    Alternatively I can do these integrations easily if I could have a GameAssembly.dll .map file produced.
     
    Last edited: Jun 22, 2020
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,773
    Note that it is possible to generate an Xcode project on macOS, similar to the Visual Studio solution.

    Also, you can pass custom linker arguments to il2cpp.exe - these will be passed on to the native linker. So it is possible to have the linker generate a map file. See this answer for more details: https://answers.unity.com/questions/1610105/how-to-add-compiler-or-linker-flags-for-il2cpp-inv.html
     
    JustAnotherName likes this.
  5. JustAnotherName

    JustAnotherName

    Joined:
    Sep 27, 2017
    Posts:
    11
    Thanks! I think I can automate the build processes enough with the xcode and visual studio solution options. Of course I'd prefer to have an event that I could subscribe to during Unity's build process instead but invoking a build from the command line with the xcode or visual studio solution will work just fine!
     
    JoshPeterson likes this.