如何编译 GCC 生成的 asm? [英] How do I compile the asm generated by GCC?

查看:22
本文介绍了如何编译 GCC 生成的 asm?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩一些 asm 代码,有些事情困扰着我.

I'm playing around with some asm code, and something is bothering me.

我编译这个:

#include <stdio.h>

int main(int argc, char** argv){
  printf("Hello World
");
  return 0;
}

使用 gcc file.c -S -o file.S 这会生成一小段不错的 asm 代码:​​

with gcc file.c -S -o file.S this generates a nice little piece of asm code:

    .cstring
LC0:
    .ascii "Hello World"
    .text
.globl _main
_main:
LFB3:
    pushq   %rbp
LCFI0:
    movq    %rsp, %rbp
LCFI1:
    subq    $16, %rsp
LCFI2:
    movl    %edi, -4(%rbp)
    movq    %rsi, -16(%rbp)
    leaq    LC0(%rip), %rdi
    call    _puts
    movl    $0, %eax
    leave
    ret
LFE3:
    .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
EH_frame1:
    .set L$set$0,LECIE1-LSCIE1
    .long L$set$0
LSCIE1:
    .long   0x0
    .byte   0x1
    .ascii "zR"
    .byte   0x1
    .byte   0x78
    .byte   0x10
    .byte   0x1
    .byte   0x10
    .byte   0xc
    .byte   0x7
    .byte   0x8
    .byte   0x90
    .byte   0x1
    .align 3
LECIE1:
.globl _main.eh
_main.eh:
LSFDE1:
    .set L$set$1,LEFDE1-LASFDE1
    .long L$set$1
LASFDE1:
    .long   LASFDE1-EH_frame1
    .quad   LFB3-.
    .set L$set$2,LFE3-LFB3
    .quad L$set$2
    .byte   0x0
    .byte   0x4
    .set L$set$3,LCFI0-LFB3
    .long L$set$3
    .byte   0xe
    .byte   0x10
    .byte   0x86
    .byte   0x2
    .byte   0x4
    .set L$set$4,LCFI1-LCFI0
    .long L$set$4
    .byte   0xd
    .byte   0x6
    .align 3
LEFDE1:
    .subsections_via_symbols

我的下一个问题真的是,我如何编译这个输出,我可以让 GCC 为我做吗?

My next problem is really, how do I compile this output, and can I make GCC do it for me?

推荐答案

是的,您可以使用 gcc 来编译您的 asm 代码.像这样使用 -c 进行编译:

Yes, You can use gcc to compile your asm code. Use -c for compilation like this:

gcc -c file.S -o file.o

这将给出名为 file.o 的目标代码文件.要调用链接器,请在上述命令后执行以下操作:

This will give object code file named file.o. To invoke linker perform following after above command:

gcc file.o -o file

这篇关于如何编译 GCC 生成的 asm?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆