I usually don't touch linker script of my development system, sincerely
I can't read every details of a linker script, so I'm in trouble now.
As explained in my previous post, I need to avoid zeroing a static big variable, because it is allocated in SDRAM and SDRAM isn't available
when zeroing of bss sections (and initialization of data sections) occurs.
My development system allows me to use .noinit section, so I'm studying
how it works.
MCUXpresso IDE generates complete linker scripts that automatically
manages .noinit sections. These sections aren't added to section table
that startup code reads to reset sections of RAM.
What I don't understand is the presence of NOLOAD directive in the
linker script:
[...]
The linker will process the section normally, but will
mark it so that a program loader will not load it into
memory.
In embedded systems we don't have program loader, at least in my case
there isn't any program loader. Code and constant variables are already
at the right addresses at startup (Flash is already written). Only
variables that changes at runtime must be initialized in RAM, but this
is done by startup code, not by a program loader.
So, if startup code doesn't reset .noinit sections (because they aren't
added in bss section table by the linker script), what's the exact
purpose of NOLOAD directive?
I was tempted to remove NOLOAD directive from the linker script
generated by MCUXpresso, but it re-generates it at every build.
In embedded systems we don't have program loader, at least in my case
there isn't any program loader.
Il 19/03/2022 11:33, David Brown ha scritto:
On 19/03/2022 08:02, pozz wrote:
I usually don't touch linker script of my development system, sincerely
I can't read every details of a linker script, so I'm in trouble now.
As explained in my previous post, I need to avoid zeroing a static big
variable, because it is allocated in SDRAM and SDRAM isn't available
when zeroing of bss sections (and initialization of data sections)
occurs.
My development system allows me to use .noinit section, so I'm studying
how it works.
MCUXpresso IDE generates complete linker scripts that automatically
manages .noinit sections. These sections aren't added to section table
that startup code reads to reset sections of RAM.
What I don't understand is the presence of NOLOAD directive in the
linker script:
[...]
The linker will process the section normally, but will
mark it so that a program loader will not load it into
memory.
In embedded systems we don't have program loader, at least in my case
there isn't any program loader. Code and constant variables are already
at the right addresses at startup (Flash is already written). Only
variables that changes at runtime must be initialized in RAM, but this
is done by startup code, not by a program loader.
So, if startup code doesn't reset .noinit sections (because they aren't
added in bss section table by the linker script), what's the exact
purpose of NOLOAD directive?
I was tempted to remove NOLOAD directive from the linker script
generated by MCUXpresso, but it re-generates it at every build.
"NOLOAD" basically means the section is not part of the binary image
that gets loaded to the device - such as by jtag download or other
programs that use the "elf" file. When you use objcopy to generate
".hex" or ".bin" files, NOLOAD sections are omitted (unless you go out
of your way to include them).
So NOLOAD is just an "attribute" of a section, but doesn't change
allocation and addresses computed by the linker, isn't it?
This attribute is used by JTAG programmer that will avoid programming sections marked as NOLOAD.
However this arises another question. What about .bss sections? They are
in RAM, but they shouldn't be "loaded" by the programmer (they will be
zeroed during startup code). How the JTAG/SWD probe know .bss sections shouldn't be loaded?
For the commonly used sections, both
".bss" and ".noinit" sections will be marked "NOLOAD",
Really? In my case .bss sections aren't marked as NOLOAD (from this my previous question).
/* MAIN BSS SECTION */
.bss : ALIGN(4)
{
_bss = .;
PROVIDE(__start_bss_RAM = .) ;
PROVIDE(__start_bss_SRAM_UPPER = .) ;
*(.bss*)
*(COMMON)
. = ALIGN(4) ;
_ebss = .;
PROVIDE(__end_bss_RAM = .) ;
PROVIDE(__end_bss_SRAM_UPPER = .) ;
PROVIDE(end = .);
} > SRAM_UPPER AT> SRAM_UPPER
I think there's a big difference between .bss and .data sections: .data sections are associated to real data (numbers that are init values for
that part of memory). These numbers are present and written in the
output executable object file.
On the contrary, .bss sections aren't associated to concrete numbers,
because they are uninitialized (they will be simply zeroed by startup
code).
If a .data section has an address, a size and some numbers, .bss has
only an address and a size.
So this could be the reason why my build system doesn't use NOLOAD for
.bss sections: a JTAG programmer will skip loading/programming of .bss sections, because there aren't any numbers to write for them.
whereas ".text",
".readonly" and ".data" sections will be "LOAD". (Variables in the
".data" sections have two sets of addresses - their "load" addresses for
the address in flash or other images of the initial value, and their
"link" addresses for their run-time variable address.)
On 19/03/2022 08:02, pozz wrote:
I usually don't touch linker script of my development system, sincerely
I can't read every details of a linker script, so I'm in trouble now.
As explained in my previous post, I need to avoid zeroing a static big
variable, because it is allocated in SDRAM and SDRAM isn't available
when zeroing of bss sections (and initialization of data sections) occurs. >>
My development system allows me to use .noinit section, so I'm studying
how it works.
MCUXpresso IDE generates complete linker scripts that automatically
manages .noinit sections. These sections aren't added to section table
that startup code reads to reset sections of RAM.
What I don't understand is the presence of NOLOAD directive in the
linker script:
[...]
The linker will process the section normally, but will
mark it so that a program loader will not load it into
memory.
In embedded systems we don't have program loader, at least in my case
there isn't any program loader. Code and constant variables are already
at the right addresses at startup (Flash is already written). Only
variables that changes at runtime must be initialized in RAM, but this
is done by startup code, not by a program loader.
So, if startup code doesn't reset .noinit sections (because they aren't
added in bss section table by the linker script), what's the exact
purpose of NOLOAD directive?
I was tempted to remove NOLOAD directive from the linker script
generated by MCUXpresso, but it re-generates it at every build.
"NOLOAD" basically means the section is not part of the binary image
that gets loaded to the device - such as by jtag download or other
programs that use the "elf" file. When you use objcopy to generate
".hex" or ".bin" files, NOLOAD sections are omitted (unless you go out
of your way to include them).
For the commonly used sections, both
".bss" and ".noinit" sections will be marked "NOLOAD",
whereas ".text",
".readonly" and ".data" sections will be "LOAD". (Variables in the
".data" sections have two sets of addresses - their "load" addresses for
the address in flash or other images of the initial value, and their
"link" addresses for their run-time variable address.)
Am 19.03.2022 um 08:02 schrieb pozz:
In embedded systems we don't have program loader, at least in my case
there isn't any program loader.
There is a loader; it's just not running on the target. A linker for an embedded target is actually three tools in one, which traditionally
where thought of as separate: the actual linker, the locator, and (part
of) the loader.
The linker proper just has the job of connecting symbols referenced by
some modules, to matching symbol definitions in other modules.
The next phase, the locator, positions the resulting sections where they
have to go in available memory, and resolves symbolic addresses to
actual places in target memory space.
The job of the loader is split between the tool we usually just call a linker, the raw/hex file extraction tool, flash programmers, and the debugger. They share the job of moving the contents of the code and
data sections from the locator's output into actual target memory.
To that end the locator has to mark which sections the loader should
load, and which it doesn't have to handle. That's kept as a "LOAD" attribute you can find, e.g. in the section headers of the generated ELF file. You can inspect these attributes by 'objdump -h'. BSS-style sections never get the LOAD attribute, because they're not part of the program image that the flasher or debugger has to transfer to the
hardware --- they only exist at run-time.
Desktop linkers, OTOH, will usually perform just parts of those three
phases, depending on the type of executable and operating environment.
E.g. linking an MS-DOS "COM" program does almost all of it, leaving out
only the actual transfer from disk to memory. That's almost exactly
what an embedded linker usually does.
If instead you build an MS-DOS EXE file, it stops early in the locator
phase, leaving the task of placing the sections in memory, and the bulk
of replacing virtual addresses by actual ones to DOS. The file on disk
is a collection of memory sections to be loaded, and recipes for
patching up references from one to the other (called "relocations"). A linker producing a typical program for, e.g. Windows or Linux does not
even fully complete the linker stage, because it cannot finally resolve
links to dynamically linked, shared libraries.
You're right, .bss has only ALLOC attribute, while .text and .data have
LOAD attribute too.
It's strange because, as I wrote to David, my linker script doesn't use NOLOAD for .bss sections.
I usually don't touch linker script of my development system, sincerely
I can't read every details of a linker script, so I'm in trouble now.
As explained in my previous post, I need to avoid zeroing a static big >variable, because it is allocated in SDRAM and SDRAM isn't available
when zeroing of bss sections (and initialization of data sections) occurs.
My development system allows me to use .noinit section, so I'm studying
how it works.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 149:35:16 |
Calls: | 10,383 |
Calls today: | 8 |
Files: | 14,054 |
D/L today: |
2 files (1,861K bytes) |
Messages: | 6,417,769 |