discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nm not finding __objc_class names Re: Loading bundle resources using


From: Niels Grewe
Subject: Re: nm not finding __objc_class names Re: Loading bundle resources using GNUstep runtime 2.0
Date: Mon, 24 Feb 2020 17:49:24 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.4.1

On 19.02.20 01:42, Matt Rice wrote:
> On Mon, Feb 17, 2020 at 12:00 PM David Chisnall
> <gnustep@theravensnest.org> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]