ecomaikgolf / alma

toy kernel written in C++ for x86-64 machines with the mere purpose of learning OS development
8 stars 1 forks source link

Write a linkscript and compile the kernel into an ELF file #12

Closed ecomaikgolf closed 3 years ago

ecomaikgolf commented 3 years ago

Write a linkerscript and compile & link (ld) the kernel with the freestandign gcc from the toolchain.

ecomaikgolf commented 3 years ago

fab73422bba2cc23b08b3c1b1439a2bec6c73ef4

ecomaikgolf commented 3 years ago

radare2 output

[0x00000000]> afl
0x00000000    1 11           entry0
[0x00000000]> s entry0
[0x00000000]> pdf
            ;-- section.:
            ;-- section..text:
            ;-- section..comment:
            ;-- section..symtab:
            ;-- section..strtab:
            ;-- section..shstrtab:
            ;-- segment.LOAD0:
            ;-- segment.ehdr:
            ;-- _start:
            (... removed ...)

┌ 11: entry0 ();
│           0x00000000      55             push rbp                    ; [06] ---- section size 52 named .shstrtab
│           0x00000001      4889e5         mov rbp, rsp
│           0x00000004      b800000000     mov eax, 0
│           0x00000009      5d             pop rbp
└           0x0000000a      c3             ret
[0x00000000]>

readelf output

Encabezado ELF:
  Mágico:  7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Clase:                             ELF64
  Datos:                             complemento a 2, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  Versión ABI:                       0
  Tipo:                              EXEC (Fichero ejecutable)
  Máquina:                           Advanced Micro Devices X86-64
  Versión:                           0x1
  Dirección del punto de entrada:    0x0
  Inicio de encabezados de programa: 64  (bytes en el fichero)
  Inicio de encabezados de sección:  4360 (bytes en el fichero)
  Opciones:                          0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         1
  Size of section headers:           64 (bytes)
  Number of section headers:         7
  Section header string table index: 6

Encabezados de Sección:
  [Nr] Nombre            Tipo             Dirección         Despl
       Tamaño            TamEnt           Opts   Enl   Info  Alin
  [ 0]                   NULL             0000000000000000  00000000
       0000000000000000  0000000000000000           0     0     0
  [ 1] .text             PROGBITS         0000000000000000  00001000
       000000000000000b  0000000000000000  AX       0     0     4096
  [ 2] .eh_frame         PROGBITS         0000000000000010  00001010
       0000000000000038  0000000000000000   A       0     0     8
  [ 3] .comment          PROGBITS         0000000000000000  00001048
       000000000000002a  0000000000000001  MS       0     0     1
  [ 4] .symtab           SYMTAB           0000000000000000  00001078
       0000000000000048  0000000000000018           5     2     8
  [ 5] .strtab           STRTAB           0000000000000000  000010c0
       0000000000000011  0000000000000000           0     0     1
  [ 6] .shstrtab         STRTAB           0000000000000000  000010d1
       0000000000000034  0000000000000000           0     0     1

(... removed ...)

Encabezados de Programa:
  Tipo           Desplazamiento     DirVirtual         DirFísica
                 TamFichero         TamMemoria          Opts   Alineación
  LOAD           0x0000000000001000 0x0000000000000000 0x0000000000000000
                 0x0000000000000048 0x0000000000000048  R E    0x1000

 mapeo de Sección a Segmento:
  Segmento Secciones...
   00     .text .eh_frame

No hay sección dinámica en este fichero.

No hay reubicaciones en este fichero.

The decoding of unwind sections for machine type Advanced Micro Devices X86-64 is not currently supported.

Symbol table '.symtab' contains 3 entries:
   Num:    Valor          Tam  Tipo    Unión  Vis      Nombre Ind
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000000     0 FILE    LOCAL  DEFAULT  ABS kernel.c
     2: 0000000000000000    11 FUNC    GLOBAL DEFAULT    1 _start