Skip to content

ClassMetadata layout #23

Answered by Azoy
NSExceptional asked this question in Q&A
Apr 15, 2021 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

So class metadata is a little weird for ObjC. The first 4 fields represent struct objc_class: objc_obejct { ... } where:

struct _ClassMetadata {
  let _kind: Int                // Class isa
  let _superclass: Any.Type?    // Class superclass
  let _reserved: (Int, Int)     // cache_t cache
  let _rodata: UnsafeRawPointer // class_data_bits_t bits
  // EVERYTHING else is Swift specific and not defined for ObjC classes.
  // So like getting the descriptor in an ObjC class will result in a runtime crash.
}

I'm unsure exactly where I got the name rodata from for this field, but in reality this is the rwdata pointer after class realization. This is actually the type of data being stored here h…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@NSExceptional
Comment options

Answer selected by NSExceptional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants