From: James Lyon Date: Thu, 25 Apr 2013 23:31:46 +0000 (+0100) Subject: Fixed i386 calling convention issue and CMake build on i386. X-Git-Tag: release_0_9_27~1081 X-Git-Url: https://repo.or.cz/w/tinycc.git/commitdiff_plain/ae2ece93da446b53b354b12f2f1dfd0cba6f57b7 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. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 845a3115..41dd81b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,8 +26,10 @@ else() endif() elseif(CMAKE_SIZEOF_VOID_P EQUAL 8) set(TCC_NATIVE_TARGET "x86_64") + set(TCC_ARCH_DIR "x86_64-linux-gnu") else() set(TCC_NATIVE_TARGET "i386") + set(TCC_ARCH_DIR "i386-linux-gnu") endif() endif() @@ -44,9 +46,9 @@ else() endif() if(NOT WIN32) - if(EXISTS /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/crti.o) - set(CONFIG_LDDIR lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu) - set(CONFIG_MULTIARCHDIR ${CMAKE_SYSTEM_PROCESSOR}-linux-gnu) + if(EXISTS /usr/lib/${TCC_ARCH_DIR}/crti.o) + set(CONFIG_LDDIR lib/${TCC_ARCH_DIR}) + set(CONFIG_MULTIARCHDIR ${TCC_ARCH_DIR}) elseif(EXISTS /usr/lib64/crti.o) set(CONFIG_LDDIR lib64) endif() @@ -164,7 +166,10 @@ macro(make_tcc native_name cross_name cross_enabled definitions tcc_sources libt tcctok.h ${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) target_link_libraries(tcc libtcc) if(NOT WIN32) diff --git a/i386-gen.c b/i386-gen.c index 67123d6b..044f9e60 100644 --- a/i386-gen.c +++ b/i386-gen.c @@ -464,6 +464,10 @@ ST_FUNC void gfunc_call(int nb_args) 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); if (args_size && func_call != FUNC_STDCALL) @@ -549,6 +553,10 @@ ST_FUNC void gfunc_prolog(CType *func_type) /* pascal type call ? */ if (func_call == FUNC_STDCALL) func_ret_sub = addr - 8; +#ifndef TCC_TARGET_PE + else if (func_vc) + func_ret_sub = 4; +#endif #ifdef CONFIG_TCC_BCHECK /* leave some room for bound checking code */ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 07c9897b..2a095477 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -5,7 +5,7 @@ if(WIN32) set(TCC_CFLAGS ${TCC_CFLAGS} -I${CMAKE_SOURCE_DIR}/win32/include) else() set(TCC_MATH_LDFLAGS -lm) - set(LIBTCC_LDFLAGS -ldl -lm) + set(LIBTCC_LDFLAGS -ldl -lm -Wl,-rpath=${CMAKE_BINARY_DIR}) endif() add_executable(abitest-cc abitest.c) @@ -61,7 +61,7 @@ if(PYTHONINTERP_FOUND) add_test(test6 ${TCCTEST_PY} ${CMAKE_CURRENT_BINARY_DIR}/${TEST6}) endif() - if(NOT WIN32 AND NOT TCC_NATIVE_TARGET STREQUAL "x86_64") + if(0) # Static output 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)