Commit 85584333 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Support for building V8 with MinGW

V8 can now be build with MinGW. It still fails the following four tests in debug mode:

  mjsunit/parse-int-float
  mjsunit/mirror-array.js
  mjsunit/integer-to-string.js
  mjsunit/regress/regress-114.js

Building with MinGW has been tested with version 5.1.4 using GCC 3.4.5.

In addition to supporting MinGW this change also makes it more explicit which targets needs to link with which libraries.

BUG=64
Review URL: http://codereview.chromium.org/20177

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1240 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent a85f5c86
...@@ -42,10 +42,8 @@ LIBRARY_FLAGS = { ...@@ -42,10 +42,8 @@ LIBRARY_FLAGS = {
}, },
'gcc': { 'gcc': {
'all': { 'all': {
'DIALECTFLAGS': ['-ansi'],
'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'], 'CCFLAGS': ['$DIALECTFLAGS', '$WARNINGFLAGS'],
'CXXFLAGS': ['$CCFLAGS', '-fno-rtti', '-fno-exceptions'], 'CXXFLAGS': ['$CCFLAGS', '-fno-rtti', '-fno-exceptions'],
'LIBS': ['pthread']
}, },
'mode:debug': { 'mode:debug': {
'CCFLAGS': ['-g', '-O0'], 'CCFLAGS': ['-g', '-O0'],
...@@ -54,8 +52,18 @@ LIBRARY_FLAGS = { ...@@ -54,8 +52,18 @@ LIBRARY_FLAGS = {
'mode:release': { 'mode:release': {
'CCFLAGS': ['-O3', '-fomit-frame-pointer', '-fdata-sections', '-ffunction-sections'] 'CCFLAGS': ['-O3', '-fomit-frame-pointer', '-fdata-sections', '-ffunction-sections']
}, },
'os:linux': {
'CCFLAGS': ['-ansi'],
},
'os:macos': {
'CCFLAGS': ['-ansi'],
},
'os:freebsd': { 'os:freebsd': {
'LIBS': ['execinfo'] 'CCFLAGS': ['-ansi'],
},
'os:win32': {
'CCFLAGS': ['-DWIN32'],
'CXXFLAGS': ['-DWIN32'],
}, },
'wordsize:64': { 'wordsize:64': {
'CCFLAGS': ['-m32'], 'CCFLAGS': ['-m32'],
...@@ -109,6 +117,9 @@ V8_EXTRA_FLAGS = { ...@@ -109,6 +117,9 @@ V8_EXTRA_FLAGS = {
'arch:arm': { 'arch:arm': {
'CPPDEFINES': ['ARM'] 'CPPDEFINES': ['ARM']
}, },
'os:win32': {
'WARNINGFLAGS': ['-Wno-long-long']
},
'disassembler:on': { 'disassembler:on': {
'CPPDEFINES': ['ENABLE_DISASSEMBLER'] 'CPPDEFINES': ['ENABLE_DISASSEMBLER']
} }
...@@ -175,6 +186,18 @@ CCTEST_EXTRA_FLAGS = { ...@@ -175,6 +186,18 @@ CCTEST_EXTRA_FLAGS = {
'all': { 'all': {
'LIBPATH': [abspath('.')] 'LIBPATH': [abspath('.')]
}, },
'os:linux': {
'LIBS': ['pthread'],
},
'os:macos': {
'LIBS': ['pthread'],
},
'os:freebsd': {
'LIBS': ['execinfo', 'pthread']
},
'os:win32': {
'LIBS': ['winmm']
},
'wordsize:64': { 'wordsize:64': {
'CCFLAGS': ['-m32'], 'CCFLAGS': ['-m32'],
'LINKFLAGS': ['-m32'] 'LINKFLAGS': ['-m32']
...@@ -182,7 +205,8 @@ CCTEST_EXTRA_FLAGS = { ...@@ -182,7 +205,8 @@ CCTEST_EXTRA_FLAGS = {
}, },
'msvc': { 'msvc': {
'all': { 'all': {
'CPPDEFINES': ['_HAS_EXCEPTIONS=0'] 'CPPDEFINES': ['_HAS_EXCEPTIONS=0'],
'LIBS': ['winmm']
}, },
'library:shared': { 'library:shared': {
'CPPDEFINES': ['USING_V8_SHARED'] 'CPPDEFINES': ['USING_V8_SHARED']
...@@ -198,11 +222,19 @@ SAMPLE_FLAGS = { ...@@ -198,11 +222,19 @@ SAMPLE_FLAGS = {
}, },
'gcc': { 'gcc': {
'all': { 'all': {
'LIBS': ['pthread'],
'LIBPATH': ['.'] 'LIBPATH': ['.']
}, },
'os:linux': {
'LIBS': ['pthread'],
},
'os:macos': {
'LIBS': ['pthread'],
},
'os:freebsd': { 'os:freebsd': {
'LIBS': ['execinfo'] 'LIBS': ['execinfo', 'pthread']
},
'os:win32': {
'LIBS': ['winmm']
}, },
'wordsize:64': { 'wordsize:64': {
'CCFLAGS': ['-m32'], 'CCFLAGS': ['-m32'],
...@@ -219,6 +251,7 @@ SAMPLE_FLAGS = { ...@@ -219,6 +251,7 @@ SAMPLE_FLAGS = {
'all': { 'all': {
'CCFLAGS': ['/nologo'], 'CCFLAGS': ['/nologo'],
'LINKFLAGS': ['/nologo'], 'LINKFLAGS': ['/nologo'],
'LIBS': ['winmm']
}, },
'library:shared': { 'library:shared': {
'CPPDEFINES': ['USING_V8_SHARED'] 'CPPDEFINES': ['USING_V8_SHARED']
...@@ -254,8 +287,25 @@ D8_FLAGS = { ...@@ -254,8 +287,25 @@ D8_FLAGS = {
'gcc': { 'gcc': {
'console:readline': { 'console:readline': {
'LIBS': ['readline'] 'LIBS': ['readline']
}
}, },
'os:linux': {
'LIBS': ['pthread'],
},
'os:macos': {
'LIBS': ['pthread'],
},
'os:freebsd': {
'LIBS': ['pthread'],
},
'os:win32': {
'LIBS': ['winmm'],
},
},
'msvc': {
'all': {
'LIBS': ['winmm']
}
}
} }
......
...@@ -51,7 +51,7 @@ void CPU::FlushICache(void* start, size_t size) { ...@@ -51,7 +51,7 @@ void CPU::FlushICache(void* start, size_t size) {
void CPU::DebugBreak() { void CPU::DebugBreak() {
#ifdef WIN32 #ifdef _MSC_VER
// To avoid Visual Studio runtime support the following code can be used // To avoid Visual Studio runtime support the following code can be used
// instead // instead
// __asm { int 3 } // __asm { int 3 }
......
...@@ -72,6 +72,11 @@ ...@@ -72,6 +72,11 @@
#include "stdlib.h" #include "stdlib.h"
#endif #endif
/* For MinGW, turn on __NO_ISOCEXT so that its strtod doesn't get added */
#ifdef __MINGW32__
#define __NO_ISOCEXT
#endif /* __MINGW32__ */
/* Make sure we use the David M. Gay version of strtod(). On Linux, we /* Make sure we use the David M. Gay version of strtod(). On Linux, we
* cannot use the same name (maybe the function does not have weak * cannot use the same name (maybe the function does not have weak
* linkage?). */ * linkage?). */
......
...@@ -30,10 +30,10 @@ ...@@ -30,10 +30,10 @@
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Types // Types
// Windows is missing the stdint.h header file. Instead we define standard // Visual Studio C++ is missing the stdint.h header file. Instead we define
// integer types for Windows here. // standard integer types for Windows here.
#ifdef WIN32 #ifdef _MSC_VER
typedef signed char int8_t; typedef signed char int8_t;
typedef unsigned char uint8_t; typedef unsigned char uint8_t;
typedef short int16_t; // NOLINT typedef short int16_t; // NOLINT
...@@ -42,9 +42,9 @@ typedef int int32_t; ...@@ -42,9 +42,9 @@ typedef int int32_t;
typedef unsigned int uint32_t; typedef unsigned int uint32_t;
typedef __int64 int64_t; typedef __int64 int64_t;
typedef unsigned __int64 uint64_t; typedef unsigned __int64 uint64_t;
#else #else // _MSC_VER
#include <stdint.h> // for intptr_t #include <stdint.h> // for intptr_t
#endif #endif // _MSC_VER
namespace v8 { namespace internal { namespace v8 { namespace internal {
...@@ -464,8 +464,10 @@ F FUNCTION_CAST(Address addr) { ...@@ -464,8 +464,10 @@ F FUNCTION_CAST(Address addr) {
#define TRACK_MEMORY(name) #define TRACK_MEMORY(name)
#endif #endif
// define used for helping GCC to make better inlining. // define used for helping GCC to make better inlining. Don't bother for debug
#ifdef __GNUC__ // builds. On GCC 3.4.5 using __attribute__((always_inline)) causes compilation
// errors in debug build.
#if defined(__GNUC__) && !defined(DEBUG)
#if (__GNUC__ >= 4) #if (__GNUC__ >= 4)
#define INLINE(header) inline header __attribute__((always_inline)) #define INLINE(header) inline header __attribute__((always_inline))
#else #else
......
...@@ -58,7 +58,10 @@ ...@@ -58,7 +58,10 @@
#include <time.h> // For LocalOffset() implementation. #include <time.h> // For LocalOffset() implementation.
#include <mmsystem.h> // For timeGetTime(). #include <mmsystem.h> // For timeGetTime().
#ifndef __MINGW32__
#include <dbghelp.h> // For SymLoadModule64 and al. #include <dbghelp.h> // For SymLoadModule64 and al.
#endif // __MINGW32__
#include <limits.h> // For INT_MAX and al.
#include <tlhelp32.h> // For Module32First and al. #include <tlhelp32.h> // For Module32First and al.
// These additional WIN32 includes have to be right here as the #undef's below // These additional WIN32 includes have to be right here as the #undef's below
...@@ -67,8 +70,6 @@ ...@@ -67,8 +70,6 @@
#include <process.h> // for _beginthreadex() #include <process.h> // for _beginthreadex()
#include <stdlib.h> #include <stdlib.h>
#pragma comment(lib, "winmm.lib") // force linkage with winmm.
#undef VOID #undef VOID
#undef DELETE #undef DELETE
#undef IN #undef IN
...@@ -83,15 +84,16 @@ ...@@ -83,15 +84,16 @@
#include "platform.h" #include "platform.h"
// Extra POSIX/ANSI routines for Win32. Please refer to The Open Group Base // Extra POSIX/ANSI routines for Win32 when when using Visual Studio C++. Please
// Specification for specification of the correct semantics for these // refer to The Open Group Base Specification for specification of the correct
// functions. // semantics for these functions.
// (http://www.opengroup.org/onlinepubs/000095399/) // (http://www.opengroup.org/onlinepubs/000095399/)
#ifdef _MSC_VER
// Test for finite value - usually defined in math.h
namespace v8 { namespace v8 {
namespace internal { namespace internal {
// Test for finite value - usually defined in math.h
int isfinite(double x) { int isfinite(double x) {
return _finite(x); return _finite(x);
} }
...@@ -152,19 +154,61 @@ int signbit(double x) { ...@@ -152,19 +154,61 @@ int signbit(double x) {
} }
// Generate a pseudo-random number in the range 0-2^31-1. Usually
// defined in stdlib.h
int random() {
return rand();
}
// Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually // Case-insensitive bounded string comparisons. Use stricmp() on Win32. Usually
// defined in strings.h. // defined in strings.h.
int strncasecmp(const char* s1, const char* s2, int n) { int strncasecmp(const char* s1, const char* s2, int n) {
return _strnicmp(s1, s2, n); return _strnicmp(s1, s2, n);
} }
#endif // _MSC_VER
// Extra functions for MinGW. Most of these are the _s functions which are in
// the Microsoft Visual Studio C++ CRT.
#ifdef __MINGW32__
int localtime_s(tm* out_tm, const time_t* time) {
tm* posix_local_time_struct = localtime(time);
if (posix_local_time_struct == NULL) return 1;
*out_tm = *posix_local_time_struct;
return 0;
}
// Not sure this the correct interpretation of _mkgmtime
time_t _mkgmtime(tm* timeptr) {
return mktime(timeptr);
}
int fopen_s(FILE** pFile, const char* filename, const char* mode) {
*pFile = fopen(filename, mode);
return *pFile != NULL ? 0 : 1;
}
int _vsnprintf_s(char* buffer, size_t sizeOfBuffer, size_t count,
const char* format, va_list argptr) {
return _vsnprintf(buffer, sizeOfBuffer, format, argptr);
}
#define _TRUNCATE 0
int strncpy_s(char* strDest, size_t numberOfElements,
const char* strSource, size_t count) {
strncpy(strDest, strSource, count);
return 0;
}
#endif // __MINGW32__
// Generate a pseudo-random number in the range 0-2^31-1. Usually
// defined in stdlib.h. Missing in both Microsoft Visual Studio C++ and MinGW.
int random() {
return rand();
}
namespace v8 { namespace internal { namespace v8 { namespace internal {
double ceiling(double x) { double ceiling(double x) {
...@@ -206,7 +250,7 @@ class Time { ...@@ -206,7 +250,7 @@ class Time {
private: private:
// Constants for time conversion. // Constants for time conversion.
static const int64_t kTimeEpoc = 116444736000000000; static const int64_t kTimeEpoc = 116444736000000000LL;
static const int64_t kTimeScaler = 10000; static const int64_t kTimeScaler = 10000;
static const int64_t kMsPerMinute = 60000; static const int64_t kMsPerMinute = 60000;
...@@ -807,9 +851,11 @@ void OS::Sleep(int milliseconds) { ...@@ -807,9 +851,11 @@ void OS::Sleep(int milliseconds) {
void OS::Abort() { void OS::Abort() {
if (!IsDebuggerPresent()) { if (!IsDebuggerPresent()) {
#ifdef _MSC_VER
// Make the MSVCRT do a silent abort. // Make the MSVCRT do a silent abort.
_set_abort_behavior(0, _WRITE_ABORT_MSG); _set_abort_behavior(0, _WRITE_ABORT_MSG);
_set_abort_behavior(0, _CALL_REPORTFAULT); _set_abort_behavior(0, _CALL_REPORTFAULT);
#endif // _MSC_VER
abort(); abort();
} else { } else {
DebugBreak(); DebugBreak();
...@@ -818,7 +864,11 @@ void OS::Abort() { ...@@ -818,7 +864,11 @@ void OS::Abort() {
void OS::DebugBreak() { void OS::DebugBreak() {
#ifdef _MSC_VER
__debugbreak(); __debugbreak();
#else
::DebugBreak();
#endif
} }
...@@ -901,6 +951,8 @@ Win32MemoryMappedFile::~Win32MemoryMappedFile() { ...@@ -901,6 +951,8 @@ Win32MemoryMappedFile::~Win32MemoryMappedFile() {
#define VOID void #define VOID void
#endif #endif
// DbgHelp isn't supported on MinGW yet
#ifndef __MINGW32__
// DbgHelp.h functions. // DbgHelp.h functions.
typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess, typedef BOOL (__stdcall *DLL_FUNC_TYPE(SymInitialize))(IN HANDLE hProcess,
IN PSTR UserSearchPath, IN PSTR UserSearchPath,
...@@ -1223,10 +1275,19 @@ int OS::StackWalk(OS::StackFrame* frames, int frames_size) { ...@@ -1223,10 +1275,19 @@ int OS::StackWalk(OS::StackFrame* frames, int frames_size) {
// Restore warnings to previous settings. // Restore warnings to previous settings.
#pragma warning(pop) #pragma warning(pop)
#else // __MINGW32__
void OS::LogSharedLibraryAddresses() { }
int OS::StackWalk(OS::StackFrame* frames, int frames_size) { return 0; }
#endif // __MINGW32__
double OS::nan_value() { double OS::nan_value() {
#ifdef _MSC_VER
static const __int64 nanval = 0xfff8000000000000; static const __int64 nanval = 0xfff8000000000000;
return *reinterpret_cast<const double*>(&nanval); return *reinterpret_cast<const double*>(&nanval);
#else // _MSC_VER
return NAN;
#endif // _MSC_VER
} }
...@@ -1267,7 +1328,7 @@ bool VirtualMemory::Commit(void* address, size_t size, bool executable) { ...@@ -1267,7 +1328,7 @@ bool VirtualMemory::Commit(void* address, size_t size, bool executable) {
bool VirtualMemory::Uncommit(void* address, size_t size) { bool VirtualMemory::Uncommit(void* address, size_t size) {
ASSERT(IsReserved()); ASSERT(IsReserved());
return VirtualFree(address, size, MEM_DECOMMIT) != NULL; return VirtualFree(address, size, MEM_DECOMMIT) != FALSE;
} }
......
...@@ -44,8 +44,12 @@ ...@@ -44,8 +44,12 @@
#ifndef V8_PLATFORM_H_ #ifndef V8_PLATFORM_H_
#define V8_PLATFORM_H_ #define V8_PLATFORM_H_
// Windows specific stuff.
#ifdef WIN32 #ifdef WIN32
// Microsoft Visual C++ specific stuff.
#ifdef _MSC_VER
enum { enum {
FP_NAN, FP_NAN,
FP_INFINITE, FP_INFINITE,
...@@ -66,11 +70,26 @@ int isgreater(double x, double y); ...@@ -66,11 +70,26 @@ int isgreater(double x, double y);
int fpclassify(double x); int fpclassify(double x);
int signbit(double x); int signbit(double x);
int strncasecmp(const char* s1, const char* s2, int n);
#endif // _MSC_VER
// MinGW specific stuff.
#ifdef __MINGW32__
// Needed for va_list.
#include <stdarg.h>
#endif // __MINGW32__
// Random is missing on both Visual Studio and MinGW.
int random(); int random();
int strncasecmp(const char* s1, const char* s2, int n); #endif // WIN32
#else // GCC specific stuff
#ifdef __GNUC__
#define __GNUC_VERSION__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
// Unfortunately, the INFINITY macro cannot be used with the '-pedantic' // Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
// warning flag and certain versions of GCC due to a bug: // warning flag and certain versions of GCC due to a bug:
...@@ -78,17 +97,13 @@ int strncasecmp(const char* s1, const char* s2, int n); ...@@ -78,17 +97,13 @@ int strncasecmp(const char* s1, const char* s2, int n);
// For now, we use the more involved template-based version from <limits>, but // For now, we use the more involved template-based version from <limits>, but
// only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x) // only when compiling with GCC versions affected by the bug (2.96.x - 4.0.x)
// __GNUC_PREREQ is not defined in GCC for Mac OS X, so we define our own macro // __GNUC_PREREQ is not defined in GCC for Mac OS X, so we define our own macro
#if defined(__GNUC__)
#define __GNUC_VERSION__ (__GNUC__ * 10000 + __GNUC_MINOR__ * 100)
#endif
#if __GNUC_VERSION__ >= 29600 && __GNUC_VERSION__ < 40100 #if __GNUC_VERSION__ >= 29600 && __GNUC_VERSION__ < 40100
#include <limits> #include <limits>
#undef INFINITY #undef INFINITY
#define INFINITY std::numeric_limits<double>::infinity() #define INFINITY std::numeric_limits<double>::infinity()
#endif #endif
#endif // WIN32 #endif // __GNUC__
namespace v8 { namespace internal { namespace v8 { namespace internal {
......
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="8,00" Version="8.00"
Name="d8" Name="d8"
ProjectGUID="{7E4C7D2D-A4B9-40B9-8192-22654E626F6C}" ProjectGUID="{7E4C7D2D-A4B9-40B9-8192-22654E626F6C}"
RootNamespace="d8" RootNamespace="d8"
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
...@@ -109,6 +110,7 @@ ...@@ -109,6 +110,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
......
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="8,00" Version="8.00"
Name="v8_cctest" Name="v8_cctest"
ProjectGUID="{97ECC711-7430-4FC4-90FD-004DA880E72A}" ProjectGUID="{97ECC711-7430-4FC4-90FD-004DA880E72A}"
RootNamespace="v8_cctest" RootNamespace="v8_cctest"
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
...@@ -109,6 +110,7 @@ ...@@ -109,6 +110,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
...@@ -109,6 +110,7 @@ ...@@ -109,6 +110,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
...@@ -109,6 +110,7 @@ ...@@ -109,6 +110,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
......
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
...@@ -109,6 +110,7 @@ ...@@ -109,6 +110,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalDependencies="winmm.lib"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment