【问题标题】:Where can I find documentation on the code in this .s file?在哪里可以找到有关此 .s 文件中代码的文档?
【发布时间】:2020-01-26 06:45:39
【问题描述】:

我通过运行生成了下面的汇编程序

clang -s hello.c

其中hello.c 是以下文件的文件名:

#include <stdio.h>

main() {

printf("Hello\n");

}

汇编器在hello.s:

  .section  __TEXT,__text,regular,pure_instructions
  .build_version macos, 10, 14  sdk_version 10, 14
  .globl  _main                   ## -- Begin function main
  .p2align  4, 0x90
_main:                                  ## @main
  .cfi_startproc
## %bb.0:
  pushq %rbp
...

【问题讨论】:

  • 我认为它叫 GNU Assembler...

标签: c macos assembly clang


【解决方案1】:

您可以在 GAS 手册中找到文档(clang/LLVM 使用相同的语法,包括指令)。 https://sourceware.org/binutils/docs/as/

有关 x86-64 AT&T 语法的更多信息,另请参阅 https://stackoverflow.com/tags/x86/infohttps://stackoverflow.com/tags/att/info 中的链接。

Clang/LLVM 可以使用 Intel 语法,就像 GCC 一样,但指令不会改变。 clang --x86-asm-syntax=intel-masm=intel 与 GCC 兼容。

clang 或 LLVM 手册中可能也有一些内容。 (但不要将此与 LLVM-IR assembly language 混淆:LLVM 内部表示的 asm 语法。)通过快速搜索,我没有找到任何关于 clang 如何处理 GAS 指令的 LLVM 文档。


.globl _main 不是标签本身。请注意,它位于对齐填充之前。它只是符号_main 的属性修饰符。

_main: 是输出文件中应用标签的位置。

如需了解指令,请参阅How to remove "noise" from GCC/clang assembly output? 了解如何去除不相关的指令。

【讨论】:

  • 嘿,我终于开始偶然发现谷歌上的一些链接。感谢您的输入!以及额外的链接和信息。
  • 请注意,这是在 macOS 上。我不确定他们是否在那里使用特殊的汇编程序。
  • @fuz:很确定它仍然是 clang/LLVM。 IDK 如果他们修补它以添加任何特殊指令。我想知道.build_version
  • @PeterCordes 我知道现在 clang 发布了 GNU 的重新实现。
  • @fuz:很确定这只是 clang,运行 clang/LLVM 的内置汇编程序。如果你运行clang -c foo.s,就像你在 Linux 上一样。不确定Installing GNU Assembler in OSX 是否已过时,但那里的答案报告说 GNU binutils as 无法创建 MachO64 目标文件。 OTOH 我还看到了一份报告说 GNU binutils objdump(显然是从 macports 安装后在 mac 上的 gobjdump)确实有效:Disassemble into x86_64 on OSX10.6 (But with _Intel_ Syntax)
【解决方案2】:

我认为它被称为 GNU Assembler,我在这里找到了它的文档:https://www.sourceware.org/binutils/docs-2.12/as.info/index.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-16
    • 2020-08-15
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 2013-09-04
    • 2018-02-20
    相关资源
    最近更新 更多