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()
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)

View File

@ -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 */

View File

@ -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)