gecko-dev/build/unix/elfhack
Mike Hommey 310043662a Bug 1470701 - Use run-time page size when changing mapping permissions in elfhack injected code. r=froydnj
When a binary has a PT_GNU_RELRO segment, the elfhack injected code
uses mprotect to add the writable flag to relocated pages before
applying relocations, removing it afterwards. To do so, the elfhack
program uses the location and size of the PT_GNU_RELRO segment, and
adjusts it to be aligned according to the PT_LOAD alignment.

The problem here is that the PT_LOAD alignment doesn't necessarily match
the actual page alignment, and the resulting mprotect may end up not
covering the full extent of what the dynamic linker has protected
read-only according to the PT_GNU_RELRO segment. In turn, this can lead
to a crash on startup when trying to apply relocations to the still
read-only locations.

Practically speaking, this doesn't end up being a problem on x86, where
the PT_LOAD alignment is usually 4096, which happens to be the page
size, but on Debian armhf, it is 64k, while the run time page size can be
4k.

--HG--
extra : rebase_source : 5ac7356f685d87c1628727e6c84f7615409c57a5
2018-06-24 09:02:38 +09:00
..
inject bug 1463425 - autopep8 on build/ r=gps 2018-05-21 23:56:34 +02:00
Makefile.in Bug 1403346 - Implement cflags filtering for elfhack in mozbuild COMPILE_FLAGS r=glandium 2017-10-25 15:12:10 -07:00
README
dummy.c
elf.cpp Bug 1423821 - Add a consistency check for section offsets to elfhack. r=froydnj 2017-12-07 15:34:58 +09:00
elfhack.cpp Bug 1470701 - Use run-time page size when changing mapping permissions in elfhack injected code. r=froydnj 2018-06-24 09:02:38 +09:00
elfxx.h Bug 1417215 - Prefer prefix ++ operator for non primitive types r=froydnj 2017-12-30 21:09:58 +01:00
inject.c Bug 1470701 - Use run-time page size when changing mapping permissions in elfhack injected code. r=froydnj 2018-06-24 09:02:38 +09:00
moz.build Bug 1457482 Correct elfhack's LTO detection to handle -flto=thin r=glandium 2018-06-01 10:10:16 -05:00
test-array.c
test-ctors.c
test.c Bug 1470701 - Use run-time page size when changing mapping permissions in elfhack injected code. r=froydnj 2018-06-24 09:02:38 +09:00

README

Elfhack is a program to optimize ELF binaries for size and cold startup
speed.

Presently, it is quite experimental, though it works well for the target
it was created for: Firefox's libxul.so.

Elfhack currently only does one thing: packing dynamic relocations ;
which ends up being a quite complex task, that can be summarized this
way:
- Remove RELATIVE relocations from the .rel.dyn/.rela.dyn section.
- Inject a small code able to apply relative relocations "by hand"
  after the .rel.dyn/.rela.dyn section.
- Inject a section containing relocative relocations in a different
  and more packed format, after the small code.
- Register the small code as DT_INIT function. Make the small code call
  what was initially the DT_INIT function, if there was one.
- Remove the hole between the new section containing relative
  relocations and the following sections, adjusting offsets and base
  addresses accordingly.
- Adjust PT_LOAD entries to fit new offsets, and add an additional
  PT_LOAD entry when that is necessary to handle the discrepancy between
  offsets and base addresses, meaning the section offsets may yet again
  need adjustments.
- Adjust various DT_* dynamic tags to fit the new ELF layout.
- Adjust section headers.
- Adjust ELF headers.

See http://glandium.org/blog/?p=1177#relocations for some figures.