internal/build:compile with c mode,when c file
This commit is contained in:
@@ -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) {
|
func clFile(ctx *context, args []string, cFile, expFile string, procFile func(linkFile string), verbose bool) {
|
||||||
llFile := expFile + filepath.Base(cFile) + ".ll"
|
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, "-emit-llvm", "-S", "-o", llFile, "-c", cFile)
|
||||||
args = append(args, ctx.crossCompile.CCFLAGS...)
|
args = append(args, ctx.crossCompile.CCFLAGS...)
|
||||||
args = append(args, ctx.crossCompile.CFLAGS...)
|
args = append(args, ctx.crossCompile.CFLAGS...)
|
||||||
|
|||||||
@@ -6,8 +6,6 @@ typedef union
|
|||||||
long long ll;
|
long long ll;
|
||||||
} castUnion;
|
} castUnion;
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
double llgoToFloat64(long long v)
|
double llgoToFloat64(long long v)
|
||||||
{
|
{
|
||||||
castUnion k;
|
castUnion k;
|
||||||
@@ -35,5 +33,3 @@ int llgoFromFloat32(float v)
|
|||||||
k.f = v;
|
k.f = v;
|
||||||
return k.v;
|
return k.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -19,7 +19,7 @@ package bitcast
|
|||||||
import _ "unsafe"
|
import _ "unsafe"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoFiles = "_cast/cast.cpp"
|
LLGoFiles = "_cast/cast.c"
|
||||||
LLGoPackage = "link"
|
LLGoPackage = "link"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,6 @@
|
|||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <libunwind.h>
|
#include <libunwind.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
void *llgo_address() {
|
void *llgo_address() {
|
||||||
return __builtin_return_address(0);
|
return __builtin_return_address(0);
|
||||||
}
|
}
|
||||||
@@ -40,6 +38,4 @@ void llgo_stacktrace(int skip, void *ctx, int (*fn)(void *ctx, void *pc, void *o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoFiles = "$(llvm-config --cflags): _wrap/debug.cpp"
|
LLGoFiles = "$(llvm-config --cflags): _wrap/debug.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
#include <ffi.h>
|
#include <ffi.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
void *llog_ffi_closure_alloc(void **code) {
|
void *llog_ffi_closure_alloc(void **code) {
|
||||||
return ffi_closure_alloc(sizeof(ffi_closure), code);
|
return ffi_closure_alloc(sizeof(ffi_closure), code);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoPackage = "link: $(pkg-config --libs libffi); -lffi"
|
LLGoPackage = "link: $(pkg-config --libs libffi); -lffi"
|
||||||
LLGoFiles = "$(pkg-config --cflags libffi): _wrap/libffi.cpp"
|
LLGoFiles = "$(pkg-config --cflags libffi): _wrap/libffi.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
int uv_tcp_get_io_watcher_fd (uv_tcp_t* handle) {
|
int uv_tcp_get_io_watcher_fd (uv_tcp_t* handle) {
|
||||||
return handle->io_watcher.fd;
|
return handle->io_watcher.fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoPackage = "link: $(pkg-config --libs libuv); -luv"
|
LLGoPackage = "link: $(pkg-config --libs libuv); -luv"
|
||||||
LLGoFiles = "$(pkg-config --cflags libuv): _wrap/libuv.cpp"
|
LLGoFiles = "$(pkg-config --cflags libuv): _wrap/libuv.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ----------------------------------------------
|
// ----------------------------------------------
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
#include <openssl/crypto.h>
|
#include <openssl/crypto.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
void opensslFree(void *ptr) {
|
void opensslFree(void *ptr) {
|
||||||
OPENSSL_free(ptr);
|
OPENSSL_free(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
|
|
||||||
const (
|
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"
|
LLGoPackage = "link: $(pkg-config --libs openssl); -lssl -lcrypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
int cliteClearenv()
|
int cliteClearenv()
|
||||||
{
|
{
|
||||||
extern char **environ;
|
extern char **environ;
|
||||||
@@ -14,5 +12,3 @@ int cliteClearenv()
|
|||||||
}
|
}
|
||||||
|
|
||||||
int cliteErrno() { return errno; }
|
int cliteErrno() { return errno; }
|
||||||
|
|
||||||
}
|
|
||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoFiles = "_os/os.cpp"
|
LLGoFiles = "_os/os.c"
|
||||||
LLGoPackage = "link"
|
LLGoPackage = "link"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoFiles = "_os/os.cpp"
|
LLGoFiles = "_os/os.c"
|
||||||
LLGoPackage = "link"
|
LLGoPackage = "link"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
#if defined(__GNUC__) || defined(__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
void llgo_getcpuid(unsigned int eax, unsigned int ecx,
|
void llgo_getcpuid(unsigned int eax, unsigned int ecx,
|
||||||
unsigned int *a, unsigned int *b,
|
unsigned int *a, unsigned int *b,
|
||||||
@@ -22,5 +19,3 @@ void llgo_getcpuid(unsigned int eax, unsigned int ecx,
|
|||||||
#else
|
#else
|
||||||
#error This code requires GCC or Clang
|
#error This code requires GCC or Clang
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoPackage = "link"
|
LLGoPackage = "link"
|
||||||
LLGoFiles = "_wrap/cpu_x86.cpp"
|
LLGoFiles = "_wrap/cpu_x86.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:linkname c_getcpuid C.llgo_getcpuid
|
//go:linkname c_getcpuid C.llgo_getcpuid
|
||||||
|
|||||||
@@ -9,8 +9,6 @@ struct fcntl_ret
|
|||||||
int32_t err; // Error code
|
int32_t err; // Error code
|
||||||
};
|
};
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
// llgo_fcntl implements the fcntl system call wrapper for Go
|
// llgo_fcntl implements the fcntl system call wrapper for Go
|
||||||
// fd: file descriptor
|
// fd: file descriptor
|
||||||
// cmd: fcntl command
|
// cmd: fcntl command
|
||||||
@@ -32,6 +30,4 @@ struct fcntl_ret llgo_fcntl2(int32_t fd, int32_t cmd, int32_t arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
// llgo:skip fcntl
|
// llgo:skip fcntl
|
||||||
const (
|
const (
|
||||||
LLGoPackage = "link"
|
LLGoPackage = "link"
|
||||||
LLGoFiles = "_unix/fcntl_unix.cpp"
|
LLGoFiles = "_unix/fcntl_unix.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
//go:linkname llgo_fcntl2 C.llgo_fcntl2
|
//go:linkname llgo_fcntl2 C.llgo_fcntl2
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
|
|
||||||
int llgo_maxprocs()
|
int llgo_maxprocs()
|
||||||
{
|
{
|
||||||
#ifdef _SC_NPROCESSORS_ONLN
|
#ifdef _SC_NPROCESSORS_ONLN
|
||||||
@@ -10,5 +8,3 @@ int llgo_maxprocs()
|
|||||||
return 1;
|
return 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
@@ -28,7 +28,7 @@ type _runtime struct{}
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
LLGoPackage = "link"
|
LLGoPackage = "link"
|
||||||
LLGoFiles = "_wrap/runtime.cpp"
|
LLGoFiles = "_wrap/runtime.c"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GOROOT returns the root of the Go tree. It uses the
|
// GOROOT returns the root of the Go tree. It uses the
|
||||||
|
|||||||
Reference in New Issue
Block a user