dynamic framework: how to hide the local symbols?
Asked Answered
N

2

2

I am building an .xcframework which contains an iphonesimulator and iphoneos frameworks. There is some Swift code, and some C++ code, which is linked into a shared object (Mach-O 64-bit dynamically linked shared library arm64). I build my C++ with -fvisibility=hidden, and only the symbols that I explicitly mark, are exported. But, when I run nm -gC, I see all kinds of symbols that are still there – and they are visible even in the iOS app that is built using this framework. For example, I have an inner class Secret (it is only used in one cpp file). And nm -gC shows me (and all hackers out there)

00010292 t Secret::getString() const

Is there a way to hide this and other sensitive information?

And, on the other hand, how can I keep the auto-generated _AlexSDKVersionNumber exported?

Neumeyer answered 5/9, 2021 at 19:44 Comment(2)
This has no 'significant' size bearings. Is that right?Metrology
@Metrology no, the size implications are irrelevantNeumeyer
T
1

You should configure your project settings correctly for Stripping to hide internal names.

Go to Your target > Build Settings > Deployment:

  1. Set Deployment Postprocessing to YES to enable Stripping.

  2. Set Strip Style to Non-Global Symbols.

Now nm should provide global (external) symbols only for your binary.

Turkoman answered 13/9, 2021 at 13:39 Comment(1)
Thanks, this works. DEPLOYMENT_POSTPROCESSING = YES; it is.Neumeyer
N
0

As for keeping the auto-generated _AlexSDKVersionNumber exported, I came up with a not-so-dirty hack:

  1. add a header file to my project, call it AlexSDK_vers.h:

    extern __attribute__ ((visibility("default"))) const double AlexSDKVersionNumber;
    
  2. in Build Settings, add OTHER_CFLAGS=-include\${PWD}/AlexSDK/AlexSDK_vers.h

Neumeyer answered 13/9, 2021 at 20:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.