GCC Inline assembly - immediate integer operand emit without $

Sam samueldotj@gmail.com
Fri Aug 31 17:16:00 GMT 2012


Hi,

The following example tries to create an elf section with three
integers using inline assembly.
    asm (".pushsection .test\n"
         ".long 0, %0, %1\n"
         ".popsection"
         :: "i"(ENUM_VAL2), "i"(2));

But it fails because gcc emits the assembly code with $.
Is there a way to instruct gcc to avoid emitting $?
    .pushsection .test
     .long 0, $1, $2 <<<<<<
     .popsection

Thanks
Samuel


$cat test.c
enum {
    ENUM_VAL1,
    ENUM_VAL2
};
int main()
{
    asm (".pushsection .test\n"
         ".long 0, %0, %1\n"
         ".popsection"
         :: "i"(ENUM_VAL2), "i"(2));

    return 0;
}

$gcc --save-temps test.c
test.o:(.test+0x4): undefined reference to `$1'
test.o:(.test+0x8): undefined reference to `$2'
collect2: ld returned 1 exit status


$cat test.s
        .file   "test.c"
        .text
        .globl  main
        .type   main, @function
main:
.LFB0:
        .cfi_startproc
        pushq   %rbp
        .cfi_def_cfa_offset 16
        .cfi_offset 6, -16
        movq    %rsp, %rbp
        .cfi_def_cfa_register 6
#APP
# 7 "test.c" 1
        .pushsection .test
.long 0, $1, $2
.popsection
# 0 "" 2
#NO_APP
        movl    $0, %eax
        popq    %rbp
        .cfi_def_cfa 7, 8
        ret
        .cfi_endproc
.LFE0:
        .size   main, .-main
        .ident  "GCC: (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1"
        .section        .note.GNU-stack,"",@progbits



More information about the Gcc-help mailing list