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

segfault on ARM64 #281

Closed
jwhere opened this issue Nov 30, 2024 · 1 comment
Closed

segfault on ARM64 #281

jwhere opened this issue Nov 30, 2024 · 1 comment

Comments

@jwhere
Copy link
Contributor

jwhere commented Nov 30, 2024

#include <stdio.h>

#include "sljit/sljitLir.h"

typedef void(SLJIT_FUNC* entry)(void);

static void SLJIT_FUNC foo(void* p) {
  (void)(p);
}

int main(int argc, char* argv[]) {

  struct sljit_compiler* compiler = sljit_create_compiler(NULL);

  sljit_emit_enter(compiler, 0, SLJIT_ARGS0V(), 1, 1, 64);

  // stack[16] = 1i64
  sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 16, SLJIT_IMM, 1);
  // stack[24] = 2i64
  sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 24, SLJIT_IMM, 2);

  // stack[0] = 0i64
  sljit_emit_op1(compiler, SLJIT_MOV, SLJIT_MEM1(SLJIT_SP), 0, SLJIT_IMM, 0);
  // stack[8] = &stack[16]
  sljit_get_local_base(compiler, SLJIT_MEM1(SLJIT_SP), 8, 16);

  // foo(&stack[0])
  sljit_get_local_base(compiler, SLJIT_R0, 0, 0);
  sljit_emit_icall(compiler, SLJIT_CALL, SLJIT_ARGS1V(P), SLJIT_IMM, SLJIT_FUNC_ADDR(foo));
  sljit_emit_return_void(compiler);

  entry f = (entry)sljit_generate_code(compiler, 0, NULL);
  f();

  sljit_free_code(f, NULL);
  sljit_free_compiler(compiler);

}

The above code works fine on X86_64 but causes a segfault on ARM64

@zherczeg
Copy link
Owner

Thank you for the report. It looks like sljit_get_local_base was bad on ARM64. #282 fixed it.

@jwhere jwhere closed this as completed Nov 30, 2024
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

No branches or pull requests

2 participants