SlideShare a Scribd company logo
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

Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
Saadi Rahman
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
moazamali28
 
STORAGE DEVICES
STORAGE DEVICESSTORAGE DEVICES
STORAGE DEVICES
Zaheer Abbasi
 
Computer Troubleshooting - T.L.E.
Computer Troubleshooting - T.L.E.Computer Troubleshooting - T.L.E.
Computer Troubleshooting - T.L.E.
BooNeil
 
File systems for Embedded Linux
File systems for Embedded LinuxFile systems for Embedded Linux
File systems for Embedded Linux
Emertxe Information Technologies Pvt Ltd
 
Disk management / hard drive partition management / create drive or partition...
Disk management / hard drive partition management / create drive or partition...Disk management / hard drive partition management / create drive or partition...
Disk management / hard drive partition management / create drive or partition...
Ajay Panchal
 
Users and groups
Users and groupsUsers and groups
Users and groups
Varnnit Jain
 
Partitioning a Hard Drive
Partitioning a Hard DrivePartitioning a Hard Drive
Partitioning a Hard Drive
Jamaica Olazo
 
Linux file system
Linux file systemLinux file system
Linux file system
Md. Tanvir Hossain
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
Anil Kumar Pugalia
 
Secondary storage
Secondary storageSecondary storage
Secondary storage
Utshuk Pandey
 
Input output redirection linux
Input output redirection linuxInput output redirection linux
Input output redirection linux
Tanishq Soni
 
Polyphase
PolyphasePolyphase
Pc assembly
Pc assemblyPc assembly
Pc assembly
Mansoor Shar
 
Linux installation
Linux installationLinux installation
Linux installation
Sofcon India Pvt Ltd.
 
00 Hardware Of Personal Computer V1 1
00 Hardware Of Personal Computer V1 100 Hardware Of Personal Computer V1 1
00 Hardware Of Personal Computer V1 1Rajan Das
 
Linux basics part 1
Linux basics part 1Linux basics part 1
Linux basics part 1
Lilesh Pathe
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
RuggedBoardGroup
 

What's hot (20)

Linux kernel Architecture and Properties
Linux kernel Architecture and PropertiesLinux kernel Architecture and Properties
Linux kernel Architecture and Properties
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Linked list
Linked listLinked list
Linked list
 
STORAGE DEVICES
STORAGE DEVICESSTORAGE DEVICES
STORAGE DEVICES
 
Computer Troubleshooting - T.L.E.
Computer Troubleshooting - T.L.E.Computer Troubleshooting - T.L.E.
Computer Troubleshooting - T.L.E.
 
File systems for Embedded Linux
File systems for Embedded LinuxFile systems for Embedded Linux
File systems for Embedded Linux
 
Disk management / hard drive partition management / create drive or partition...
Disk management / hard drive partition management / create drive or partition...Disk management / hard drive partition management / create drive or partition...
Disk management / hard drive partition management / create drive or partition...
 
Users and groups
Users and groupsUsers and groups
Users and groups
 
Partitioning a Hard Drive
Partitioning a Hard DrivePartitioning a Hard Drive
Partitioning a Hard Drive
 
Linux file system
Linux file systemLinux file system
Linux file system
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
Secondary storage
Secondary storageSecondary storage
Secondary storage
 
Input output redirection linux
Input output redirection linuxInput output redirection linux
Input output redirection linux
 
Polyphase
PolyphasePolyphase
Polyphase
 
Pc assembly
Pc assemblyPc assembly
Pc assembly
 
Linux installation
Linux installationLinux installation
Linux installation
 
00 Hardware Of Personal Computer V1 1
00 Hardware Of Personal Computer V1 100 Hardware Of Personal Computer V1 1
00 Hardware Of Personal Computer V1 1
 
Linux basics part 1
Linux basics part 1Linux basics part 1
Linux basics part 1
 
Unix Basics For Testers
Unix Basics For TestersUnix Basics For Testers
Unix Basics For Testers
 
U-Boot Porting on New Hardware
U-Boot Porting on New HardwareU-Boot Porting on New Hardware
U-Boot Porting on New Hardware
 

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.pptx
SKUP1
 
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
LECO9
 
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
 
C programming language
C programming languageC programming language
C programming language
Mahmoud Eladawi
 
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
Kuntal Bhowmick
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with files
kirupasuchi1996
 
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
ramya marichamy
 
File Input and output.pptx
File Input  and output.pptxFile Input  and output.pptx
File Input and output.pptx
cherryreddygannu
 
intro unix/linux 03
intro unix/linux 03intro unix/linux 03
intro unix/linux 03
duquoi
 
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
Kuntal Bhowmick
 
Chapter28 data-file-handling
Chapter28 data-file-handlingChapter28 data-file-handling
Chapter28 data-file-handlingDeepak Singh
 
Namespaces in C#
Namespaces in C#Namespaces in C#
Namespaces in C#
yogita kachve
 
Python Programming Basics for begginners
Python Programming Basics for begginnersPython Programming Basics for begginners
Python Programming Basics for begginners
Abishek 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

Can AI do good? at 'offtheCanvas' India HCI prelude
Can AI do good? at 'offtheCanvas' India HCI preludeCan AI do good? at 'offtheCanvas' India HCI prelude
Can AI do good? at 'offtheCanvas' India HCI prelude
Alan Dix
 
Book Formatting: Quality Control Checks for Designers
Book Formatting: Quality Control Checks for DesignersBook Formatting: Quality Control Checks for Designers
Book Formatting: Quality Control Checks for Designers
Confidence Ago
 
原版定做(penn毕业证书)美国宾夕法尼亚大学毕业证文凭学历证书原版一模一样
原版定做(penn毕业证书)美国宾夕法尼亚大学毕业证文凭学历证书原版一模一样原版定做(penn毕业证书)美国宾夕法尼亚大学毕业证文凭学历证书原版一模一样
原版定做(penn毕业证书)美国宾夕法尼亚大学毕业证文凭学历证书原版一模一样
gpffo76j
 
Expert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting ServicesExpert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting Services
ResDraft
 
Research 20 slides Amelia gavryliuks.pdf
Research 20 slides Amelia gavryliuks.pdfResearch 20 slides Amelia gavryliuks.pdf
Research 20 slides Amelia gavryliuks.pdf
ameli25062005
 
一比一原版(NCL毕业证书)纽卡斯尔大学毕业证成绩单如何办理
一比一原版(NCL毕业证书)纽卡斯尔大学毕业证成绩单如何办理一比一原版(NCL毕业证书)纽卡斯尔大学毕业证成绩单如何办理
一比一原版(NCL毕业证书)纽卡斯尔大学毕业证成绩单如何办理
7sd8fier
 
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
kecekev
 
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
pmgdscunsri
 
一比一原版(UAL毕业证书)伦敦艺术大学毕业证成绩单如何办理
一比一原版(UAL毕业证书)伦敦艺术大学毕业证成绩单如何办理一比一原版(UAL毕业证书)伦敦艺术大学毕业证成绩单如何办理
一比一原版(UAL毕业证书)伦敦艺术大学毕业证成绩单如何办理
708pb191
 
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Mansi Shah
 
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
asuzyq
 
Transforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting ProfitabilityTransforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting Profitability
aaryangarg12
 
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
ameli25062005
 
Borys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior designBorys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior design
boryssutkowski
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证成绩单如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证成绩单如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证成绩单如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证成绩单如何办理
n0tivyq
 
Design Thinking Design thinking Design thinking
Design Thinking Design thinking Design thinkingDesign Thinking Design thinking Design thinking
Design Thinking Design thinking Design thinking
cy0krjxt
 
Game Concept Presentation for Ukrainian Mythology Based Game With Designs
Game Concept Presentation for Ukrainian Mythology Based Game With DesignsGame Concept Presentation for Ukrainian Mythology Based Game With Designs
Game Concept Presentation for Ukrainian Mythology Based Game With Designs
184804
 
Mohannad Abdullah portfolio _ V2 _22-24
Mohannad Abdullah  portfolio _ V2 _22-24Mohannad Abdullah  portfolio _ V2 _22-24
Mohannad Abdullah portfolio _ V2 _22-24
M. A. Architect
 
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
jyz59f4j
 
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
h7j5io0
 

Recently uploaded (20)

Can AI do good? at 'offtheCanvas' India HCI prelude
Can AI do good? at 'offtheCanvas' India HCI preludeCan AI do good? at 'offtheCanvas' India HCI prelude
Can AI do good? at 'offtheCanvas' India HCI prelude
 
Book Formatting: Quality Control Checks for Designers
Book Formatting: Quality Control Checks for DesignersBook Formatting: Quality Control Checks for Designers
Book Formatting: Quality Control Checks for Designers
 
原版定做(penn毕业证书)美国宾夕法尼亚大学毕业证文凭学历证书原版一模一样
原版定做(penn毕业证书)美国宾夕法尼亚大学毕业证文凭学历证书原版一模一样原版定做(penn毕业证书)美国宾夕法尼亚大学毕业证文凭学历证书原版一模一样
原版定做(penn毕业证书)美国宾夕法尼亚大学毕业证文凭学历证书原版一模一样
 
Expert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting ServicesExpert Accessory Dwelling Unit (ADU) Drafting Services
Expert Accessory Dwelling Unit (ADU) Drafting Services
 
Research 20 slides Amelia gavryliuks.pdf
Research 20 slides Amelia gavryliuks.pdfResearch 20 slides Amelia gavryliuks.pdf
Research 20 slides Amelia gavryliuks.pdf
 
一比一原版(NCL毕业证书)纽卡斯尔大学毕业证成绩单如何办理
一比一原版(NCL毕业证书)纽卡斯尔大学毕业证成绩单如何办理一比一原版(NCL毕业证书)纽卡斯尔大学毕业证成绩单如何办理
一比一原版(NCL毕业证书)纽卡斯尔大学毕业证成绩单如何办理
 
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
一比一原版(UW毕业证)西雅图华盛顿大学毕业证如何办理
 
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
Maximize Your Content with Beautiful Assets : Content & Asset for Landing Page
 
一比一原版(UAL毕业证书)伦敦艺术大学毕业证成绩单如何办理
一比一原版(UAL毕业证书)伦敦艺术大学毕业证成绩单如何办理一比一原版(UAL毕业证书)伦敦艺术大学毕业证成绩单如何办理
一比一原版(UAL毕业证书)伦敦艺术大学毕业证成绩单如何办理
 
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
Between Filth and Fortune- Urban Cattle Foraging Realities by Devi S Nair, An...
 
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
一比一原版(Columbia毕业证)哥伦比亚大学毕业证如何办理
 
Transforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting ProfitabilityTransforming Brand Perception and Boosting Profitability
Transforming Brand Perception and Boosting Profitability
 
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
Коричневый и Кремовый Деликатный Органический Копирайтер Фрилансер Марке...
 
Borys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior designBorys Sutkowski portfolio interior design
Borys Sutkowski portfolio interior design
 
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证成绩单如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证成绩单如何办理一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证成绩单如何办理
一比一原版(Glasgow毕业证书)格拉斯哥大学毕业证成绩单如何办理
 
Design Thinking Design thinking Design thinking
Design Thinking Design thinking Design thinkingDesign Thinking Design thinking Design thinking
Design Thinking Design thinking Design thinking
 
Game Concept Presentation for Ukrainian Mythology Based Game With Designs
Game Concept Presentation for Ukrainian Mythology Based Game With DesignsGame Concept Presentation for Ukrainian Mythology Based Game With Designs
Game Concept Presentation for Ukrainian Mythology Based Game With Designs
 
Mohannad Abdullah portfolio _ V2 _22-24
Mohannad Abdullah  portfolio _ V2 _22-24Mohannad Abdullah  portfolio _ V2 _22-24
Mohannad Abdullah portfolio _ V2 _22-24
 
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
一比一原版(LSE毕业证书)伦敦政治经济学院毕业证成绩单如何办理
 
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
一比一原版(BU毕业证书)伯恩茅斯大学毕业证成绩单如何办理
 

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.