diff --git a/src/librustc/metadata/loader.rs b/src/librustc/metadata/loader.rs index 9c61205667750..cfe9c8cd40a66 100644 --- a/src/librustc/metadata/loader.rs +++ b/src/librustc/metadata/loader.rs @@ -206,7 +206,8 @@ fn get_metadata_section(os: os, while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False { let name_buf = llvm::LLVMGetSectionName(si.llsi); let name = unsafe { str::raw::from_c_str(name_buf) }; - if name == meta_section_name(os) { + debug!("get_matadata_section: name %s", name); + if name == read_meta_section_name(os) { let cbuf = llvm::LLVMGetSectionContents(si.llsi); let csz = llvm::LLVMGetSectionSize(si.llsi) as uint; let mut found = None; @@ -251,6 +252,16 @@ pub fn meta_section_name(os: os) -> ~str { } } +pub fn read_meta_section_name(os: os) -> ~str { + match os { + os_macos => ~"__note.rustc", + os_win32 => ~".note.rustc", + os_linux => ~".note.rustc", + os_android => ~".note.rustc", + os_freebsd => ~".note.rustc" + } +} + // A diagnostic function for dumping crate metadata to an output stream pub fn list_file_metadata(intr: @ident_interner, os: os, diff --git a/src/llvm b/src/llvm index accc36b3e3f22..56dd407f4f97a 160000 --- a/src/llvm +++ b/src/llvm @@ -1 +1 @@ -Subproject commit accc36b3e3f22319b16609460f4cdf964f33f6cb +Subproject commit 56dd407f4f97a01b8df6554c569170d2fc276fcb diff --git a/src/rt/arch/arm/morestack.S b/src/rt/arch/arm/morestack.S index 1afce5bd848b7..4f1431a33927a 100644 --- a/src/rt/arch/arm/morestack.S +++ b/src/rt/arch/arm/morestack.S @@ -8,6 +8,64 @@ .arm .align -.globl __morestack +.global upcall_new_stack +.global upcall_del_stack +.global __morestack .hidden __morestack + +// r4 and r5 are scratch registers for __morestack due to llvm +// ARMFrameLowering::adjustForSegmentedStacks() implementation. + .type __morestack,%function __morestack: + .fnstart + // Save frame pointer and return address + .save {r4, r5} + .save {lr} + .save {r6, fp, lr} + push {r6, fp, lr} + + .movsp r6 + mov r6, sp + .setfp fp, sp, #4 + add fp, sp, #4 + + // Save argument registers of the original function + push {r0, r1, r2, r3, lr} + + mov r0, r4 // The amount of stack needed + add r1, fp, #20 // Address of stack arguments + mov r2, r5 // Size of stack arguments + + // Create new stack + bl upcall_new_stack@plt + + // Hold new stack pointer + mov r5, r0 + + // Pop the saved arguments + pop {r0, r1, r2, r3, lr} + + // Grab the return pointer + add r4, lr, #16 // Skip past the return + mov sp, r5 // Swich to the new stack + mov lr, pc + mov pc, r4 // Call the original function + + // Switch back to rust stack + mov sp, r6 + + // Save return value + mov r4, r0 + mov r5, r1 + + // Remove the new allocated stack + bl upcall_del_stack@plt + + // Restore return value + mov r0, r4 + mov r1, r5 + + // Return + pop {r6, fp, lr} + mov pc, lr + .fnend diff --git a/src/rt/arch/arm/record_sp.S b/src/rt/arch/arm/record_sp.S index abd8fbb6a5b05..fe680004a89aa 100644 --- a/src/rt/arch/arm/record_sp.S +++ b/src/rt/arch/arm/record_sp.S @@ -14,53 +14,18 @@ .globl get_sp record_sp_limit: - mov r3, r0 - ldr r0, =my_cpu - mov r1, #0 - mov r2, #0 - stmfd sp!, {r3, r7} - ldr r7, =345 - swi #0 - ldmfd sp!, {r3, r7} - movs r0, r0 - movmi r0, #0 - - ldr r1, =my_array - str r3, [r1, r0] + mrc p15, #0, r3, c13, c0, #3 + add r3, r3, #252 + str r0, [r3] mov pc, lr - get_sp_limit: - ldr r0, =my_cpu - mov r1, #0 - mov r2, #0 - stmfd sp!, {r4, r7} - ldr r7, =345 - swi #0 - ldmfd sp!, {r4, r7} - movs r0, r0 - movmi r0, #0 - mov r3, r0 - - ldr r1, =my_array - ldr r0, [r1, r3] + mrc p15, #0, r3, c13, c0, #3 + add r3, r3, #252 + ldr r0, [r3] mov pc, lr - get_sp: mov r0, sp mov pc, lr -.data -my_cpu: .long 0 -.global my_array -my_array: - .long 0 - .long 0 - .long 0 - .long 0 - .long 0 - .long 0 - .long 0 - .long 0 -.end diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index bdf13746f3ebf..5d422b2d2edc3 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -15,14 +15,12 @@ // //===----------------------------------------------------------------------=== -#include "llvm/InlineAsm.h" -#include "llvm/LLVMContext.h" #include "llvm/Linker.h" #include "llvm/PassManager.h" +#include "llvm/IR/InlineAsm.h" +#include "llvm/IR/LLVMContext.h" #include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Passes.h" -#include "llvm/Transforms/Scalar.h" -#include "llvm/Transforms/IPO.h" #include "llvm/ADT/Triple.h" #include "llvm/ADT/DenseSet.h" #include "llvm/Assembly/Parser.h" @@ -31,11 +29,9 @@ #include "llvm/Support/FormattedStream.h" #include "llvm/Support/Timer.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Target/TargetMachine.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/TargetRegistry.h" #include "llvm/Support/SourceMgr.h" -#include "llvm/Target/TargetOptions.h" #include "llvm/Support/Host.h" #include "llvm/Support/Debug.h" #include "llvm/Support/DynamicLibrary.h" @@ -45,6 +41,10 @@ #include "llvm/ExecutionEngine/JITMemoryManager.h" #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/Interpreter.h" +#include "llvm/Target/TargetMachine.h" +#include "llvm/Target/TargetOptions.h" +#include "llvm/Transforms/Scalar.h" +#include "llvm/Transforms/IPO.h" #include "llvm-c/Core.h" #include "llvm-c/BitReader.h" #include "llvm-c/Object.h" @@ -218,6 +218,12 @@ class RustMCJITMemoryManager : public JITMemoryManager { virtual void deallocateExceptionTable(void *ET) { llvm_unreachable("Unimplemented call"); } + virtual uint8_t* allocateDataSection(uintptr_t, unsigned int, unsigned int, bool) { + llvm_unreachable("Unimplemented call"); + } + virtual bool applyPermissions(std::string*) { + llvm_unreachable("Unimplemented call"); + } }; bool RustMCJITMemoryManager::loadCrate(const char* file, std::string* err) { @@ -446,6 +452,8 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR, Options.NoFramePointerElim = true; Options.EnableSegmentedStacks = EnableSegmentedStacks; + PassManager *PM = unwrap(PMR); + std::string Err; std::string Trip(Triple::normalize(triple)); std::string FeaturesStr; @@ -455,8 +463,9 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR, TheTarget->createTargetMachine(Trip, CPUStr, FeaturesStr, Options, Reloc::PIC_, CodeModel::Default, OptLevel); + Target->addAnalysisPasses(*PM); + bool NoVerify = false; - PassManager *PM = unwrap(PMR); std::string ErrorInfo; raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary); @@ -481,7 +490,7 @@ extern "C" LLVMModuleRef LLVMRustParseAssemblyFile(const char *Filename) { if (m) { return wrap(m); } else { - LLVMRustError = d.getMessage().c_str(); + LLVMRustError = d.getMessage().data(); return NULL; } } diff --git a/src/rustllvm/rustllvm.def.in b/src/rustllvm/rustllvm.def.in index 8b1c9d5ec7fbc..73bf1af90cd34 100644 --- a/src/rustllvm/rustllvm.def.in +++ b/src/rustllvm/rustllvm.def.in @@ -383,8 +383,6 @@ LLVMInitializeInstCombine LLVMInitializeScalarOpts LLVMInitializeTarget LLVMInitializeTransformUtils -LLVMInitializeARMAsmLexer -LLVMInitializeX86AsmLexer LLVMInitializeARMAsmParser LLVMInitializeMipsAsmParser LLVMInitializeX86AsmParser