无法为 x86 编译代码,但可以为 arm 编译代码
Can't compile code for x86 but can for arm
我有一个奇怪的问题。我可以使用 gcc v 6.3(以及其他版本)为 arm
编译代码,但不能为 x86
编译代码。
这是导致问题的示例代码。
#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");
}
}
这是一个 online example 和 gcc
这导致 assemble 错误:
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' 信号。
$
不是有效的标识符字符。它是一个 gcc 扩展,可能适用于也可能不适用于所有可能的头文件。不要使用 $
,错误就会消失。
我有一个奇怪的问题。我可以使用 gcc v 6.3(以及其他版本)为 arm
编译代码,但不能为 x86
编译代码。
这是导致问题的示例代码。
#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");
}
}
这是一个 online example 和 gcc
这导致 assemble 错误:
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' 信号。
$
不是有效的标识符字符。它是一个 gcc 扩展,可能适用于也可能不适用于所有可能的头文件。不要使用 $
,错误就会消失。