Required ELF segments

Nick Clifton nickc@redhat.com
Mon May 11 11:26:56 GMT 2020


Hi Johannes,

> 1. Why is the segment table itself a segment? 

It does not have to be, but it does make things a lot easier if it is.
Essentially it means that programs that need to manage in-memory ELF 
executables, for example the loader, can rely upon the fact that the 
segment table has been loaded into memory, and they do not have to
attempt to find it on the filing system.


> 2. Why is the whole ELF file mapped as a segment at all? If my
> understanding is correct, then there should be only the need to map a
> single segment which could be RWX and another one for the interpreter
> reference. Security concerns aside (no-execute and read/write of RO
> data), what's the minimum number of segments required to be able to
> properly execute under Linux?

The simply answer is that any segment with a non-zero memory size (p_memsz)
should be loaded.  It may be possible for the program to execute without
some of these segments loaded, but this should not be relied upon, nor
should the loader attempt to police which segments are or are not loaded.


> 3. How can you debug the loader?  

Read the manual page for the loader (ld.so or ld-linux.so).  In particular
there are some environment variables that you can define to enable various
debugging and tracing functions.  Also consider using tools like readelf
and eu-elflint to check the program for problems before even attempting
to load it.

Also, since the loader is part of the glibc project, you can always
post questions on their mailing list.

Cheers
  Nick



More information about the Binutils mailing list