From 20946e697010f886cb9aec2390e083439b274123 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 13 Oct 2011 17:11:28 -0700 Subject: [PATCH] start going back to an i386 build --- Makefile.in | 4 +- configure | 2 +- .../mac/src/rt/libuv/run-benchmarks.target.mk | 4 +- .../mac/src/rt/libuv/run-tests.target.mk | 4 +- mk/libuv/x86_64/mac/src/rt/libuv/uv.target.mk | 4 +- mk/platform.mk | 10 ++-- mk/rt.mk | 17 ++++-- src/etc/gyp-uv | 11 ++-- src/rt/arch/x86_64/_context.S | 56 +++++++++---------- src/rt/arch/x86_64/ccall.S | 12 ++-- src/rt/arch/x86_64/context.cpp | 2 +- src/rt/arch/x86_64/context.h | 4 +- 12 files changed, 69 insertions(+), 61 deletions(-) diff --git a/Makefile.in b/Makefile.in index 648acee5263..227dc87b6cb 100644 --- a/Makefile.in +++ b/Makefile.in @@ -50,9 +50,7 @@ include config.mk OUR_MKFILES := Makefile config.mk $(wildcard $(CFG_SRC_DIR)/mk/*.mk) 3RDPARTY_MKFILES := $(CFG_SRC_DIR)/src/rt/libuv/Makefile \ $(wildcard $(CFG_SRC_DIR)/src/rt/libuv/*.mk) -GEN_MKFILES := $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/*) \ - $(wildcard $(CFG_SRC_DIR)/mk/libuv/unix/*) \ - $(wildcard $(CFG_SRC_DIR)/mk/libuv/win/*) \ +GEN_MKFILES := $(wildcard $(CFG_SRC_DIR)/mk/libuv/*/*/*) \ $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/rt/libuv/*) \ $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/rt/libuv/*) \ $(wildcard $(CFG_SRC_DIR)/mk/libuv/mac/src/rt/libuv/*) diff --git a/configure b/configure index 88528291beb..20706bbdc9d 100755 --- a/configure +++ b/configure @@ -391,7 +391,7 @@ step_msg "making directories" for i in \ doc doc/std \ nd nd/std \ - rt rt/isaac rt/bigint rt/sync rt/test rt/arch/i386 \ + rt rt/isaac rt/bigint rt/sync rt/test rt/arch/i386 rt/arch/x86_64 \ rt/libuv rt/libuv/src/ares rt/libuv/src/eio rt/libuv/src/ev \ rustllvm dl \ test/run-pass test/run-fail test/compile-fail \ diff --git a/mk/libuv/x86_64/mac/src/rt/libuv/run-benchmarks.target.mk b/mk/libuv/x86_64/mac/src/rt/libuv/run-benchmarks.target.mk index d4c4a17a93b..84bb33200f5 100644 --- a/mk/libuv/x86_64/mac/src/rt/libuv/run-benchmarks.target.mk +++ b/mk/libuv/x86_64/mac/src/rt/libuv/run-benchmarks.target.mk @@ -9,7 +9,7 @@ CFLAGS_Default := -fasm-blocks \ -mpascal-strings \ -Os \ -gdwarf-2 \ - -arch i386 + -arch x86_64 # Flags passed to only C files. CFLAGS_C_Default := @@ -68,7 +68,7 @@ $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD # End of this set of suffix rules ### Rules for final target. -LDFLAGS_Default := -arch i386 \ +LDFLAGS_Default := -arch x86_64 \ -L$(builddir) LIBS := -framework Carbon \ diff --git a/mk/libuv/x86_64/mac/src/rt/libuv/run-tests.target.mk b/mk/libuv/x86_64/mac/src/rt/libuv/run-tests.target.mk index f3ef6c3eae3..4222c11b975 100644 --- a/mk/libuv/x86_64/mac/src/rt/libuv/run-tests.target.mk +++ b/mk/libuv/x86_64/mac/src/rt/libuv/run-tests.target.mk @@ -12,7 +12,7 @@ CFLAGS_Default := -fasm-blocks \ -mpascal-strings \ -Os \ -gdwarf-2 \ - -arch i386 + -arch x86_64 # Flags passed to only C files. CFLAGS_C_Default := @@ -104,7 +104,7 @@ $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD # End of this set of suffix rules ### Rules for final target. -LDFLAGS_Default := -arch i386 \ +LDFLAGS_Default := -arch x86_64 \ -L$(builddir) LIBS := -framework Carbon \ diff --git a/mk/libuv/x86_64/mac/src/rt/libuv/uv.target.mk b/mk/libuv/x86_64/mac/src/rt/libuv/uv.target.mk index e6983a24554..1bb681f0ff9 100644 --- a/mk/libuv/x86_64/mac/src/rt/libuv/uv.target.mk +++ b/mk/libuv/x86_64/mac/src/rt/libuv/uv.target.mk @@ -15,7 +15,7 @@ CFLAGS_Default := -fasm-blocks \ -mpascal-strings \ -Os \ -gdwarf-2 \ - -arch i386 + -arch x86_64 # Flags passed to only C files. CFLAGS_C_Default := @@ -120,7 +120,7 @@ $(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.c FORCE_DO_CMD # End of this set of suffix rules ### Rules for final target. -LDFLAGS_Default := -arch i386 \ +LDFLAGS_Default := -arch x86_64 \ -L$(builddir) LIBS := -lm diff --git a/mk/platform.mk b/mk/platform.mk index c14c88c9671..312ea3bc566 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -66,13 +66,13 @@ ifneq ($(findstring darwin,$(CFG_OSTYPE)),) # approaches welcome! # # NB: Currently GCC's optimizer breaks rustrt (task-comm-1 hangs) on Darwin. - CFG_GCC_CFLAGS += -m64 #NDM - CFG_CLANG_CFLAGS += -m64 #NDM + CFG_GCC_CFLAGS += -m32 + CFG_CLANG_CFLAGS += -m32 ifeq ($(CFG_CPUTYPE), x86_64) - CFG_GCCISH_CFLAGS += -arch x86_64 #NDM - CFG_GCCISH_LINK_FLAGS += -arch x86_64 #NDM + CFG_GCCISH_CFLAGS += -arch i386 + CFG_GCCISH_LINK_FLAGS += -arch i386 endif - CFG_GCCISH_LINK_FLAGS += -m64 + CFG_GCCISH_LINK_FLAGS += -m32 CFG_DSYMUTIL := dsymutil CFG_DEF_SUFFIX := .darwin.def # Mac requires this flag to make rpath work diff --git a/mk/rt.mk b/mk/rt.mk index c45e0b9b4da..09b6dc20262 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -32,8 +32,8 @@ RUNTIME_CS := rt/sync/timer.cpp \ rt/memory_region.cpp \ rt/test/rust_test_harness.cpp \ rt/test/rust_test_runtime.cpp \ - rt/test/rust_test_util.cpp #NDM -#NDM rt/arch/i386/context.cpp + rt/test/rust_test_util.cpp \ + rt/arch/i386/context.cpp RUNTIME_LL := @@ -76,25 +76,30 @@ RUNTIME_HDR := rt/globals.h \ rt/test/rust_test_harness.h \ rt/test/rust_test_runtime.h \ rt/test/rust_test_util.h \ +<<<<<<< HEAD rt/arch/i386/context.h +======= + rt/arch/i386/context.h +>>>>>>> start going back to an i386 build ifeq ($(CFG_WINDOWSY), 1) LIBUV_OSTYPE := win - LIBUV_ARCH := x86_64 #NDM + LIBUV_ARCH := i386 LIBUV_LIB := rt/libuv/Default/obj.target/src/rt/libuv/libuv.a else ifeq ($(CFG_OSTYPE), apple-darwin) LIBUV_OSTYPE := mac - LIBUV_ARCH := x86_64 #NDM + LIBUV_ARCH := i386 LIBUV_LIB := rt/libuv/Default/libuv.a else LIBUV_OSTYPE := unix - LIBUV_ARCH := x86_64 #NDM + LIBUV_ARCH := i386 LIBUV_LIB := rt/libuv/Default/obj.target/src/rt/libuv/libuv.a endif RUNTIME_DEF := rt/rustrt$(CFG_DEF_SUFFIX) RUNTIME_INCS := -I $(S)src/rt/isaac -I $(S)src/rt/uthash \ - -I $(S)src/rt/arch/i386 -I $(S)src/rt/libuv/include + -I $(S)src/rt/arch/x86_64 \ + -I $(S)src/rt/libuv/include RUNTIME_OBJS := $(RUNTIME_CS:.cpp=.o) $(RUNTIME_LL:.ll=.o) $(RUNTIME_S:.S=.o) RUNTIME_LIBS := $(LIBUV_LIB) diff --git a/src/etc/gyp-uv b/src/etc/gyp-uv index d7477e09354..5de63976edf 100755 --- a/src/etc/gyp-uv +++ b/src/etc/gyp-uv @@ -40,14 +40,17 @@ do # Comment out the gyp auto regeneration for os in mac unix win; do - sed -i ".save" \ + sed -i "" \ -e 's/^\(Makefile: $(srcdir)\/src\/rt\/libuv\/uv\.gyp\)/#\1/' \ mk/libuv/$ARCH/$os/Makefile - sed -i ".save" \ + sed -i "" \ -e 's/^\( $(call do_cmd,regen_makefile)\)/#\1/' \ mk/libuv/$ARCH/$os/Makefile - - rm mk/libuv/$ARCH/$os/Makefile.save done done + +# On Mac, GYP hardcodes a -arch i386 into the output. Fix that. +sed -i "" \ + -e 's/-arch i386/-arch x86_64/' \ + mk/libuv/x86_64/mac/src/rt/libuv/*.mk diff --git a/src/rt/arch/x86_64/_context.S b/src/rt/arch/x86_64/_context.S index 7c689a88bf7..66b4fd9d3a7 100644 --- a/src/rt/arch/x86_64/_context.S +++ b/src/rt/arch/x86_64/_context.S @@ -54,44 +54,44 @@ swap_registers: // jump back into the old code. // Save instruction pointer: - popl %rax - movl %rax, 104(%rdi) + pop %rax + mov %rax, 104(%rdi) // Save non-volatile integer registers: // (including RSP) - movl %rbx, 0(%rdi) - movl %rsp, 8(%rdi) - movl %rbp, 16(%rdi) - movl %r12, 24(%rdi) - movl %r13, 32(%rdi) - movl %r14, 40(%rdi) - movl %r15, 48(%rdi) + mov %rbx, 0(%rdi) + mov %rsp, 8(%rdi) + mov %rbp, 16(%rdi) + mov %r12, 24(%rdi) + mov %r13, 32(%rdi) + mov %r14, 40(%rdi) + mov %r15, 48(%rdi) // Save non-volatile XMM registers: - movl %xmm0, 56(%rdi) - movl %xmm1, 64(%rdi) - movl %xmm2, 72(%rdi) - movl %xmm3, 80(%rdi) - movl %xmm4, 88(%rdi) - movl %xmm5, 96(%rdi) + movapd %xmm0, 56(%rdi) + movapd %xmm1, 64(%rdi) + movapd %xmm2, 72(%rdi) + movapd %xmm3, 80(%rdi) + movapd %xmm4, 88(%rdi) + movapd %xmm5, 96(%rdi) // Restore non-volatile integer registers: // (including RSP) - movl 0(%rsi), %rbx - movl 8(%rsi), %rsp - movl 16(%rsi), %rbp - movl 24(%rsi), %r12 - movl 32(%rsi), %r13 - movl 40(%rsi), %r14 - movl 48(%rsi), %r15 + mov 0(%rsi), %rbx + mov 8(%rsi), %rsp + mov 16(%rsi), %rbp + mov 24(%rsi), %r12 + mov 32(%rsi), %r13 + mov 40(%rsi), %r14 + mov 48(%rsi), %r15 // Restore non-volatile XMM registers: - movl 56(%rsi), %xmm0 - movl 64(%rsi), %xmm1 - movl 72(%rsi), %xmm2 - movl 80(%rsi), %xmm3 - movl 88(%rsi), %xmm4 - movl 96(%rsi), %xmm5 + movapd 56(%rsi), %xmm0 + movapd 64(%rsi), %xmm1 + movapd 72(%rsi), %xmm2 + movapd 80(%rsi), %xmm3 + movapd 88(%rsi), %xmm4 + movapd 96(%rsi), %xmm5 // Jump to the instruction pointer // found in regs: diff --git a/src/rt/arch/x86_64/ccall.S b/src/rt/arch/x86_64/ccall.S index dd1efda289c..60edf114b0a 100644 --- a/src/rt/arch/x86_64/ccall.S +++ b/src/rt/arch/x86_64/ccall.S @@ -11,11 +11,11 @@ _upcall_call_c_stack: .globl upcall_call_c_stack upcall_call_c_stack: #endif - pushl %rbp - movl %rsp,%rbp // save rsp - movl %rsi,%rsp // switch stack - calll *%rdi - movl %rbp,%rsp // would like to use "leave" but it's slower - popl %rbp + push %rbp + mov %rsp,%rbp // save rsp + mov %rsi,%rsp // switch stack + call *%rdi + mov %rbp,%rsp // would like to use "leave" but it's slower + pop %rbp ret diff --git a/src/rt/arch/x86_64/context.cpp b/src/rt/arch/x86_64/context.cpp index 0d108549396..0190261c7d3 100644 --- a/src/rt/arch/x86_64/context.cpp +++ b/src/rt/arch/x86_64/context.cpp @@ -33,6 +33,6 @@ void context::call(void *f, void *arg, void *stack) { *--sp = (uint64_t)arg; *--sp = 0xdeadbeef; - regs.regs[1] = (uint64_t)sp; + regs.regs[RSP] = (uint64_t)sp; regs.ip = (uint64_t)f; } diff --git a/src/rt/arch/x86_64/context.h b/src/rt/arch/x86_64/context.h index 8f0478d6b74..4341365fd5b 100644 --- a/src/rt/arch/x86_64/context.h +++ b/src/rt/arch/x86_64/context.h @@ -27,6 +27,8 @@ struct registers_t { class context { public: + static const int RSP = 1; + registers_t regs; context(); @@ -42,7 +44,7 @@ public: // function being called causes the task to fail, then we have to avoid // leaking space on the C stack. inline void *alloc_stack(size_t nbytes) { - uint32_t bot = regs.esp; + uint32_t bot = regs.regs[RSP]; uint32_t top = align_down(bot - nbytes); #ifdef HAVE_VALGRIND