diff --git a/internal/build/build.go b/internal/build/build.go index 654b3746..44b01134 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -953,6 +953,13 @@ func clFiles(ctx *context, files string, pkg *packages.Package, procFile func(li func clFile(ctx *context, args []string, cFile, expFile string, procFile func(linkFile string), verbose bool) { llFile := expFile + filepath.Base(cFile) + ".ll" + ext := filepath.Ext(cFile) + + // default clang++ will use c++ to compile c file,will cause symbol be mangled + if ext == ".c" { + args = append(args, "-x", "c") + } + args = append(args, "-emit-llvm", "-S", "-o", llFile, "-c", cFile) args = append(args, ctx.crossCompile.CCFLAGS...) args = append(args, ctx.crossCompile.CFLAGS...) diff --git a/runtime/internal/clite/bitcast/_cast/cast.cpp b/runtime/internal/clite/bitcast/_cast/cast.c similarity index 95% rename from runtime/internal/clite/bitcast/_cast/cast.cpp rename to runtime/internal/clite/bitcast/_cast/cast.c index 8c5b12a1..ea567ce5 100644 --- a/runtime/internal/clite/bitcast/_cast/cast.cpp +++ b/runtime/internal/clite/bitcast/_cast/cast.c @@ -6,8 +6,6 @@ typedef union long long ll; } castUnion; -extern "C" { - double llgoToFloat64(long long v) { castUnion k; @@ -35,5 +33,3 @@ int llgoFromFloat32(float v) k.f = v; return k.v; } - -} diff --git a/runtime/internal/clite/bitcast/bitcast.go b/runtime/internal/clite/bitcast/bitcast.go index 07a79515..3fa7f6fa 100644 --- a/runtime/internal/clite/bitcast/bitcast.go +++ b/runtime/internal/clite/bitcast/bitcast.go @@ -19,7 +19,7 @@ package bitcast import _ "unsafe" const ( - LLGoFiles = "_cast/cast.cpp" + LLGoFiles = "_cast/cast.c" LLGoPackage = "link" ) diff --git a/runtime/internal/clite/debug/_wrap/debug.cpp b/runtime/internal/clite/debug/_wrap/debug.c similarity index 98% rename from runtime/internal/clite/debug/_wrap/debug.cpp rename to runtime/internal/clite/debug/_wrap/debug.c index 64d2a846..32d87903 100644 --- a/runtime/internal/clite/debug/_wrap/debug.cpp +++ b/runtime/internal/clite/debug/_wrap/debug.c @@ -9,8 +9,6 @@ #include #include -extern "C" { - void *llgo_address() { return __builtin_return_address(0); } @@ -40,6 +38,4 @@ void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *o } } } -} - -} +} \ No newline at end of file diff --git a/runtime/internal/clite/debug/debug.go b/runtime/internal/clite/debug/debug.go index 5aa793f2..7a1efc4d 100644 --- a/runtime/internal/clite/debug/debug.go +++ b/runtime/internal/clite/debug/debug.go @@ -9,7 +9,7 @@ import ( ) const ( - LLGoFiles = "$(llvm-config --cflags): _wrap/debug.cpp" + LLGoFiles = "$(llvm-config --cflags): _wrap/debug.c" ) type Info struct { diff --git a/runtime/internal/clite/ffi/_wrap/libffi.cpp b/runtime/internal/clite/ffi/_wrap/libffi.c similarity index 87% rename from runtime/internal/clite/ffi/_wrap/libffi.cpp rename to runtime/internal/clite/ffi/_wrap/libffi.c index 59b4cfd8..53fa1c70 100644 --- a/runtime/internal/clite/ffi/_wrap/libffi.cpp +++ b/runtime/internal/clite/ffi/_wrap/libffi.c @@ -1,9 +1,5 @@ #include -extern "C" { - void *llog_ffi_closure_alloc(void **code) { return ffi_closure_alloc(sizeof(ffi_closure), code); } - -} diff --git a/runtime/internal/clite/ffi/ffi_other.go b/runtime/internal/clite/ffi/ffi_other.go index 06fef2f3..6953dfdc 100644 --- a/runtime/internal/clite/ffi/ffi_other.go +++ b/runtime/internal/clite/ffi/ffi_other.go @@ -10,7 +10,7 @@ import ( const ( LLGoPackage = "link: $(pkg-config --libs libffi); -lffi" - LLGoFiles = "$(pkg-config --cflags libffi): _wrap/libffi.cpp" + LLGoFiles = "$(pkg-config --cflags libffi): _wrap/libffi.c" ) /* diff --git a/runtime/internal/clite/libuv/_wrap/libuv.cpp b/runtime/internal/clite/libuv/_wrap/libuv.c similarity index 82% rename from runtime/internal/clite/libuv/_wrap/libuv.cpp rename to runtime/internal/clite/libuv/_wrap/libuv.c index 30114341..d3d51448 100644 --- a/runtime/internal/clite/libuv/_wrap/libuv.cpp +++ b/runtime/internal/clite/libuv/_wrap/libuv.c @@ -1,9 +1,5 @@ #include -extern "C" { - int uv_tcp_get_io_watcher_fd (uv_tcp_t* handle) { return handle->io_watcher.fd; -} - -} +} \ No newline at end of file diff --git a/runtime/internal/clite/libuv/libuv.go b/runtime/internal/clite/libuv/libuv.go index b9dd6424..b781f1b5 100644 --- a/runtime/internal/clite/libuv/libuv.go +++ b/runtime/internal/clite/libuv/libuv.go @@ -9,7 +9,7 @@ import ( const ( LLGoPackage = "link: $(pkg-config --libs libuv); -luv" - LLGoFiles = "$(pkg-config --cflags libuv): _wrap/libuv.cpp" + LLGoFiles = "$(pkg-config --cflags libuv): _wrap/libuv.c" ) // ---------------------------------------------- diff --git a/runtime/internal/clite/openssl/_wrap/openssl.cpp b/runtime/internal/clite/openssl/_wrap/openssl.c similarity index 84% rename from runtime/internal/clite/openssl/_wrap/openssl.cpp rename to runtime/internal/clite/openssl/_wrap/openssl.c index 8d7c8680..7cc5bbdb 100644 --- a/runtime/internal/clite/openssl/_wrap/openssl.cpp +++ b/runtime/internal/clite/openssl/_wrap/openssl.c @@ -1,9 +1,5 @@ #include -extern "C" { - void opensslFree(void *ptr) { OPENSSL_free(ptr); } - -} \ No newline at end of file diff --git a/runtime/internal/clite/openssl/openssl.go b/runtime/internal/clite/openssl/openssl.go index 8bca7d28..df237c85 100644 --- a/runtime/internal/clite/openssl/openssl.go +++ b/runtime/internal/clite/openssl/openssl.go @@ -25,7 +25,7 @@ import ( // ----------------------------------------------------------------------------- const ( - LLGoFiles = "$(pkg-config --cflags openssl): _wrap/openssl.cpp" + LLGoFiles = "$(pkg-config --cflags openssl): _wrap/openssl.c" LLGoPackage = "link: $(pkg-config --libs openssl); -lssl -lcrypto" ) diff --git a/runtime/internal/clite/os/_os/os.cpp b/runtime/internal/clite/os/_os/os.c similarity index 91% rename from runtime/internal/clite/os/_os/os.cpp rename to runtime/internal/clite/os/_os/os.c index db43043c..45c2e8e8 100644 --- a/runtime/internal/clite/os/_os/os.cpp +++ b/runtime/internal/clite/os/_os/os.c @@ -1,8 +1,6 @@ #include #include -extern "C" { - int cliteClearenv() { extern char **environ; @@ -14,5 +12,3 @@ int cliteClearenv() } int cliteErrno() { return errno; } - -} diff --git a/runtime/internal/clite/os/os_darwin.go b/runtime/internal/clite/os/os_darwin.go index 5dccd605..3de6684e 100644 --- a/runtime/internal/clite/os/os_darwin.go +++ b/runtime/internal/clite/os/os_darwin.go @@ -23,7 +23,7 @@ import ( ) const ( - LLGoFiles = "_os/os.cpp" + LLGoFiles = "_os/os.c" LLGoPackage = "link" ) diff --git a/runtime/internal/clite/os/os_other.go b/runtime/internal/clite/os/os_other.go index e07e04a6..55bf6132 100644 --- a/runtime/internal/clite/os/os_other.go +++ b/runtime/internal/clite/os/os_other.go @@ -25,7 +25,7 @@ import ( ) const ( - LLGoFiles = "_os/os.cpp" + LLGoFiles = "_os/os.c" LLGoPackage = "link" ) diff --git a/runtime/internal/lib/internal/cpu/_wrap/cpu_x86.cpp b/runtime/internal/lib/internal/cpu/_wrap/cpu_x86.c similarity index 97% rename from runtime/internal/lib/internal/cpu/_wrap/cpu_x86.cpp rename to runtime/internal/lib/internal/cpu/_wrap/cpu_x86.c index 1305c86c..3756ee17 100644 --- a/runtime/internal/lib/internal/cpu/_wrap/cpu_x86.cpp +++ b/runtime/internal/lib/internal/cpu/_wrap/cpu_x86.c @@ -1,6 +1,3 @@ - -extern "C" { - #if defined(__GNUC__) || defined(__clang__) void llgo_getcpuid(unsigned int eax, unsigned int ecx, unsigned int *a, unsigned int *b, @@ -22,5 +19,3 @@ void llgo_getcpuid(unsigned int eax, unsigned int ecx, #else #error This code requires GCC or Clang #endif - -} \ No newline at end of file diff --git a/runtime/internal/lib/internal/cpu/cpu_x86.go b/runtime/internal/lib/internal/cpu/cpu_x86.go index 47374b9e..46022c42 100644 --- a/runtime/internal/lib/internal/cpu/cpu_x86.go +++ b/runtime/internal/lib/internal/cpu/cpu_x86.go @@ -10,7 +10,7 @@ import ( const ( LLGoPackage = "link" - LLGoFiles = "_wrap/cpu_x86.cpp" + LLGoFiles = "_wrap/cpu_x86.c" ) //go:linkname c_getcpuid C.llgo_getcpuid diff --git a/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp b/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.c similarity index 96% rename from runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp rename to runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.c index 1224ab0e..fa1ad6f9 100644 --- a/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp +++ b/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.c @@ -9,8 +9,6 @@ struct fcntl_ret int32_t err; // Error code }; -extern "C" { - // llgo_fcntl implements the fcntl system call wrapper for Go // fd: file descriptor // cmd: fcntl command @@ -32,6 +30,4 @@ struct fcntl_ret llgo_fcntl2(int32_t fd, int32_t cmd, int32_t arg) } return ret; -} - -} +} \ No newline at end of file diff --git a/runtime/internal/lib/internal/syscall/unix/fcntl_unix.go b/runtime/internal/lib/internal/syscall/unix/fcntl_unix.go index 140c6c94..93c768d9 100644 --- a/runtime/internal/lib/internal/syscall/unix/fcntl_unix.go +++ b/runtime/internal/lib/internal/syscall/unix/fcntl_unix.go @@ -8,7 +8,7 @@ import ( // llgo:skip fcntl const ( LLGoPackage = "link" - LLGoFiles = "_unix/fcntl_unix.cpp" + LLGoFiles = "_unix/fcntl_unix.c" ) //go:linkname llgo_fcntl2 C.llgo_fcntl2 diff --git a/runtime/internal/lib/runtime/_wrap/runtime.cpp b/runtime/internal/lib/runtime/_wrap/runtime.c similarity index 89% rename from runtime/internal/lib/runtime/_wrap/runtime.cpp rename to runtime/internal/lib/runtime/_wrap/runtime.c index 269a7b22..4dc23cfd 100644 --- a/runtime/internal/lib/runtime/_wrap/runtime.cpp +++ b/runtime/internal/lib/runtime/_wrap/runtime.c @@ -1,7 +1,5 @@ #include -extern "C" { - int llgo_maxprocs() { #ifdef _SC_NPROCESSORS_ONLN @@ -10,5 +8,3 @@ int llgo_maxprocs() return 1; #endif } - -} diff --git a/runtime/internal/lib/runtime/runtime.go b/runtime/internal/lib/runtime/runtime.go index 116bcc48..398d248a 100644 --- a/runtime/internal/lib/runtime/runtime.go +++ b/runtime/internal/lib/runtime/runtime.go @@ -28,7 +28,7 @@ type _runtime struct{} const ( LLGoPackage = "link" - LLGoFiles = "_wrap/runtime.cpp" + LLGoFiles = "_wrap/runtime.c" ) // GOROOT returns the root of the Go tree. It uses the