Bulky, seemingly unnecessary section .data

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

For some time now, I've tried to figure out what the .data section in the flash is for. However, I find searching for it in the forum quite difficult. One obstacle is that I apparently can't search for .data (including the dot). The website either doesn't respond, or it omits the dot. Looking forward to the new AVRFreaks site.

Anyway, what puzzels me is that there are about 1284 bytes that are visible in the .hex file, and pretty much nowhere else. It definitely isn't actual code. Then I thought that it could be pointers to variables, but the addresses don't match at all, and besides, I don't use THAT many variables.

I also thought that it could be some debugging stuff, although it doesn't seem to hold much useful information. And changing the debug settings in the makefile did nothing. I'm using the avr32-gcc compiler with a makefile. No ASF, and no AVR Studio.

The only reference in the .lss file is this line:

 12 .data         00000504  00000024  80001ac8  00002024  2**2
                  CONTENTS, ALLOC, LOAD, DATA

The mentioned flash area (0x80001ac8) begins with a few pointers, all pointing at addresses outside what is visible in the .lss file.

Then follows just over 200 bytes, all 0. And at last, a bunch of 32-bit constants in a pattern:
0x00000118
0x00000118
0x00000120
0x00000120
0x00000128
0x00000128
and so on up to
0x00000510
0x00000510
and then 8 bytes of other stuff in the end.

In the actual code in the .lss file, I cannot find any reference at all to this part of the flash. The closest I can find is the reference to the .ctors section (which is called _data_lma in the .sym file). But that looks like it is just a few words being loaded into the RAM.

So why is it there? Is it necessary? And if not, is there an easy way to get rid of it?

This is for a UC3C bootloader (which works nicely, by the way), so I'd like the code to be as compact as possible. Changing optimization options had some effect on the actual code, but not on this section.

Here is the "offending" part of the .hex file. Sorry about the size.

:101AC80080001A4480001A6480001A840000000014
:101AD80000000000000000000000000000000000FE
:101AE80080001A3C00000000000000000000000018
:101AF80000000000000000000000000000000000DE
:101B080000000000000000000000000000000000CD
:101B180000000000000000000000000000000000BD
:101B280000000000000000000000000000000000AD
:101B3800000000000000000000000000000000009D
:101B4800000000000000000000000000000000008D
:101B5800000000000000000000000000000000007D
:101B6800000000000000000000000000000000006D
:101B7800000000000000000000000000000000005D
:101B8800000000000000000000000000000000004D
:101B9800000000000000000000000000000000003D
:101BA800000000000000000000000000000000002D
:101BB80000000024000000000000000000000118E0
:101BC8000000011800000120000001200000012889
:101BD8000000012800000130000001300000013839
:101BE80000000138000001400000014000000148E9
:101BF8000000014800000150000001500000015899
:101C08000000015800000160000001600000016848
:101C180000000168000001700000017000000178F8
:101C280000000178000001800000018000000188A8
:101C38000000018800000190000001900000019858
:101C480000000198000001A0000001A0000001A808
:101C5800000001A8000001B0000001B0000001B8B8
:101C6800000001B8000001C0000001C0000001C868
:101C7800000001C8000001D0000001D0000001D818
:101C8800000001D8000001E0000001E0000001E8C8
:101C9800000001E8000001F0000001F0000001F878
:101CA800000001F800000200000002000000020825
:101CB80000000208000002100000021000000218D4
:101CC8000000021800000220000002200000022884
:101CD8000000022800000230000002300000023834
:101CE80000000238000002400000024000000248E4
:101CF8000000024800000250000002500000025894
:101D08000000025800000260000002600000026843
:101D180000000268000002700000027000000278F3
:101D280000000278000002800000028000000288A3
:101D38000000028800000290000002900000029853
:101D480000000298000002A0000002A0000002A803
:101D5800000002A8000002B0000002B0000002B8B3
:101D6800000002B8000002C0000002C0000002C863
:101D7800000002C8000002D0000002D0000002D813
:101D8800000002D8000002E0000002E0000002E8C3
:101D9800000002E8000002F0000002F0000002F873
:101DA800000002F800000300000003000000030820
:101DB80000000308000003100000031000000318CF
:101DC800000003180000032000000320000003287F
:101DD800000003280000033000000330000003382F
:101DE80000000338000003400000034000000348DF
:101DF800000003480000035000000350000003588F
:101E0800000003580000036000000360000003683E
:101E180000000368000003700000037000000378EE
:101E2800000003780000038000000380000003889E
:101E3800000003880000039000000390000003984E
:101E480000000398000003A0000003A0000003A8FE
:101E5800000003A8000003B0000003B0000003B8AE
:101E6800000003B8000003C0000003C0000003C85E
:101E7800000003C8000003D0000003D0000003D80E
:101E8800000003D8000003E0000003E0000003E8BE
:101E9800000003E8000003F0000003F0000003F86E
:101EA800000003F80000040000000400000004081B
:101EB80000000408000004100000041000000418CA
:101EC800000004180000042000000420000004287A
:101ED800000004280000043000000430000004382A
:101EE80000000438000004400000044000000448DA
:101EF800000004480000045000000450000004588A
:101F08000000045800000460000004600000046839
:101F180000000468000004700000047000000478E9
:101F28000000047800000480000004800000048899
:101F38000000048800000490000004900000049849
:101F480000000498000004A0000004A0000004A8F9
:101F5800000004A8000004B0000004B0000004B8A9
:101F6800000004B8000004C0000004C0000004C859
:101F7800000004C8000004D0000004D0000004D809
:101F8800000004D8000004E0000004E0000004E8B9
:101F9800000004E8000004F0000004F0000004F869
:101FA800000004F800000500000005000000050816
:101FB80000000508000005100000051000020000E0
:041FC800FFFFFFFF19

I won't be surprised, if there are several posts about this topic already. But I havn't been able to locate any of them. If they exist, I'd really appreciate a link.

Br, E

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Follow-up: Well, it seems that it actually isn't unnecessary, whatever it is. Just to try it, I just cropped the section from the .hex file and uploaded it to the UC3C. The program didn't seem to run without that section. But what it actually does, still puzzles me.

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I agree that the search function in this forum is quite often not really productive.
Since you know that you're using gcc, have a look at your corresponding gcc linker script, the gcc (libc) documentation and/or use google...

http://www.atmel.no/webdoc/AVRLi...

-sb

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much for the highly informative link. Point taken – googling would probably work better than using the forum's search function.

The weird thing is, I cannot recognize the data in the data section at all. It certainly doesn't look like any constants I've got in my program.

Ah, well. I think I'll just ignore it and live with it.

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try using "avr32-objdump -t" on the output elf file to get a list of all program sections and their contents. The output is unordered and contains some less useful information, so you should sort and filter it.

If you’re on Linux and want to see everything that’s not a function:

avr32-objdump -t out.elf | grep 'O ' | sort

Here’s the shortened output of one of my projects:

00000008 g     O .data  00000004 flashcdw_wait_until_ready
00000010 l     O .bss   00000004 gain_pins
00000014 l     O .bss   00000001 reserved
00000015 l     O .bss   00000001 fm_state
00000018 l     O .bss   00000004 flashc_workaround_scfg_flash
0000001c l     O .bss   00000004 flashc_workaround_mcfg_cpuins
00000020 l     O .bss   0000000c dac_chipsel
0000002c l     O .bss   00000004 conversion_function
00000030 l     O .bss   00000004 _int_line_handler_table_0
00000034 l     O .bss   00000008 _int_line_handler_table_1
[snip]
80003f3c g     O .exception  00000000 ipr_val
80004010 l     O .rodata     00000100 static_crc8_table

///////////////////////////////DearForumPleaseDontBreakMyLines

1. Memory address of the object (in hex)
2. Visibility local or global
3. Object (Functions if you don’t filter them out)
4. Section
5. Size of the object in bytes (in hex)
6. Name of the object, aka. name of the variable

Now about the sections:
.data is for initialised global variables. I only have one of those, named flashcdw_wait_until_ready, probably from the FLASHC ASF driver. It’s a simple int (4 bytes).
Example: int flashcdw_wait_until_ready = 0;

.bss is for uninitialised global variables. My variable dac_chipsel is an array with a total size of 12 bytes. It’s declared as static, so visibility is local.
Example: static uint32_t dac_chipsel[3];

.exception is a special section, usually in the Flash, where the ASF’s INTC driver places the interrupt handler table named ipr_val and some code for it.

.rodata is for read-only data in the Flash. That’s where your global variables go if you declare them const.
Example: static const uint8_t static_crc8_table[256] = { ... };

Hope this helps.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot. I'll try that.

Linux? Unfortunately not. If I utter the word out loud, our administrator will probably burn incense and start chanting to ward off evil...

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Strange... this 0x0504 bytes large area doesn't show up in the object dump. But after reading the .map file once more, I see that the area contains a number of things:
.data.impure_data
.data._impure_ptr
.data.__malloc_av_
.data.__malloc_trim_threshold
.data.__malloc_sbrk_base

So now I have some more stuff to search for. Have a nice weekend! :)

You're absolutely right. This member is stupid. Please help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As far as I can tell, the .data section is memory allocation.
In my (assembler) projects I use these for fixed memory allocation:

.data
SRAM_VAR0: .word 0x00000000    // Arbitrary 32 bit variable 0
SRAM_VAR1: .word 0x00000000    // Arbitrary 32 bit variable 1
SRAM_ARR0: .fill 16,1,0x00     // Array of 16 bytes
SRAM_VAR2: .word 0x00000000    // Arbitrary 32 bit variable 3

SRAM_VAR0 is alias for address 0x00000004 (skipping NULL pointer)
SRAM_VAR1 is alias for address 0x00000008
SRAM_VAR2 is alias for address 0x0000001C
and so on.

This way I get a compile-error if I allocate too much memory, and avr32-size.exe shows how much memory I have allocated whenever I build the project.