avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] Remove .bss size from RAM segment of AVR ELF?


From: Tero Sinervo
Subject: [avr-gcc-list] Remove .bss size from RAM segment of AVR ELF?
Date: Thu, 05 Jun 2008 16:51:43 +0300
User-agent: Thunderbird 1.5.0.14 (Windows/20071210)

This may seem like nitpicking but I think it should be considered as current operation seems to conflict with ELF specification.

There's a very slight problem with ELF files that have a .bss section regarding chip programming. If you read the RAM initialization segment header of an ELF file you see that its filesz equals the size of .data (which is to be written to Flash) and memsz equals the sizes of .data and .bss combined (initialized data and data to be initialized to zero). The ELF specification states that if memsz is greater than filesz, bytes after filesz should be initialized to zero and follow the segment's initialized area. This is all nice and smooth. The problem comes with AVRs that don't actually have their RAM initialized at this point but the data is actually written to Flash for startup code to read and initialize the RAM with. The startup code handles .bss by zeroing that RAM area in a loop and not by reading it from Flash memory. Currently it is ambiguous whether the .bss part of the RAM initialization segment should be written to Flash after the .data part or not.

This can be easily fixed in programming software but I wonder if it should be done in AVR ELF files too. Would it be possible to exclude .bss from AVR ELF file segments by setting memsz==filesz and only keep .bss as a section header? That would make the program part of the ELF file more consistent with actual programming.

Here's an example project's section and program header list:
-----
Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .data         00000036  00800100  0000152c  000015a0  2**0
                  CONTENTS, ALLOC, LOAD, DATA
  1 .text         0000152c  00000000  00000000  00000074  2**1
                  CONTENTS, ALLOC, LOAD, READONLY, CODE
  2 .bss          000000f9  00800136  00001562  000015d6  2**0
                  ALLOC

Program Header:
    LOAD off    0x00000074 vaddr 0x00000000 paddr 0x00000000 align 2**0
         filesz 0x0000152c memsz 0x0000152c flags r-x
    LOAD off    0x000015a0 vaddr 0x00800100 paddr 0x0000152c align 2**0
         filesz 0x00000036 memsz 0x0000012f flags rw-
-----


The part of ELF specification I mentioned:
-----
PT_LOAD
The array element specifies a loadable segment, described by p_filesz and p_memsz. The bytes from the file are mapped to the beginning of the memory segment. If the segment's memory size (p_memsz) is larger than the file size (p_filesz), the "extra" bytes are defined to hold the value 0 and to follow the segment's initialized area. The file size may not be larger than the memory size. Loadable segment entries in the program header table appear in ascending order,
sorted on the p_vaddr member.
-----


--
Tero Sinervo
Elekno Oy
http://www.elekno.com/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]