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 4483 - The JIT allocates global data inside of function bodies, which can be freed
Summary: The JIT allocates global data inside of function bodies, which can be freed
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: MCJIT (show other bugs)
Version: trunk
Hardware: All All
: P normal
Assignee: Reid Kleckner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-06-29 18:22 PDT by Reid Kleckner
Modified: 2015-10-21 16:41 PDT (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
Failing test case. (3.77 KB, text/x-c++src)
2009-06-29 18:22 PDT, Reid Kleckner
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Kleckner 2009-06-29 18:22:27 PDT
Consider the program:

int counter = 0;
void foo() { return ++counter; }
void bar() { return ++counter; }

If we use the JIT, and make a call to foo, free the code for foo, and then call bar, we'll access freed memory.  Of course, you won't notice the problem until something else is allocated in the freed region, but if you poison freed memory it's easier to detect.

This also interferes with reattempting to JIT machine code, which I was working on when I found this bug.  I ran into it because I free the machine code before retrying, and if the function allocated any globals before reattempting, the old addresses are saved in the GlobalValue to address map.

I've attached a failing test case, and I'm working on a fix.
Comment 1 Reid Kleckner 2009-06-29 18:22:57 PDT
Created attachment 3140 [details]
Failing test case.
Comment 2 Reid Kleckner 2009-06-29 18:58:42 PDT
I found the revision that introduced this bug:
http://llvm.org/viewvc/llvm-project?view=rev&revision=54442

The log message is very clear about what it is doing, but it gives no indication as to *why* the change was made.
Comment 3 Evan Cheng 2009-07-02 17:58:18 PDT
On going discussion on llvmdev. We should add a mechanism to change the behavior.
Comment 4 Jeffrey Yasskin 2009-07-08 18:00:21 PDT
r75059 provides a workaround for this. I'm leaving the bug open because the behavior is still broken by default.
Comment 5 Reid Kleckner 2015-10-21 16:41:10 PDT
The old JIT is gone. I'm pretty sure MCJIT doesn't have this problem.