Skip to content

Commit b42c438

Browse files
committed
auto merge of #10631 : klutzy/rust/win-fixes, r=alexcrichton
This patchset fixes some parts broken on Win64. This also adds `--disable-pthreads` flags to llvm on mingw-w64 archs (both 32-bit and 64-bit, not mingw) due to bad performance. See #8996 for discussion.
2 parents c6a87c2 + 472b618 commit b42c438

File tree

5 files changed

+60
-185
lines changed

5 files changed

+60
-185
lines changed

configure

+7
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,13 @@ do
878878
# Try to have LLVM pull in as few dependencies as possible (#9397)
879879
LLVM_OPTS="$LLVM_OPTS --disable-zlib --disable-libffi"
880880

881+
# pthreads works badly on mingw-w64 systems: #8996
882+
case "$CFG_BUILD" in
883+
(*w64-mingw32)
884+
LLVM_OPTS="$LLVM_OPTS --disable-pthreads"
885+
;;
886+
esac
887+
881888
case "$CFG_C_COMPILER" in
882889
("ccache clang")
883890
LLVM_CXX_32="ccache clang++ -m32 -Qunused-arguments"

src/libstd/libc.rs

+44-181
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ pub mod types {
663663
}
664664
}
665665

666-
#[cfg(target_arch = "x86")]
667666
pub mod arch {
668667
pub mod c95 {
669668
pub type c_char = i8;
@@ -677,27 +676,53 @@ pub mod types {
677676
pub type c_ulong = u32;
678677
pub type c_float = f32;
679678
pub type c_double = f64;
679+
680+
#[cfg(target_arch = "x86")]
680681
pub type size_t = u32;
682+
#[cfg(target_arch = "x86_64")]
683+
pub type size_t = u64;
684+
685+
#[cfg(target_arch = "x86")]
681686
pub type ptrdiff_t = i32;
687+
#[cfg(target_arch = "x86_64")]
688+
pub type ptrdiff_t = i64;
689+
682690
pub type clock_t = i32;
691+
692+
#[cfg(target_arch = "x86")]
683693
pub type time_t = i32;
694+
#[cfg(target_arch = "x86_64")]
695+
pub type time_t = i64;
696+
684697
pub type wchar_t = u16;
685698
}
699+
686700
pub mod c99 {
687701
pub type c_longlong = i64;
688702
pub type c_ulonglong = u64;
689703
pub type intptr_t = int;
690704
pub type uintptr_t = uint;
691705
}
706+
692707
pub mod posix88 {
693708
pub type off_t = i32;
694709
pub type dev_t = u32;
695710
pub type ino_t = i16;
711+
712+
#[cfg(target_arch = "x86")]
696713
pub type pid_t = i32;
714+
#[cfg(target_arch = "x86_64")]
715+
pub type pid_t = i64;
716+
697717
pub type useconds_t = u32;
698718
pub type mode_t = u16;
719+
720+
#[cfg(target_arch = "x86")]
699721
pub type ssize_t = i32;
722+
#[cfg(target_arch = "x86_64")]
723+
pub type ssize_t = i64;
700724
}
725+
701726
pub mod posix01 {
702727
}
703728
pub mod posix08 {
@@ -725,19 +750,23 @@ pub mod types {
725750

726751
pub type LONG = c_long;
727752
pub type PLONG = *mut c_long;
753+
754+
#[cfg(target_arch = "x86")]
728755
pub type LONG_PTR = c_long;
756+
#[cfg(target_arch = "x86_64")]
757+
pub type LONG_PTR = i64;
729758

730759
pub type LARGE_INTEGER = c_longlong;
731760
pub type PLARGE_INTEGER = *mut c_longlong;
732761

733762
pub type LPCWSTR = *WCHAR;
734763
pub type LPCSTR = *CHAR;
735-
pub type LPCTSTR = *CHAR;
736-
pub type LPTCH = *CHAR;
737764

738765
pub type LPWSTR = *mut WCHAR;
739766
pub type LPSTR = *mut CHAR;
740-
pub type LPTSTR = *mut CHAR;
767+
768+
pub type LPWCH = *mut WCHAR;
769+
pub type LPCH = *mut CHAR;
741770

742771
// Not really, but opaque to us.
743772
pub type LPSECURITY_ATTRIBUTES = LPVOID;
@@ -760,9 +789,9 @@ pub mod types {
760789

761790
pub struct STARTUPINFO {
762791
cb: DWORD,
763-
lpReserved: LPTSTR,
764-
lpDesktop: LPTSTR,
765-
lpTitle: LPTSTR,
792+
lpReserved: LPWSTR,
793+
lpDesktop: LPWSTR,
794+
lpTitle: LPWSTR,
766795
dwX: DWORD,
767796
dwY: DWORD,
768797
dwXSize: DWORD,
@@ -843,172 +872,6 @@ pub mod types {
843872
pub type LPOVERLAPPED = *mut OVERLAPPED;
844873
}
845874
}
846-
847-
#[cfg(target_arch = "x86_64")]
848-
pub mod arch {
849-
pub mod c95 {
850-
pub type c_char = i8;
851-
pub type c_schar = i8;
852-
pub type c_uchar = u8;
853-
pub type c_short = i16;
854-
pub type c_ushort = u16;
855-
pub type c_int = i32;
856-
pub type c_uint = u32;
857-
pub type c_long = i32;
858-
pub type c_ulong = u32;
859-
pub type c_float = f32;
860-
pub type c_double = f64;
861-
pub type size_t = u64;
862-
pub type ptrdiff_t = i64;
863-
pub type clock_t = i32;
864-
pub type time_t = i64;
865-
pub type wchar_t = u16;
866-
}
867-
pub mod c99 {
868-
pub type c_longlong = i64;
869-
pub type c_ulonglong = u64;
870-
pub type intptr_t = int;
871-
pub type uintptr_t = uint;
872-
}
873-
pub mod posix88 {
874-
pub type off_t = i32; // XXX unless _FILE_OFFSET_BITS == 64
875-
pub type dev_t = u32;
876-
pub type ino_t = i16;
877-
pub type pid_t = i64;
878-
pub type useconds_t = u32;
879-
pub type mode_t = u16;
880-
pub type ssize_t = i64;
881-
}
882-
pub mod posix01 {
883-
}
884-
pub mod posix08 {
885-
}
886-
pub mod bsd44 {
887-
}
888-
pub mod extra {
889-
use ptr;
890-
use libc::types::common::c95::c_void;
891-
use libc::types::os::arch::c95::{c_char, c_int, c_uint, size_t};
892-
use libc::types::os::arch::c95::{c_ulong};
893-
use libc::types::os::arch::c95::{wchar_t};
894-
use libc::types::os::arch::c99::{c_ulonglong};
895-
896-
pub type BOOL = c_int;
897-
pub type BYTE = u8;
898-
pub type CCHAR = c_char;
899-
pub type CHAR = c_char;
900-
901-
pub type DWORD = c_ulong;
902-
pub type DWORDLONG = c_ulonglong;
903-
904-
pub type HANDLE = LPVOID;
905-
pub type HMODULE = c_uint;
906-
907-
pub type LONG_PTR = i64; // changed
908-
909-
pub type LPCWSTR = *WCHAR;
910-
pub type LPCSTR = *CHAR;
911-
pub type LPCTSTR = *CHAR;
912-
pub type LPTCH = *CHAR;
913-
914-
pub type LPWSTR = *mut WCHAR;
915-
pub type LPSTR = *mut CHAR;
916-
pub type LPTSTR = *mut CHAR;
917-
918-
// Not really, but opaque to us.
919-
pub type LPSECURITY_ATTRIBUTES = LPVOID;
920-
921-
pub type LPVOID = *mut c_void;
922-
pub type LPCVOID = *c_void;
923-
pub type LPBYTE = *mut BYTE;
924-
pub type LPWORD = *mut WORD;
925-
pub type LPDWORD = *mut DWORD;
926-
pub type LPHANDLE = *mut HANDLE;
927-
928-
pub type LRESULT = LONG_PTR;
929-
pub type PBOOL = *mut BOOL;
930-
pub type WCHAR = wchar_t;
931-
pub type WORD = u16;
932-
pub type SIZE_T = size_t;
933-
934-
pub type time64_t = i64;
935-
pub type int64 = i64;
936-
937-
pub struct STARTUPINFO {
938-
cb: DWORD,
939-
lpReserved: LPTSTR,
940-
lpDesktop: LPTSTR,
941-
lpTitle: LPTSTR,
942-
dwX: DWORD,
943-
dwY: DWORD,
944-
dwXSize: DWORD,
945-
dwYSize: DWORD,
946-
dwXCountChars: DWORD,
947-
dwYCountCharts: DWORD,
948-
dwFillAttribute: DWORD,
949-
dwFlags: DWORD,
950-
wShowWindow: WORD,
951-
cbReserved2: WORD,
952-
lpReserved2: LPBYTE,
953-
hStdInput: HANDLE,
954-
hStdOutput: HANDLE,
955-
hStdError: HANDLE
956-
}
957-
pub type LPSTARTUPINFO = *mut STARTUPINFO;
958-
959-
pub struct PROCESS_INFORMATION {
960-
hProcess: HANDLE,
961-
hThread: HANDLE,
962-
dwProcessId: DWORD,
963-
dwThreadId: DWORD
964-
}
965-
pub type LPPROCESS_INFORMATION = *mut PROCESS_INFORMATION;
966-
967-
pub struct SYSTEM_INFO {
968-
wProcessorArchitecture: WORD,
969-
wReserved: WORD,
970-
dwPageSize: DWORD,
971-
lpMinimumApplicationAddress: LPVOID,
972-
lpMaximumApplicationAddress: LPVOID,
973-
dwActiveProcessorMask: DWORD,
974-
dwNumberOfProcessors: DWORD,
975-
dwProcessorType: DWORD,
976-
dwAllocationGranularity: DWORD,
977-
wProcessorLevel: WORD,
978-
wProcessorRevision: WORD
979-
}
980-
pub type LPSYSTEM_INFO = *mut SYSTEM_INFO;
981-
982-
impl SYSTEM_INFO {
983-
pub fn new() -> SYSTEM_INFO {
984-
SYSTEM_INFO {
985-
wProcessorArchitecture: 0,
986-
wReserved: 0,
987-
dwPageSize: 0,
988-
lpMinimumApplicationAddress: ptr::mut_null(),
989-
lpMaximumApplicationAddress: ptr::mut_null(),
990-
dwActiveProcessorMask: 0,
991-
dwNumberOfProcessors: 0,
992-
dwProcessorType: 0,
993-
dwAllocationGranularity: 0,
994-
wProcessorLevel: 0,
995-
wProcessorRevision: 0
996-
}
997-
}
998-
}
999-
1000-
pub struct MEMORY_BASIC_INFORMATION {
1001-
BaseAddress: LPVOID,
1002-
AllocationBase: LPVOID,
1003-
AllocationProtect: DWORD,
1004-
RegionSize: SIZE_T,
1005-
State: DWORD,
1006-
Protect: DWORD,
1007-
Type: DWORD
1008-
}
1009-
pub type LPMEMORY_BASIC_INFORMATION = *mut MEMORY_BASIC_INFORMATION;
1010-
}
1011-
}
1012875
}
1013876

1014877
#[cfg(target_os = "macos")]
@@ -3515,8 +3378,8 @@ pub mod funcs {
35153378
pub mod kernel32 {
35163379
use libc::types::os::arch::c95::{c_uint};
35173380
use libc::types::os::arch::extra::{BOOL, DWORD, SIZE_T, HMODULE};
3518-
use libc::types::os::arch::extra::{LPCWSTR, LPWSTR, LPCTSTR,
3519-
LPTSTR, LPTCH, LPDWORD, LPVOID,
3381+
use libc::types::os::arch::extra::{LPCWSTR, LPWSTR, LPCSTR, LPSTR, LPCH,
3382+
LPDWORD, LPVOID,
35203383
LPCVOID, LPOVERLAPPED};
35213384
use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, LPSTARTUPINFO,
35223385
LPPROCESS_INFORMATION,
@@ -3532,8 +3395,8 @@ pub mod funcs {
35323395
-> DWORD;
35333396
pub fn SetEnvironmentVariableW(n: LPCWSTR, v: LPCWSTR)
35343397
-> BOOL;
3535-
pub fn GetEnvironmentStringsA() -> LPTCH;
3536-
pub fn FreeEnvironmentStringsA(env_ptr: LPTCH) -> BOOL;
3398+
pub fn GetEnvironmentStringsA() -> LPCH;
3399+
pub fn FreeEnvironmentStringsA(env_ptr: LPCH) -> BOOL;
35373400
pub fn GetModuleFileNameW(hModule: HMODULE,
35383401
lpFilename: LPWSTR,
35393402
nSize: DWORD)
@@ -3572,16 +3435,16 @@ pub mod funcs {
35723435
dwProcessId: DWORD)
35733436
-> HANDLE;
35743437
pub fn GetCurrentProcess() -> HANDLE;
3575-
pub fn CreateProcessA(lpApplicationName: LPCTSTR,
3576-
lpCommandLine: LPTSTR,
3438+
pub fn CreateProcessA(lpApplicationName: LPCSTR,
3439+
lpCommandLine: LPSTR,
35773440
lpProcessAttributes:
35783441
LPSECURITY_ATTRIBUTES,
35793442
lpThreadAttributes:
35803443
LPSECURITY_ATTRIBUTES,
35813444
bInheritHandles: BOOL,
35823445
dwCreationFlags: DWORD,
35833446
lpEnvironment: LPVOID,
3584-
lpCurrentDirectory: LPCTSTR,
3447+
lpCurrentDirectory: LPCSTR,
35853448
lpStartupInfo: LPSTARTUPINFO,
35863449
lpProcessInformation:
35873450
LPPROCESS_INFORMATION)
@@ -3621,7 +3484,7 @@ pub mod funcs {
36213484
flProtect: DWORD,
36223485
dwMaximumSizeHigh: DWORD,
36233486
dwMaximumSizeLow: DWORD,
3624-
lpName: LPCTSTR)
3487+
lpName: LPCWSTR)
36253488
-> HANDLE;
36263489
pub fn MapViewOfFile(hFileMappingObject: HANDLE,
36273490
dwDesiredAccess: DWORD,

src/libstd/rt/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,8 @@ pub unsafe fn record_stack_bounds(stack_lo: uint, stack_hi: uint) {
311311
// https://github.com/mozilla/rust/issues/3445#issuecomment-26114839
312312
//
313313
// stack range is at TIB: %gs:0x08 (top) and %gs:0x10 (bottom)
314-
asm!("mov $0, %gs:0x08" :: "r"(stack_lo) :: "volatile");
315-
asm!("mov $0, %gs:0x10" :: "r"(stack_hi) :: "volatile");
314+
asm!("mov $0, %gs:0x08" :: "r"(stack_hi) :: "volatile");
315+
asm!("mov $0, %gs:0x10" :: "r"(stack_lo) :: "volatile");
316316
}
317317
}
318318

src/libstd/rt/crate_map.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ pub fn get_crate_map() -> Option<&'static CrateMap<'static>> {
5656

5757
let sym = unsafe {
5858
let module = dl::open_internal();
59-
let sym = do "__rust_crate_map_toplevel".with_c_str |buf| {
59+
let rust_crate_map_toplevel = if cfg!(target_arch = "x86") {
60+
"__rust_crate_map_toplevel"
61+
} else {
62+
"_rust_crate_map_toplevel"
63+
};
64+
let sym = do rust_crate_map_toplevel.with_c_str |buf| {
6065
dl::symbol(module, buf)
6166
};
6267
dl::close(module);

src/libstd/rt/thread.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl Thread {
4848
let f: ~proc() = cast::transmute(trampoline);
4949
(*f)();
5050
}
51-
unsafe { cast::transmute(0) }
51+
unsafe { cast::transmute(0 as rust_thread_return) }
5252
}
5353

5454
let native = native_thread_create(thread_start, ~main);

0 commit comments

Comments
 (0)