gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
434 stars 118 forks source link

libobjc2 on risc-v #209

Closed andrekandore closed 9 months ago

andrekandore commented 3 years ago

hi

is there any work on getting libobjc2 working on risc-v?

i tried to build libobjc2 on riscv64 linux and couldnt get it compiled because it seems most of the primitive functions require assembly implementations, of which risc-v seems missing...

if there is no way to compile without assembly, then those parts would need to be implemented... is anyone already working on those?

if help is needed id by happy to collaborate!

please let me know, and thanks in advance ^^

davidchisnall commented 3 years ago

I'm not actively working on it, but I'm happy to review a PR. You will need to modify three places:

The message-send logic needs to:

  1. Check if the receiver is 0, if so return nil (may need to be different for integer / FP returns, but I believe RISC-V can just return integer and floating point, but does need to zero all return registers). For the structure-return variants, no extra logic is necessary, the compiler zeroes the structure.
  2. Check if the low bit (32-bit) or 3 bits (64-bit) are zero. If not, then find the class from the SmallObjectClasses array (64-bit) or SmallIntClass (32-bit) global, otherwise load it from the isa pointer.
  3. Load the dtable pointer from the class, then follow the chain of these until you reach the method.
  4. If this is non-null, jump to it.
  5. If this is null, we are on a slow path:
    1. Spill all argument registers (we can't tell which are in use, so we need to spill any register that can be an argument register, including any vector ones).
    2. Call the slow-path forwarding function slowMsgLookup. This takes the address of the receiver as an argument because it can rewrite the receiver (e.g. for -forwardingTargetForSelector).
    3. Restore all arguments. Typically, if you spill the receiver as an argument you can pass the on-stack spill address in step 2 here and not need any special-case logic for restoring it.
    4. Jump to the pointer that it returns.
andrekandore commented 3 years ago

@davidchisnall

thanks for the super detailed reply, especially for the message-send logic

ill try to take a look at what i can do over the weekend, and if i have any progress or issue ill come back here if its ok with you (ill try not to bother with anything trivial)

thank you again!

hmelder commented 9 months ago

See https://github.com/gnustep/libobjc2/pull/261