Sign in to follow this  
GaryNas

Linker - Small data sections

Recommended Posts

GaryNas    134
I've been looking into linker command files (.lcf) and I'm confused by some of the different linker sections specifically .data and .sdata. As I understand it, .data is a read-write data section. So any data in my C++ code that I can read-write will be placed here (sort of). Now, .sdata is defined as the same thing except for "small data". What is small data? ints? chars? Is regular .data "bigger" objects such as structs? What's the point of having two different sections for this data? Besides linker docs, where can I read more on this topic? Thanks!

Share this post


Link to post
Share on other sites
osmanb    2082
Many architectures have features or addressing modes that make 'small data' an optimization. Typically, you can put some amount (like up to 64k) of data at a certain address, and then refer directly to that data using a single instruction with a 16-bit offset. This is faster than normal data sections, which could be anywhere, thus requiring at least two instructions just to construct the address in a register (assuming 32-bit RISC architecture), then another to do an actual load or store.

So, compilers will have a small-data option that lets you pick some threshold for small-data-size. We typically get away with either 4 or 8 bytes. The compiler puts any statics/globals/etc... that are that size (or smaller), and packs them into the small data section. This makes accesses to those variables faster. If you end up with more than 64k of data of that size, it generally just gives an error, and you have to recompile/relink with a different threshold.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this