2017-03-20 1 views
0

이상한 문제가 있습니다. arm에 대한 코드를 컴파일 할 수 있지만 gcc v 6.3 (및 기타도 사용)은 x86 일 수 없습니다. 다음은 문제를 일으키는 예제 코드입니다.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 매개 변수 (X-내가 기억하지 않습니다) GCC 버전 4.8, 5.x를, 6.3을 시도했습니다.

#include <csignals>도 제거하면 (<signal.h>) 모든 부양 가족은 문제가 없습니다. 그러나 'INT'신호를 포착하는 것이 좋습니다.

답변

5

$은 유효한 식별자 문자가 아닙니다. 가능한 모든 헤더 파일에서 작동하지 않을 수도있는 gcc 확장입니다. $을 사용하지 마십시오. 오류가 사라집니다.

+0

확장 프로그램에 버그가 있습니까? 미친 진단! –

+0

@BoundaryImposition gcc가이를 아주 잘 처리하고 결과를 어셈블러에 전달합니다. 이제 $는 다른 어셈블러와는 다른 의미를가집니다. binutils가 이해할 수있는 '$'를 피할 수있는 방법이 있는지 나는 모른다. x86에서 "작동"하게하려면 gcc가 변수 이름을 mangle 할 수도 있지만 그렇게 유용하지는 않습니다. –

+0

@ n.m. 어쩌면 왜 경고가 없는지 아십니까? 조립 오류는별로 도움이되지 않습니다. (나는 단지 호기심이다). –

관련 문제