public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* libgccjit: question about the GCC_JIT_FUNCTION_IMPORTED
@ 2023-12-06 16:21 zhao xin
  2023-12-07 13:23 ` zhao xin
  0 siblings, 1 reply; 2+ messages in thread
From: zhao xin @ 2023-12-06 16:21 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 492 bytes --]

Hi, I was trying to write a toy luajit, use the libgccjit. 
and I want to call my defined functon from the jit code. not the libc function like printf or getchar. but it failed with error:

undefined reference to `wrap_return_var'
collect2.exe: error: ld returned 1 exit status
libgccjit.so: error: error invoking gcc driver


I checked my code, it seems ok, and if I change the name to printf, it compile success.
so I wonder maybe the gccjit could not call user defined function?


thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re:libgccjit: question about the GCC_JIT_FUNCTION_IMPORTED
  2023-12-06 16:21 libgccjit: question about the GCC_JIT_FUNCTION_IMPORTED zhao xin
@ 2023-12-07 13:23 ` zhao xin
  0 siblings, 0 replies; 2+ messages in thread
From: zhao xin @ 2023-12-07 13:23 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1162 bytes --]

after many try, I solute it. for some one has the same problem, here is the solution:


1. add the link option -Wl,-E

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-E")


2. check if the compiled binary has the function
objdump -d bin | grep wrap_return_var
if there isn't, may be gcc optimize it. add the __attribute__((used))


extern "C" __attribute__((used)) void *wrap_return_var(void *s) {
    return 0;
}

3. mingw still don't work, I dont't know why, may be this link is the answer https://stackoverflow.com/questions/39759060/compile-to-dll-with-some-undefined-references-with-mingw





At 2023-12-07 00:21:05, "zhao xin" <esrrhs@163.com> wrote:

Hi, I was trying to write a toy luajit, use the libgccjit. 
and I want to call my defined functon from the jit code. not the libc function like printf or getchar. but it failed with error:

undefined reference to `wrap_return_var'
collect2.exe: error: ld returned 1 exit status
libgccjit.so: error: error invoking gcc driver


I checked my code, it seems ok, and if I change the name to printf, it compile success.
so I wonder maybe the gccjit could not call user defined function?


thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-12-07 13:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-06 16:21 libgccjit: question about the GCC_JIT_FUNCTION_IMPORTED zhao xin
2023-12-07 13:23 ` zhao xin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).