2017-03-20 15 views
0

私は奇妙な問題があります。 armのコードをコンパイルできますが、x86の場合はgcc v 6.3を使用できません。 問題の原因となるコードの例を次に示します。x86用のコードをコンパイルできませんが、アーム用にすることができます

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 

私が打ち鳴らすとそれをコンパイルすることができます何より奇妙である:ここでは

#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です。ここでonline example

私は-O0-O2-03パラメータを使用してgccのバージョン4.8、5.xの、6.3(私は覚えていないのx)を試してみました。

もし私が#include <csignals>を削除した場合、(<signal.h>)とすべての扶養家族は問題ありません。しかし、INT信号を捕捉するのはいいことです。

答えて

5

$は有効な識別子文字ではありません。すべての可能なヘッダーファイルで動作するかどうかはgcc拡張です。 $を使用しないでください。エラーは消えます。

+0

拡張機能のバグですか?マッド診断! –

+0

@BoundaryImposition gccはそれをかなりうまく処理しており、結果をアセンブラに渡しています。今では$が異なるアセンブラとは異なる意味を持っています。 binutilsが理解できる '$'を逃れる方法があるかどうかはわかりません。それをx86上で「動作させる」ために、gccは変数名をマングルすることもできますが、それはあまり有用でないようです。 –

+0

@ n.m。たぶんあなたは警告がない理由を知っていますか?アセンブルのエラーはそれほど役に立ちません。 (ただ興味があるだけ)。 –

関連する問題