Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,762 Views

elf size too large for hello world application

Hi All,  

i am new to Altera's Nios-II, so as usual started with hello world template  

i am able to build it but the elf size is comes about 677274 bytes after applying all the optimizations (according to Nios II software developer's handbook)  

this is too big i guess(for a single printf statement), also the comment in the template specifies it should be ~69KB  

even the single while(1); in main() also building with 660159 elf size. 

 

My settings for optimizations are : 

 

enable_light_weight_driver_api CHECKED 

max_file_descriptor 4 

small newlib C CHECKED 

-Os CHECKED 

debug level OFF 

system/timestamp timer NONE 

enable_clean_exit UNCHECKED 

enable_exit UNCHECKED 

disable C++ support CHECKED 

reduced_device_drivers CHECKED 

 

Also my console shows (after build finished) :  

 

Info: (hello_world.elf) 1320 Bytes program size (code + initialized data). 

Info: 126 KBytes free for stack + heap. 

 

but when i look at properties of hello_world.elf OR "ls -l" the directory , it shows size as 677274 

 

one thing i noticed is it includes hell lot of headers, even though m not using OR disabled support 

 

can anybody point me, what am i missing
0 Kudos
9 Replies
Altera_Forum
Honored Contributor I
169 Views

Basically printf() pulls in a large amount of library code from libc. 

 

There is a 'small BSP' template which will give a much smaller image, I think you than have to use alt_printf(). 

 

If you look carefully at the generated program, you'll find that the actual entry point is alt_main() - which does a load of setup (of stdio etc) before calling your main() function. 

You can avoid most of it by calling your code alt_main() ! 

 

A C program to read switches and change LEDs can be very small indeed - but last I looked (some time ago) Altera don't make that one easy to generate.
Altera_Forum
Honored Contributor I
169 Views

The 677k size is definitely too large, even with stdio printf and without optimization. 

I confirm you it should fit in 64k: I checked a similar hello world elf I have here. 

Try this shell command: nios2-elf-size <filename>.elf  

It will briefly report the size of your memory sections
Altera_Forum
Honored Contributor I
169 Views

Thnx cris for the reply  

 

my nios2-elf-size hello_world.elf shows  

 

Berkley Style : 

 

text data bss dec hex  

1064 240 16 1320 528 

 

 

SysV style : 

 

section size addr 

.entry 32 131072 

.text 1008 131104 

.rodata 24 132112 

.rwdata 240 132136 

.bss 16 132616 

.comment 35 0 

.thread_model 3 0 

.cpu 5 0 

.simulation_enabled 1 0 

.stderr_dev 9 0 

.stdin_dev 9 0 

.stdout_dev 9 0 

.sopc_system_name 10 0 

.quartus_project_dir 63 0 

.jdi 40375 0 

.sopcinfo 612051 0 

total 653890 

 

any clue ?? 

 

it seems like jdi and sopcinfo contributes majorly to size (not sure , cuz they dnt have any address). i dont know weather they should be included OR accidently turns up in my build
Altera_Forum
Honored Contributor I
169 Views

Thnx dsl for reply 

this all i know , but thats the "freestanding" kind of application and i am interested in "hosted" (ease of programming) 

and according to examples provided in Quartus installations, size of hosted(with main() not alt_main()) hello world application should be around ~69KB means i must had misconfigured something)  

other things is does using alt_main() and alt_printf instead of main() and printf() can brings down the footprint to 1/10th
Altera_Forum
Honored Contributor I
169 Views

The elf file includes a lot of information used for jtag debugging. 

The size of the file itself is not an indication of the actual memory requirements of your program. 

Infact the report states your code fits in 1320bytes (plus the space required for stack and heap), 

so you shouldn't have any problem with loading your application into onchip ram. 

However, afaik jdi and sopc files are normally not included into elf file: probably you have switched on some option in project settings.
Altera_Forum
Honored Contributor I
169 Views

Thnx for the information  

but i dont have actual hardware to test  

anyways is there any way to exclude jdi and sopc  

somebody in a archive post talked about changing configuration from debug to release to shrink footprint. where's that configuration setting ? 

 

 

 

 

--- Quote Start ---  

The elf file includes a lot of information used for jtag debugging. 

The size of the file itself is not an indication of the actual memory requirements of your program. 

Infact the report states your code fits in 1320bytes (plus the space required for stack and heap), 

so you shouldn't have any problem with loading your application into onchip ram. 

However, afaik jdi and sopc files are normally not included into elf file: probably you have switched on some option in project settings. 

--- Quote End ---  

Altera_Forum
Honored Contributor I
169 Views

If you run 'objdump -h' (probably nios-elf-objdump -h) you'll see that only some of the areas are marked LOAD. 

'objdump -p' shows the program headers that are processed when loading the program. 

The other ones are just for debuggers (of various sorts), and possibly extra information for loaders (eg the OS the file was built for).
Altera_Forum
Honored Contributor I
169 Views

 

--- Quote Start ---  

 

anyways is there any way to exclude jdi and sopc  

 

--- Quote End ---  

 

You may try nios2-elf-strip command. 

Used without any option, it will greatly reduce elf file size, since it strips all symbols. 

You may also use the -S and -R options to remove all debug info or specific sections.
Altera_Forum
Honored Contributor I
169 Views

Note that stripping out unwanted sections wont affect the amount of memory the code needs to run, it only affects the size of the program file itself.

Reply