簡體   English   中英

無法為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");
    }
}

這是gcc的在線示例

這會導致組裝錯誤:

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編譯它。 這里在線示例

我已經嘗試了使用-O0 -O2-03參數的gcc版本4.8、5.x,6.3(x,我不記得了)。

如果刪除#include <csignals>也嘗試了( <signal.h> )和所有依賴項,則沒有問題。 但是捕捉“ INT”信號真是太好了。

$不是有效的標識符字符。 這是一個gcc擴展名,它可能會或可能不會與所有可能的頭文件一起使用。 不要使用$ ,錯誤就會消失。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM