On 19.02.20 01:42, Matt Rice wrote: > On Mon, Feb 17, 2020 at 12:00 PM David Chisnall > <[email protected]> wrote: >> >> Note that, if you want to enumerate all of the classes in a library, you >> can do so on ELF platforms by using dl_iterate_phdr to find the >> `__objc_classes` section in each loaded ELF image and collect the >> classes directly (this section is an array of pointers to classes >> declared in the ELF file). This will work irrespective of build system goo. >> >> On Windows, the corresponding section is `.objcrt$CLS` (though I believe >> the CLS part is a sub-section and is stripped during linkage). > > I believe that there is (or at least was) already dl_iterate_phdr, > and that for some reason this was added to get the list of classes > without actually loading > the object file? If that path still exists, its perhaps possible this > series of issues, is people using this API, > and calling frameworkClasses without causing the loading shared object.
I've just gotten around to look at this and concluded that +frameworkClasses can never be used to get the list of class names without causing the shared object to be loaded. The workflow here is (roughly) as follows: When compiling the framework, gnustep-make does the following: * compile all the "regular" sources of a framework/bundle into individual object files * use the EXTRACT_CLASS_NAMES_COMMAND to get the list of classes defined in those objects * synthesise a new source file with a NSFramework_$MANGLED_FRAMEWORK_NAME class, compiles that and links it into final .so On the reader-side, gnustep-base calls +frameworkClasses on all NSFramework_$MANGLED_FRAMEWORK_NAME classes to construct a mapping from class names into bundles (used for +bundleForClass and for checking whether we need to load a bundle to get the class, afaikt). We don't currently have a code path (anymore?) that does that, but I think that it mostly would work using dl_iterate_phdr as well (map all classes in the image to the bundle described by NS_Framework_$MANGLED_FRAMEWORK_NAME, if there is one), but I'd be a bit concerned about possible failure modes in the presence of static linking. Cheers, Niels
