go runtime fails to compile - go

I am just wondering why would go runtime fail to build. How do we pass flags (-fpermissive in this case) to the c compiler which golang compiler is using to build the runtime. I am using gcc-4.6.2 on ubuntu 12.04
../../../thirdparty/go1.4.2/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/src/runtime/cgo/gcc_linux_amd64.c: In function ‘void _cgo_sys_thread_start(ThreadStart*)’:
../../../thirdparty/go1.4.2/x86_64-unknown-linux-gnu/x86_64-unknown-linux-gnu/src/runtime/cgo/gcc_linux_amd64.c:45:41: error: invalid conversion from ‘void*’ to ‘__sigset_t*’ [-fpermissive]
A sample program written also fails to compile, it seems the nil defined in the go code is the problem, i wonder how others are working, when does the golang compiler compiles this runtime code ?
gcc t.c -lpthread -o t
t.c: In function ‘void* hello_world(void*)’:
t.c:12:41: error: invalid conversion from ‘void*’ to ‘__sigset_t*’ [-fpermissive]
/usr/include/x86_64-linux-gnu/bits/sigthread.h:31:12: error: initializing argument 3 of ‘int pthread_sigmask(int, const __sigset_t*, __sigset_t*)’ [-fpermissive]
rk#rk-VirtualBox:~$ gcc -fpermissive t.c -lpthread -o t
t.c: In function ‘void* hello_world(void*)’:
t.c:12:41: warning: invalid conversion from ‘void*’ to ‘__sigset_t*’ [-fpermissive]
rk#rk-VirtualBox:~$ cat t.c
#include<pthread.h>
#include<stdio.h>
#include<signal.h>
#define nil ((void*)0)
static void*
hello_world(void *vptr)
{
sigset_t set;
sigemptyset(&set);
pthread_sigmask(SIG_BLOCK, &set, nil);
printf("hello world");
return NULL;
}
int main(int ac, char **av)
{
pthread_t t;
pthread_create(&t, NULL, hello_world, NULL);
pthread_join(t, NULL);
return 0;
}
/usr/include/x86_64-linux-gnu/bits/sigthread.h:31:12: error: initializing argument 3 of ‘int pthread_sigmask(int, const __sigset_t*, __sigset_t*)’ [-fpermissive]
make: *** [rulemanager] Error 2

Related

An error occurred while converting the C extension file( test1.c ) compiled by the pro*c file into a wasm file through Emscripten

An error occurred while converting the C extension file( test1.c ) compiled by the pro*c file into a wasm file through Emscripten.
I am using Emscripten to convert legacy code to WebAssembly's WASM file. After compiling the Pro*C file into a .C file, converting it using Emscipten, the following error occurred.
Thank you in advance.
The following is the output of the execution command and errors.
D:\C-connection\FASSDB>emcc test1.c -s WASM=1 -s -o public/test.js
test1.c:117:8: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
extern sqlcxt ( void **, unsigned int *,
~~~~~~ ^
int
test1.c:119:8: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
extern sqlcx2t( void **, unsigned int *,
~~~~~~ ^
int
test1.c:121:8: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
extern sqlbuft( void **, char * );
~~~~~~ ^
int
test1.c:122:8: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
extern sqlgs2t( void **, char * );
~~~~~~ ^
int
test1.c:123:8: error: type specifier missing, defaults to 'int'; ISO C99 and later do not support implicit int [-Wimplicit-int]
extern sqlorat( void **, unsigned int *, void * );
~~~~~~ ^
int
5 errors generated.
emcc: error: 'D:/C-connection/emsdk/upstream/bin\clang.exe -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -D__EMSCRIPTEN_major__=3 -D__EMSCRIPTEN_minor__=1 -D__EMSCRIPTEN_tiny__=18 -Werror=implicit-function-declaration -ID:\C-connection\emsdk\upstream\emscripten\cache\sysroot\include\SDL --sysroot=D:\C-connection\emsdk\upstream\emscripten\cache\sysroot -Xclang -iwithsysroot/include\compat test1.c -c -o C:\Users\REALHO~1\AppData\Local\Temp\emscripten_temp_337o8xxh\test1_0.o' failed (returned 1)
The following is a Pro*C file before compiling into *.c.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
EXEC SQL INCLUDE sqlca.h;
EXEC SQL BEGIN DECLARE SECTION;
varchar id[50];
varchar password[50];
varchar tns[50];
EXEC SQL END DECLARE SECTION;
memset(&id, 0x00, sizeof(id));
memset(&password, 0x00, sizeof(password));
memset(&tns, 0x00, sizeof(tns));
strcpy((char*)id.arr, "dbid");
strcpy((char*)password.arr, "dbpassword");
strcpy((char*)tns.arr, "orcl");
id.len = strlen((char*)id.arr);
password.len = strlen((char*)password.arr);
tns.len = strlen((char*)tns.arr);
// EXEC SQL CONNECT :id IDENTIFIED BY :password ;
EXEC SQL CONNECT :id IDENTIFIED BY :password USING :tns ;
if(sqlca.sqlcode < 0) {
printf("connect error\n");
}
else {
printf("connect success\n");
}
return 0;
}

How to bind member function with std::function?

I want to bind member function, but it seems failed.
Q4kDeviceSource.hh
class Q4kDeviceSource {
public:
void videoStreamCallback(QIPCamStreamCbType streamCbType, uint32_t streamId, uint8_t *buffer, size_t bufferSize);
。。。
}
typedef std::function<void(QIPCamStreamCbType cbType, uint32_t streamId,
uint8_t* buffer, size_t bufferSize)>
StreamCallback;
Q4kDeviceSource.cpp
。。。
StreamCallback videoElementryCb = std::bind(&Q4kDeviceSource::videoStreamCallback, this,
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
videoElementryCb(QIPCamStreamCbType::QIPCAM_STREAMCBTYPE_NORMAL,id,NULL,0);
。。。
build failed!
./prebuilts/ndk/9/sources/cxx-stl/gnu-libstdc++/4.8/include/functional:2463: error: undefined reference to 'std::__throw_bad_function_call()'
collect2: error: ld returned 1 exit status
Looks like you link with gcc instead of g++.
The difference is that g++ also links in libstdc++, whereas gcc does not.
Either link with g++ or add -lstdc++ to your linker command line.

GCC gives confusing warning message when using pointer to struct <typedef>

On compiling the following C program, GCC emits a warning message which is somewhat confusing.
Program Source
#include <stdio.h>
typedef struct {
int x;
} dummy_t;
void myfunc (dummy_t *pointer)
{
printf("x = %d\n", pointer->x);
}
int main ()
{
dummy_t d = { 10 };
/* INCORRECT. */
myfunc((struct dummy_t *)&d);
/* Correct. */
// myfunc((dummy_t *)&d);
return 0;
}
Compilation
bash$ gcc c.c
c.c: In function ‘main’:
c.c:17:20: warning: passing argument 1 of ‘myfunc’ from incompatible pointer type
myfunc((struct dummy_t *)&d);
^
c.c:7:6: note: expected ‘struct dummy_t *’ but argument is of type ‘struct dummy_t *’
void myfunc (dummy_t *pointer)
Notice how both the expected type and the argument type are reported to have the same value struct dummy_t *. This is confusing.
Shouldn't the expected type be dummy_t *?
The above program is a simplified version of the actual code where I faced this problem.
GCC Version
bash$ gcc --version
gcc (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4
You're right that the error message is confusing. A newer version gives a much better error message:
note: expected 'dummy_t * {aka struct <anonymous> *}' but argument is
of type 'struct dummy_t *'
As you can see, dummy_t and struct dummy_t are different types. With this declaration:
typedef struct {
int x;
} dummy_t;
You are typedef'ing an anonymous struct. However, later when you do struct dummy_t, you are forward declaring a new struct named dummy_t. Clearly, these are two different types, hence the error.

Building Crypto++ 5.6.2 with Cygwin x86_64

I am attempting to build CryptoPP with Cygwin x86_64, but I'm having some trouble with osrng.cpp.
I'm using gcc's C++ compiler, and I'm getting the following error at line 50 of osrng.cpp
$ make
g++ -DNDEBUG -g -O2 -march=native -pipe -c osrng.cpp
osrng.cpp: In constructor ‘CryptoPP::MicrosoftCryptoProvider::MicrosoftCryptoProvider()’:
osrng.cpp:50:80: error: invalid conversion from ‘CryptoPP::MicrosoftCryptoProvider::ProviderHandle* {aka long unsigned int*}’ to ‘HCRYPTPROV* {aka long long unsigned int*}’ [-fpermissive]
if(!CryptAcquireContext(&m_hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
^
In file included from /usr/include/w32api/windows.h:95:0,
from osrng.cpp:19:
/usr/include/w32api/wincrypt.h:646:26: error: initializing argument 1 of ‘WINBOOL CryptAcquireContextA(HCRYPTPROV*, LPCSTR, LPCSTR, DWORD, DWORD)’ [-fpermissive]
WINIMPM WINBOOL WINAPI CryptAcquireContextA(HCRYPTPROV *phProv,LPCSTR szContainer,LPCSTR szProvider,DWORD dwProvType,DWORD dwFlags);
^
GNUmakefile:208: recipe for target 'osrng.o' failed
make: *** [osrng.o] Error 1
I have successfully compiled the whole thing under the 32bit version of Cygwin before.
How can I fix this for the 64bit edition?
EDIT As suggested by #Yakov's answer, I replaced if defined(_WIN64)if defined(__x86_64__) by if in line 30 of osrng.h.
Sadly though, I immediately run into the next problem, indicated by the following error:
$ make
g++ -DNDEBUG -g -O2 -march=native -pipe -c fipstest.cpp
In file included from dll.h:30:0,
from fipstest.cpp:8:
osrng.h:34:19: error: expected ‘;’ at end of member declaration
typedef unsigned __int64 ProviderHandle; // type HCRYPTPROV, avoid #include <windows.h>
^
osrng.h:34:27: error: ‘ProviderHandle’ does not name a type
typedef unsigned __int64 ProviderHandle; // type HCRYPTPROV, avoid #include <windows.h>
^
osrng.h:38:2: error: ‘ProviderHandle’ does not name a type
ProviderHandle GetProviderHandle() const {return m_hProvider;}
^
osrng.h:40:2: error: ‘ProviderHandle’ does not name a type
ProviderHandle m_hProvider;
^
GNUmakefile:208: recipe for target 'fipstest.o' failed
make: *** [fipstest.o] Error 1
Thankfully, GCC error messages have improved significantly in recent releases. The {aka}s tell you that there is a mismatch between long and long long. Keep in mind that Win64 is LLP64: long is still only 32-bits, and you need a long long to match the size of a pointer. Most (all?) other 64-bit platforms are LP64, meaning that long matches the size of a pointer.
In this particular case, see the if defined(_WIN64) in osrng.h; you will need to change that condition to if defined(__x86_64__) instead.
You might run into problems with the __int64 type as well. Replace those with long long. (Occurs here, here and here.)
You might also find word64 useful. From Crypto++'s config.h:
#if defined(_MSC_VER) || defined(__BORLANDC__)
typedef unsigned __int64 word64;
#define W64LIT(x) x##ui64
#else
typedef unsigned long long word64;
#define W64LIT(x) x##ULL
#endif
There's a couple of Cygwin defines in there too. But they don't look interesting. For example:
#ifndef TYPE_OF_SOCKLEN_T
# if defined(_WIN32) || defined(__CYGWIN__)
# define TYPE_OF_SOCKLEN_T int
# else
# define TYPE_OF_SOCKLEN_T ::socklen_t
# endif
#endif
#if defined(__CYGWIN__) && defined(PREFER_WINDOWS_STYLE_SOCKETS)
# define __USE_W32_SOCKETS
#endif
(Sorry about the comment here. Its too bing to fit in the little comment block).

Pthreads compile not working

I have written some code but it doesn't seem to work when I compile it. I am trying to run this in Ubuntu:
#include <pthread.h>
#include <ctype.h>
#include <unistd.h>
char buffer[128];
void *write_thread(void *args)
{
int count = *((int*)args);
write(STDOUT_FILENO, buffer, count);
pthread_exit(0);
}
void *toupper_thread(void *args)
{
int i;
int count = *((int*)args);
for(i = 0; i < count; i++) {
buffer[i] = toupper(buffer[i]);
}
pthread_t writeId;
pthread_create(&writeId, NULL, write_thread, &count);
pthread_join(writeId, NULL);
pthread_exit(0);
}
void *read_thread(void *args)
{
int count = read(STDIN_FILENO, buffer, 128);
pthread_t toupperId;
pthread_create(&toupperId, NULL, toupper_thread, &count);
pthread_join(toupperId, NULL);
//buffer[count] = 0;
pthread_exit(0);
}
int main()
{
pthread_t threadId;
pthread_create(&threadId, NULL, read_thread, NULL);
pthread_join(threadId, NULL);
}
and I get these errors when I try to compile it with gcc -pthread prob41.c or with gcc prob41.c -lpthread:
prob41.c:1:21: error: pthread.h: No such file or directory
prob41.c: In function ‘toupper_thread’:
prob41.c:23: error: ‘pthread_t’ undeclared (first use in this function)
prob41.c:23: error: (Each undeclared identifier is reported only once
prob41.c:23: error: for each function it appears in.)
prob41.c:23: error: expected ‘;’ before ‘writeId’
prob41.c:24: error: ‘writeId’ undeclared (first use in this function)
prob41.c: In function ‘read_thread’:
prob41.c:33: error: ‘pthread_t’ undeclared (first use in this function)
prob41.c:33: error: expected ‘;’ before ‘toupperId’
prob41.c:34: error: ‘toupperId’ undeclared (first use in this function)
prob41.c: In function ‘main’:
prob41.c:45: error: ‘pthread_t’ undeclared (first use in this function)
prob41.c:45: error: expected ‘;’ before ‘threadId’
prob41.c:46: error: ‘threadId’ undeclared (first use in this function)
I don't know what I'm doing wrong.
It seems that you missed some dependencies.
Try this:
$ sudo apt-get install -y libc6-dev
Need to add -I flag in the compile command to enable the compiler to find pthread.h
You don't have a pthread.h library in the system. Try to install the
suitable library for it.
You need to be sure to use #include <sys/type.h>
Don't forget to add the -lpthread while compiling: gcc -lpthread {x}.c -o {y}

Resources