Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

When using C-bindings, on x86_64 ELF, fails to generate the correct instruction for external call #31599

Open Quuxplusone opened 7 years ago

Quuxplusone commented 7 years ago
Bugzilla Link PR32628
Status NEW
Importance P normal
Reported by vlad@cloudflare.com
Reported on 2017-04-11 10:55:28 -0700
Last modified on 2020-03-13 15:34:21 -0700
Version 4.0
Hardware PC Linux
CC llvm-bugs@lists.llvm.org, vlad@cloudflare.com
Fixed by commit(s)
Attachments min.c (2780 bytes, text/x-csrc)
Blocks
Blocked by
See also

Created attachment 18271 Code to reproduce the problem

Debian 8, using llvm 4.0, as well as the trunk, when running the attached code I get a segfault.

It looks like the generated call is of the near, ip-relative type, and when the symbol is resolved, the offset is incorrect, as it can't fit into 32-bit allowed for that type of instruction.

$ clang -g min.c llvm-config --cflags --ldflags --system-libs --libs core orcjit native -rdynamic -lstdc++ -o min $ gdb min $ (gdb) run $ Program received signal SIGSEGV, Segmentation fault. $ 0x00007ffff7ff0001 in ?? () $ (gdb) x/i 0x00007ffff7ff0001 $ => 0x7ffff7ff0001: callq 0x800000edbd50

Quuxplusone commented 7 years ago

Attached min.c (2780 bytes, text/x-csrc): Code to reproduce the problem

Quuxplusone commented 7 years ago

Might not be a bug, because using LLVMRelocPIC for the relocation model solves the problem.

Quuxplusone commented 4 years ago

Hi Vlad,

Sorry for the late response. Were you able to solve this?

For now, even in LLM 10, JIT'd code on Linux requires use of the large code model to avoid direct PC-relative calls (calls should be indirect through registers instead). If you're seeing a direct branch my first inclination would be to check the code model.

This situation should change soon: We already support the small code model for MachO objects linked with JITLink (LLVM's new JIT linker). Hopefully we will get an ELF version of JITLink soon and we will be able to avoid this issue on Linux too.