Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22151

C: Weird label behavior with -O3?

$
0
0

Given this code (minimal example; there's no deeper meaning in it):

#include <stdio.h>int main() {    start:    asm volatile(".code64\n\t""push %rax\n\t""pop %rax"    );    end:    printf("%ld\n", (const char *)&&end - (const char *)&&start);}

We obtain the assembler code by executing gcc -O3 -S dummy.c -o -. As one can see, these lines are included:

        subq    $8, %rsp        .cfi_def_cfa_offset 16#APP# 5 "dummy.c" 1        .code64        push %rax        pop %rax# 0 "" 2#NO_APP        leaq    .L2(%rip), %rax

This actually means the original assembler code is still in the binary (which is expected).

But if the program is executed, then it outputs 0. Which basically means that the start label is equal to the end label. On the other side, if the program is compiled with -O0, it does output 2.

Why does gcc -O3 dummy.c && ./a.out output 0 even if it includes the assembler code?

Thanks


Viewing all articles
Browse latest Browse all 22151

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>