From f2f93c7f5faf3d05b3e4e1bb21dd6ec4f3893c28 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 17:01:12 +0800 Subject: [PATCH 01/13] cl:compile with clang++ --- internal/build/build.go | 2 ++ .../clite/bitcast/_cast/{cast.c => cast.cpp} | 18 ++++++++---------- runtime/internal/clite/bitcast/bitcast.go | 2 +- .../clite/debug/_wrap/{debug.c => debug.cpp} | 15 +++++++-------- runtime/internal/clite/debug/debug.go | 2 +- xtool/clang/clang.go | 3 +++ xtool/env/llvm/llvm.go | 2 +- 7 files changed, 23 insertions(+), 21 deletions(-) rename runtime/internal/clite/bitcast/_cast/{cast.c => cast.cpp} (61%) rename runtime/internal/clite/debug/_wrap/{debug.c => debug.cpp} (78%) diff --git a/internal/build/build.go b/internal/build/build.go index 654b3746..1bc6078a 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -490,6 +490,8 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, conf *Co } linkArgs = append(linkArgs, exargs...) + fmt.Fprintf(os.Stderr, "linkArgs: %v\n", linkArgs) + err = compileAndLinkLLFiles(ctx, app, llFiles, linkArgs, verbose) check(err) diff --git a/runtime/internal/clite/bitcast/_cast/cast.c b/runtime/internal/clite/bitcast/_cast/cast.cpp similarity index 61% rename from runtime/internal/clite/bitcast/_cast/cast.c rename to runtime/internal/clite/bitcast/_cast/cast.cpp index ea567ce5..ae4d6707 100644 --- a/runtime/internal/clite/bitcast/_cast/cast.c +++ b/runtime/internal/clite/bitcast/_cast/cast.cpp @@ -1,35 +1,33 @@ -typedef union -{ +typedef union { double d; float f; long v; long long ll; } castUnion; -double llgoToFloat64(long long v) -{ +extern "C" { + +double llgoToFloat64(long long v) { castUnion k; k.ll = v; return k.d; } -float llgoToFloat32(int v) -{ +float llgoToFloat32(int v) { castUnion k; k.v = v; return k.f; } -long long llgoFromFloat64(double v) -{ +long long llgoFromFloat64(double v) { castUnion k; k.d = v; return k.ll; } -int llgoFromFloat32(float v) -{ +int llgoFromFloat32(float v) { castUnion k; k.f = v; return k.v; } +} \ No newline at end of file diff --git a/runtime/internal/clite/bitcast/bitcast.go b/runtime/internal/clite/bitcast/bitcast.go index 3fa7f6fa..07a79515 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.c" + LLGoFiles = "_cast/cast.cpp" LLGoPackage = "link" ) diff --git a/runtime/internal/clite/debug/_wrap/debug.c b/runtime/internal/clite/debug/_wrap/debug.cpp similarity index 78% rename from runtime/internal/clite/debug/_wrap/debug.c rename to runtime/internal/clite/debug/_wrap/debug.cpp index 32d87903..441cd971 100644 --- a/runtime/internal/clite/debug/_wrap/debug.c +++ b/runtime/internal/clite/debug/_wrap/debug.cpp @@ -9,13 +9,11 @@ #include #include -void *llgo_address() { - return __builtin_return_address(0); -} +extern "C" { -int llgo_addrinfo(void *addr, Dl_info *info) { - return dladdr(addr, info); -} +void *llgo_address() { return __builtin_return_address(0); } + +int llgo_addrinfo(void *addr, Dl_info *info) { return dladdr(addr, info); } void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *offset, void *sp, char *name)) { unw_cursor_t cursor; @@ -33,9 +31,10 @@ void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *o if (unw_get_reg(&cursor, UNW_REG_IP, &pc) == 0) { unw_get_proc_name(&cursor, fname, sizeof(fname), &offset); unw_get_reg(&cursor, UNW_REG_SP, &sp); - if (fn(ctx, (void*)pc, (void*)offset, (void*)sp, fname) == 0) { + if (fn(ctx, (void *)pc, (void *)offset, (void *)sp, fname) == 0) { return; } } } -} \ No newline at end of file +} +} diff --git a/runtime/internal/clite/debug/debug.go b/runtime/internal/clite/debug/debug.go index f762cb4d..2a02b718 100644 --- a/runtime/internal/clite/debug/debug.go +++ b/runtime/internal/clite/debug/debug.go @@ -9,7 +9,7 @@ import ( ) const ( - LLGoFiles = "_wrap/debug.c" + LLGoFiles = "_wrap/debug.cpp" ) type Info struct { diff --git a/xtool/clang/clang.go b/xtool/clang/clang.go index 9ac3974d..78ca3e18 100644 --- a/xtool/clang/clang.go +++ b/xtool/clang/clang.go @@ -91,6 +91,7 @@ func (p *Cmd) execWithFlags(flags []string, args ...string) error { if p.Env != nil { cmd.Env = p.Env } + fmt.Fprintln(os.Stderr, cmd.String()) return cmd.Run() } @@ -131,6 +132,8 @@ func (p *Cmd) CheckLinkArgs(cmdArgs []string, wasm bool) error { srcIn := strings.NewReader(src) p.Stdin = srcIn + fmt.Fprintf(os.Stderr, "args: %v\n", args) + // Execute the command return p.execWithFlags([]string{"LDFLAGS", "CCFLAGS"}, args...) } diff --git a/xtool/env/llvm/llvm.go b/xtool/env/llvm/llvm.go index 82d0d13e..a34757c9 100644 --- a/xtool/env/llvm/llvm.go +++ b/xtool/env/llvm/llvm.go @@ -72,7 +72,7 @@ func (e *Env) BinDir() string { return e.binDir } // Clang returns a new [clang.Cmd] instance. func (e *Env) Clang() *clang.Cmd { - bin := filepath.Join(e.BinDir(), "clang") + bin := filepath.Join(e.BinDir(), "clang++") return clang.New(bin) } From ac352179dab694f0ac1b761373809efff38eb036 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 18:13:41 +0800 Subject: [PATCH 02/13] ci:install libc++-dev in linux --- .github/actions/setup-deps/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-deps/action.yml b/.github/actions/setup-deps/action.yml index 5ab296b2..a4da7614 100644 --- a/.github/actions/setup-deps/action.yml +++ b/.github/actions/setup-deps/action.yml @@ -34,7 +34,7 @@ runs: echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${{inputs.llvm-version}} main" | sudo tee /etc/apt/sources.list.d/llvm.list wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - sudo apt-get update - sudo apt-get install -y llvm-${{inputs.llvm-version}}-dev clang-${{inputs.llvm-version}} libclang-${{inputs.llvm-version}}-dev lld-${{inputs.llvm-version}} pkg-config libgc-dev libssl-dev zlib1g-dev libffi-dev libcjson-dev libunwind-dev libuv1-dev + sudo apt-get install -y llvm-${{inputs.llvm-version}}-dev clang-${{inputs.llvm-version}} libclang-${{inputs.llvm-version}}-dev lld-${{inputs.llvm-version}} pkg-config libgc-dev libssl-dev zlib1g-dev libffi-dev libcjson-dev libunwind-dev libuv1-dev libc++-${{inputs.llvm-version}}-dev echo "PATH=/usr/lib/llvm-${{inputs.llvm-version}}/bin:$PATH" >> $GITHUB_ENV # Install optional deps for demos. From c2a50fa98d22bfdf7bbec536e5492865c0de0b5f Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 18:18:52 +0800 Subject: [PATCH 03/13] internal/clite:wrap with cpp --- runtime/internal/clite/os/_os/os.c | 14 -------------- runtime/internal/clite/os/_os/os.cpp | 15 +++++++++++++++ runtime/internal/clite/os/os_darwin.go | 2 +- 3 files changed, 16 insertions(+), 15 deletions(-) delete mode 100644 runtime/internal/clite/os/_os/os.c create mode 100644 runtime/internal/clite/os/_os/os.cpp diff --git a/runtime/internal/clite/os/_os/os.c b/runtime/internal/clite/os/_os/os.c deleted file mode 100644 index 45c2e8e8..00000000 --- a/runtime/internal/clite/os/_os/os.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -int cliteClearenv() -{ - extern char **environ; - if (environ != NULL) - { - *environ = NULL; - } - return 0; -} - -int cliteErrno() { return errno; } diff --git a/runtime/internal/clite/os/_os/os.cpp b/runtime/internal/clite/os/_os/os.cpp new file mode 100644 index 00000000..cc3d29d5 --- /dev/null +++ b/runtime/internal/clite/os/_os/os.cpp @@ -0,0 +1,15 @@ +#include +#include + +extern "C" { + +int cliteClearenv() { + extern char **environ; + if (environ != NULL) { + *environ = NULL; + } + return 0; +} + +int cliteErrno() { return errno; } +} \ No newline at end of file diff --git a/runtime/internal/clite/os/os_darwin.go b/runtime/internal/clite/os/os_darwin.go index 3de6684e..5dccd605 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.c" + LLGoFiles = "_os/os.cpp" LLGoPackage = "link" ) From 9c66cb9b00ab42f8758c34654c9afe4f885f873c Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 18:23:32 +0800 Subject: [PATCH 04/13] ci:install libunwind-19-dev --- .github/actions/setup-deps/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/setup-deps/action.yml b/.github/actions/setup-deps/action.yml index a4da7614..ffd0f733 100644 --- a/.github/actions/setup-deps/action.yml +++ b/.github/actions/setup-deps/action.yml @@ -34,7 +34,7 @@ runs: echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-${{inputs.llvm-version}} main" | sudo tee /etc/apt/sources.list.d/llvm.list wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - sudo apt-get update - sudo apt-get install -y llvm-${{inputs.llvm-version}}-dev clang-${{inputs.llvm-version}} libclang-${{inputs.llvm-version}}-dev lld-${{inputs.llvm-version}} pkg-config libgc-dev libssl-dev zlib1g-dev libffi-dev libcjson-dev libunwind-dev libuv1-dev libc++-${{inputs.llvm-version}}-dev + sudo apt-get install -y llvm-${{inputs.llvm-version}}-dev clang-${{inputs.llvm-version}} libclang-${{inputs.llvm-version}}-dev lld-${{inputs.llvm-version}} pkg-config libgc-dev libssl-dev zlib1g-dev libffi-dev libcjson-dev libunwind-${{inputs.llvm-version}}-dev libuv1-dev libc++-${{inputs.llvm-version}}-dev echo "PATH=/usr/lib/llvm-${{inputs.llvm-version}}/bin:$PATH" >> $GITHUB_ENV # Install optional deps for demos. From 0cb29ab388a3080d27e97905ed75c28aefffa770 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 19:02:58 +0800 Subject: [PATCH 05/13] internal/runtime:runtime.cpp --- .../internal/lib/runtime/_wrap/{runtime.c => runtime.cpp} | 6 ++++-- runtime/internal/lib/runtime/runtime.go | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) rename runtime/internal/lib/runtime/_wrap/{runtime.c => runtime.cpp} (77%) diff --git a/runtime/internal/lib/runtime/_wrap/runtime.c b/runtime/internal/lib/runtime/_wrap/runtime.cpp similarity index 77% rename from runtime/internal/lib/runtime/_wrap/runtime.c rename to runtime/internal/lib/runtime/_wrap/runtime.cpp index 4dc23cfd..f97d91bd 100644 --- a/runtime/internal/lib/runtime/_wrap/runtime.c +++ b/runtime/internal/lib/runtime/_wrap/runtime.cpp @@ -1,10 +1,12 @@ #include -int llgo_maxprocs() -{ +extern "C" { + +int llgo_maxprocs() { #ifdef _SC_NPROCESSORS_ONLN return (int)sysconf(_SC_NPROCESSORS_ONLN); #else return 1; #endif } +} \ No newline at end of file diff --git a/runtime/internal/lib/runtime/runtime.go b/runtime/internal/lib/runtime/runtime.go index 398d248a..116bcc48 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.c" + LLGoFiles = "_wrap/runtime.cpp" ) // GOROOT returns the root of the Go tree. It uses the From a5fd7f2eba8fbf7f3d0b7c41308bac42b753807f Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 19:31:50 +0800 Subject: [PATCH 06/13] internal/cl:include llvm-config --cflags to find libunwind.h --- internal/crosscompile/cosscompile.go | 6 ++++++ xtool/env/llvm/llvm.go | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/crosscompile/cosscompile.go b/internal/crosscompile/cosscompile.go index 8865aba6..cc4b15c6 100644 --- a/internal/crosscompile/cosscompile.go +++ b/internal/crosscompile/cosscompile.go @@ -6,9 +6,11 @@ import ( "os" "path/filepath" "runtime" + "strings" "github.com/goplus/llgo/internal/env" "github.com/goplus/llgo/internal/xtool/llvm" + envllvm "github.com/goplus/llgo/xtool/env/llvm" ) type Export struct { @@ -66,6 +68,10 @@ func Use(goos, goarch string, wasiThreads, changeRpath bool) (export Export, err "-latomic", "-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions. ) + llvmEnv := envllvm.New("") + if cflags := llvmEnv.Cflags(); cflags != "" { + export.CFLAGS = append(export.CFLAGS, strings.Fields(cflags)...) + } } return } diff --git a/xtool/env/llvm/llvm.go b/xtool/env/llvm/llvm.go index a34757c9..e1a18abd 100644 --- a/xtool/env/llvm/llvm.go +++ b/xtool/env/llvm/llvm.go @@ -50,6 +50,7 @@ func defaultLLVMConfigBin() string { // Env represents an LLVM installation. type Env struct { binDir string + cflags string } // New creates a new [Env] instance. @@ -62,7 +63,12 @@ func New(llvmConfigBin string) *Env { // executables are assumed to be in PATH. binDir, _ := exec.Command(llvmConfigBin, "--bindir").Output() - e := &Env{binDir: strings.TrimSpace(string(binDir))} + cflags, _ := exec.Command(llvmConfigBin, "--cflags").Output() + + e := &Env{ + binDir: strings.TrimSpace(string(binDir)), + cflags: strings.TrimSpace(string(cflags)), + } return e } @@ -70,6 +76,8 @@ func New(llvmConfigBin string) *Env { // means LLVM executables are assumed to be in PATH. func (e *Env) BinDir() string { return e.binDir } +func (e *Env) Cflags() string { return e.cflags } + // Clang returns a new [clang.Cmd] instance. func (e *Env) Clang() *clang.Cmd { bin := filepath.Join(e.BinDir(), "clang++") From f36098d704199dcb9a9a5e3a41d3393ee4f543f7 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 19:43:38 +0800 Subject: [PATCH 07/13] internal:link by LLGoFile to find libunwind --- internal/crosscompile/cosscompile.go | 6 ------ runtime/internal/clite/debug/debug.go | 2 +- runtime/internal/clite/os/os_other.go | 2 +- xtool/env/llvm/llvm.go | 10 +--------- 4 files changed, 3 insertions(+), 17 deletions(-) diff --git a/internal/crosscompile/cosscompile.go b/internal/crosscompile/cosscompile.go index cc4b15c6..8865aba6 100644 --- a/internal/crosscompile/cosscompile.go +++ b/internal/crosscompile/cosscompile.go @@ -6,11 +6,9 @@ import ( "os" "path/filepath" "runtime" - "strings" "github.com/goplus/llgo/internal/env" "github.com/goplus/llgo/internal/xtool/llvm" - envllvm "github.com/goplus/llgo/xtool/env/llvm" ) type Export struct { @@ -68,10 +66,6 @@ func Use(goos, goarch string, wasiThreads, changeRpath bool) (export Export, err "-latomic", "-lpthread", // libpthread is built-in since glibc 2.34 (2021-08-01); we need to support earlier versions. ) - llvmEnv := envllvm.New("") - if cflags := llvmEnv.Cflags(); cflags != "" { - export.CFLAGS = append(export.CFLAGS, strings.Fields(cflags)...) - } } return } diff --git a/runtime/internal/clite/debug/debug.go b/runtime/internal/clite/debug/debug.go index 2a02b718..5aa793f2 100644 --- a/runtime/internal/clite/debug/debug.go +++ b/runtime/internal/clite/debug/debug.go @@ -9,7 +9,7 @@ import ( ) const ( - LLGoFiles = "_wrap/debug.cpp" + LLGoFiles = "$(llvm-config --cflags): _wrap/debug.cpp" ) type Info struct { diff --git a/runtime/internal/clite/os/os_other.go b/runtime/internal/clite/os/os_other.go index 55bf6132..e07e04a6 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.c" + LLGoFiles = "_os/os.cpp" LLGoPackage = "link" ) diff --git a/xtool/env/llvm/llvm.go b/xtool/env/llvm/llvm.go index e1a18abd..a34757c9 100644 --- a/xtool/env/llvm/llvm.go +++ b/xtool/env/llvm/llvm.go @@ -50,7 +50,6 @@ func defaultLLVMConfigBin() string { // Env represents an LLVM installation. type Env struct { binDir string - cflags string } // New creates a new [Env] instance. @@ -63,12 +62,7 @@ func New(llvmConfigBin string) *Env { // executables are assumed to be in PATH. binDir, _ := exec.Command(llvmConfigBin, "--bindir").Output() - cflags, _ := exec.Command(llvmConfigBin, "--cflags").Output() - - e := &Env{ - binDir: strings.TrimSpace(string(binDir)), - cflags: strings.TrimSpace(string(cflags)), - } + e := &Env{binDir: strings.TrimSpace(string(binDir))} return e } @@ -76,8 +70,6 @@ func New(llvmConfigBin string) *Env { // means LLVM executables are assumed to be in PATH. func (e *Env) BinDir() string { return e.binDir } -func (e *Env) Cflags() string { return e.cflags } - // Clang returns a new [clang.Cmd] instance. func (e *Env) Clang() *clang.Cmd { bin := filepath.Join(e.BinDir(), "clang++") From efabdf27c8f8e206fdcb6653fcca0bc12e0f7582 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 20:04:13 +0800 Subject: [PATCH 08/13] fcntl_unix.cpp --- .../syscall/unix/_unix/{fcntl_unix.c => fcntl_unix.cpp} | 0 runtime/internal/lib/internal/syscall/unix/fcntl_unix.go | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename runtime/internal/lib/internal/syscall/unix/_unix/{fcntl_unix.c => fcntl_unix.cpp} (100%) diff --git a/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.c b/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp similarity index 100% rename from runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.c rename to runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp diff --git a/runtime/internal/lib/internal/syscall/unix/fcntl_unix.go b/runtime/internal/lib/internal/syscall/unix/fcntl_unix.go index 93c768d9..140c6c94 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.c" + LLGoFiles = "_unix/fcntl_unix.cpp" ) //go:linkname llgo_fcntl2 C.llgo_fcntl2 From 4f5c95045dfd22e86204039c939d31cb05379741 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 20:30:44 +0800 Subject: [PATCH 09/13] chore:keep origin c format --- internal/build/build.go | 2 -- runtime/internal/clite/bitcast/_cast/cast.cpp | 20 ++++++++++++------- runtime/internal/clite/debug/_wrap/debug.cpp | 11 +++++++--- runtime/internal/clite/os/_os/os.cpp | 19 ++++++++++-------- .../syscall/unix/_unix/fcntl_unix.cpp | 6 +++++- .../internal/lib/runtime/_wrap/runtime.cpp | 6 ++++-- xtool/clang/clang.go | 3 --- 7 files changed, 41 insertions(+), 26 deletions(-) diff --git a/internal/build/build.go b/internal/build/build.go index 1bc6078a..654b3746 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -490,8 +490,6 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, conf *Co } linkArgs = append(linkArgs, exargs...) - fmt.Fprintf(os.Stderr, "linkArgs: %v\n", linkArgs) - err = compileAndLinkLLFiles(ctx, app, llFiles, linkArgs, verbose) check(err) diff --git a/runtime/internal/clite/bitcast/_cast/cast.cpp b/runtime/internal/clite/bitcast/_cast/cast.cpp index ae4d6707..8c5b12a1 100644 --- a/runtime/internal/clite/bitcast/_cast/cast.cpp +++ b/runtime/internal/clite/bitcast/_cast/cast.cpp @@ -1,33 +1,39 @@ -typedef union { +typedef union +{ double d; float f; long v; long long ll; } castUnion; -extern "C" { +extern "C" { -double llgoToFloat64(long long v) { +double llgoToFloat64(long long v) +{ castUnion k; k.ll = v; return k.d; } -float llgoToFloat32(int v) { +float llgoToFloat32(int v) +{ castUnion k; k.v = v; return k.f; } -long long llgoFromFloat64(double v) { +long long llgoFromFloat64(double v) +{ castUnion k; k.d = v; return k.ll; } -int llgoFromFloat32(float v) { +int llgoFromFloat32(float v) +{ castUnion k; k.f = v; return k.v; } -} \ No newline at end of file + +} diff --git a/runtime/internal/clite/debug/_wrap/debug.cpp b/runtime/internal/clite/debug/_wrap/debug.cpp index 441cd971..64d2a846 100644 --- a/runtime/internal/clite/debug/_wrap/debug.cpp +++ b/runtime/internal/clite/debug/_wrap/debug.cpp @@ -11,9 +11,13 @@ extern "C" { -void *llgo_address() { return __builtin_return_address(0); } +void *llgo_address() { + return __builtin_return_address(0); +} -int llgo_addrinfo(void *addr, Dl_info *info) { return dladdr(addr, info); } +int llgo_addrinfo(void *addr, Dl_info *info) { + return dladdr(addr, info); +} void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *offset, void *sp, char *name)) { unw_cursor_t cursor; @@ -31,10 +35,11 @@ void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *o if (unw_get_reg(&cursor, UNW_REG_IP, &pc) == 0) { unw_get_proc_name(&cursor, fname, sizeof(fname), &offset); unw_get_reg(&cursor, UNW_REG_SP, &sp); - if (fn(ctx, (void *)pc, (void *)offset, (void *)sp, fname) == 0) { + if (fn(ctx, (void*)pc, (void*)offset, (void*)sp, fname) == 0) { return; } } } } + } diff --git a/runtime/internal/clite/os/_os/os.cpp b/runtime/internal/clite/os/_os/os.cpp index cc3d29d5..db43043c 100644 --- a/runtime/internal/clite/os/_os/os.cpp +++ b/runtime/internal/clite/os/_os/os.cpp @@ -1,15 +1,18 @@ -#include #include +#include extern "C" { -int cliteClearenv() { - extern char **environ; - if (environ != NULL) { - *environ = NULL; - } - return 0; +int cliteClearenv() +{ + extern char **environ; + if (environ != NULL) + { + *environ = NULL; + } + return 0; } int cliteErrno() { return errno; } -} \ No newline at end of file + +} diff --git a/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp b/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp index fa1ad6f9..1224ab0e 100644 --- a/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp +++ b/runtime/internal/lib/internal/syscall/unix/_unix/fcntl_unix.cpp @@ -9,6 +9,8 @@ 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 @@ -30,4 +32,6 @@ 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/runtime/_wrap/runtime.cpp b/runtime/internal/lib/runtime/_wrap/runtime.cpp index f97d91bd..269a7b22 100644 --- a/runtime/internal/lib/runtime/_wrap/runtime.cpp +++ b/runtime/internal/lib/runtime/_wrap/runtime.cpp @@ -2,11 +2,13 @@ extern "C" { -int llgo_maxprocs() { +int llgo_maxprocs() +{ #ifdef _SC_NPROCESSORS_ONLN return (int)sysconf(_SC_NPROCESSORS_ONLN); #else return 1; #endif } -} \ No newline at end of file + +} diff --git a/xtool/clang/clang.go b/xtool/clang/clang.go index 78ca3e18..9ac3974d 100644 --- a/xtool/clang/clang.go +++ b/xtool/clang/clang.go @@ -91,7 +91,6 @@ func (p *Cmd) execWithFlags(flags []string, args ...string) error { if p.Env != nil { cmd.Env = p.Env } - fmt.Fprintln(os.Stderr, cmd.String()) return cmd.Run() } @@ -132,8 +131,6 @@ func (p *Cmd) CheckLinkArgs(cmdArgs []string, wasm bool) error { srcIn := strings.NewReader(src) p.Stdin = srcIn - fmt.Fprintf(os.Stderr, "args: %v\n", args) - // Execute the command return p.execWithFlags([]string{"LDFLAGS", "CCFLAGS"}, args...) } From bdff346a20a8e2a07fe7e013c33070f430e4f0fb Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 20:49:56 +0800 Subject: [PATCH 10/13] temp moveup testdemo --- .github/workflows/llgo.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/llgo.yml b/.github/workflows/llgo.yml index bc375f97..f3f4ed7b 100644 --- a/.github/workflows/llgo.yml +++ b/.github/workflows/llgo.yml @@ -70,11 +70,6 @@ jobs: with: go-version: ${{matrix.go}} - - name: _xtool build tests - run: | - cd _xtool - llgo build -v ./... - - name: Test demos run: | # TODO(lijie): force python3-embed to be linked with python-3.12-embed @@ -88,6 +83,11 @@ jobs: export PKG_CONFIG_PATH=$pcdir bash .github/workflows/test_demo.sh + - name: _xtool build tests + run: | + cd _xtool + llgo build -v ./... + - name: Show test result run: cat result.md From e7e9530eb86a1d3e31ca782ef901156f923f1feb Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 21:02:32 +0800 Subject: [PATCH 11/13] some wrap to cpp --- runtime/internal/clite/ffi/_wrap/{libffi.c => libffi.cpp} | 4 ++++ runtime/internal/clite/ffi/ffi_other.go | 2 +- runtime/internal/clite/libuv/_wrap/{libuv.c => libuv.cpp} | 6 +++++- runtime/internal/clite/libuv/libuv.go | 2 +- .../internal/clite/openssl/_wrap/{openssl.c => openssl.cpp} | 4 ++++ runtime/internal/clite/openssl/openssl.go | 2 +- .../lib/internal/cpu/_wrap/{cpu_x86.c => cpu_x86.cpp} | 5 +++++ runtime/internal/lib/internal/cpu/cpu_x86.go | 2 +- 8 files changed, 22 insertions(+), 5 deletions(-) rename runtime/internal/clite/ffi/_wrap/{libffi.c => libffi.cpp} (87%) rename runtime/internal/clite/libuv/_wrap/{libuv.c => libuv.cpp} (82%) rename runtime/internal/clite/openssl/_wrap/{openssl.c => openssl.cpp} (84%) rename runtime/internal/lib/internal/cpu/_wrap/{cpu_x86.c => cpu_x86.cpp} (97%) diff --git a/runtime/internal/clite/ffi/_wrap/libffi.c b/runtime/internal/clite/ffi/_wrap/libffi.cpp similarity index 87% rename from runtime/internal/clite/ffi/_wrap/libffi.c rename to runtime/internal/clite/ffi/_wrap/libffi.cpp index 53fa1c70..59b4cfd8 100644 --- a/runtime/internal/clite/ffi/_wrap/libffi.c +++ b/runtime/internal/clite/ffi/_wrap/libffi.cpp @@ -1,5 +1,9 @@ #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 6953dfdc..06fef2f3 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.c" + LLGoFiles = "$(pkg-config --cflags libffi): _wrap/libffi.cpp" ) /* diff --git a/runtime/internal/clite/libuv/_wrap/libuv.c b/runtime/internal/clite/libuv/_wrap/libuv.cpp similarity index 82% rename from runtime/internal/clite/libuv/_wrap/libuv.c rename to runtime/internal/clite/libuv/_wrap/libuv.cpp index d3d51448..30114341 100644 --- a/runtime/internal/clite/libuv/_wrap/libuv.c +++ b/runtime/internal/clite/libuv/_wrap/libuv.cpp @@ -1,5 +1,9 @@ #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 b781f1b5..b9dd6424 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.c" + LLGoFiles = "$(pkg-config --cflags libuv): _wrap/libuv.cpp" ) // ---------------------------------------------- diff --git a/runtime/internal/clite/openssl/_wrap/openssl.c b/runtime/internal/clite/openssl/_wrap/openssl.cpp similarity index 84% rename from runtime/internal/clite/openssl/_wrap/openssl.c rename to runtime/internal/clite/openssl/_wrap/openssl.cpp index 7cc5bbdb..8d7c8680 100644 --- a/runtime/internal/clite/openssl/_wrap/openssl.c +++ b/runtime/internal/clite/openssl/_wrap/openssl.cpp @@ -1,5 +1,9 @@ #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 df237c85..8bca7d28 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.c" + LLGoFiles = "$(pkg-config --cflags openssl): _wrap/openssl.cpp" LLGoPackage = "link: $(pkg-config --libs openssl); -lssl -lcrypto" ) diff --git a/runtime/internal/lib/internal/cpu/_wrap/cpu_x86.c b/runtime/internal/lib/internal/cpu/_wrap/cpu_x86.cpp similarity index 97% rename from runtime/internal/lib/internal/cpu/_wrap/cpu_x86.c rename to runtime/internal/lib/internal/cpu/_wrap/cpu_x86.cpp index 3756ee17..1305c86c 100644 --- a/runtime/internal/lib/internal/cpu/_wrap/cpu_x86.c +++ b/runtime/internal/lib/internal/cpu/_wrap/cpu_x86.cpp @@ -1,3 +1,6 @@ + +extern "C" { + #if defined(__GNUC__) || defined(__clang__) void llgo_getcpuid(unsigned int eax, unsigned int ecx, unsigned int *a, unsigned int *b, @@ -19,3 +22,5 @@ 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 46022c42..47374b9e 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.c" + LLGoFiles = "_wrap/cpu_x86.cpp" ) //go:linkname c_getcpuid C.llgo_getcpuid From 9001cdb8f2e907d932c15e081a1215e1f51ba879 Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Wed, 11 Jun 2025 21:11:21 +0800 Subject: [PATCH 12/13] test:lib/cpp test --- _demo/cppstr/cppstr.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 _demo/cppstr/cppstr.go diff --git a/_demo/cppstr/cppstr.go b/_demo/cppstr/cppstr.go new file mode 100644 index 00000000..25bb941a --- /dev/null +++ b/_demo/cppstr/cppstr.go @@ -0,0 +1,12 @@ +package main + +import ( + "github.com/goplus/lib/c" + "github.com/goplus/lib/cpp/std" +) + +func main() { + s := std.Str("Hello world\n") + c.Printf(s.CStr()) + print(s.Str(), s.Size(), "\n") +} From 93197e76214d992227e9a90c4ebaa12180e7c99d Mon Sep 17 00:00:00 2001 From: luoliwoshang <2643523683@qq.com> Date: Thu, 12 Jun 2025 11:52:41 +0800 Subject: [PATCH 13/13] internal/build:compile with c mode,when c file --- internal/build/build.go | 7 +++++++ runtime/internal/clite/bitcast/_cast/{cast.cpp => cast.c} | 4 ---- runtime/internal/clite/bitcast/bitcast.go | 2 +- runtime/internal/clite/debug/_wrap/{debug.cpp => debug.c} | 6 +----- runtime/internal/clite/debug/debug.go | 2 +- runtime/internal/clite/ffi/_wrap/{libffi.cpp => libffi.c} | 4 ---- runtime/internal/clite/ffi/ffi_other.go | 2 +- runtime/internal/clite/libuv/_wrap/{libuv.cpp => libuv.c} | 6 +----- runtime/internal/clite/libuv/libuv.go | 2 +- .../clite/openssl/_wrap/{openssl.cpp => openssl.c} | 4 ---- runtime/internal/clite/openssl/openssl.go | 2 +- runtime/internal/clite/os/_os/{os.cpp => os.c} | 4 ---- runtime/internal/clite/os/os_darwin.go | 2 +- runtime/internal/clite/os/os_other.go | 2 +- .../lib/internal/cpu/_wrap/{cpu_x86.cpp => cpu_x86.c} | 5 ----- runtime/internal/lib/internal/cpu/cpu_x86.go | 2 +- .../syscall/unix/_unix/{fcntl_unix.cpp => fcntl_unix.c} | 6 +----- runtime/internal/lib/internal/syscall/unix/fcntl_unix.go | 2 +- .../internal/lib/runtime/_wrap/{runtime.cpp => runtime.c} | 4 ---- runtime/internal/lib/runtime/runtime.go | 2 +- 20 files changed, 20 insertions(+), 50 deletions(-) rename runtime/internal/clite/bitcast/_cast/{cast.cpp => cast.c} (95%) rename runtime/internal/clite/debug/_wrap/{debug.cpp => debug.c} (98%) rename runtime/internal/clite/ffi/_wrap/{libffi.cpp => libffi.c} (87%) rename runtime/internal/clite/libuv/_wrap/{libuv.cpp => libuv.c} (82%) rename runtime/internal/clite/openssl/_wrap/{openssl.cpp => openssl.c} (84%) rename runtime/internal/clite/os/_os/{os.cpp => os.c} (91%) rename runtime/internal/lib/internal/cpu/_wrap/{cpu_x86.cpp => cpu_x86.c} (97%) rename runtime/internal/lib/internal/syscall/unix/_unix/{fcntl_unix.cpp => fcntl_unix.c} (96%) rename runtime/internal/lib/runtime/_wrap/{runtime.cpp => runtime.c} (89%) 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