Fixed i386 calling convention issue and CMake build on i386.

The i386 calling convention expects the callee to pop 1 word of the
stack when performing a struct ret.
This commit is contained in:
James Lyon 2013-04-26 00:31:46 +01:00
parent 1caee8ab3b
commit ae2ece93da
3 changed files with 19 additions and 6 deletions

View File

@ -26,8 +26,10 @@ else()
endif() endif()
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(TCC_NATIVE_TARGET "x86_64") set(TCC_NATIVE_TARGET "x86_64")
set(TCC_ARCH_DIR "x86_64-linux-gnu")
else() else()
set(TCC_NATIVE_TARGET "i386") set(TCC_NATIVE_TARGET "i386")
set(TCC_ARCH_DIR "i386-linux-gnu")
endif() endif()
endif() endif()
@ -44,9 +46,9 @@ else()
endif() endif()
if(NOT WIN32) if(NOT WIN32)
if(EXISTS /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/crti.o) if(EXISTS /usr/lib/${TCC_ARCH_DIR}/crti.o)
set(CONFIG_LDDIR lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu) set(CONFIG_LDDIR lib/${TCC_ARCH_DIR})
set(CONFIG_MULTIARCHDIR ${CMAKE_SYSTEM_PROCESSOR}-linux-gnu) set(CONFIG_MULTIARCHDIR ${TCC_ARCH_DIR})
elseif(EXISTS /usr/lib64/crti.o) elseif(EXISTS /usr/lib64/crti.o)
set(CONFIG_LDDIR lib64) set(CONFIG_LDDIR lib64)
endif() endif()
@ -164,7 +166,10 @@ macro(make_tcc native_name cross_name cross_enabled definitions tcc_sources libt
tcctok.h tcctok.h
${tcc_sources} ${tcc_sources}
) )
set_target_properties(libtcc PROPERTIES OUTPUT_NAME tcc PREFIX lib LINK_FLAGS "-Wl,--output-def,libtcc.def") set_target_properties(libtcc PROPERTIES OUTPUT_NAME tcc PREFIX lib)
if(WIN32)
set_target_properties(libtcc PROPERTIES LINK_FLAGS "-Wl,--output-def,libtcc.def")
endif()
add_executable(tcc tcc.c) add_executable(tcc tcc.c)
target_link_libraries(tcc libtcc) target_link_libraries(tcc libtcc)
if(NOT WIN32) if(NOT WIN32)

View File

@ -464,6 +464,10 @@ ST_FUNC void gfunc_call(int nb_args)
args_size -= 4; args_size -= 4;
} }
} }
#ifndef TCC_TARGET_PE
else if ((vtop->type.ref->type.t & VT_BTYPE) == VT_STRUCT)
args_size -= 4;
#endif
gcall_or_jmp(0); gcall_or_jmp(0);
if (args_size && func_call != FUNC_STDCALL) if (args_size && func_call != FUNC_STDCALL)
@ -549,6 +553,10 @@ ST_FUNC void gfunc_prolog(CType *func_type)
/* pascal type call ? */ /* pascal type call ? */
if (func_call == FUNC_STDCALL) if (func_call == FUNC_STDCALL)
func_ret_sub = addr - 8; func_ret_sub = addr - 8;
#ifndef TCC_TARGET_PE
else if (func_vc)
func_ret_sub = 4;
#endif
#ifdef CONFIG_TCC_BCHECK #ifdef CONFIG_TCC_BCHECK
/* leave some room for bound checking code */ /* leave some room for bound checking code */

View File

@ -5,7 +5,7 @@ if(WIN32)
set(TCC_CFLAGS ${TCC_CFLAGS} -I${CMAKE_SOURCE_DIR}/win32/include) set(TCC_CFLAGS ${TCC_CFLAGS} -I${CMAKE_SOURCE_DIR}/win32/include)
else() else()
set(TCC_MATH_LDFLAGS -lm) set(TCC_MATH_LDFLAGS -lm)
set(LIBTCC_LDFLAGS -ldl -lm) set(LIBTCC_LDFLAGS -ldl -lm -Wl,-rpath=${CMAKE_BINARY_DIR})
endif() endif()
add_executable(abitest-cc abitest.c) add_executable(abitest-cc abitest.c)
@ -61,7 +61,7 @@ if(PYTHONINTERP_FOUND)
add_test(test6 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST6}) add_test(test6 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST6})
endif() endif()
if(NOT WIN32 AND NOT TCC_NATIVE_TARGET STREQUAL "x86_64") if(0)
# Static output # Static output
set(TEST7 test7${CMAKE_EXECUTABLE_SUFFIX}) set(TEST7 test7${CMAKE_EXECUTABLE_SUFFIX})
add_custom_command(OUTPUT ${TEST7} COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -static -o ${TEST7} DEPENDS tcc tcctest.c) add_custom_command(OUTPUT ${TEST7} COMMAND tcc ${TCC_TEST_CFLAGS} ${CMAKE_CURRENT_SOURCE_DIR}/tcctest.c -static -o ${TEST7} DEPENDS tcc tcctest.c)