在 Linux 中生成可执行文件(与实现编译器有关)
对于我的大学最后一年的论文,我将为 C 编程语言的骨架形式实现一个编译器,然后对其进行扩展,直到它类似于带有数组边界检查、类型检查等功能的 Java 语言。四。
我对与编译器构造相关的大部分理论都比较有能力,并且有使用 MIPS 汇编语言进行编程的经验,因此我确实了解一些编写极低级代码的含义。
我主要担心的是,我可能能够一直到达需要生成实际机器代码输出的程度,但从运行的操作系统的角度来看,对机器代码是如何执行的了解不够它。
所以,我的实际问题基本上是,“有谁知道阅读有关编写在 Linux 下的 intel x86-64 处理器上运行的程序集的最佳位置吗?”
我知识中的主要差距是机器代码在实践中是如何实际运行的。它是直接在处理器上运行,在需要内核提供的服务时进行“系统调用”(或 x86 等效项),还是汇编语言以某种方式封装描述,告诉内核如何 执行指令(以类似于 Java 等解释性语言的方式)?
如果您能提供任何帮助,我们将不胜感激。
For my university, final-year dissertation, I am going to implement a compiler for a skeletal form of the C programming language, then go about extending it until it resembles something a little more like Java with array bounds checking, type-checking and so forth.
I am relatively competent at much of the theory that relates to compiler construction, and have experience programming in MIPS assembly language, so I do understand a little of what it is to write extremely low-level code.
My main concern is that I am likely to be able to get all the way to the point where I need to produce the actual machine-code output, but then not understand enough about how machine code is executed from the perspective of the operating system running it.
So, my actual question is basically, "does anyone know the best place to read up about writing assembly to run on an intel x86-64 processor under linux?"
The main gap in my knowledge is how the machine code is actually run in practise. Is it run directly on the processor, making "syscall"s (or the x86 equivalent) when it needs services provided by the kernel, or is the assembly language somehow an encapsulated description that tells the kernel how to execute the instructions (in a manner similar to an interpreted language such as Java)?
Any help you can provide would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
本文档解释了如何实现外部函数接口以与其他代码交互:http:// www.x86-64.org/documentation/abi.pdf
This document explains how you can implement a foreign function interface to interact with other code: http://www.x86-64.org/documentation/abi.pdf
首先,对于机器代码,从这里开始: http://www.intel.com/products/processor /manuals/
接下来,我假设您关于机器代码如何运行的问题实际上是关于操作系统如何将 exe 加载到内存并调用 main() 的?这些链接可能对
链接器和加载器有帮助:
http://www.linuxjournal.com/article/6463
ELF 文件格式:
http://en.wikipedia.org/wiki/Executable_and_Linkable_Format 和
http://www.linuxjournal.com/article/1060
您的机器代码将进入 .可执行文件的文本部分
最后,祝你好运。您的项目与我最后一年的项目类似,只是我针对 JVM 并编译了 Visual Basic 的子集!
Firstly, for the machine code start here: http://www.intel.com/products/processor/manuals/
Next, I assume your question about how the machine code is run is really about how the OS loads the exe into memory and calls main()? These links may help
Linkers and loaders:
http://www.linuxjournal.com/article/6463
ELF file format:
http://en.wikipedia.org/wiki/Executable_and_Linkable_Format and
http://www.linuxjournal.com/article/1060
Your machine code will go into the .text section of the executable
Finally, best of luck. Your project is similar to my final year project, except I targeted the JVM and compiled a subset of Visual Basic!