LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 32628 - When using C-bindings, on x86_64 ELF, fails to generate the correct instruction for external call
Summary: When using C-bindings, on x86_64 ELF, fails to generate the correct instructi...
Status: NEW
Alias: None
Product: libraries
Classification: Unclassified
Component: OrcJIT (show other bugs)
Version: 4.0
Hardware: PC Linux
: P normal
Assignee: Lang Hames
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-04-11 10:55 PDT by vlad
Modified: 2020-03-13 15:34 PDT (History)
2 users (show)

See Also:
Fixed By Commit(s):


Attachments
Code to reproduce the problem (2.71 KB, text/x-csrc)
2017-04-11 10:55 PDT, vlad
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vlad 2017-04-11 10:55:28 PDT
Created attachment 18271 [details]
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
Comment 1 vlad 2017-04-12 10:28:49 PDT
Might not be a bug, because using LLVMRelocPIC for the relocation model solves the problem.
Comment 2 Lang Hames 2020-03-13 15:34:21 PDT
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.