Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix segmentation fault due to varargs on Apple M1 #48

Merged
merged 1 commit into from
Jul 23, 2022

Conversation

thierry-martinez
Copy link
Contributor

Calling conventions on Apple M1 seem to differ for varargs: the program below prints "The answer is " on M1 while it prints "The answer is 42" on Linux.

void f(int something, int answer) {
  printf("The answer is %d\n", answer);
}

int
main(int argc, char *argv[])
{
  void (*ptr)(int, ...) = (void *) f;
  ptr(18, 42);
}

This commit fixes all type annotations for functions that are extracted from ap_manager_t*. This solves segmentation faults observed when apron is compiled on Apple M1.

Another solution would have been to use the type void (*ptr)(), but expliciting types look like a safer approach. Types allow us to find and fix the following suspicious line (apron/ap_generic.c, line 167):

    res = destructive ? abs : copy(abs);

whereas copy is AP_FUNID_COPY of type void* (*copy)(ap_manager_t*,void*) (the argument man was obviously missing).

Calling convention on Apple M1 seems to differ for varargs: the
program below prints "The answer is <some arbitrary value>" on M1
while it prints "The answer is 42" on Linux.

```

void f(int something, int answer) {
  printf("The answer is %d\n", answer);
}

int
main(int argc, char *argv[])
{
  void (*ptr)(int, ...) = (void *) f;
  ptr(18, 42);
}
```

This commit fixes all type annotations for functions that are
extracted from `ap_manager_t*`.

Another solution would have been to use the type `void (*ptr)()`, but
expliciting types look like a safer approach. Types allow us to find
and fix the following suspicious line (`apron/ap_generic.c`, line 167):

```
    res = destructive ? abs : copy(abs);
```

whereas `copy` is `AP_FUNID_COPY` of type
`void* (*copy)(ap_manager_t*,void*)` (the argument `man` was
obviously missing).
@antoinemine
Copy link
Owner

Thank you very much, the patch looks good. Thank you also for catching the erroneous call to copy.

@antoinemine antoinemine merged commit 919d1d5 into antoinemine:master Jul 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants