【发布时间】:2017-03-20 10:45:34
【问题描述】:
我有一个奇怪的问题。我可以为arm 编译我的代码,但不能为x86 使用gcc v 6.3(以及其他)。
这是导致问题的示例代码。
#include <stdint.h>
#include <cstdio>
#include <unistd.h>
#include <csignal>
volatile bool $run = true;
static void quitHandler(int __attribute__((unused)) signum)
{
$run = false;
}
void setupQuitHandler()
{
struct sigaction action;
action.sa_handler = quitHandler;
action.sa_flags = SA_RESETHAND;
if (sigemptyset(&action.sa_mask) < 0) printf("[SetupQuit] sigemptyset");
if (sigaction(SIGINT, &action, nullptr) < 0) printf("[SetupQuit] sigaction SIGINT");
if (sigaction(SIGQUIT, &action, nullptr) < 0) printf("[SetupQuit] sigaction SIGQUIT");
if (sigaction(SIGTERM, &action, nullptr) < 0) printf("[SetupQuit] sigaction SIGTERM");
if (sigaction(SIGABRT, &action, nullptr) < 0) printf("[SetupQuit] sigaction SIGABRT");
}
int main(int argc, char **argv) {
setupQuitHandler();
while($run)
{
sleep(1);
printf("Do nothing! \n");
}
}
这是一个带有 gcc 的online example
这会导致汇编错误:
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.o" -o "main.o" "../main.cpp"
/tmp/ccEUYGVm.s: Assembler messages:
/tmp/ccEUYGVm.s:19: Error: junk `(%rip)' after expression
/tmp/ccEUYGVm.s:19: Error: unsupported instruction `mov'
/tmp/ccEUYGVm.s:137: Error: junk `(%rip)' after expression
/tmp/ccEUYGVm.s:137: Error: operand type mismatch for `movzb'
make: *** [subdir.mk:26: main.o] Błąd 1
更奇怪的是我可以用clang编译它。这里online example
我已经尝试使用 -O0 -O2 和 -03 参数的 gcc 版本 4.8、5.x、6.3(x- 我不记得了)。
如果我删除 #include <csignals> 也尝试过 (<signal.h>) 并且所有家属都没有问题。但很高兴能捕捉到“INT”信号。
【问题讨论】:
标签: c++ gcc compiler-errors g++ cross-compiling