What are callee and caller saved registers?

Caller-saved registers (AKA volatile registers, or call-clobbered) are used to hold temporary quantities that need not be preserved across calls. For that reason, it is the caller’s responsibility to push these registers onto the stack or copy them somewhere else if it wants to restore this value after a procedure call. It’s normal to let … Read more

What’s the difference of section and segment in ELF file format

But what’s difference between section and segment? Exactly what you quoted: the segments contain information needed at runtime, while the sections contain information needed during linking. does a segment contain one or more sections? A segment can contain 0 or more sections. Example: readelf -l /bin/date Elf file type is EXEC (Executable file) Entry point … Read more

What exactly does GCC’s -Wpsabi option do? What are the implications of supressing it?

You only need to worry about ABIs when you are crossing library boundaries. Within your own applications/libraries the ABI doesn’t really matter as presumably all your object files are compiled with the same compiler version and switches. If you have a library compiled with ABI1 and an application compiled with ABI2 then the application will … Read more

Why can a T* be passed in register, but a unique_ptr cannot?

Is this actually an ABI requirement, or maybe it’s just some pessimization in certain scenarios? One example is System V Application Binary Interface AMD64 Architecture Processor Supplement. This ABI is for 64-bit x86-compatible CPUs (Linux x86_64 architecure). It is followed on Solaris, Linux, FreeBSD, macOS, Windows Subsystem for Linux: If a C++ object has either … Read more

How do I safely pass objects, especially STL objects, to and from a DLL?

The short answer to this question is don’t. Because there’s no standard C++ ABI (application binary interface, a standard for calling conventions, data packing/alignment, type size, etc.), you will have to jump through a lot of hoops to try and enforce a standard way of dealing with class objects in your program. There’s not even … Read more

Are there any downsides to passing structs by value in C, rather than passing a pointer?

For small structs (eg point, rect) passing by value is perfectly acceptable. But, apart from speed, there is one other reason why you should be careful passing/returning large structs by value: Stack space. A lot of C programming is for embedded systems, where memory is at a premium, and stack sizes may be measured in … Read more