开发者

Can't use __objc_msg_forward on x86_64

开发者 https://www.devze.com 2023-01-12 00:49 出处:网络
No matter what I do I can\'t get __objc_msg_forward to work on x86_64 on Linux. If I compile with -m32 it works fine. I put together this simple program to开发者_如何学Go demonstrate. It should print

No matter what I do I can't get __objc_msg_forward to work on x86_64 on Linux. If I compile with -m32 it works fine. I put together this simple program to开发者_如何学Go demonstrate. It should print Crasho Barfo twice.

#import <objc/Object.h>
#import <objc/objc-api.h>

#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>

@interface Object (Test)
-(id) doSomething:(id) anObject;
@end

typedef void *(*vafunc)(void *a1, void *a2, ...);
vafunc getvtest(void *s1);

int main(int argc, char *argv[])
{
  id o1;
  vafunc ptr;
  int na;


  ptr = getvtest(NULL);
  na = 4;
  (*ptr)(ptr, &na, "dog", "cat");

  __objc_msg_forward = getvtest;
  o1 = [[Object alloc] init];
  [o1 doSomething:o1];
  exit(0);
}

void *aptest(void *a1, void *a2, va_list ap)
{
  fprintf(stderr, "Barfo\n");
  return nil;
}

void *vtest(void *a1, void *a2, ...)
{
  va_list ap;
  void *ret = NULL;


  fprintf(stderr, "Crasho\n");
  va_start(ap, a2);
  ret = aptest(a1, a2, ap);
  va_end(ap);

  return ret;
}

vafunc getvtest(void *s1)
{
  return (vafunc) vtest;
}

What the heck am I doing wrong? When I run it this happens:

./vtest 
Crasho
Barfo
Segmentation fault

If I pull it up in gdb it says Illegal Instruction.


Whose 64-bit Obj-C runtime are you using? As far as I know, Apple's only supporting the Obj-C 2.0 runtime on x86_64.

0

精彩评论

暂无评论...
验证码 换一张
取 消