Q:

Why are functions loaded at aligned addresses in x86 Linux for elf executables?

I've been looking at Linux elf executables on x86, mostly using IDA but
also gdb. One thing I've noticed is functions are always loaded
at word aligned addresses? Anybody knows the reason of that?
I am not aware of any requirement of x86 instructions to start
at aligned addresses. And it cannot be due to page alignment cause
the page boundary can still be anywhere within the function.
I would appreciate any insight at all.
Thanks.

A:

You are right, instructions do not need to be aligned.  On x86 processors, assembly instructions are encoded using variable length codes from 1 to at least 15 bytes.
But instructions are read from a cache usually aligned on 64 bytes, and some parts of the execution pipeline operate faster when code is correctly aligned: decoding, loops, branch prediction, etc. 
The best source of info on this are Agner Fog's documents: http://www.agner.org/optimize/

