Runs programs – command line Not the only program that runs other programs make gcc and more … How this happens ? Who is responsible for that? Operating System System call exec family - execvp, execl, execv, … 2 These functions receive the path of the program executable file receive a list of the program arguments loads the program into memory, and run it … Last lecture, fork( ) and exec( ) why these function are used together ? 3 Unix has several different types of executable files You are already familiar with some of them: Binary files Bash script more ? Are these files executed similarly by the OS ? 4 Binary file Scripts Compiled – intermediate binary Loading data and code to memory Moving control to the entry point Running the machine-code No compilation We don’t have the binary code nor the memory content A specified program parses and runs the commands Commands are interpreted line-by-line How do we specify which interpreter runs the script ? 5 The first line - #!/bin/sh exec( ) uses this to determine the type of the executable shebang is encountered it is a script file The first line contains the path of the relevant program too What can we do with it ? 6 No sanity checks for the shebang line Every program/utility could appear there #!/bin/cat Hello world #!/bin/rm ls -l 7 8 ELF defines a format of executable binary files There are three main types Relocatable ▪ Created by compilers or assemblers. Need to be processed by the linker before running Executable ▪ Have all relocation done and all symbol resolved except perhaps shared library symbols that must be resolved at run time Shared Object ▪ Shared library containing both symbol information for the linker and directly runnable code for run time 9 Compilers, assemblers, and linkers treat the file as a set of logical sections The system loader treats the file as a set of segments Sections are intended for further processing by a linker Segments are intended to be mapped into memory 10 Program and section header table offsets section .text global _start ; _start: mov mov mov mov int ;tell linker entry point edx,len ecx,msg ebx,1 eax,4 0x80 mov eax,1 int 0x80 ;message length ;message to write ;file descriptor (stdout) ;system call number (sys_write) ;call kernel ;system call number (sys_exit) ;call kernel section .data msg db 'Hello world!',0xa len equ $ - msg ;our dear string ;length of our dear string 12 Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: Intel 80386 Version: 0x1 Entry point address: 0x8048080 Start of program headers: 52 (bytes into file) Start of section headers: 256 (bytes into file) Flags: 0x0 Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 2 Size of section headers: 40 (bytes) Number of section headers: 7 Section header string table index: 4 13 A relocatable or shared object file is a collection of sections Each section contains a single type of information, such as program code, read-only data, read/write data, symbols Every symbol’s address is defined relative to a section For example, the entry point is relative to the code section 14 [Nr] [ 0] [ 1] [ 2] [ 3] [ 4] [ 5] [ 6] Name NULL .text .data .comment .shstrtab .symtab .strtab Type 00000000 PROGBITS PROGBITS PROGBITS STRTAB SYMTAB STRTAB Addr 000000 08048080 080490a0 00000000 00000000 00000000 00000000 Off 000000 000080 0000a0 0000ae 0000cd 000218 0002c8 Size 000000 00001d 00000e 00001f 000030 0000b0 000032 15 An object file symbol table holds information needed to locate and relocate a program’s symbolic definition and references Num: 0: 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: Value 00000000 00000000 00000000 00000000 00000000 0000000e 0000000e 08048080 080490ae 080490ae 080490b0 Size 0 0 0 0 0 0 0 0 0 0 0 Type NOTYPE FILE SECTION SECTION NOTYPE NOTYPE NOTYPE NOTYPE NOTYPE NOTYPE NOTYPE Bind LOCAL LOCAL LOCAL LOCAL LOCAL LOCAL LOCAL GLOBAL GLOBAL GLOBAL GLOBAL Vis DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT DEFAULT Ndx Name UND ABS hello.asm 1 2 2 msg ABS len ABS len 1 _start ABS __bss_start ABS _edata ABS _end 16 17 18
© Copyright 2026 Paperzz