我们是否被迫创建必须具有文本、数据、堆和栈内存部分的进程?

huangapple go评论97阅读模式
英文:

Are we forced to create processes that must have the text, data ,heap and stack memory sections?

问题

我知道C程序在内存中的基本布局是代码/文本、数据、堆和栈。C程序的内存布局确实对应于内存中进程的更一般布局。

我的问题是:

1)“C程序布局=一般进程布局”的关联是从哪里来的?(如果我们考虑所有的计算机科学文献……)

2)如果我要为我创建的编程语言(我们称之为“ONE”)编写编译器,我应该遵守哪些主要规则(假设我们在Linux操作系统上,使用Intel x86_64)?

英文:

I know that the basic C program layout in memory is code/text, data, heap and stack. The C program memory layout does correspond to the more general layout of a process in memory.

My questions are :

  1. Where does the "C program layout = General process layout" association stem from ? ( If we consider all the computer science literature out there...)

  2. If I were to write a compiler for a programming language that I create ( let's call it "ONE" ) what are the main rules that I should comply with ( let's say that we are in a Linux OS with intel x86_64 ) ?

答案1

得分: 5

“C程序布局=通用进程布局”这种关联是从哪里来的?(如果我们考虑所有的计算机科学文献...)

每个操作系统都有一种(或多种)加载程序并启动执行的方法。这包括它可以读取和加载的可执行文件格式。可执行文件格式通常包含一些头部,描述文件中的程序段,然后包含描述每个程序段的信息。程序段可以包含要加载到内存中作为对象的初始值的数据,也可以包含要加载到内存中执行的指令。或者程序段可能只是需要在内存中提供的一定空间。

没有C程序布局。编译器是一个翻译器。它将C语言翻译成机器语言。(这个过程通常涉及多个步骤:将C翻译成内部表示,对内部表示进行优化和其他操作,将内部表示翻译成汇编语言或其表示形式,将汇编语言翻译成机器语言,将机器语言和数据写入目标模块,将目标模块链接成可执行程序。)

在C源代码中,使用了计算的抽象模型,如C标准中所述。没有指定特定的硬件堆栈(尽管在函数调用中,参数和自动对象具有后进先出的行为,因此指定了堆栈语义)。没有指定特定的程序布局。编译器将C源代码翻译成目标平台的可执行程序,这就是给程序赋予其进程布局的原因。

如果我要为我创建的编程语言(我们称之为“ONE”)编写编译器,我应该遵守哪些主要规则(假设我们在Linux操作系统上使用Intel x86_64)?

按照链接器和程序加载器期望的格式编写文件。符合操作系统指定的应用程序二进制接口(ABI)。

英文:

> Where does the "C program layout = General process layout" association stem from ? ( If we consider all the computer science literature out there...)

Each operating system has a method (or methods) of loading programs and starting their execution. This includes formats of executable files that it can read and load. An executable file format typically contains some header that describes what program sections are in the file and then information that describes each program section. Program sections may contain data to be loaded into memory as initial values for objects or may contain instructions to be loaded into memory to be executed. Or a program section may simply be an amount of space that needs to be made available in memory.

There is no C program layout. A compiler is a translator. It translates from the C language into machine language. (This process typically involves multiple steps: Translating C into an internal representation, perform optimization and other operations on the internal representation, translating the internal representation into assembly or a representation of it, translation assembly into machine language, writing machine language and data into object modules, and linking object modules into an executable program.)

In the C source code, an abstract model of computing is used, as described in the C standard. No specific hardware stack is specified (although stack semantics are specified because parameters and automatic objects have last-in first-out behavior in function calls). No specific program layout is specified. The compiler translates C source code to an executable program of the target platform, and that is what gives the program its process layout.

> If I were to write a compiler for a programming language that I create ( let's call it "ONE" ) what are the main rules that I should comply with ( let's say that we are in a Linux OS with intel x86_64 ) ?

Write files in the formats expected by the linker and the program loader. Conform to the Application Binary Interface specified by the operating system.

huangapple
  • 本文由 发表于 2023年8月8日 20:31:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76859596.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定