Author: tkreuzer Date: Wed Dec 29 23:58:17 2010 New Revision: 50217
URL: http://svn.reactos.org/svn/reactos?rev=50217&view=rev Log: [CMAKE] LD is stupid and doesn't handle stdcall decoration as proper as dlltool does (after we provided a patch). Passing --kill-at, also kills C++ mangled names and exports with stdcall decoration are imposible. In trunk we use dlltool to generate an exp file that we link with LD, but in the cmake branch we pass the def file to LD directly. Luckily we have a tool called spec2def that can handle these things. We now generate 2 different .def files, one for LD, containing the undecorated export name forwarded to the decorated symbol name (FooFunc=FooFunc@12), while the 2nd def file which is passed to dlltool for exportlib generation has full stdcall decorations. --kill-at is now passed to dlltool only. This commit might break msvc, but should be pretty easy to fix.
Modified: branches/cmake-bringup/gcc.cmake branches/cmake-bringup/toolchain-mingw32.cmake branches/cmake-bringup/tools/spec2def/spec2def.c
Modified: branches/cmake-bringup/gcc.cmake URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/gcc.cmake?rev=5021... ============================================================================== --- branches/cmake-bringup/gcc.cmake [iso-8859-1] (original) +++ branches/cmake-bringup/gcc.cmake [iso-8859-1] Wed Dec 29 23:58:17 2010 @@ -9,7 +9,7 @@ link_directories("${REACTOS_SOURCE_DIR}/importlibs" ${REACTOS_BINARY_DIR}/lib/3rdparty/mingw) set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <FLAGS> <CMAKE_C_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") set(CMAKE_CXX_LINK_EXECUTABLE "<CMAKE_CXX_COMPILER> <FLAGS> <CMAKE_CXX_LINK_FLAGS> <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") -set(CMAKE_EXE_LINKER_FLAGS "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--kill-at -Wl,--disable-auto-import") +set(CMAKE_EXE_LINKER_FLAGS "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--disable-auto-import") # -Wl,-T,${REACTOS_SOURCE_DIR}/global.lds set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS_INIT} -Wl,--disable-stdcall-fixup")
@@ -242,8 +242,8 @@
add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a - COMMAND native-spec2def ${DLLNAME_OPTION} ${DECO_OPTION} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_name}.def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} - COMMAND ${MINGW_PREFIX}dlltool --def ${CMAKE_CURRENT_BINARY_DIR}/${_name}.def --kill-at --output-lib=${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a + COMMAND native-spec2def ${DLLNAME_OPTION} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} + COMMAND ${MINGW_PREFIX}dlltool --def ${CMAKE_CURRENT_BINARY_DIR}/${_name}_implib.def --kill-at --output-lib=${CMAKE_BINARY_DIR}/importlibs/lib${_name}.a DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file})
elseif(${_extension} STREQUAL ".def") @@ -265,7 +265,7 @@ get_filename_component(_file ${_spec_file} NAME_WE) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c - COMMAND native-spec2def -n=${_dllname} ${DECO_OPTION} -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} + COMMAND native-spec2def -n=${_dllname} --kill-at -a=${ARCH2} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}) set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}.def PROPERTIES GENERATED TRUE EXTERNAL_OBJECT TRUE)
Modified: branches/cmake-bringup/toolchain-mingw32.cmake URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/toolchain-mingw32.... ============================================================================== --- branches/cmake-bringup/toolchain-mingw32.cmake [iso-8859-1] (original) +++ branches/cmake-bringup/toolchain-mingw32.cmake [iso-8859-1] Wed Dec 29 23:58:17 2010 @@ -49,14 +49,14 @@ set(CMAKE_CXX_STANDARD_LIBRARIES "" CACHE STRING "Standard C++ Libraries")
if(ARCH MATCHES i386) - set(CMAKE_SHARED_LINKER_FLAGS_INIT "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--kill-at -Wl,--disable-auto-import") + set(CMAKE_SHARED_LINKER_FLAGS_INIT "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--disable-auto-import") #-Wl,-T,${REACTOS_SOURCE_DIR}/global.lds elseif(ARCH MATCHES amd64) - set(CMAKE_SHARED_LINKER_FLAGS_INIT "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--kill-at -Wl,--disable-auto-import") + set(CMAKE_SHARED_LINKER_FLAGS_INIT "-nodefaultlibs -nostdlib -Wl,--enable-auto-image-base -Wl,--disable-auto-import") endif()
# adjust the default behaviour of the FIND_XXX() commands: -# search headers and libraries in the target environment, search +# search headers and libraries in the target environment, search # programs in the host environment set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
Modified: branches/cmake-bringup/tools/spec2def/spec2def.c URL: http://svn.reactos.org/svn/reactos/branches/cmake-bringup/tools/spec2def/spe... ============================================================================== --- branches/cmake-bringup/tools/spec2def/spec2def.c [iso-8859-1] (original) +++ branches/cmake-bringup/tools/spec2def/spec2def.c [iso-8859-1] Wed Dec 29 23:58:17 2010 @@ -2,10 +2,6 @@ #include <stdlib.h> #include <ctype.h> #include <string.h> - -#ifndef _WIN32 -#define _stricmp strcasecmp -#endif
typedef struct { @@ -22,7 +18,8 @@ } EXPORT;
typedef int (*PFNOUTLINE)(FILE *, EXPORT *); -int no_decoration = 0; +int gbKillAt = 0; +int gbUseDeco = 0; int no_redirections = 0; char *pszArchString = "i386"; char *pszArchString2; @@ -182,8 +179,8 @@ case ARG_PTR: fprintf(file, "0x%%p"); break; case ARG_STR: fprintf(file, "'%%s'"); break; case ARG_WSTR: fprintf(file, "'%%ws'"); break; - case ARG_DBL: fprintf(file, "%%"PRix64""); break; - case ARG_INT64: fprintf(file, "0x%%ll"); break; + case ARG_DBL: fprintf(file, "%%f"); break; + case ARG_INT64: fprintf(file, "%%"PRix64""); break; } } fprintf(file, ")\n""); @@ -197,7 +194,7 @@ case ARG_PTR: fprintf(file, "(void*)a%d", i); break; case ARG_STR: fprintf(file, "(char*)a%d", i); break; case ARG_WSTR: fprintf(file, "(wchar_t*)a%d", i); break; - case ARG_DBL: fprintf(file, "(__int64)a%d", i); break; + case ARG_DBL: fprintf(file, "(double)a%d", i); break; case ARG_INT64: fprintf(file, "(__int64)a%d", i); break; } } @@ -268,6 +265,22 @@ libname); }
+void +PrintName(FILE *fileDest, EXPORT *pexp, int fRedir, int fDeco) +{ + char *pcName = fRedir ? pexp->pcRedirection : pexp->pcName; + int nNameLength = fRedir ? pexp->nRedirectionLength : pexp->nNameLength; + + if (fDeco && pexp->nCallingConvention == CC_FASTCALL) + fprintf(fileDest, "@"); + fprintf(fileDest, "%.*s", nNameLength, pcName); + if ((pexp->nCallingConvention == CC_STDCALL || + pexp->nCallingConvention == CC_FASTCALL) && fDeco) + { + fprintf(fileDest, "@%d", pexp->nStackBytes); + } +} + int OutputLine_def(FILE *fileDest, EXPORT *pexp) { @@ -280,42 +293,22 @@ } else { - if (pexp->nCallingConvention == CC_FASTCALL && !no_decoration) - { - fprintf(fileDest, "@"); - } - - fprintf(fileDest, "%.*s", pexp->nNameLength, pexp->pcName); - - if ((pexp->nCallingConvention == CC_STDCALL || - pexp->nCallingConvention == CC_FASTCALL) && !no_decoration) - { - fprintf(fileDest, "@%d", pexp->nStackBytes); - } + PrintName(fileDest, pexp, 0, gbUseDeco && !gbKillAt); }
if (pexp->pcRedirection && !no_redirections) { - int bAddDecorations = 1; + int fDeco = (gbUseDeco && !ScanToken(pexp->pcRedirection, '.'));
fprintf(fileDest, "="); - - /* No decorations, if switch was passed or this is an external */ - if (no_decoration || ScanToken(pexp->pcRedirection, '.')) - { - bAddDecorations = 0; - } - - if (pexp->nCallingConvention == CC_FASTCALL && bAddDecorations) - { - fprintf(fileDest, "@"); - } - fprintf(fileDest, "%.*s", pexp->nRedirectionLength, pexp->pcRedirection); - if ((pexp->nCallingConvention == CC_STDCALL || - pexp->nCallingConvention == CC_FASTCALL) && bAddDecorations) - { - fprintf(fileDest, "@%d", pexp->nStackBytes); - } + PrintName(fileDest, pexp, 1, fDeco); + } + else if (gbUseDeco && gbKillAt && + (pexp->nCallingConvention == CC_STDCALL || + pexp->nCallingConvention == CC_FASTCALL)) + { + fprintf(fileDest, "="); + PrintName(fileDest, pexp, 0, 1); }
if (pexp->nOrdinal != -1) @@ -452,7 +445,7 @@ } else if (CompareToken(pc, "-i386")) { - if (_stricmp(pszArchString, "i386") != 0) included = 0; + if (strcasecmp(pszArchString, "i386") != 0) included = 0; } else if (CompareToken(pc, "-private")) { @@ -628,7 +621,7 @@ " -d=<file> generates a def file\n" " -s=<file> generates a stub file\n" " -n=<name> name of the dll\n" - " -@ removes @xx decorations from def file\n" + " --kill-at removes @xx decorations from exports\n" " -r removes redirections from def file\n" " -a=<arch> Set architecture to <arch>. (i386, x86_64, arm)\n"); } @@ -650,8 +643,8 @@ /* Read options */ for (i = 1; i < argc && *argv[i] == '-'; i++) { - if ((_stricmp(argv[i], "--help") == 0) || - (_stricmp(argv[i], "-h") == 0)) + if ((strcasecmp(argv[i], "--help") == 0) || + (strcasecmp(argv[i], "-h") == 0)) { usage(); return 0; @@ -672,11 +665,11 @@ { pszDllName = argv[i] + 3; } - else if ((_stricmp(argv[i], "-@") == 0)) - { - no_decoration = 1; - } - else if ((_stricmp(argv[i], "-r") == 0)) + else if ((strcasecmp(argv[i], "--kill-at") == 0)) + { + gbKillAt = 1; + } + else if ((strcasecmp(argv[i], "-r") == 0)) { no_redirections = 1; } @@ -691,13 +684,18 @@ } }
- if ((_stricmp(pszArchString, "x86_64") == 0) || - (_stricmp(pszArchString, "ia64") == 0)) + if ((strcasecmp(pszArchString, "x86_64") == 0) || + (strcasecmp(pszArchString, "ia64") == 0)) { pszArchString2 = "win64"; } else pszArchString2 = "win32"; + + if (strcasecmp(pszArchString, "i386") == 0) + { + gbUseDeco = 1; + }
/* Set a default dll name */ if (!pszDllName)