Commit Graph

474 Commits

Author SHA1 Message Date
Elliott Hughes
8f2a5a0b40 Clean up internal libc logging.
We only need one logging API, and I prefer the one that does no
allocation and is thus safe to use in any context.

Also use O_CLOEXEC when opening the /dev/log files.

Move everything logging-related into one header file.

Change-Id: Ic1e3ea8e9b910dc29df351bff6c0aa4db26fbb58
2013-03-15 16:12:58 -07:00
Elliott Hughes
746f128602 am 5d998b4a: am f21aa3b6: Merge "Use more types than just \'unsigned\' in the linker."
* commit '5d998b4a21aab09da750e8e43cb608f5ee6b1f3d':
  Use more types than just 'unsigned' in the linker.
2013-03-12 12:03:06 -07:00
Elliott Hughes
ca0c11bd82 Use more types than just 'unsigned' in the linker.
Still chipping away at the situation where every variable in the
linker was of type 'unsigned'. This patch switches counts over to
being size_t and adds an explicit type for init/fini function pointers
and arrays of function pointers.

Also improve logging from CallArray.

Also remove trailing "\n"s from log messages.

Change-Id: Ie036d2622caac50f4d29f0570888bb527661d77e
2013-03-12 11:26:56 -07:00
Elliott Hughes
e9cdce33f3 am 3c9afb5e: am 6b4c77f8: Merge "Use Elf32_Addr instead of unsigned in linker"
* commit '3c9afb5e17eaa2ed5a12d71a1a09fe85f06fcb48':
  Use Elf32_Addr instead of unsigned in linker
2013-03-12 10:40:56 -07:00
Kito Cheng
fa8c05dc00 Use Elf32_Addr instead of unsigned in linker
Change-Id: I52dcbb4b0ff0a4052e0ad7a9bbeb2df65c9d2f66
2013-03-12 10:19:14 -07:00
Elliott Hughes
8a01572272 resolved conflicts for merge of 4706606c to jb-mr2-dev
Change-Id: Ibf6340df901c870cd05a2ab56536ad23b6fd491c
2013-03-07 13:19:20 -08:00
Elliott Hughes
0493a6f7be Regenerate NOTICE files.
Also clean up some obsolete cruft.

Change-Id: Iec3b36f6607f7a08b72de99294ed5b6cd910dd5f
2013-03-07 11:51:10 -08:00
Brian Carlstrom
c7b9f954a5 am 91392116: am 33031fed: Merge "Fix typo of DT_NEEDED for DT_NULL"
* commit '91392116ff859b2e7656ded729b8c758107241aa':
  Fix typo of DT_NEEDED for DT_NULL
2013-03-07 00:12:13 +00:00
Brian Carlstrom
2d4b9b7cff Fix typo of DT_NEEDED for DT_NULL
(cherry-pick of 138b205ea9efc117fe522c2d7191378023a6e2cd)

Change-Id: Ia895cb3018df55554627f1f61dcdfdada4a961ce
2013-03-06 15:50:30 -08:00
Elliott Hughes
bac72abae4 am 50a2cd86: am 0b4a85bf: Merge "Fix TIMING/STATS/COUNT_PAGES dynamic linker build"
* commit '50a2cd865e7cc8c72d926548ed5d64e269003055':
  Fix TIMING/STATS/COUNT_PAGES dynamic linker build
2013-03-06 17:44:43 +00:00
Kito Cheng
5e2492eb89 Fix TIMING/STATS/COUNT_PAGES dynamic linker build
Change-Id: I6432ac378816da253b83d1c7fb1d3fb64647b89e
2013-03-06 23:58:48 +08:00
Brian Carlstrom
2527a8b5a6 am 9043202b: am 20958207: Merge "Fix MIPS linker build"
* commit '9043202b5bb8e0725b0302e9da9d3a57c837e798':
  Fix MIPS linker build
2013-03-06 09:18:59 +00:00
Brian Carlstrom
43cc7f795b Fix MIPS linker build
(cherry-picked from 8c7d8c2057e303985f78eab96da747ddaa013c78)

Change-Id: Idcf62ab95f8fccbc2d7c3e771a4cfbe768a1555e
2013-03-06 01:05:08 -08:00
Elliott Hughes
c1a5d20d08 am 9a0b658c: am c41dcad0: Merge "More linker cleanup."
* commit '9a0b658c9c1f8f4492f61a75909e5ca2f05c3ac1':
  More linker cleanup.
2013-03-06 06:44:06 +00:00
Elliott Hughes
650be4e584 More linker cleanup.
Change-Id: I9fb3c7c0d4b4ffef0eeaf092d4e30ffe63a08671
2013-03-05 22:24:34 -08:00
Brian Carlstrom
8c65a1e466 am a2517de3: am 036f9097: Merge "Minor linker cleanup, primarily to use Elf32_Dyn"
* commit 'a2517de3844d95b5f00a4666b8dae00ef893ac24':
  Minor linker cleanup, primarily to use Elf32_Dyn
2013-03-06 01:22:25 +00:00
Brian Carlstrom
d4ee82dfa3 Minor linker cleanup, primarily to use Elf32_Dyn
Change-Id: Ifa9408e9859c6f79444715bed4808b7c13fdced5
2013-03-05 15:27:21 -08:00
Elliott Hughes
6f55284103 am b5862d4d: Merge "Update linker README."
* commit 'b5862d4d8a1246dc1e21695cf3bacafefedf0428':
  Update linker README.
2013-02-19 11:39:40 -08:00
Elliott Hughes
aa772a33ba Update linker README.
Change-Id: Icaa353e9cf1848c86e7445f4ad590bdab44f7941
2013-02-19 11:13:44 -08:00
Elliott Hughes
2db16ea38e am 3002d64b: Merge "Everyone has a TLS register."
# Via Elliott Hughes (1) and Gerrit Code Review (1)
* commit '3002d64bcd4644456803dd0547d20b39e14be02c':
  Everyone has a TLS register.
2013-02-13 08:11:24 -08:00
Elliott Hughes
91a9925998 Everyone has a TLS register.
Change-Id: Id7cdf67087aa7d5074c9c59b7e595bc391d9f146
2013-02-12 21:56:42 -08:00
Elliott Hughes
63358ae068 am 8f509e8b: am 9a9bb243: Merge "Switch to using AT_RANDOM for the stack guards."
# Via Android Git Automerger (1) and others
* commit '8f509e8be11876023d4bcb3e827ca096f22fc0c5':
  Switch to using AT_RANDOM for the stack guards.
2013-02-08 11:43:09 -08:00
Elliott Hughes
d3920b3a99 Switch to using AT_RANDOM for the stack guards.
Bug: 7959813
Change-Id: I8db4b8912ba649bfe668c6f22aa44690ddd401a2
2013-02-08 11:16:13 -08:00
Elliott Hughes
8c372fc77e am 5bb67760: am f6afd3b6: Merge "Fix x86 build, remove void* arithmetic."
# Via Android Git Automerger (1) and others
* commit '5bb67760f0baddd815334bf87be79f0e7fd9fafe':
  Fix x86 build, remove void* arithmetic.
2013-02-07 14:45:28 -08:00
Elliott Hughes
389ebfa16f am 6f67cd22: am 2f41531f: Merge "Clean up the argc/argv/envp/auxv handling."
# Via Android Git Automerger (1) and others
* commit '6f67cd224e6ffdfa2619849eb4b9b2ff6c1e2c59':
  Clean up the argc/argv/envp/auxv handling.
2013-02-07 14:45:24 -08:00
Elliott Hughes
646e058136 Fix x86 build, remove void* arithmetic.
Change-Id: Idc7f14af2e094ac33de315e808176237af063bb8
2013-02-07 12:16:10 -08:00
Elliott Hughes
42b2c6a5ee Clean up the argc/argv/envp/auxv handling.
There's now only one place where we deal with this stuff, it only needs to
be parsed once by the dynamic linker (rather than by each recipient), and it's
now easier for us to get hold of auxv data early on.

Change-Id: I6314224257c736547aac2e2a650e66f2ea53bef5
2013-02-07 11:44:21 -08:00
Elliott Hughes
1c3039301b am 0e51a861: am 4fc2a74b: Merge "Remove partial implementation of MIPS non-PIC support."
# Via Android Git Automerger (1) and others
* commit '0e51a861241ea49455c519890b34e80eccfd4709':
  Remove partial implementation of MIPS non-PIC support.
2013-02-06 11:55:06 -08:00
Elliott Hughes
d2b1a7311f Remove partial implementation of MIPS non-PIC support.
Change-Id: I3c287e52aae10559508174e73113367aea40e5c2
2013-02-06 11:02:28 -08:00
Elliott Hughes
a1b8c145cb am a7f44b5a: am 172e038f: am f09f6db5: Merge "Use the NetBSD <sys/exec_elf.h>."
# Via Android Git Automerger (2) and others
* commit 'a7f44b5afe64199eeee715e613c7d42d2724232c':
  Use the NetBSD <sys/exec_elf.h>.
2013-01-29 17:09:11 -08:00
Elliott Hughes
a6a3ac5924 Use the NetBSD <sys/exec_elf.h>.
Replace a kernel header file dependency with files from NetBSD.
They're more complete, and ELF is ELF, whether you're on Linux or a BSD.

Bug: 7973611
Change-Id: I83ee719e7efdf432ec2ddbe8be271d05b2f558d7
2013-01-29 15:02:50 -08:00
Elliott Hughes
bdd209561e am 1029364e: am e8e1f34a: am 85597e2b: Merge "Clean up debuggerd-related logging."
* commit '1029364ec5710755164ec9a7f0fe625cc184bb60':
  Clean up debuggerd-related logging.
2013-01-22 15:23:49 -08:00
Elliott Hughes
6b8e321e61 Clean up debuggerd-related logging.
Bug: 7291287
Change-Id: Ia7aa386e8b75b8058d7d9e707e11b1da7dc62f00
2013-01-22 14:17:14 -08:00
Elliott Hughes
16f7b78fd1 am 4cd5703b: am 75b64a1b: am ca483765: Merge "Fix the duplication in the debugging code."
* commit '4cd5703b9eef30a32271819503808576666e1601':
  Fix the duplication in the debugging code.
2013-01-22 10:05:19 -08:00
Elliott Hughes
ca483765bd Merge "Fix the duplication in the debugging code." 2013-01-22 17:44:15 +00:00
Elliott Hughes
1e980b6bc8 Fix the duplication in the debugging code.
We had two copies of the backtrace code, and two copies of the
libcorkscrew /proc/pid/maps code. This patch gets us down to one.

We also had hacks so we could log in the malloc debugging code.
This patch pulls the non-allocating "printf" code out of the
dynamic linker so everyone can share.

This patch also makes the leak diagnostics easier to read, and
makes it possible to paste them directly into the 'stack' tool (by
using relative PCs).

This patch also fixes the stdio standard stream leak that was
causing a leak warning every time tf_daemon ran.

Bug: 7291287
Change-Id: I66e4083ac2c5606c8d2737cb45c8ac8a32c7cfe8
2013-01-18 22:20:06 -08:00
Guang Zhu
4df577fef7 Revert "Filter ANDROID_PROPERTY_WORKSPACE"
Temporarily revert the change since DNS resolution seems
broken right now in ping util.

Bug: 8029617

This reverts commit a0f64756a4.
2013-01-18 11:28:47 -08:00
Guang Zhu
bf1d225593 Revert "Filter ANDROID_PROPERTY_WORKSPACE"
Temporarily revert the change since DNS resolution seems
broken right now in ping util.

Bug: 8029617

This reverts commit a0f64756a4.
2013-01-17 23:25:24 -08:00
Nick Kralevich
dbcf3ed458 am 36c4eb18: am 3a72fe58: am f3fe1945: Merge "linker: add -Wl,--exclude-libs,ALL to LDFLAGS"
* commit '36c4eb188c6594db877bd7b9f46c55264180dc3f':
  linker: add -Wl,--exclude-libs,ALL to LDFLAGS
2013-01-17 11:34:20 -08:00
Nick Kralevich
d89ce40d8e linker: add -Wl,--exclude-libs,ALL to LDFLAGS
The linker is essentially a shared library, and incorporates
it's own copy of libc. Even though it's unnecessary, currently
/system/bin/linker is exporting various libc symbols (only to
apps which explicitly dlopen /system/bin/linker)

Add --exclude-libs,ALL, which tells the static linker to mark
all of the imported libc symbols as hidden. This reduces the
size of /system/bin/linker from 92K to 67K with no obvious
loss in functionality.

  $ adb shell ls -l /system/bin/linker
  -rwxrwxrwx root     root        92260 2013-01-16 16:52 linker

  $ adb shell ls -l /system/bin/linker
  -rwxrwxrwx root     root        67660 2013-01-16 16:49 linker

Documentation on exclude-libs can be found at
http://sourceware.org/binutils/docs-2.21/ld/Options.html

Change-Id: I4508287770e4b7a845def2e6b4af969f9c866c6a
2013-01-16 16:43:58 -08:00
Nick Kralevich
927d904d52 am 91bc5865: am 8d01c055: am 1271cdc1: Merge "Revert "stack protector: use AT_RANDOM""
* commit '91bc5865a333212e7cac934b0a2ac7c522911d58':
  Revert "stack protector: use AT_RANDOM"
2013-01-16 13:58:04 -08:00
Nick Kralevich
bcd18c0485 am 27ff1ae4: am de666485: am ba117e41: Merge "stack protector: use AT_RANDOM"
* commit '27ff1ae414915789b27d0a485ff6d856ae742aad':
  stack protector: use AT_RANDOM
2013-01-16 13:34:46 -08:00
Nick Kralevich
dde6b88a9f am 079e4356: am 30894bdf: am 1b34228b: Merge "Filter ANDROID_PROPERTY_WORKSPACE"
* commit '079e4356550030e8bacec86b8aa058ade2b7142c':
  Filter ANDROID_PROPERTY_WORKSPACE
2013-01-16 13:34:45 -08:00
Nick Kralevich
36bd371e26 Revert "stack protector: use AT_RANDOM"
The AT_RANDOM changes broke setuid / setgid executables
such as "ping". When the linker executes a setuid program,
it cleans the environment, removing any invalid environment
entries, and adding "NULL"s to the end of the environment
array for each removed variable. Later on, we try to determine
the location of the aux environment variable, and get tripped
up by these extra NULLs.

Reverting this patch will get setuid executables working again,
but getauxval() is still broken for setuid programs because of
this bug.

This reverts commit e3a49a8661.

Change-Id: I05c58a896b1fe32cfb5d95d43b096045cda0aa4a
2013-01-16 13:16:42 -08:00
Nick Kralevich
ba117e4172 Merge "stack protector: use AT_RANDOM" 2013-01-16 11:23:26 -08:00
Nick Kralevich
e3a49a8661 stack protector: use AT_RANDOM
Populate the stack canaries from the kernel supplied
AT_RANDOM value, which doesn't involve any system calls.
This is slightly faster (6 fewer syscalls) and avoids
unnecessarily reading /dev/urandom, which depletes entropy.

Bug: 7959813

Change-Id: If2b43100a2a9929666df3de56b6139fed969e0f1
2013-01-16 10:09:52 -08:00
Nick Kralevich
a0f64756a4 Filter ANDROID_PROPERTY_WORKSPACE
When executing a setuid executable, filter out ANDROID_PROPERTY_WORKSPACE
from the environment. Some applications implicitly trust the property
space and don't realize that it's passed by an environment variable
which can be modified by the caller.

Change-Id: I3e3a98941f0a1f249a2ff983ecbcfe1278aa9159
2013-01-15 16:02:03 -08:00
Elliott Hughes
32cefdbc7a am 375db86a: am 09d13c39: Merge "Fix my git mistake."
* commit '375db86aeaedfe716b69a62f81a2484ee446d5e5':
  Fix my git mistake.
2013-01-14 10:34:44 -08:00
Elliott Hughes
99c32055cb Fix my git mistake.
This was the formatting change that was supposed to be in
cf23905a4b.

Change-Id: Ib79fa031b68f6f541f532507eb589afeaedb831f
2013-01-14 09:56:21 -08:00
Elliott Hughes
14ab1a63d6 am bc3c7183: am 48c632a3: Merge "[MIPS] Set DT_DEBUG dyntab entry if it is writable"
* commit 'bc3c718346d81c04451c35c2d8fb00c68b0a815d':
  [MIPS] Set DT_DEBUG dyntab entry if it is writable
2013-01-14 09:50:50 -08:00
Chris Dearman
cf23905a4b [MIPS] Set DT_DEBUG dyntab entry if it is writable
This is primarily for MIPS exutables that do not have a
DT_MIPS_RLD_MAP entry.

Change-Id: I4c221d92debcfed961eeee2515123f3fb21ec8e6
Signed-off-by: Chris Dearman <chris@mips.com>
2013-01-14 09:30:25 -08:00
Elliott Hughes
8dd63f31ba am 81508de3: am f0036944: Merge "Fix debug malloc."
* commit '81508de3d277db2ef3c8aa55b57ce3ce0a142e48':
  Fix debug malloc.
2013-01-03 16:47:22 -08:00
Elliott Hughes
db492b3ca7 Fix debug malloc.
...which has been broken since the linker data structures went read-only.

Bug: 7941716
Change-Id: If28f6bac0fcb13e371e4d85b064544f561c8d692
2013-01-03 15:44:03 -08:00
Elliott Hughes
36a9f354c0 am c0c05ff8: am 918d776f: Merge "Support System.loadLibrary for libraries with transitive dependencies."
* commit 'c0c05ff8ecfe5f27aedcd6315e191245aa7b4824':
  Support System.loadLibrary for libraries with transitive dependencies.
2012-12-28 09:48:19 -08:00
Elliott Hughes
0ce87c8984 am df5c77c9: am f6524f8b: Merge "Fix format_number."
* commit 'df5c77c91a276a79d05f58241df3695b56422d54':
  Fix format_number.
2012-12-28 09:46:53 -08:00
Elliott Hughes
918d776f7e Merge "Support System.loadLibrary for libraries with transitive dependencies." 2012-12-21 17:46:22 -08:00
Elliott Hughes
eababde214 Fix format_number.
I broke this the other day when silencing x86 gcc warnings.

Bug: 7904160
Change-Id: I8e60cc1f8cbaff95248c8738d84e515413d839e4
2012-12-20 19:00:48 -08:00
Elliott Hughes
cade4c36e7 Support System.loadLibrary for libraries with transitive dependencies.
Also fix the FLAG_ERROR annoyance --- it's not helpful to cache failures.

Bug: 7896159
Bug: http://code.google.com/p/android/issues/detail?id=34416
Bug: http://code.google.com/p/android/issues/detail?id=22143
Change-Id: I60f235edb4ea4756e1f7ce56f7739f18e8a50789
2012-12-20 14:42:14 -08:00
Elliott Hughes
d020802e37 am 5fd31f68: am 4b582142: Merge "Fix x86 dynamic linker build."
* commit '5fd31f6891a6e0b5db84c4c7992d0a4b08f3dddd':
  Fix x86 dynamic linker build.
2012-12-19 09:51:36 -08:00
Elliott Hughes
05ab167cf7 am a0edecf3: am a4ebdcf5: Merge "Check for unknown flags passed to dlopen(3)."
* commit 'a0edecf3438d036ee2353076d171ee68939c2a5e':
  Check for unknown flags passed to dlopen(3).
2012-12-18 19:44:10 -08:00
Elliott Hughes
45288c5ce3 Fix x86 dynamic linker build.
Change-Id: Ia9fc6342e3d409de86dcd187c7402e8ac2ae96c8
2012-12-18 18:13:19 -08:00
Elliott Hughes
e66190d2a9 Check for unknown flags passed to dlopen(3).
Change-Id: I56f4aab0e5a1487bc32d2c4d231e8bd15c4ac8da
2012-12-18 15:57:55 -08:00
Elliott Hughes
2e51dc444f am 4835e6ef: am 97b70b2b: Merge "Replace .S version of x86 crtfiles with .c version"
* commit '4835e6ef519fc941651bbc13909cff971a6ec81b':
  Replace .S version of x86 crtfiles with .c version
2012-11-30 10:16:06 -08:00
Elliott Hughes
97b70b2bda Merge "Replace .S version of x86 crtfiles with .c version" 2012-11-30 10:07:19 -08:00
Pavel Chupin
20c4a3a8ee Replace .S version of x86 crtfiles with .c version
This patch replaces .S versions of x86 crtfiles with .c which are much
easier to support. Some of the files are matching .c version of Arm
crtfiles. x86 files required some cleanup anyway and this cleanup actually
led to matching Arm files.

I didn't change anything to share the same crt*.c between x86 and Arm. I
prefer to keep them separate for a while in case any change is required
for one of the arch, but it's good thing to do in the following patches.

Change-Id: Ibcf033f8d15aa5b10c05c879fd4b79a64dfc70f3
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2012-11-30 17:41:25 +04:00
Elliott Hughes
4867b00666 am f2de6b0f: Merge "Do not include \'\0\' when writing error messages to stderr"
* commit 'f2de6b0f6e873f9cb28682b8fc6764b0ab41c6ee':
  Do not include '\0' when writing error messages to stderr
2012-11-26 16:04:19 -08:00
Chris Dearman
20a24403bc Do not include '\0' when writing error messages to stderr
Change-Id: I6adc806c3920e5a4ae61ca55c40613fcf338b18c
Signed-off-by: Chris Dearman <chris@mips.com>
2012-11-26 15:43:17 -08:00
Nick Kralevich
c16ea16134 am 8784709a: Merge "We should use load_bias. This patch fixes MIPS NDK device exception test failures."
* commit '8784709a2cfe6d32b5fff2c6b826b8d9cbf73d7b':
  We should use load_bias.  This patch fixes MIPS NDK device exception test failures.
2012-11-19 11:08:49 -08:00
Nick Kralevich
8784709a2c Merge "We should use load_bias. This patch fixes MIPS NDK device exception test failures." 2012-11-19 10:45:18 -08:00
Chao-Ying Fu
c5db969aa4 We should use load_bias. This patch fixes MIPS NDK device exception test failures.
Change-Id: I4b718c36666e66062c1f13e4deea1ec7a7951c54
2012-11-19 10:30:15 -08:00
Nick Kralevich
aec9a254a2 am 170168cd: Merge "Temporarily address gcc 4.7 breakage."
* commit '170168cdf37111b45b15817fab9e3df54cbc27b7':
  Temporarily address gcc 4.7 breakage.
2012-11-16 10:42:55 -08:00
Nick Kralevich
83697b8b76 Temporarily address gcc 4.7 breakage.
Change-Id: I8ebb2d5df2f8f8aedf252c94ff69505e61ed0a74
2012-11-15 15:48:19 -08:00
Elliott Hughes
da71c7d9a3 am ce876beb: am a41e6426: Merge "Tone down some of the overly-verbose linker logging."
* commit 'ce876bebf250d386a06ebc1145c6959e30bf413c':
  Tone down some of the overly-verbose linker logging.
2012-11-05 09:21:57 -08:00
Elliott Hughes
ce876bebf2 am a41e6426: Merge "Tone down some of the overly-verbose linker logging."
* commit 'a41e6426073c57881f49bdaec46ca90a5b164401':
  Tone down some of the overly-verbose linker logging.
2012-11-05 09:19:57 -08:00
Elliott Hughes
9c94fc9fbe Tone down some of the overly-verbose linker logging.
We don't need to see every dlopen(3)/dlsym(3) failure unless LD_DEBUG is on.

Change-Id: I1edfe8b72f32ff54dd30e1acf32e20d470d5e9f7
2012-11-05 09:11:43 -08:00
Elliott Hughes
f1566fd692 am bc35807f: am 9df2e000: Merge "Cleaning the linker environment as we initialize it requires less API."
* commit 'bc35807fc6c5f11b6d057b20250d41ebc419da62':
  Cleaning the linker environment as we initialize it requires less API.
2012-11-02 13:58:48 -07:00
Elliott Hughes
d752fc0286 am cfb47daf: am 01271b18: Merge "Make dynamic linker debugging always available."
* commit 'cfb47daf4eb4741ac462c7350c73ad1cf96cf83f':
  Make dynamic linker debugging always available.
2012-11-02 13:58:47 -07:00
Elliott Hughes
bc35807fc6 am 9df2e000: Merge "Cleaning the linker environment as we initialize it requires less API."
* commit '9df2e000b5d56b2e529656034d684e370aa6a8d1':
  Cleaning the linker environment as we initialize it requires less API.
2012-11-02 13:56:00 -07:00
Elliott Hughes
cfb47daf4e am 01271b18: Merge "Make dynamic linker debugging always available."
* commit '01271b1812f2cec8aaf3c105b9f960f027b33a95':
  Make dynamic linker debugging always available.
2012-11-02 13:55:59 -07:00
Elliott Hughes
9df2e000b5 Merge "Cleaning the linker environment as we initialize it requires less API." 2012-11-02 13:47:50 -07:00
Elliott Hughes
61a9ccb41e Make dynamic linker debugging always available.
If you need to build your own linker to get debugging, the debugging
is never available when you need it.

Change-Id: I5ff7e55753459d49a2990f25d9aa155e0b8602e0
2012-11-02 13:46:23 -07:00
Elliott Hughes
0894b2c5d3 Cleaning the linker environment as we initialize it requires less API.
Change-Id: I612fd699e46833a411589478564a1f859223c380
2012-11-02 12:40:11 -07:00
Elliott Hughes
1d0129b1b2 am cdc5a17c: am ed537239: Merge "Adjust symbol lookup for DT_SYMBOLIC case"
* commit 'cdc5a17cef00c49086e1bfe4c3715d2ebd61addb':
  Adjust symbol lookup for DT_SYMBOLIC case
2012-11-02 11:39:02 -07:00
Elliott Hughes
cdc5a17cef am ed537239: Merge "Adjust symbol lookup for DT_SYMBOLIC case"
* commit 'ed537239a94ebd11a8c262a319d81fd1f0d3f73f':
  Adjust symbol lookup for DT_SYMBOLIC case
2012-11-02 11:37:40 -07:00
Elliott Hughes
ed537239a9 Merge "Adjust symbol lookup for DT_SYMBOLIC case" 2012-11-02 11:25:49 -07:00
Pavel Chupin
c77c434149 Adjust symbol lookup for DT_SYMBOLIC case
According ELF spec re. DT_SYMBOLIC:
This element's presence in a shared object library alters the dynamic
linker's symbol resolution algorithm for references within the library.
Instead of starting a symbol search with the executable file, the
dynamic linker starts from the shared object itself. If the shared
object fails to supply the referenced symbol, the dynamic linker then
searches the executable file and other shared objects as usual.

This change implements the last part.

Change-Id: Iae95d53d455313a4306f11733941bcd3596ac85f
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2012-11-02 18:34:22 +04:00
Elliott Hughes
eb15e1d485 am e109930e: am dc77a228: Merge "Allow dlopen("egl/blah.so")."
* commit 'e109930e9fd0922280e6f74b3df270093ee95fa6':
  Allow dlopen("egl/blah.so").
2012-11-01 23:10:56 -07:00
Elliott Hughes
e109930e9f am dc77a228: Merge "Allow dlopen("egl/blah.so")."
* commit 'dc77a22850e31eb369ec9776c13c967566bf61d0':
  Allow dlopen("egl/blah.so").
2012-11-01 23:08:27 -07:00
Elliott Hughes
6971fe4ca5 Allow dlopen("egl/blah.so").
NVIDIA binary blobs construct strings to pass to dlopen(3) that
contain '/' but require that we fall back to LD_LIBRARY_PATH.

Change-Id: Iad831899986baace6962f4b335eeb288250a1e22
2012-11-01 22:59:19 -07:00
Elliott Hughes
d781dfdb09 am 6db8f5bb: am d30116cf: Merge "Keep the dynamic linker\'s soinfo pools mostly read-only."
* commit '6db8f5bb75bb79e0b4873e6d293aa25e2c9f090b':
  Keep the dynamic linker's soinfo pools mostly read-only.
2012-11-01 17:02:23 -07:00
Elliott Hughes
6db8f5bb75 am d30116cf: Merge "Keep the dynamic linker\'s soinfo pools mostly read-only."
* commit 'd30116cf4a590e7bea3b73fa49bb27502a920819':
  Keep the dynamic linker's soinfo pools mostly read-only.
2012-11-01 17:00:13 -07:00
Elliott Hughes
d23736e4f2 Keep the dynamic linker's soinfo pools mostly read-only.
We'll need a lot more refactoring of this code before we can reduce
the granularity, but this is a step forward.

Change-Id: I07061720e734b571a8399c1d5b4f2f35cd681307
2012-11-01 16:48:14 -07:00
Elliott Hughes
02c3513e5f am 65ba5b62: am 064f862d: Merge "Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too."
* commit '65ba5b62c5a59181317b86f772d9ebb756d4741f':
  Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too.
2012-11-01 14:15:11 -07:00
Elliott Hughes
65ba5b62c5 am 064f862d: Merge "Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too."
* commit '064f862d557ab741575dfae479499a07ca0ab742':
  Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too.
2012-11-01 14:14:00 -07:00
Elliott Hughes
1a6961650c Stop defining our own PAGE_SIZE and PAGE_MASK, and test dlclose(3) too.
Also remove an unnecessary #include and a now-obsolete TODO.

Change-Id: I36d923721e349a286934b9534090a67ce0786e7b
2012-11-01 13:53:26 -07:00
Elliott Hughes
00fe4a20d7 am 3bb62578: am 0be1819b: Merge "Dynamically allocate soinfo-structs in linker"
* commit '3bb62578beb36a35d3b1d2fbe18bd34a9d4ecca4':
  Dynamically allocate soinfo-structs in linker
2012-11-01 11:47:31 -07:00
Elliott Hughes
3bb62578be am 0be1819b: Merge "Dynamically allocate soinfo-structs in linker"
* commit '0be1819b22b33fbedcb150f96a196ed096abe2fc':
  Dynamically allocate soinfo-structs in linker
2012-11-01 11:44:29 -07:00
Magnus Malmborn
ba98d9237b Dynamically allocate soinfo-structs in linker
Request memory from the system when needed instead of having a fixed
array for soinfo structs. Note that malloc() et al can't be used in
linker, so use mmap() instead.

Change-Id: I4b495995931d7752b0e8c944e64d1fe41b9f7144
2012-11-01 11:31:39 -07:00
Elliott Hughes
e892414bd3 am 1de3af51: am c0ac7eba: Merge "Reject .so files with no sysv hash table."
* commit '1de3af51d459c2ced602f10e4f7e7fe704400cdc':
  Reject .so files with no sysv hash table.
2012-10-31 15:15:45 -07:00
Elliott Hughes
1de3af51d4 am c0ac7eba: Merge "Reject .so files with no sysv hash table."
* commit 'c0ac7eba934fb88f321c75a71312ea482e9a85e9':
  Reject .so files with no sysv hash table.
2012-10-31 15:13:30 -07:00
Elliott Hughes
124fae9eab Reject .so files with no sysv hash table.
Also ensure that dlopen(3) errors always include the name of the library we
failed to open.

Also fix a bug where we'd fall back to searching LD_LIBRARY_PATH and the
built-in paths for names that include slashes.

Bug: http://code.google.com/p/android/issues/detail?id=38479
Change-Id: Ib2c009ed083344a7a012749d58f8679db2f26c78
2012-10-31 14:30:50 -07:00
Elliott Hughes
8478dbc85f am 3cd7a165: am 084be591: Merge "linker: handle R_ARM_COPY relocations in a proper way"
* commit '3cd7a1653aa579213cb68a666bd9949e2b8fff95':
  linker: handle R_ARM_COPY relocations in a proper way
2012-10-30 17:20:01 -07:00
Elliott Hughes
3cd7a1653a am 084be591: Merge "linker: handle R_ARM_COPY relocations in a proper way"
* commit '084be591923d3d509cea0a0f4b11b073e362d730':
  linker: handle R_ARM_COPY relocations in a proper way
2012-10-30 17:18:04 -07:00
Ard Biesheuvel
5ae44f302b linker: handle R_ARM_COPY relocations in a proper way
If an executable contain copy relocations, other references
to the symbol it points to should be preempted and made to
point to the copy instead.

Also, the linker should make sure the target area has
sufficient space to contain the copy. It also checks
whether the library that supplies the symbol is built
with -Bsymbolic, and errors out if this is the case.

Change-Id: If135c83590092741cfd8f82f54816f363a4a4a3b
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-10-30 17:09:21 -07:00
Elliott Hughes
864d48917a am 914112ea: am 155e8d1d: Merge "More dynamic linker cleanup."
* commit '914112ea21a62c7658dc4b094a369358009be6a9':
  More dynamic linker cleanup.
2012-10-30 16:59:17 -07:00
Elliott Hughes
914112ea21 am 155e8d1d: Merge "More dynamic linker cleanup."
* commit '155e8d1df5b8fdfeabda3e7b61d95beb5b8d1467':
  More dynamic linker cleanup.
2012-10-30 16:56:29 -07:00
Elliott Hughes
18a206c81d More dynamic linker cleanup.
I still want to break linker_format out into its own library so we can reuse
it for malloc debugging and so forth. (There are many similar pieces of code
in bionic, but the linker's one seems to be the most complete/functional.)

Change-Id: If3721853d28937c8e821ca1d23cf200e228a409a
2012-10-30 16:35:38 -07:00
Elliott Hughes
4e0b489a0c am 8cacc639: am 7193731a: Merge "Workaround g++ 4.7 compfail"
* commit '8cacc639b6ae660c494aca07c537cb443c6c6cd9':
  Workaround g++ 4.7 compfail
2012-10-25 15:23:29 -07:00
Elliott Hughes
8cacc639b6 am 7193731a: Merge "Workaround g++ 4.7 compfail"
* commit '7193731ae6b8083bc7a5e5e468fb98b1dbcf3f3d':
  Workaround g++ 4.7 compfail
2012-10-25 15:20:29 -07:00
Pavel Chupin
20aa6c0f4c Workaround g++ 4.7 compfail
error: C99 designator 'name' outside aggregate initializer

G++ 4.7+ can't handle some of C99 designated initializers.
Most likely it's just not implemented yet. Other possible workarounds is
to compile this as C not C++ or define name as char* instead of char[SIZE].

Appeared after this change https://android-review.googlesource.com/#/c/44470

Change-Id: Ib28157848ce759b8bb5dbb2ac0d9a768fa4e5107
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2012-10-25 17:58:45 +04:00
Elliott Hughes
9eaa953642 am 06abe13c: am a2f596b6: Merge "Make dlerror(3) thread-safe."
* commit '06abe13c5f7a318eef316268d0d25d92ff128c19':
  Make dlerror(3) thread-safe.
2012-10-17 11:05:19 -07:00
Elliott Hughes
06abe13c5f am a2f596b6: Merge "Make dlerror(3) thread-safe."
* commit 'a2f596b65075db7916ffffa2f5059e7953719578':
  Make dlerror(3) thread-safe.
2012-10-17 11:03:12 -07:00
Elliott Hughes
5419b94747 Make dlerror(3) thread-safe.
I gave up trying to use the usual thread-local buffer idiom; calls to
calloc(3) and free(3) from any of the "dl" functions -- which live in
the dynamic linker -- end up resolving to the dynamic linker's stubs.
I tried to work around that, but was just making things more complicated.
This alternative costs us a well-known TLS slot (instead of the
dynamically-allocated TLS slot we'd have used otherwise, so no difference
there), plus an extra buffer inside every pthread_internal_t.

Bug: 5404023
Change-Id: Ie9614edd05b6d1eeaf7bf9172792d616c6361767
2012-10-16 17:58:17 -07:00
Elliott Hughes
4089dea451 am c2483ea9: am 9434e8fe: Merge "Make the dlfcn mutex static."
* commit 'c2483ea9b63de373e7521e39162395a8c667239a':
  Make the dlfcn mutex static.
2012-10-12 11:24:25 -07:00
Elliott Hughes
c2483ea9b6 am 9434e8fe: Merge "Make the dlfcn mutex static."
* commit '9434e8febc8b223db2d49e7f97140771700113b9':
  Make the dlfcn mutex static.
2012-10-12 11:21:59 -07:00
Elliott Hughes
22d629211d Make the dlfcn mutex static.
More style fixes too, and removal of yet another lingering SH reference!

Change-Id: Iebc34a46475dd11845ad172b9108bb6ddd7585bb
2012-10-12 10:50:21 -07:00
Elliott Hughes
66d71c8f13 am ab4e2ed1: am db4fdf1a: Merge "Fix dlerror(3)."
* commit 'ab4e2ed182011998751ff5d6c321ff5bae20c6cd':
  Fix dlerror(3).
2012-10-12 10:49:08 -07:00
Elliott Hughes
ab4e2ed182 am db4fdf1a: Merge "Fix dlerror(3)."
* commit 'db4fdf1aafb63b09ee967066d9b8107a9812db2d':
  Fix dlerror(3).
2012-10-12 10:47:59 -07:00
Elliott Hughes
3b297c4079 Fix dlerror(3).
Add unit tests for dlerror(3) in various situations. I think We're at least
as good as glibc now.

Also factor out the ScopedPthreadMutexLock and use it here too.

Bug: http://code.google.com/p/android/issues/detail?id=38398
Change-Id: I040938b4366ab836e3df46d1d8055b92f4ea6ed8
2012-10-11 16:08:51 -07:00
Ying Wang
a55f0a1007 am b04598a6: Set up the private variables.
* commit 'b04598a63c3f0df597f6186beea3adafc665ef56':
  Set up the private variables.
2012-10-08 14:21:38 -07:00
Ying Wang
b04598a63c Set up the private variables.
Now we use private variables in transform-o-to-executable to support
build executables against the NDK.

Bug: 7170098
Change-Id: I6e505b33001b76f4b11fcbbb1d35392c4ddf4c70
2012-10-08 14:12:56 -07:00
Andy McFadden
1db6f2db49 Test flags before using "info"
Our debugger signal catcher expects to receive three args, but if
somebody cleared SA_SIGINFO we only get one, and bad things happen
when we try to use the second one.  Test to see if SA_SIGINFO is
still set before we try to use the argument.

(cherry-pick of f84bc8d6f6368f1c846124a8168761ee8cc589c0.)

Bug: 7272866
Change-Id: I69a65c25e833aea70acb78f9ba40ed93308583e6
2012-10-03 17:20:06 -07:00
Andy McFadden
399f54c133 am 51c7167d: am 7c67e4e4: am 98957db5: Merge "Test flags before using "info"" into jb-mr1-dev
* commit '51c7167d2245286e3458ffb06b0b5068d8f04e1b':
  Test flags before using "info"
2012-10-02 15:28:17 -07:00
Andy McFadden
51c7167d22 am 7c67e4e4: am 98957db5: Merge "Test flags before using "info"" into jb-mr1-dev
* commit '7c67e4e423f7608c50a1fc7c355d87593cfdbcca':
  Test flags before using "info"
2012-10-02 15:27:09 -07:00
Andy McFadden
f84bc8d6f6 Test flags before using "info"
Our debugger signal catcher expects to receive three args, but if
somebody cleared SA_SIGINFO we only get one, and bad things happen
when we try to use the second one.  Test to see if SA_SIGINFO is
still set before we try to use the argument.

Bug: 7272866
Change-Id: If682a2262fe8a575f3802fb0c60a53eea3082456
2012-10-02 14:30:41 -07:00
Elliott Hughes
7f1464c03c am 068f3398: am 0fa6279f: am 5b6346f6: Merge "bionic: linker: Need update the map->l_addr for execution."
* commit '068f33981ddaee7e397eee73ea5ea97827aabeb7':
  bionic: linker: Need update the map->l_addr for execution.
2012-10-01 09:25:18 -07:00
Elliott Hughes
5b6346f6d5 Merge "bionic: linker: Need update the map->l_addr for execution." 2012-10-01 09:09:17 -07:00
Ying Wang
1be6e685a5 Merge "Set up the private variables." 2012-09-26 11:27:48 -07:00
Ying Wang
f680b0f404 Set up the private variables.
Now we use private variables in transform-o-to-executable to support
build executables against the NDK.

Bug: 7170098
Change-Id: I6e505b33001b76f4b11fcbbb1d35392c4ddf4c70
2012-09-26 10:54:45 -07:00
Elliott Hughes
2fb6457efb am c3233178: am 00f33977: am 3307bff0: Merge "Revert dl_fbase initialization to the address where the shared object is loaded."
* commit 'c32331781097b51a46c03b002cd813752677236a':
  Revert dl_fbase initialization to the address where the shared object is loaded.
2012-09-26 10:46:39 -07:00
Raghu Gandham
e6dc2a664e Revert dl_fbase initialization to the address where the shared object is loaded.
Change-Id: If868cab774a1ae5ff370208216cecda9b8c3b9fd
2012-09-25 15:58:01 -07:00
Elliott Hughes
0647355bef am 28bd96cc: am d5c654c0: am 3b6914bf: Merge "Fix dlsym and dladdr to use load_bias instead of base"
* commit '28bd96cc0b9a5eed785df09a4c1bffc43b95fe6b':
  Fix dlsym and dladdr to use load_bias instead of base
2012-09-24 13:43:58 -07:00
Raghu Gandham
c1993cac40 Fix dlsym and dladdr to use load_bias instead of base
Change-Id: If0f9aa944ccb1f90451aa6674428e34494331d2d
2012-09-21 17:00:30 -07:00
Xiaokang Qin
9c3449ecd9 bionic: linker: Need update the map->l_addr for execution.
Currently, linker doesn't update the map->l_addr for execution.
Which could break the Unwind_Backtrace with PT_GNU_EH_FRAME enabled
in new toolchain.

Change-Id: Ifbd853134da64a962f7e4c4105e56a3f20def1b2
Author: Fengwei Yin <fengwei.yin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Author-tracking-BZ: 57077
2012-09-13 18:09:20 +08:00
Elliott Hughes
6709aba126 am 418ecb7e: am 8c368b5d: am dde94f4c: am 8b4e8a93: Merge "Improve the dynamic linker diagnostics."
* commit '418ecb7ec800d8caa97b01a84d7403272fab4e28':
  Improve the dynamic linker diagnostics.
2012-08-29 14:11:52 -07:00
Elliott Hughes
e9b6fc6f82 Improve the dynamic linker diagnostics.
Lose the pid, only show the name of the function (not its whole signature),
and include the name of the library we failed to load. (I hadn't noticed
that the library name was missing before because in Java we add that into
the UnsatisfiedLinkError detail message.)

The new output looks like this:

  Cannot load library: soinfo_relocate(linker.cpp:968): cannot locate symbol "__libc_malloc_default_dispatch" referenced by "libc_malloc_debug_leak.so"...

Change-Id: I3bb5c9780d9aaf3a9e4418ea55bc98122a81f80f
2012-08-29 13:10:54 -07:00
Nick Kralevich
c64bb00cdf am 773a7832: am d7440f37: am 7cab2188: am ad180738: Merge "linker: Fix ARM_R_COPY relocations"
* commit '773a783295e758bdef1a7e205761bcc1f832af95':
  linker: Fix ARM_R_COPY relocations
2012-08-28 13:09:39 -07:00
Nick Kralevich
ad18073897 Merge "linker: Fix ARM_R_COPY relocations" 2012-08-28 12:48:01 -07:00
Nick Kralevich
d39c3abd5a linker: Fix ARM_R_COPY relocations
Per http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044d/IHI0044D_aaelf.pdf
Section 4.7.1.10, ARM_R_COPY relocations are only suppose to reference shared
libraries, not the executable itself.  When resolving an R_ARM_COPY symbol,
ensure we don't look in our own symbol.

This partially addresses
http://code.google.com/p/android/issues/detail?id=28598 .  After this
patch, the printfs generated by the test program are:

global = 0x42 (0x401c7000)
global = 0x42 (0x11000)

before, the output was:

global = 0x42 (0x40071000)
global = 0x0 (0x11000)

I'm still not very happy with this patch, but I think it's an improvement
over where we were at before.

This change was modeled after https://android-review.googlesource.com/38871

Change-Id: Id7ad921e58395e76a36875bcc742ec5eeba53f08
2012-08-28 11:48:32 -07:00
Nick Kralevich
47cac977f5 am 5443561d: am 48c88804: am 775dabd4: am 9dfaa63a: Merge "Allow linker to compile with -DLINKER_DEBUG=1"
* commit '5443561d5d9fd8ababac989116a036b3ab7b15b0':
  Allow linker to compile with -DLINKER_DEBUG=1
2012-08-27 16:12:39 -07:00
Nick Kralevich
3697b52605 Allow linker to compile with -DLINKER_DEBUG=1
Change-Id: I27e734048cbcb9ed936369115582b3c734de1280
2012-08-24 17:11:45 -07:00
Elliott Hughes
1f6639a1bf am d060b824: am efd39834: am e5242bfd: am 1771a33d: Merge "Add link.h for all platforms with dl_phdr_info"
* commit 'd060b824dd293bf1ecd7814cd2e75a77186cefcb':
  Add link.h for all platforms with dl_phdr_info
2012-08-17 14:04:52 -07:00
Pavel Chupin
b7beb69075 Add link.h for all platforms with dl_phdr_info
This header is used on bionic build and should be propagated into
sysroot on toolchain rebuild. Discussion re. this header is here:
http://gcc.gnu.org/ml/gcc-patches/2012-08/msg00936.html

It is available already in mips NDK platforms:
development/ndk/platforms/android-9/arch-mips/include/link.h

Change-Id: I39ff467cdac9f448e31c11ee3e14a6200e82ab57
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2012-08-17 12:44:23 -07:00
Elliott Hughes
1d16b89289 am 31041a01: am 29af938c: am ab8850f7: am 07cd1125: Merge "Fix comment typos."
* commit '31041a0138d62879257d6980abd1e006c299752b':
  Fix comment typos.
2012-08-15 17:11:48 -07:00
Elliott Hughes
b8d2695c82 am cdbd3406: am 4d63f33c: am 76aad1d2: am e1cd69a7: Merge "Regenerate all NOTICE files with the latest version of the script."
* commit 'cdbd3406f51d7f21326fe99df21e48a9191dddc1':
  Regenerate all NOTICE files with the latest version of the script.
2012-08-15 17:11:47 -07:00
Elliott Hughes
105bc26fa6 Fix comment typos.
Change-Id: I8feeec1ee9935a6d6baebe57f1c0043ff90ff94f
2012-08-15 16:56:00 -07:00
Elliott Hughes
32dbc03c73 Regenerate all NOTICE files with the latest version of the script.
This sorts every entry, so we should have more stability and fewer
merge conflicts in future.

Change-Id: Ifc5347dc53352da22c82d41ca59b483966fcfc6b
2012-08-15 15:43:13 -07:00
Elliott Hughes
ea4900b89a am 0a3f66e9: am fdbecf3b: am 63696738: am b6a97196: Merge "More cleanup."
* commit '0a3f66e9a0ef47dc2f751292a69434405221ef90':
  More cleanup.
2012-08-14 15:14:56 -07:00
Elliott Hughes
bedfe38b8b More cleanup.
Make more stuff static, remove some dead code, and fix a few typos.

Change-Id: I010b0eadeaf61e2899c37014ad1e7082c70bd510
2012-08-14 14:07:59 -07:00
Elliott Hughes
6bdc30e923 am 028ed539: am dc320d99: am 82b69fcb: am b9c6854c: Merge "linker: avoid clobbering the .dynamic section of shared libs"
* commit '028ed539ddbe577687ac9778382c98aab3bf279f':
  linker: avoid clobbering the .dynamic section of shared libs
2012-08-14 12:21:21 -07:00
Ard Biesheuvel
12c78bbded linker: avoid clobbering the .dynamic section of shared libs
This patch removes the DT_NEEDED hack which stores pointers
to soinfo structs in the .dynamic section of the library
being loaded.

Instead, it caches the soinfo struct pointers on the stack
during relocation time. After relocation time, i.e. when
calling constructors and destructors of the shared library
and its dependencies, uncached access is used instead,
doing lookups using the string table entries pointed to by
the DT_NEEDED entries.

By removing this hack, it is no longer needed to undo the
PT_GNURELRO protection, i.e., all non-writable mappings
can remain non-writable during their entire lifespan.

Even though, strictly speaking, the algorithmic complexity
has increased somewhat, the real-world adverse effect
is negligible on the systems I have tested.

Change-Id: I2361502560b96b5878f7f94a8e8a215350d70d64
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-08-14 19:38:28 +02:00
Elliott Hughes
66c033868f am c64c1b49: am ad8ff472: am c1eb7619: am 440e417d: Merge "Add dependencies on all the makefiles."
* commit 'c64c1b49fd5c51b1b6e87d88b233d23fa172d372':
  Add dependencies on all the makefiles.
2012-08-13 16:10:31 -07:00
Elliott Hughes
ae5c64413b Add dependencies on all the makefiles.
This should help prevent broken builds next time I'm messing with
assembler/compiler/linker flags...

Change-Id: I30f15a3ce3c3f3c60cad7bc59aaba9f42d792224
2012-08-13 14:06:05 -07:00
Elliott Hughes
5dcf871abb am 94d7f701: am 71c0366f: am e135d7f3: am a61ac525: Merge "Fix module constructor order."
* commit '94d7f701d1b5cda0621eb46160e11ccbeb85cdd3':
  Fix module constructor order.
2012-08-13 11:15:25 -07:00
Evgeniy Stepanov
9181a5dcfe Fix module constructor order.
.preinit_array goes before the constructors of LD_PRELOAD-ed libraries.

Change-Id: I1af32ce29eaf3ca4351ae8a0f7f5da5165853216
2012-08-13 11:05:47 -07:00
Nick Kralevich
f574ce603a am 34e52129: am 19b10419: am 89fd9ecc: am 20b94c0c: Merge "linker: don\'t perform unnecessary mprotects"
* commit '34e5212961cb64cf690289bc94c59b3b6245694c':
  linker: don't perform unnecessary mprotects
2012-08-13 09:51:48 -07:00
Nick Kralevich
5135b3ae6e linker: don't perform unnecessary mprotects
The linker only needs to mark the text segment as
writable iff the file has text relocations. Unnecessarily
calling mprotect when it isn't necessary is slow, and some
security enhanced kernels don't like it. Pages which are
simultaneously writable and executable are considered a no-no.

The vast majority of executables / shared libraries on Android
do NOT have text relocations.

Change-Id: Ic38ce30a99b7e33ecf21efd9c108547a58eafa35
2012-08-13 08:50:11 -07:00
Ben Cheng
dd8cd5d6bc am daedcfc5: am 9eeaa4bd: am 7e3918eb: am 0bf5cf87: Merge "Set the dynamic field in the link map for the linker itself."
* commit 'daedcfc595f51b1fe22b53d272cee1a142305a11':
  Set the dynamic field in the link map for the linker itself.
2012-08-11 15:19:33 -07:00
Ying Wang
c97c5fc788 Split out LOCAL_ASFLAGS.
Bug: 6967574
Change-Id: I5be50d582c1cb8075039b06292cf0745a996c3c4
2012-08-11 14:23:19 -07:00
Ben Cheng
0bf5cf87c6 Merge "Set the dynamic field in the link map for the linker itself." 2012-08-10 16:46:09 -07:00
Ben Cheng
06f0e74a2b Set the dynamic field in the link map for the linker itself.
Otherwise gdb will print a spurious warning each time gdb is used:

warning: .dynamic section for "/system/bin/linker" is not at the expected
address (wrong library or version mismatch?)

BUG:6946614
Change-Id: Ib21b8db0615751189c1601140deb43bc089289b6
2012-08-10 16:07:02 -07:00
Elliott Hughes
387d4b7de9 Auto-generate a complete NOTICE file.
Remove the hand-collated ones, and switch to a script that pulls the
copyright headers out of every file and collects the unique ones.

Change-Id: Ied3b98b3f56241df97166c410ff81de4e0157c9d
2012-08-09 16:05:31 -07:00
Elliott Hughes
57e6d9ab48 Fix x86 build.
Change-Id: Ice50ca71a19f3bf26de7cfd4c02075f1e6e0823f
2012-08-08 16:06:51 -07:00
Elliott Hughes
4688279db5 Clean up the linker a bit, remove prelinking support.
Also make the errors more readable, since none of us seemed to know
what they actually meant. The new style is still as verbose as the
old, but that's probably necessary in the absence of chained exceptions
in C. Here's what you'd see if you try to boot after removing
libsurfaceflinger.so:

  32267 32267 E AndroidRuntime: java.lang.UnsatisfiedLinkError: Cannot load library: (linker.c:1629, pid 32259) soinfo_link_image: could not load library "libsystem_server.so" needed by "libandroid_servers.so"; caused by (linker.c:1629, pid 32259) soinfo_link_image: could not load library "libsurfaceflinger.so" needed by "libsystem_server.so"; caused by (linker.c:709, pid 32259) load_library: library "libsurfaceflinger.so" not found

This patch also fixes almost all of the compiler warnings.

Change-Id: I64bb59aed6d4e039c15ea45be2367f319ef879f8
2012-08-07 11:41:10 -07:00
Raghu Gandham
d7daacb463 MIPS support to the linker
Change-Id: I37ec2d6c51d82bb9e9dbfef4b38c85366bead255
Signed-off-by: Chris Dearman <chris@mips.com>
Signed-off-by: Raghu Gandham <raghu@mips.com>
Signed-off-by: Bhanu Chetlapalli <bhanu@mips.com>
2012-08-02 14:39:50 -07:00
Elliott Hughes
8dfc073b14 Fix a TEMP_FAILURE_RETRY usage error in the linker.
Similar to the fix in c20d0f3993.

grep(1) says this was the only other instance in bionic.

Change-Id: I1729038762ee1c7c4743a6bd11d5558afd6f5749
2012-07-27 15:30:51 -07:00
Nick Kralevich
f6ee33cee7 Merge "linker: Fix LD_PRELOADS for calling constructors" 2012-07-18 14:02:22 -07:00
Elliott Hughes
3fd5e91e58 Merge "bionic: Report linker relocation address to gdb" 2012-07-16 11:38:23 -07:00
Robin Burchell
8211bc6325 linker: cleanup of undefined state handling, which is really dead code
Given that _elf_lookup (and thus, _do_lookup) cannot possibly return an
undefined symbol (due to the check for SHN_UNDEF in _elf_lookup), there's
no need for spurious checks for SHN_UNDEF on its return value.

Conflicts:

	linker/linker.c

Change-Id: Ic73cf439924b45f72d4d9ba3f64a888c96cbbd9b
2012-07-16 10:03:35 -07:00
Robin Burchell
439fa8ea8c linker: Use SHN_UNDEF instead of describing what it is trying to do. 2012-07-16 09:51:17 -07:00
Elliott Hughes
856512ea9c Use std=gnu99 for the dynamic linker as well as libc.
Change-Id: I76dd78576c5af6eb6282555f069647b6260edc31
2012-07-16 09:43:14 -07:00
Ryan V. Bissell
bb5c30a3ee bionic: Report linker relocation address to gdb
GDB needs the runtime linker's base address in order to
locate the latter's ".text" and ".plt" sections, for the
purpose of detecting solib trampolines.  It also can
potentially use this to calculate the relocated address
of rtld_db_dlactivity.

Bug: http://code.google.com/p/android/issues/detail?id=34856
Change-Id: I63d3e7ae4e20a684ceb25967f2241e7d58dd685d
Signed-off-by: Ryan V. Bissell <ryan@bissell.org>
2012-07-16 02:16:18 -05:00
Kito Cheng
326e85eca6 linker: Fix LD_PRELOADS for calling constructors
Change-Id: I1eae77a4c59e8a5acc009127d271455bb6fc01b6
2012-07-15 00:49:34 +08:00
Andrew Hsieh
793e6aedf2 am 67636eea: am 40e7ed58: Unhide rtld_db_dlactivity()
* commit '67636eea20f7789e6689ee8cf6017e7d48735ca1':
  Unhide rtld_db_dlactivity()
2012-07-09 11:07:46 -07:00
Andrew Hsieh
67636eea20 am 40e7ed58: Unhide rtld_db_dlactivity()
* commit '40e7ed58d73eae59d0cf2fed61284d16692e307b':
  Unhide rtld_db_dlactivity()
2012-07-09 11:05:16 -07:00
Andrew Hsieh
40e7ed58d7 Unhide rtld_db_dlactivity()
Since linker is built with -fvisibility=hidden rtld_db_dlactivity()
if hidden from gdb.  Unhide it otherwise gdb may not know linker
activity and rescan solib

Change-Id: Ia8cd8d9738c6ea5696ba2ef0ebf2cf783f9ca70a
2012-07-02 11:17:04 -07:00
David 'Digit' Turner
b52e4385c4 linker: improve loadable segment protection.
Use the functions in linker_phdr.c to load the PT_LOAD segments
in memory, and toggle their mapping's writable protection bit
as needed. In particular:

  - when loading a library, load the segments then unprotected
    them to allow relocations to work.

  - when relocating the linker of the executable, unprotect
    the segments loaded by the kernel to make relocations work
    too.

  - after all relocations are done, re-protect the segments,
    and apply GNU RELRO protection if needed.

  - just before calling the destructors, undo the GNU RELRO
    protection.

Change-Id: I50e709f03958204b8d6140c0f51ebe24fe089a1b
2012-06-26 10:39:55 +02:00
David 'Digit' Turner
63f99f4a4e linker: simplify code for dynamic and ARM exidx sections.
This moves the code that determines where the .dynamic and .ARM.exidx
sections are to a single place in soinfo_link_image().

Change-Id: I98adcb440577bed86442349f03f3c629c945efec
2012-06-26 10:39:55 +02:00
David 'Digit' Turner
bea23e59f7 linker: rename load_offset to load_bias.
This patch changes the definition of the 'load_offset' field
in struct soinfo. The field is renamed because it is not the
basic load bias to add to every p_vaddr value read from the ELF
file to get the corresponding memory address.

This also slightly simplifies the relocation code.

+ Fix for proper load_bias computation for relocatable executables.

Change-Id: I72502c75a70751cba324deee7d313ae61f96609e
2012-06-25 11:52:40 +02:00
David 'Digit' Turner
23363ed750 linker: avoid mapping the whole library before load.
This patch changes the load_library() function in the
dynamic linker to avoid reserving a huge read-only
address-space range just to read the ELF header and
program header (which are typically very small and easily
fit in the first page).

Instead, we use the functions in linker_phdr.c to only
load the data that we need in a temporary mmap-allocated
page of memory, which we release when the function exits.

This avoids issues when loading very large libraries, or
simply debug versions that only need to load a tiny percentage
of their overall file content in RAM.

Change-Id: Id3a189fad2119a870a1b3d43dd81380c54ea6044
2012-06-25 11:52:40 +02:00
David 'Digit' Turner
a6545f4678 linker: Add PAGE_START/OFFSET/END convenience macros
This patch adds a few macros related to memory pages to help
clarify some of the code in linker.c

Change-Id: I36c727132d257b1497398dd0a9e8a5a4505467ca
2012-06-25 11:52:40 +02:00
David 'Digit' Turner
c1bd559d5b linker: New sources to manage the ELF program header table.
This patch introduces two new source files containing a set of functions
to manage the program header table in an ELF binary, including the ability
to load PT_LOAD segments, and apply PT_GNU_RELRO protection.

Note: the files are not used currently, this will appear in a series
      of future patches that will gradually modify linker.c to use
      the phdr_table_xxx functions properly.

Change-Id: Ia3d4c1ff5fc3e265d8258b64b492f4e643f51bdc
2012-06-25 11:52:40 +02:00
Evgeniy Stepanov
20bc061dc7 Add module base to main executable's ARM_exidx.
BUG:6697872

Change-Id: I448f4b86397307086231776da38a7af334a75fe5
2012-06-22 14:56:01 +04:00
Andrew Hsieh
63d0ceec75 am fa136e8c: am a5948157: Merge "Define __stack_chk_fail_local.S"
* commit 'fa136e8ca71cb20956cd1792251869cac8bed257':
  Define __stack_chk_fail_local.S
2012-06-20 19:00:55 -07:00
Andrew Hsieh
fa136e8ca7 am a5948157: Merge "Define __stack_chk_fail_local.S"
* commit 'a5948157fd34acb2b1d1bfaf129901af865ab5fc':
  Define __stack_chk_fail_local.S
2012-06-20 18:58:18 -07:00
Andrew Hsieh
6973e3da87 Define __stack_chk_fail_local.S
With -fstack-protector, x86 -m32 needs __stack_chk_fail_local
defined in crtbegin_*.o.

Include __stack_chk_fail_local.S in begin.S otherwise linker
(which is built w/o crt*) may not link.

Change-Id: Id242fcf3eff157264afe3b04f27288ab7991220a
2012-06-21 09:26:33 +08:00
David 'Digit' Turner
166b7dbd4a linker: reduce size by nearly 20KB
This patch adds a trivial implementation of snprintf() that calls
our internal vsnprintf().

Inspection of the generated machine code showed that the linker
contained a full implementation of stdio's vfprintf. It was pulled
in because the pthread implementation uses snprintf() somewhere.

ProTip: It's possible to see why specific objects files are included
in a final binary by adding the following to your Android.mk, then
looking at the content of /tmp/MAP.TXT:

  LOCAL_LDFLAGS += -Wl,-Map=/tmp/MAP.TXT

Change-Id: I325e71b0cad1d01116a2e00c09e30a80cb716aa3
2012-06-19 10:53:11 +02:00
David 'Digit' Turner
1608416811 linker: small code-cleanup
This patch adds to make the linker a little bit easier to understand
by making all functions that acts on a sofino object with a soinfo_
prefix.

This is to more easily distinguish functions that operate on global
state, and those that operate on individual libraries.

This should be purely stylistic, i.e. no feature/behaviour change.

Change-Id: Ie510d13d743aa4317644caefa9910b8af7e84f44
2012-06-13 22:47:20 +02:00
Jeff Brown
f41855949d am e4db460a: am b7630f01: Use new debuggerd protocol.
* commit 'e4db460a54e4f024b83a7df9a3f9920d695da9f3':
  Use new debuggerd protocol.
2012-06-08 15:33:31 -07:00
Jeff Brown
b7630f018a Use new debuggerd protocol.
Bug: 6615693
Change-Id: Ibfddc0de3fa2a882f7d0238ab797e5b29296b54b
2012-06-06 18:37:48 -07:00
Ji-Hwan Lee
f186a1819a Support non-zero p_vaddr in first PT_LOAD segment
Before changing mmap() permission to PROT_NONE in alloc_mem_region(),
such libraries once worked with a bug that uses mmap'ed region outside of
memory region allocated by alloc_mem_region().  This possibly incurs
SIGSEGV because it can overwrite memory region of previously loaded
library, but it sometimes worked, depending on loading order.

After PROT_NONE, this caused SIGSEGV earlier during calculation of
si->phdr in load_library(), but this was fixed by:

    75917c84d1  Use mmap to read an ...

Now the behaviour is the same as before applying PROT_NONE in
alloc_mem_region().

This CL fixed the original issue, supporting shared libraries that have
non-zero p_vaddr in first (= with lowest p_vaddr) PT_LOAD segment.

Bug: 6561258
Change-Id: Ib6176dd3e44c4d99a340eb1cbd16fb037586b0bc
2012-06-04 07:44:10 -07:00
Ji-Hwan Lee
75917c84d1 Use mmap to read an initial ELF header of library
Also, fixes SIGSEV during calculation of si->phdr in load_library(),
which is caused by accessing PHDR area, which is not guaranteed to be
loaded.

Note that this usually does not happen because program header area is
covered by immediately following PT_LOAD entry.  But it does not hold
always.

Bug: 6561258
Change-Id: Ie376253c773b5420279ca89044e81b1aad5a5736
2012-05-26 06:15:50 +09:00
Nick Kralevich
dcbc3787bf Make the linker relocatable.
Previously, the linker always loaded itself into the same
location in memory, which inhibited the effectiveness of Android's
ASLR implementation. Modify the linker code so it can be relocatable
and link itself at runtime.

Change-Id: Ia80273d7a00ff648b4da545f4b69debee6343968
2012-05-15 10:41:14 -07:00
Nick Kralevich
e742c1f564 linker: set LOCAL_NO_CRT := true
Use LOCAL_NO_CRT to prevent linking against crtbegin.o, rather than
messing with build rules. This also prevents linking against crtend.o,
which isn't needed for the linker.

Change-Id: I0c5b9999be7e8676560fe145c1c033ffce8db4d1
2012-05-15 10:08:39 -07:00
David 'Digit' Turner
077891b199 linker: Fix the computation of si->base
The computation of si->base assumed that the first entry in the
program header table is a PT_PHDR. This results in the dynamic
linker crashing with a SIGSEGV/MAPERR when trying to load some
of the NDK unit test programs, which happen to have an EXIDX
header first, followed byu a PHDR one.

This patch fixes the computation by parsing the program header
table, looking explicitely for the PHDR entry. This fixes the
load of the NDK unit test programs, and doesn't affect system
libraries.

Change-Id: Id18ea6037dbe950b5abbbce816c2960321f0b81d
2012-05-15 09:58:33 -07:00
Nick Kralevich
6cdefd06c0 Add linker support for PIE
Modify the dynamic linker so that executables can be loaded
at locations other than 0x00000000.

Modify crtbegin* so that non-PIC compilant "thumb interwork
veneers" are not created by the linker.

Bug: 5323301
Change-Id: Iece0272e2b708c79034f302c20160e1fe9029588
2012-05-15 09:56:32 -07:00
Nick Kralevich
94179a509e linker: remove STB_LOCAL hack
The ARM static linker wasn't properly handling __exidx_start
and __exidx_end symbols. Now that the static linker has been fixed,
we don't need the dynamic linker to work around this problem.

Change-Id: I041b94903609fafab33663a7d441a5e70b7ffcdd
2012-04-23 16:50:34 -07:00
Evgeniy Stepanov
1a78fbb5c8 Initialize TLS before any application code is run.
Since e19d702b8e, dlsym and friends use recursive mutexes that
require the current thread id, which is not available before the libc
constructor. This prevents us from using dlsym() in .preinit_array.

This change moves TLS initialization from libc constructor to the earliest
possible point - immediately after linker itself is relocated. As a result,
pthread_internal_t for the initial thread is available from the start.

As a bonus, values stored in TLS in .preinit_array are not lost when libc is
initialized.

Change-Id: Iee5a710ee000173bff63e924adeb4a4c600c1e2d
2012-04-13 00:08:11 +04:00
Nick Kralevich
7f03d2356f Revert "linker: remove STB_LOCAL hack"
This reverts commit 61ff83475c.

This code is harmless, and only applies to the linker, so
there's no harm in keeping it in the tree a little bit longer.
Let's roll this back while we try to figure out the root cause
of bug 6314858.

Bug: 6314858
Change-Id: I9f5ed81d23a7abe273baf792aa8a0a2839ef094c
2012-04-10 13:49:35 -07:00
Nick Kralevich
61ff83475c linker: remove STB_LOCAL hack
The ARM static linker wasn't properly handling __exidx_start
and __exidx_end symbols. Now that the static linker has been fixed,
we don't need the dynamic linker to work around this problem.

Change-Id: Ic567122b6c7746cc016795e2befba2c6bd7c0478
2012-04-09 12:50:17 -07:00