SlideShare a Scribd company logo
1 of 14
Download to read offline
Linker scripts
Introduction

Linker script is written in the linker command language.

Every link is controlled by a linker script.

The main purpose of the linker script is to describe how
the sections in the input files should be mapped into the
output file.

Also used to control the memory layout of the output file.

The linker will use a default script that is compiled into the
linker executable.

We may supply our own linker script by using the `-T'
command line option.
ld -o prog -T my_script.lds main.o
Keywords used in linker scripts

ENTRY

OUTPUT_FORMAT

STARTUP

SEARCH_DIR

INPUT

OUTPUT

MEMORY

SECTIONS
ENTRY

ENTRY takes one argument.
ENTRY(main)
ENTRY(Multi bootEntry)

That is the symbol name for the entry point of the
linked program/kernel.

This can be "start" or "__main", but this will be the
very first byte of your loaded program.

(or) the first byte of the .text section in ELF and PE
binaries.
OUTPUT_FORMAT

OUTPUT_FORMAT also takes one argument.

It specifies the output format of our executable.
OUTPUT_FORMAT(elf64-x86-64)
OUTPUT_FORMAT("pe-i386")
The more common formats are

binary --This is just a flat binary with no formatting at all.

elf32-i386 --This is just the ELF format, usually little endian too.

elf64-x86-64 --This is the ELF format for 64bit, usually little endian.

pe-i386 --The PE format.
STARTUP

STARTUP takes one argument.
STARTUP(Boot.o)
STARTUP(crt0.o)

i.e. which file you want to be linked to the beginning of the
executable.
SEARCH_DIR
 It treats linker script specified search directories as standard
directories.
 This will add a path to your library search directory.
SEARCH_DIR(Directory)
INPUT

INPUT is a 'in-linker script' replacement for adding object
files to the command line.
INPUT(File1.o File2.o File3.o ...)
INPUT
(
File1.o
File2.o
File3.o
...
)
OUTPUT

OUTPUT specifies the file that has to be output by
the linker.

This is the name of the executable.
OUTPUT(Kernel.bin)

OUTPUT(filename) in the linker script is exactly
like using `-o filename' on the command line.

You can use the OUTPUT command to define a
default name for the output file other than the usual
default of a.out.
MEMORY

MEMORY declares one or more memory regions with
attributes specifying whether the region can be written to,
read from or executed.

This is mostly used in embedded systems where different
regions of address space may contain different access
permissions.

For example:
MEMORY
{
ROM (rx) : ORIGIN = 0, LENGTH = 256k
RAM (wx) : org = 0x00100000, len = 1M
}
This script tells the linker that there are two
memory regions.
"ROM" starts at address 0x00000000, is 256kB in
length, can be read and executed.
"RAM" starts at address 0x00100000, is 1MB in
length, can be written, read and executed.
SECTIONS

We will use the SECTIONS command to describe
the memory layout of the output file.
SECTIONS
{
. = 0x10000;
.text : { *(.text) }
. = 0x8000000;
.data : { *(.data) }
.bss : { *(.bss) }
}

We will write the SECTIONS command as the keyword
SECTIONS, followed by a series of symbol assignments and output
section descriptions enclosed in curly braces.

code will be loaded at address 0x10000, and data will start at address
0x8000000.

Dot(.) is the location counter.

If we do not specify the address of an output section, the address is
set from the current value of the location counter.

The location counter is then incremented by the size of the output
section.

At the start of the SECTIONS command, the location counter has
the value 0.

The * is a wildcard which matches any file name.

The expression *(.text) means all .text input sections in all input
files.

After the linker places the .data output section, the value of the
location counter will be 0x8000000 plus the size of the .data output
section.

The linker will place the .bss output section immediately after the
.data output section in memory.
Linker scripts

More Related Content

What's hot

Trabalho de sistema operativo servidor
Trabalho de sistema operativo servidorTrabalho de sistema operativo servidor
Trabalho de sistema operativo servidordtml2k
 
Introdução - Arquitetura e Organização de Computadores
Introdução - Arquitetura e Organização de ComputadoresIntrodução - Arquitetura e Organização de Computadores
Introdução - Arquitetura e Organização de ComputadoresWellington Oliveira
 
Sistemas Operacionais - Aula 4 - Revisão e Exercícios
Sistemas Operacionais - Aula 4 - Revisão e ExercíciosSistemas Operacionais - Aula 4 - Revisão e Exercícios
Sistemas Operacionais - Aula 4 - Revisão e ExercíciosCharles Fortes
 
Banco de Dados I - Aula 03 - Conceitos de Sistemas de Banco de Dados
Banco de Dados I - Aula 03 - Conceitos de Sistemas de Banco de DadosBanco de Dados I - Aula 03 - Conceitos de Sistemas de Banco de Dados
Banco de Dados I - Aula 03 - Conceitos de Sistemas de Banco de DadosLeinylson Fontinele
 
Barramento do Sistema - Arquitetura e Organização de Computadores
Barramento do Sistema - Arquitetura e Organização de ComputadoresBarramento do Sistema - Arquitetura e Organização de Computadores
Barramento do Sistema - Arquitetura e Organização de ComputadoresWellington Oliveira
 
FreeBSD para leigos
FreeBSD para leigosFreeBSD para leigos
FreeBSD para leigosPedro Neto
 
Algoritmos e Estrutura de Dados - Aula 01
Algoritmos e Estrutura de Dados - Aula 01Algoritmos e Estrutura de Dados - Aula 01
Algoritmos e Estrutura de Dados - Aula 01thomasdacosta
 
Sistemas Operacionais - Aula 06 (Estrutura do S.O)
Sistemas Operacionais - Aula 06 (Estrutura do S.O)Sistemas Operacionais - Aula 06 (Estrutura do S.O)
Sistemas Operacionais - Aula 06 (Estrutura do S.O)Leinylson Fontinele
 
Sistemas operacionais de redes particionamento de discos ii
Sistemas operacionais de redes   particionamento de discos iiSistemas operacionais de redes   particionamento de discos ii
Sistemas operacionais de redes particionamento de discos iiCarlos Melo
 
Sistemas Operativos (Operating Systems)
Sistemas Operativos (Operating Systems)Sistemas Operativos (Operating Systems)
Sistemas Operativos (Operating Systems)Pepe Rocker
 
Sistemas operacionais
Sistemas operacionaisSistemas operacionais
Sistemas operacionaisvini_campos
 

What's hot (20)

Trabalho de sistema operativo servidor
Trabalho de sistema operativo servidorTrabalho de sistema operativo servidor
Trabalho de sistema operativo servidor
 
Introdução - Arquitetura e Organização de Computadores
Introdução - Arquitetura e Organização de ComputadoresIntrodução - Arquitetura e Organização de Computadores
Introdução - Arquitetura e Organização de Computadores
 
Sistemas Operacionais - Aula 4 - Revisão e Exercícios
Sistemas Operacionais - Aula 4 - Revisão e ExercíciosSistemas Operacionais - Aula 4 - Revisão e Exercícios
Sistemas Operacionais - Aula 4 - Revisão e Exercícios
 
Lenguaje Ensamblador
Lenguaje EnsambladorLenguaje Ensamblador
Lenguaje Ensamblador
 
Banco de Dados I - Aula 03 - Conceitos de Sistemas de Banco de Dados
Banco de Dados I - Aula 03 - Conceitos de Sistemas de Banco de DadosBanco de Dados I - Aula 03 - Conceitos de Sistemas de Banco de Dados
Banco de Dados I - Aula 03 - Conceitos de Sistemas de Banco de Dados
 
Barramento do Sistema - Arquitetura e Organização de Computadores
Barramento do Sistema - Arquitetura e Organização de ComputadoresBarramento do Sistema - Arquitetura e Organização de Computadores
Barramento do Sistema - Arquitetura e Organização de Computadores
 
Formatando o computador
Formatando o computadorFormatando o computador
Formatando o computador
 
Aula 07 - Os tipos de computador - Operador de computador
Aula 07 - Os tipos de computador - Operador de computadorAula 07 - Os tipos de computador - Operador de computador
Aula 07 - Os tipos de computador - Operador de computador
 
FreeBSD para leigos
FreeBSD para leigosFreeBSD para leigos
FreeBSD para leigos
 
Linguagem SQL
Linguagem SQLLinguagem SQL
Linguagem SQL
 
Algoritmos e Estrutura de Dados - Aula 01
Algoritmos e Estrutura de Dados - Aula 01Algoritmos e Estrutura de Dados - Aula 01
Algoritmos e Estrutura de Dados - Aula 01
 
SGBD
SGBDSGBD
SGBD
 
Sistemas Operacionais - Aula 06 (Estrutura do S.O)
Sistemas Operacionais - Aula 06 (Estrutura do S.O)Sistemas Operacionais - Aula 06 (Estrutura do S.O)
Sistemas Operacionais - Aula 06 (Estrutura do S.O)
 
Aula 3 banco de dados
Aula 3   banco de dadosAula 3   banco de dados
Aula 3 banco de dados
 
Setup; bios; post.
Setup; bios; post.Setup; bios; post.
Setup; bios; post.
 
Arquitetura de-computadores-apostila-avançada completa
Arquitetura de-computadores-apostila-avançada completaArquitetura de-computadores-apostila-avançada completa
Arquitetura de-computadores-apostila-avançada completa
 
Sistemas operacionais de redes particionamento de discos ii
Sistemas operacionais de redes   particionamento de discos iiSistemas operacionais de redes   particionamento de discos ii
Sistemas operacionais de redes particionamento de discos ii
 
Sistemas Operativos (Operating Systems)
Sistemas Operativos (Operating Systems)Sistemas Operativos (Operating Systems)
Sistemas Operativos (Operating Systems)
 
Aula de hardware
Aula de hardwareAula de hardware
Aula de hardware
 
Sistemas operacionais
Sistemas operacionaisSistemas operacionais
Sistemas operacionais
 

Similar to Linker scripts

Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assemblyAbdul Khan
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxSKUP1
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptxLECO9
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCIS321
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsKuntal Bhowmick
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with fileskirupasuchi1996
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with filesramya marichamy
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptxcherryreddygannu
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03duquoi
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsKuntal Bhowmick
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handlingDeepak Singh
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginnersAbishek Purushothaman
 

Similar to Linker scripts (20)

Lec 04 intro assembly
Lec 04 intro assemblyLec 04 intro assembly
Lec 04 intro assembly
 
File Handling in C++
File Handling in C++File Handling in C++
File Handling in C++
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptxC-Programming  C LIBRARIES AND USER DEFINED LIBRARIES.pptx
C-Programming C LIBRARIES AND USER DEFINED LIBRARIES.pptx
 
Cis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential filesCis 170 c ilab 7 of 7 sequential files
Cis 170 c ilab 7 of 7 sequential files
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 
Linux
LinuxLinux
Linux
 
C programming language
C programming languageC programming language
C programming language
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with files
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with files
 
Linux com
Linux comLinux com
Linux com
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03
 
Class notes(week 5) on command line arguments
Class notes(week 5) on command line argumentsClass notes(week 5) on command line arguments
Class notes(week 5) on command line arguments
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handling
 
Namespaces in C#
Namespaces in C#Namespaces in C#
Namespaces in C#
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
 

More from Koganti Ravikumar (7)

Qemu
QemuQemu
Qemu
 
Variadic functions
Variadic functionsVariadic functions
Variadic functions
 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
 
Preprocessors
PreprocessorsPreprocessors
Preprocessors
 
Loaders
LoadersLoaders
Loaders
 
Linkers
LinkersLinkers
Linkers
 
ELF
ELFELF
ELF
 

Recently uploaded

Karim apartment ideas 01 ppppppppppppppp
Karim apartment ideas 01 pppppppppppppppKarim apartment ideas 01 ppppppppppppppp
Karim apartment ideas 01 pppppppppppppppNadaMohammed714321
 
Karim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppKarim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppNadaMohammed714321
 
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...Pranav Subramanian
 
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisFW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisPeclers Paris
 
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...Pranav Subramanian
 
PORTFOLIO 2024 ANASTASIYA KUDINOVA
PORTFOLIO 2024       ANASTASIYA KUDINOVAPORTFOLIO 2024       ANASTASIYA KUDINOVA
PORTFOLIO 2024 ANASTASIYA KUDINOVAAnastasiya Kudinova
 
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSIONPORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSIONAnastasiya Kudinova
 
The spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyThe spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyChristopher Totten
 
guest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssguest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssNadaMohammed714321
 
10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designersPixeldarts
 
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinGeneral Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinSamar Hossam ElDin Ahmed
 
Sharif's 9-BOX Monitoring Model for Adaptive Programme Management
Sharif's 9-BOX Monitoring Model for Adaptive Programme ManagementSharif's 9-BOX Monitoring Model for Adaptive Programme Management
Sharif's 9-BOX Monitoring Model for Adaptive Programme ManagementMd. Shariful Hoque
 
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - MorgenboosterAI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster1508 A/S
 
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...Thomas Schielke
 
City Hall London, Norman Foster building description with building details.pptx
City Hall London, Norman Foster building description with building details.pptxCity Hall London, Norman Foster building description with building details.pptx
City Hall London, Norman Foster building description with building details.pptxYaminiDabbara
 
guest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssguest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssNadaMohammed714321
 
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Yantram Animation Studio Corporation
 
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptMaking and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptJIT KUMAR GUPTA
 
ArtWaves 2024 - embracing Curves in Modern Homes
ArtWaves 2024 - embracing Curves in Modern HomesArtWaves 2024 - embracing Curves in Modern Homes
ArtWaves 2024 - embracing Curves in Modern HomesVellyslav Petrov
 

Recently uploaded (20)

Karim apartment ideas 01 ppppppppppppppp
Karim apartment ideas 01 pppppppppppppppKarim apartment ideas 01 ppppppppppppppp
Karim apartment ideas 01 ppppppppppppppp
 
Karim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 pppppppppppppppKarim apartment ideas 02 ppppppppppppppp
Karim apartment ideas 02 ppppppppppppppp
 
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
TIMBRE: HOW MIGHT WE REMEDY MUSIC DESERTS AND FACILITATE GROWTH OF A MUSICAL ...
 
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers ParisFW25-26 Knit Cut & Sew Trend Book Peclers Paris
FW25-26 Knit Cut & Sew Trend Book Peclers Paris
 
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
LIGHTSCAPES: HOW MIGHT WE DESIGN AN INCLUSIVE AND ACCESSIBLE CLASSICAL CONCER...
 
PORTFOLIO 2024 ANASTASIYA KUDINOVA
PORTFOLIO 2024       ANASTASIYA KUDINOVAPORTFOLIO 2024       ANASTASIYA KUDINOVA
PORTFOLIO 2024 ANASTASIYA KUDINOVA
 
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSIONPORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
PORTFOLIO 2024_ANASTASIYA KUDINOVA / EXTENDED VERSION
 
The spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenologyThe spirit of digital place - game worlds and architectural phenomenology
The spirit of digital place - game worlds and architectural phenomenology
 
guest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssssguest bathroom white and bluesssssssssss
guest bathroom white and bluesssssssssss
 
10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers10 must-have Chrome extensions for designers
10 must-have Chrome extensions for designers
 
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDinGeneral Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
General Simple Guide About AI in Design By: A.L. Samar Hossam ElDin
 
Sharif's 9-BOX Monitoring Model for Adaptive Programme Management
Sharif's 9-BOX Monitoring Model for Adaptive Programme ManagementSharif's 9-BOX Monitoring Model for Adaptive Programme Management
Sharif's 9-BOX Monitoring Model for Adaptive Programme Management
 
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - MorgenboosterAI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
AI and Design Vol. 2: Navigating the New Frontier - Morgenbooster
 
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
Cities Light Up in Solidarity With Ukraine: From Internationally Synchronized...
 
City Hall London, Norman Foster building description with building details.pptx
City Hall London, Norman Foster building description with building details.pptxCity Hall London, Norman Foster building description with building details.pptx
City Hall London, Norman Foster building description with building details.pptx
 
guest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssssguest bathroom white and blue ssssssssss
guest bathroom white and blue ssssssssss
 
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
Exploring Tehran's Architectural Marvels: A Glimpse into Vilaas Studio's Dyna...
 
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.pptMaking and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
Making and Unmaking of Chandigarh - A City of Two Plans2-4-24.ppt
 
ArtWaves 2024 - embracing Curves in Modern Homes
ArtWaves 2024 - embracing Curves in Modern HomesArtWaves 2024 - embracing Curves in Modern Homes
ArtWaves 2024 - embracing Curves in Modern Homes
 
ASME B31.4-2022 estandar ductos año 2022
ASME B31.4-2022 estandar ductos año 2022ASME B31.4-2022 estandar ductos año 2022
ASME B31.4-2022 estandar ductos año 2022
 

Linker scripts

  • 2. Introduction  Linker script is written in the linker command language.  Every link is controlled by a linker script.  The main purpose of the linker script is to describe how the sections in the input files should be mapped into the output file.  Also used to control the memory layout of the output file.  The linker will use a default script that is compiled into the linker executable.  We may supply our own linker script by using the `-T' command line option. ld -o prog -T my_script.lds main.o
  • 3. Keywords used in linker scripts  ENTRY  OUTPUT_FORMAT  STARTUP  SEARCH_DIR  INPUT  OUTPUT  MEMORY  SECTIONS
  • 4. ENTRY  ENTRY takes one argument. ENTRY(main) ENTRY(Multi bootEntry)  That is the symbol name for the entry point of the linked program/kernel.  This can be "start" or "__main", but this will be the very first byte of your loaded program.  (or) the first byte of the .text section in ELF and PE binaries.
  • 5. OUTPUT_FORMAT  OUTPUT_FORMAT also takes one argument.  It specifies the output format of our executable. OUTPUT_FORMAT(elf64-x86-64) OUTPUT_FORMAT("pe-i386") The more common formats are  binary --This is just a flat binary with no formatting at all.  elf32-i386 --This is just the ELF format, usually little endian too.  elf64-x86-64 --This is the ELF format for 64bit, usually little endian.  pe-i386 --The PE format.
  • 6. STARTUP  STARTUP takes one argument. STARTUP(Boot.o) STARTUP(crt0.o)  i.e. which file you want to be linked to the beginning of the executable. SEARCH_DIR  It treats linker script specified search directories as standard directories.  This will add a path to your library search directory. SEARCH_DIR(Directory)
  • 7. INPUT  INPUT is a 'in-linker script' replacement for adding object files to the command line. INPUT(File1.o File2.o File3.o ...) INPUT ( File1.o File2.o File3.o ... )
  • 8. OUTPUT  OUTPUT specifies the file that has to be output by the linker.  This is the name of the executable. OUTPUT(Kernel.bin)  OUTPUT(filename) in the linker script is exactly like using `-o filename' on the command line.  You can use the OUTPUT command to define a default name for the output file other than the usual default of a.out.
  • 9. MEMORY  MEMORY declares one or more memory regions with attributes specifying whether the region can be written to, read from or executed.  This is mostly used in embedded systems where different regions of address space may contain different access permissions.  For example: MEMORY { ROM (rx) : ORIGIN = 0, LENGTH = 256k RAM (wx) : org = 0x00100000, len = 1M }
  • 10. This script tells the linker that there are two memory regions. "ROM" starts at address 0x00000000, is 256kB in length, can be read and executed. "RAM" starts at address 0x00100000, is 1MB in length, can be written, read and executed.
  • 11. SECTIONS  We will use the SECTIONS command to describe the memory layout of the output file. SECTIONS { . = 0x10000; .text : { *(.text) } . = 0x8000000; .data : { *(.data) } .bss : { *(.bss) } }
  • 12.  We will write the SECTIONS command as the keyword SECTIONS, followed by a series of symbol assignments and output section descriptions enclosed in curly braces.  code will be loaded at address 0x10000, and data will start at address 0x8000000.  Dot(.) is the location counter.  If we do not specify the address of an output section, the address is set from the current value of the location counter.  The location counter is then incremented by the size of the output section.
  • 13.  At the start of the SECTIONS command, the location counter has the value 0.  The * is a wildcard which matches any file name.  The expression *(.text) means all .text input sections in all input files.  After the linker places the .data output section, the value of the location counter will be 0x8000000 plus the size of the .data output section.  The linker will place the .bss output section immediately after the .data output section in memory.