An ELF PT_LOAD segment is allowed to specify an
address that is not aligned according to the alignment
it requests. In that case, the loader rounds the va
and file offset down to the nearest boundary and
increases the total size up by the same amount.
Similarly, the total size is then rounded up to the
nearest boundary.
It sounds like this upx program does not know about
that rule.
Russ
Because that's where the Go binary's text segment begins.
The stuff before it is the ELF header, and strictly speaking
does not need to be loaded. If it is, fine.
That said, I had to change the ELF headers we write out
to do the rounding ourselves, because there are buggy
qemu binaries floating around that I wanted to use with
Go ARM binaries. So in a release or two you won't have
to worry about this case tripping up upx.
Russ
The 0xc00 value comes from the ELFRESERVE
constant in http://golang.org/src/cmd/ld/elf.h.
Originally we packed the ELF hdr, phdrs, shdrs,
string data, and interp string into a fixed-size chunk
at the beginning of the file, just because it was easy.
The string data kept growing, though, so we had to
keep making the chunk bigger, and then the ELF layout
code had various assumptions that the chunk was
smaller than a page, so rather than track them all down,
I stopped growing the chunk when it hit 3k and took
the time to move the string data into the read-only data.
Now that the string data is gone the 3k could probably
be reduced back to something like 1k, but I haven't
bothered.
The interp string is at the end of the chunk just because
it was an easy address to calculate without knowing
exactly how many phdr/shdrs there were.
It's all a bit sloppy, but it's the kind of thing that
is hard enough to test on all the various platforms,
so once it works, I just back quietly away.
So 0xc00 is definitely not an unjustified whim, but
it's also more something that evolved than something
that was intelligently designed.
Russ