Commit Graph

149 Commits

Author SHA1 Message Date
Mike Hommey
0e0c6496e4 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.
2018-06-24 09:02:38 +09:00
Tom Ritter
35eabce52b Bug 1457482 Correct elfhack's LTO detection to handle -flto=thin r=glandium
MozReview-Commit-ID: LnDLrDN0W9O
2018-06-01 10:10:16 -05:00
Sylvestre Ledru
5c11f87d6e bug 1463425 - autopep8 on build/ r=gps
MozReview-Commit-ID: ETzx4HsjbEF
2018-05-21 23:56:34 +02:00
Mike Hommey
83f6c6295f Bug 1440037 - Add support for R_X86_64_PLT32 relocations in elfhack. r=froydnj 2018-02-22 07:15:23 +09:00
Jean-Luc Bonnafoux
af40c367ad Bug 1428629 - elfhack.cpp prefer prefix ++ operator for non primitive types r=froydnj
MozReview-Commit-ID: C0L2NUsbmc4
2018-01-08 09:30:32 +01:00
Jean-Luc Bonnafoux
22f7e153fb Bug 1417215 - Prefer prefix ++ operator for non primitive types r=froydnj
MozReview-Commit-ID: Hjbj0PEjAnf
2017-12-30 21:09:58 +01:00
Mike Hommey
f340ab735e Bug 1423821 - Add a consistency check for section offsets to elfhack. r=froydnj
lld is being too smart for its own good, and places non-relocatable data
right after the program headers, which prevents the program headers from
growing. But elfhack wasn't checking for that, so happily placed the
non-relocatable data at its non-relocated location, overwriting the last
item of the program headers.
2017-12-07 15:34:58 +09:00
Mike Hommey
3a59e2eb56 Bug 1423813 - Properly handle elfhack -r after bug 1385783. r=froydnj
Bug 1385783 changed things such that the two elfhack sections are not
adjacent anymore. They can even be in different segments in some cases,
but the undo code doesn't know how to actually handle that case.

So for now, allow non adjacent sections, but still verify that they are
in the same segment.
2017-12-07 15:22:22 +09:00
Chris Manchester
cdef76c96c Bug 1407388 - Remove build/unix/elfhack/inject/Makefile.in and replace with generated files. r=mshal
MozReview-Commit-ID: Cr2RUlksKBJ
2017-11-07 16:54:22 -08:00
Nathan Froyd
356e5eec49 Bug 1163171 - part 2 - switch to using -isystem rather than -idirafter for Android; r=glandium
This command-line flag is a little more evocative and works correctly
with both GCC and clang.
2017-10-28 17:38:59 -04:00
Chris Manchester
b70f004562 Bug 1403346 - Implement cflags filtering for elfhack in mozbuild COMPILE_FLAGS r=glandium
MozReview-Commit-ID: GO2mqMjHuHd
2017-10-25 15:12:10 -07:00
Mike Hommey
ce1ab2fa9c Bug 1401005 - Handle the case where the relocation addend is not found at the relocation location. r=froydnj 2017-09-21 11:37:30 +09:00
Chris Manchester
d68e6d052c Bug 1386876 - Replace all uses of NO_VISIBILITY_FLAGS with a template and remove NO_VISIBILITY_FLAGS. r=glandium
MozReview-Commit-ID: 194U1WMCAM0
2017-05-01 18:12:35 -07:00
Eugen Sawin
71d61acfcb Bug 1388893 - [1.0] Abort code insertion if executable section was not found. r=glandium 2017-08-15 13:58:41 +02:00
Mike Hommey
5061636ace Bug 1388713 - Change how elfhack looks for the bss section. r=froydnj
In bug 635961, elfhack was made to (ab)use the bss section as a
temporary space for a pointer. To find it, it scanned writable PT_LOAD
segments to find one that has a different file and memory size,
indicating the presence of .bss. This usually works fine, but when
the binary is linked with lld and relro is enabled, the end of the
file-backed part of the PT_LOAD segment containing the .bss section
ends up in the RELRO segment, making that location read-only and
subsequently making the elfhacked binary crash when it tries to restore
the .bss to a clean state, because it's not actually writing in the .bss
section: lld page aligns it after the RELRO segment.

So instead of scanning PT_LOAD segments, we scan for SHT_NOBITS
sections that are not SHF_TLS (i.e. not .tbss).
2017-08-10 07:55:55 +09:00
Mike Hommey
4dd5c54a20 Bug 1385783 - Insert the elfhack code before the first executable section. r=froydnj
The lld linker creates separate segments for purely executable sections
(such as .text) and sections preceding those (such as .rel.dyn). Neither
gold nor bfd ld do that, and just put all those sections in the same
executable segment.

Since elfhack is putting its executable code between the two relocation
sections, it ends up in a non-executable segment, leading to a crash
when it's time to run that code.

We thus insert the elfhack code before the first executable section
instead of between the two relocation sections (which is where the
elfhack data lies, and stays).
2017-08-02 16:39:12 +09:00
Mike Hommey
b09d245c16 Bug 1385783 - Don't assume both elfhack sections are next to each other. r=froydnj 2017-08-02 16:05:07 +09:00
Sylvestre Ledru
a725fd3aa1 Bug 1385910 - In the error message, also ask to upload the pre-elfhacked library r=froydnj
MozReview-Commit-ID: A7ADGyQunjN
2017-07-31 16:35:03 +02:00
Cameron McCormack
eb38b43907 Bug 1385537 - Check for writable segments correctly. r=glandium
MozReview-Commit-ID: FItpvVeiMJM
2017-07-29 13:56:25 +08:00
Mike Hommey
402899e0f0 Bug 1385117 - Make the bss section of the elfhack testcase large enough. r=froydnj
Since bug 635961, building with relro makes elfhack try to use the bss
data for a temporary function pointer. If there is not enough space for
a pointer in the bss, elfhack will complain it couldn't find the bss.

In normal circumstances, this is most likely fine. Libraries with a bss
so small that it can't fit a pointer are already too small to be
elfhacked anyways. In Firefox, the two libraries with the smallest bss
have enough space for two pointers, and aren't elfhacked (libmozgtk.so
and libplds4.so).

However, the testcase that is used during the build to validate that
elfhack works doesn't have a large enough bss on x86-64, making elfhack
bail out, and the build fail as a consequence.

This, in turn, is due to the only non-thread-local zeroed data being an
int, which is not enough to fit a pointer on x86-64. We thus make it a
size_t.
2017-07-28 07:15:39 +09:00
Mike Hommey
c0b84a749c Bug 635961 - Allow elfhack to relocate data under the GNU_RELRO segment. r=froydnj 2017-07-11 07:41:07 +09:00
Wes Kocher
cc389365c2 Backed out 2 changesets (bug 635961) at developer's request a=backout
Backed out changeset c56fa9c1eda0 (bug 635961)
Backed out changeset ddda63d5366e (bug 635961)

MozReview-Commit-ID: I6NxBctFn8e
2017-07-25 17:57:43 -07:00
Mike Hommey
63f270d06d Bug 1378986 - Avoid crashing in elfhack when the input file has no relocations. r=me a=bustage
MozReview-Commit-ID: 8jXvB8iRJkC
2017-07-25 15:50:34 -07:00
Mike Hommey
870d2795e2 Bug 635961 - Allow elfhack to relocate data under the GNU_RELRO segment. r=froydnj 2017-07-11 07:41:07 +09:00
Mike Hommey
30fcb40e18 Bug 1379835 - Don't filter out -idirafter flag when building elfhack injected code. r=gps 2017-07-11 08:02:16 +09:00
Mike Hommey
2c2487eb56 Bug 1378986 - Adjust the fake phdr section properly. r=froydnj
The PT_PHDR segment is optional, but the Android toolchain decides to
create one in some cases, and places it first. When that happens, the
work around for bug 1233963 fails, because the fake phdr section has not
been adjusted yet (it only happens when we see a PT_LOAD).

So we adjust the fake phdr section when we see a PT_PHDR segment (and
avoid re-updating it when we see a subsequent PT_LOAD).
2017-07-07 18:29:06 +09:00
Mike Hommey
8d189d4ddd Bug 1378986 - Avoid elfhack failing on weird DT_INIT_ARRAYs. r=froydnj
Somehow, with the Android toolchain, we end up with
non-empty-but-really-empty DT_INIT_ARRAYs.

In practical terms, they are arrays with no relocations, and content
that is meaningless:

  $ objdump -s -j .init_array libnss3.so

  libnss3.so:     file format elf32-little

  Contents of section .init_array:
   1086e0 00000000                             ....

  $ readelf -r libnss3.so | grep 1086e0

  $ objdump -s -j .init_array libplugin-container-pie.so

  libplugin-container-pie.so:     file format elf32-little

  Contents of section .init_array:
   4479c ffffffff 00000000 ffffffff 00000000  ................

  $ readelf -r libplugin-container-pie.so | grep 4479c

Because so far, elfhack expected meaningful DT_INIT_ARRAYs, it bailed out
early in that case.
2017-07-07 14:44:46 +09:00
Mike Hommey
88c00ebb52 Bug 1353661 - Don't build elfhack/inject during export. r=mshal
When the clang plugin is used, building something during export needs to
happen after the plugin is built. But there is no dependency ensuring
this happens.

OTOH, these sources in elfhack/inject don't need to be built that early,
so we'll just leave to the build system to build it at a proper time.
2017-04-05 18:01:33 +09:00
Tom Tromey
1b5a2bdb96 Bug 1286877 - do not set c-basic-offset for python-mode; r=gps
This removes the unnecessary setting of c-basic-offset from all
python-mode files.

This was automatically generated using

    perl -pi -e 's/; *c-basic-offset: *[0-9]+//'

... on the affected files.

The bulk of these files are moz.build files but there a few others as
well.

MozReview-Commit-ID: 2pPf3DEiZqx
2016-07-14 10:16:42 -06:00
Mike Hommey
aae5b9dda8 Bug 1245763 - Don't emit Sources objects when there is no Linkable in the same directory. r=gps
We have very few directories where we have SOURCES declared that are not
part of a library or program in some way. In fact, there is only one
where it is legitimate because we only use the object file
(build/unix/elfhack/inject). Others are the result of moz.build control
flow (see e.g. netwerk/standalone), and we end up building more objects
than we need to.

There are other cases where we need objects without actually linking
them anywhere, but there are other sources in the same directory, and a
corresponding Linkable is emitted. And in fact, the only case I knew
about (media/libvpx), doesn't use such objects since bug 1151175.
2016-02-04 17:16:29 +09:00
Mike Hommey
45de988f32 Bug 1233963 - Work around recent GNU gold behavior with segments starting before the first section they contain. r=froydnj 2016-01-21 13:54:03 +09:00
Ms2ger
1c8f9dbc82 Bug 1194603 - Remove INTERNAL_TOOLS; r=mshal
Its only purpose is to disable PGO. Where that was not already explicitly done,
or irrelevant (because the directory only contains python), I disabled it in
moz.build.
2015-09-10 13:49:19 +02:00
Mike Hommey
e5760853c7 Bug 991983 - Use objdir-relative SOURCES instead of GENERATED_SOURCES. r=gps 2015-05-28 07:34:16 +09:00
Mike Hommey
a56022eb59 Bug 1167474 - Remove ELFHACK_BUILD hack. r=mshal
It used to be necessary because of how elfhack was built in the past, but it
happens to be unnecessary nowadays.
2015-05-26 16:17:55 +09:00
Mike Hommey
5efb7c235d Bug 1043692 - Add a DIST_INSTALL variable to moz.build, and replace NO_DIST_INSTALL with it. r=gps 2015-05-12 07:55:21 +09:00
Mike Hommey
14358d24bd Bug 1154596 - Build elfhack tests with -fno-lto. r=nfroyd
LTO changes in GCC5 make it break the assumptions made in the test-ctors
source. The simplest and more correct thing to do is to just force the
test files never to be built with LTO. They are meant to have a particular
layout that LTO might break at any time anyways.
2015-04-16 14:35:13 +09:00
Masatoshi Kimura
bae0a32948 Bug 1120062 - Part 1: Remove most Nullptr.h includes. r=waldo 2015-01-11 11:34:52 +09:00
Mike Hommey
632dbaeb90 Bug 1077148 part 4 - Add and use new moz.build templates for Gecko programs and libraries. r=gps
There are, sadly, many combinations of linkage in use throughout the tree.
The main differentiator, though, is between program/libraries related to
Gecko or not. Kind of. Some need mozglue, some don't. Some need dependent
linkage, some standalone.

Anyways, these new templates remove the need to manually define the
right dependencies against xpcomglue, nspr, mozalloc and mozglue
in most cases.

Places that build programs and were resetting MOZ_GLUE_PROGRAM_LDFLAGS
or that build libraries and were resetting MOZ_GLUE_LDFLAGS can now
just not use those Gecko-specific templates.
2014-10-30 13:06:12 +09:00
Mike Hommey
aec0b61280 Bug 1041941 - Use templates for programs, simple programs, libraries and C++ unit tests. r=gps 2014-09-03 14:10:54 +09:00
Mike Hommey
21cfc0c686 Bug 1043289 - Don't declare SOURCES and USE_LIBS when there is nothing to build. r=mshal 2014-07-25 07:10:15 +09:00
Mike Hommey
0dd927f601 Bug 1043084 - Fix elfhack test build failure with gold after bug 1036894. r=mshal 2014-07-25 07:08:34 +09:00
Robert O'Callahan
cf2dda8536 Bug 1001320. Part 5: Use #pragma GCC visibility on B2G. r=glandium 2014-05-11 23:37:14 -07:00
Mike Hommey
b218c7ae91 Bug 982014 - Fix what sections are copied from injection object after bug 932737. r=nfroyd 2014-04-04 14:56:36 +09:00
Ehsan Akhgari
c5e2a6629f Bug 978594 - Part 3: Port some of the per-source flags to moz.build; r=glandium 2014-03-02 15:41:32 -05:00
Mike Shal
0b12894332 Bug 875013 - VPATH removals in build, roboextender, crashreporter; r=ted 2014-01-21 18:01:22 -05:00
Mike Hommey
c29763a26a Bug 945042 - Move NO_PROFILE_GUIDED_OPTIMIZE to moz.build. r=gps,r=njn 2013-12-09 13:39:26 +09:00
Mike Hommey
9566d097cb Bug 943728 - Replace double quotes with single quotes in Makefiles (or remove them when it makes sense). r=mshal 2013-12-03 06:34:21 +09:00
Mike Hommey
06f022b38f Bug 874266 - Move all DEFINES that can be moved to moz.build. r=mshal 2013-11-27 22:55:07 +09:00
Mike Hommey
3a5f5f0076 Backout changeset 3fd4b546eed4 (bug 874266) and changeset a35d2e3a872f (bug 942043) for ASAN build bustage and Windows test bustage 2013-11-28 14:24:05 +09:00
Mike Hommey
3405bc48c6 Bug 874266 - Move all DEFINES that can be moved to moz.build. r=mshal 2013-11-28 13:08:16 +09:00