Measure size of libraries in Linux
Asked Answered
I

1

6

I'm developing S/W for some device which uses Linux O.S. So, the size of libraries (RAM/ROM) which I use is very important.

How can I easily calculate RAM / ROM required by my software? (including libraries I used). I think it's too easy question for experienced Linux developer.

Indaba answered 24/10, 2011 at 9:54 Comment(1)
This is in fact a difficult question. If your program uses dynamic memory allocation malloc or has nontrivial call patterns (especially if it has recursion), it's impossible even theoretically to predict how much RAM will be needed for the heap/stack. There are analyzers that work reasonably well at determining the stack requirements for typical embedded programs, but they often don't come cheap.Odysseus
N
4

Run

size <object>

or

size <archive>

or

size <shared-object>

. (or "target-"size in case you're cross-compiling: arm-size if you're using arm-gcc)

It will give you a

text    data     bss     dec     hex filename

table where text is program-size, bss the initialized globals and data the read-only data.

While this answers your question, you probably will want to use a specific LdScript (when using ld as linker) where you will place the sections into the available memories manually when doing the final link.

Nancienancy answered 24/10, 2011 at 10:1 Comment(2)
Note that this tool only displays the static memory. Run-time memory use will be larger. How much larger depends on the program and it's use of the stack and heap.Paedo
Also can use "ldd" to check shared libraries. With "ldd" and "size", I can guess how much ROM/RAM used including libraries.Indaba

© 2022 - 2024 — McMap. All rights reserved.