Skip to content

Commit 559058b

Browse files
z0w0brson
authored andcommitted
---
yaml --- r: 32310 b: refs/heads/dist-snap c: efb576a h: refs/heads/master v: v3
1 parent 207273a commit 559058b

File tree

5 files changed

+81
-39
lines changed

5 files changed

+81
-39
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
10-
refs/heads/dist-snap: e27b8f7f02a6d9f963aae5823bbe07a962c04e33
10+
refs/heads/dist-snap: efb576a60dbd12cdd9c732cb5d8b202283b9864a
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/dist-snap/mk/rustllvm.mk

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ RUSTLLVM_OBJS_OBJS_$(1) := $$(RUSTLLVM_OBJS_CS_$(1):rustllvm/%.cpp=rustllvm/$(1)
2323
ALL_OBJ_FILES += $$(RUSTLLVM_OBJS_OBJS_$(1))
2424

2525
rustllvm/$(1)/$(CFG_RUSTLLVM): $$(RUSTLLVM_OBJS_OBJS_$(1)) \
26-
rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a \
2726
$$(MKFILE_DEPS) $$(RUSTLLVM_DEF_$(1))
2827
@$$(call E, link: $$@)
2928
$$(Q)$$(call CFG_LINK_C_$(1),$$@,$$(RUSTLLVM_OBJS_OBJS_$(1)) \
30-
$$(CFG_GCCISH_PRE_LIB_FLAGS) $$(LLVM_LIBS_$(1)) rt/$(1)/arch/$$(HOST_$(1))/libmorestack.a \
29+
$$(CFG_GCCISH_PRE_LIB_FLAGS) $$(LLVM_LIBS_$(1)) \
3130
$$(CFG_GCCISH_POST_LIB_FLAGS) \
3231
$$(LLVM_LDFLAGS_$(1)),$$(RUSTLLVM_DEF_$(1)),$$(CFG_RUSTLLVM))
3332

branches/dist-snap/src/rustc/back/link.rs

Lines changed: 53 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import std::sha1::sha1;
1212
import syntax::ast;
1313
import syntax::print::pprust;
1414
import lib::llvm::{ModuleRef, mk_pass_manager, mk_target_data, True, False,
15-
FileType};
15+
PassManagerRef, FileType};
1616
import metadata::filesearch;
1717
import syntax::ast_map::{path, path_mod, path_name};
1818
import io::{Writer, WriterUtil};
@@ -54,6 +54,57 @@ fn WriteOutputFile(sess:session,
5454
}
5555
}
5656

57+
#[cfg(stage0)]
58+
mod jit {
59+
fn exec(_sess: session,
60+
_pm: PassManagerRef,
61+
_m: ModuleRef,
62+
_opt: c_int,
63+
_stacks: bool) {
64+
fail
65+
}
66+
}
67+
68+
#[cfg(stage1)]
69+
#[cfg(stage2)]
70+
#[cfg(stage3)]
71+
mod jit {
72+
#[nolink]
73+
#[abi = "rust-intrinsic"]
74+
extern mod rusti {
75+
fn morestack_addr() -> *();
76+
}
77+
78+
struct Closure {
79+
code: *();
80+
env: *();
81+
}
82+
83+
fn exec(sess: session,
84+
pm: PassManagerRef,
85+
m: ModuleRef,
86+
opt: c_int,
87+
stacks: bool) unsafe {
88+
let ptr = llvm::LLVMRustJIT(rusti::morestack_addr(), pm, m, opt, stacks);
89+
90+
if ptr::is_null(ptr) {
91+
llvm_err(sess, ~"Could not JIT");
92+
} else {
93+
let bin = match os::self_exe_path() {
94+
Some(path) => path.to_str(),
95+
_ => ~"rustc"
96+
};
97+
let closure = Closure {
98+
code: ptr,
99+
env: ptr::null()
100+
};
101+
let func: fn(~[~str]) = unsafe::transmute(closure);
102+
103+
func(~[bin]);
104+
}
105+
}
106+
}
107+
57108
mod write {
58109
fn is_object_or_assembly_or_exe(ot: output_type) -> bool {
59110
if ot == output_type_assembly || ot == output_type_object ||
@@ -174,12 +225,7 @@ mod write {
174225
});
175226
}*/
176227

177-
if !llvm::LLVMRustJIT(pm.llpm,
178-
llmod,
179-
CodeGenOptLevel,
180-
true) {
181-
llvm_err(sess, ~"Could not JIT");
182-
}
228+
jit::exec(sess, pm.llpm, llmod, CodeGenOptLevel, true);
183229

184230
if sess.time_llvm_passes() {
185231
llvm::LLVMRustPrintPassTimings();

branches/dist-snap/src/rustc/lib/llvm.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,10 +990,11 @@ extern mod llvm {
990990
fn LLVMRustLoadLibrary(Filename: *c_char) -> bool;
991991

992992
/** Create and execute the JIT engine. */
993-
fn LLVMRustJIT(PM: PassManagerRef,
993+
fn LLVMRustJIT(__morestack: *(),
994+
PM: PassManagerRef,
994995
M: ModuleRef,
995996
OptLevel: c_int,
996-
EnableSegmentedStacks: bool) -> bool;
997+
EnableSegmentedStacks: bool) -> *();
997998

998999
/** Parses the bitcode in the given memory buffer. */
9991000
fn LLVMRustParseBitcode(MemBuf: MemoryBufferRef) -> ModuleRef;

branches/dist-snap/src/rustllvm/RustWrapper.cpp

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
#include <unistd.h>
5353
#endif
5454

55-
// Does this need to be done, or can it be made to resolve from the main program?
56-
extern "C" void __morestack(void *args, void *fn_ptr, uintptr_t stack_ptr);
57-
5855
using namespace llvm;
5956

6057
static const char *LLVMRustError;
@@ -95,11 +92,13 @@ void LLVMInitializeX86AsmParser();
9592
// that rustllvm doesn't actually link to and it's pointless to put target info
9693
// into the registry that Rust can not generate machine code for.
9794

98-
#define INITIALIZE_TARGETS() LLVMInitializeX86TargetInfo(); \
99-
LLVMInitializeX86Target(); \
100-
LLVMInitializeX86TargetMC(); \
101-
LLVMInitializeX86AsmPrinter(); \
102-
LLVMInitializeX86AsmParser();
95+
void LLVMRustInitializeTargets() {
96+
LLVMInitializeX86TargetInfo();
97+
LLVMInitializeX86Target();
98+
LLVMInitializeX86TargetMC();
99+
LLVMInitializeX86AsmPrinter();
100+
LLVMInitializeX86AsmParser();
101+
}
103102

104103
extern "C" bool
105104
LLVMRustLoadLibrary(const char* file) {
@@ -113,8 +112,6 @@ LLVMRustLoadLibrary(const char* file) {
113112
return true;
114113
}
115114

116-
ExecutionEngine* EE;
117-
118115
// Custom memory manager for MCJITting. It needs special features
119116
// that the generic JIT memory manager doesn't entail. Based on
120117
// code from LLI, change where needed for Rust.
@@ -123,8 +120,9 @@ class RustMCJITMemoryManager : public JITMemoryManager {
123120
SmallVector<sys::MemoryBlock, 16> AllocatedDataMem;
124121
SmallVector<sys::MemoryBlock, 16> AllocatedCodeMem;
125122
SmallVector<sys::MemoryBlock, 16> FreeCodeMem;
123+
void* __morestack;
126124

127-
RustMCJITMemoryManager() { }
125+
RustMCJITMemoryManager(void* sym) : __morestack(sym) { }
128126
~RustMCJITMemoryManager();
129127

130128
virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
@@ -275,7 +273,7 @@ void *RustMCJITMemoryManager::getPointerToNamedFunction(const std::string &Name,
275273
if (Name == "mknod") return (void*)(intptr_t)&mknod;
276274
#endif
277275

278-
if (Name == "__morestack") return (void*)(intptr_t)&__morestack;
276+
if (Name == "__morestack") return &__morestack;
279277

280278
const char *NameStr = Name.c_str();
281279
void *Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(NameStr);
@@ -294,13 +292,13 @@ RustMCJITMemoryManager::~RustMCJITMemoryManager() {
294292
free(AllocatedDataMem[i].base());
295293
}
296294

297-
extern "C" bool
298-
LLVMRustJIT(LLVMPassManagerRef PMR,
295+
extern "C" void*
296+
LLVMRustJIT(void* __morestack,
297+
LLVMPassManagerRef PMR,
299298
LLVMModuleRef M,
300299
CodeGenOpt::Level OptLevel,
301300
bool EnableSegmentedStacks) {
302301

303-
INITIALIZE_TARGETS();
304302
InitializeNativeTarget();
305303
InitializeNativeTargetAsmPrinter();
306304

@@ -315,39 +313,37 @@ LLVMRustJIT(LLVMPassManagerRef PMR,
315313
PM->add(createInstructionCombiningPass());
316314
PM->add(createReassociatePass());
317315
PM->add(createGVNPass());
318-
PM->add(createPromoteMemoryToRegisterPass());
319316
PM->add(createCFGSimplificationPass());
320317
PM->add(createFunctionInliningPass());
318+
PM->add(createPromoteMemoryToRegisterPass());
321319
PM->run(*unwrap(M));
322320

323-
RustMCJITMemoryManager* MM = new RustMCJITMemoryManager();
324-
EE = EngineBuilder(unwrap(M))
321+
RustMCJITMemoryManager* MM = new RustMCJITMemoryManager(__morestack);
322+
ExecutionEngine* EE = EngineBuilder(unwrap(M))
325323
.setTargetOptions(Options)
326324
.setJITMemoryManager(MM)
327325
.setOptLevel(OptLevel)
328326
.setUseMCJIT(true)
327+
.setAllocateGVsWithCode(false)
329328
.create();
330329

331330
if(!EE || Err != "") {
332331
LLVMRustError = Err.c_str();
333-
return false;
332+
return 0;
334333
}
335334

336335
MM->invalidateInstructionCache();
337-
Function* func = EE->FindFunctionNamed("main");
336+
Function* func = EE->FindFunctionNamed("_rust_main");
338337

339338
if(!func || Err != "") {
340339
LLVMRustError = Err.c_str();
341-
return false;
340+
return 0;
342341
}
343342

344-
typedef int (*Entry)(int, int);
345-
Entry entry = (Entry) EE->getPointerToFunction(func);
346-
343+
void* entry = EE->getPointerToFunction(func);
347344
assert(entry);
348-
entry(0, 0);
349345

350-
return true;
346+
return entry;
351347
}
352348

353349
extern "C" bool
@@ -359,7 +355,7 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
359355
CodeGenOpt::Level OptLevel,
360356
bool EnableSegmentedStacks) {
361357

362-
INITIALIZE_TARGETS();
358+
LLVMRustInitializeTargets();
363359

364360
TargetOptions Options;
365361
Options.NoFramePointerElim = true;

0 commit comments

Comments
 (0)