Before compiling/loading/running the C file, understand the concept of elf file, Elf (executable and linking format) is an object file. The elf file format is a UNIX system lab developed as an application binary interface, and is the main executable file format for Linux.
In simple terms, the elf is a binary interface before the "compiler/connector" and "Kernel/cpu", a fixed file format. Compiling the linker compiles the C program into the machine executable under the corresponding architecture, and the file and CPU as well as the kernel are agreed in ELF format, such as the code snippet/data segment/BSS paragraph is stated in the Elf file. When the kernel is loaded, read the contents of each section in the elf file format to physical memory, set up its own memory mapping table, prepare the process environment, write the memory address of each segment to the CPU register, and then dispatch, our program occupies the CPU, The CPU executes the instructions we compiled out of the code snippet, followed by a line sentence.
So, what does the kernel and compiler do in a "Hello World" that wants to execute on ARM and x86?
ARM-LINUX-GCC Hello.c-o Hello_arm
Use Arm's GCC compilation toolchain to generate the executable file Hello_arm under arm. Use the file command to view the properties of the Hello_arm file and see that Hello_arm is the elf file for arm.
Execute./hello_arm on bash, the kernel loads the data segment/code snippet/BSS segment in Hello_arm into physical memory, and establishes a process environment for hello_arm, which sets the CPU's data segment Register/code segment Register/ The stack segment register value is written as the actual physical memory address, then the control is given to the arm CPU, and the arm's CPU starts executing our executable file.
In contrast to x86, the only change is to use the x86 compiler to compile the C code into an executable file consisting of X86 machine instructions, which is then loaded by the x86 kernel and executed by the x86 CPU.
Loading and execution of Linux applications