TIL dynamic libraries are only partially loaded at launch in iOS

Recently I’ve stumbled on the issue that I didn’t receive a “Class is implemented in both” warning message, whereas I should’ve, because I referenced the same static library both from the app and indirectly through my custom dynamic framework.

The reason was, even though I imported the dynamic framework, I never referenced its symbols.

AFAIK there is no precise doc on how dynamic libraries are loaded in iOS, but there is good investigation in SO answer by Caleb, which particularly references info from Overview Of Dynamic Libraries, that says:

The dynamic loader resolves only the undefined external symbols the app actually uses during the launch process. Other symbols remain unresolved until the app uses them.

Even though the article is about OS X, I believe this was the case for me too. By using nm -gu I was able to see which symbols are “external” + “undefined”, and which are not. The symbols that would lead to “duplicate symbols” issue weren’t there, because they were in “s” section of symbol table, symbols of which probably not loaded unless/until actually referenced in code.

PS: Another fun TIL from today: seems that “Dynamic library” is not the same as “Dynamically loaded library” 🤷

The dynamic loader—in addition to automatically loading dynamic libraries at launch time—loads dynamic libraries at runtime, at the app’s request…

…Dynamic libraries loaded at runtime are known as dynamically loaded libraries.

(same Apple library mentioned above)

Leave a comment