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

How to add a custom label in the compiled binary

$
0
0

I want to add a custom label in my compiled C code which I will be using later. For example, the C code might look like:

#include <stdio.h>                                                                                                                                             #include <stdbool.h>int main(){        volatile bool x = false;        volatile int y = 0;        asm(".MyLabel");        if(x)        {                y = 1;        }           return 0;}

I want to add a label before the if(x) statement. As shown above, I tried to do this by inserting a label via inline assembly. I am compile my code using:

$ gcc -O3 -g -march=native -pedantic

However, when I look at the assembly generated using objdump, I get:

Disassembly of section .text:0000000000001020 <main>:    1020:   c6 44 24 fb 00          movb   $0x0,-0x5(%rsp)    1025:   31 c0                   xor    %eax,%eax    1027:   c7 44 24 fc 00 00 00    movl   $0x0,-0x4(%rsp)    102e:   00     102f:   c3                      ret0000000000001030 <_start>:    1030:   f3 0f 1e fa             endbr64    1034:   31 ed                   xor    %ebp,%ebp    1036:   49 89 d1                mov    %rdx,%r9    1039:   5e                      pop    %rsi    103a:   48 89 e2                mov    %rsp,%rdx    103d:   48 83 e4 f0             and    $0xfffffffffffffff0,%rsp    1041:   50                      push   %rax    1042:   54                      push   %rsp    ...

As you can see, in the main section of the assembly, there is no label called MyLabel. How can I force gcc to insert the label before the if condition?


Viewing all articles
Browse latest Browse all 22176

Trending Articles



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