Commit graph

590 commits

Author SHA1 Message Date
Elliott Hughes
0266ae5f88 Switch <elf.h> over to linux uapi under the covers.
Remove the linker's reliance on BSD cruft and use the glibc-style
ElfW macro. (Other code too, but the linker contains the majority
of the code that needs to work for Elf32 and Elf64.)

All platforms need dl_iterate_phdr_static, so it doesn't make sense
to have that part of the per-architecture configuration.

Bug: 12476126
Change-Id: I1d7f918f1303a392794a6cd8b3512ff56bd6e487
2014-02-10 18:22:24 -08:00
Elliott Hughes
3a9c5d66dc Fix <link.h>.
Also move some of the stuff that should be in <link.h> out of the
private "linker.h", to make it clearer that these are public API
known to gdb that we can't change.

Bug: 12554197
Change-Id: I830e1260d3d8b833ed99bc1518f1c6b6102be8af
2014-02-10 13:31:13 -08:00
Elliott Hughes
62e9c76ee8 Clean up debugger.cpp slightly.
In particular, don't do weird things with 'int tid'.

Change-Id: I0fd9158a452967163508ada8987de9494ad5f9af
2014-01-31 17:27:00 -08:00
Elliott Hughes
f858bd1c6e LP64 binaries should talk to debuggerd64.
Change-Id: I7eb30f9d04f80b6b45d3148757970d3f1117493c
2014-01-31 16:56:39 -08:00
Weiwu Chen
5ceb889ac9 bionic: Change the type of soinfo's size to size_t
Some system functions like munmap expect soinfo's size to be size_t, but currently
it is unsigned. Change it to size_t to fit 64bit's portability.

Change-Id: I0bf6d522b38b0cd9bf1db05b004b5326217412a2
Signed-off-by: Weiwu Chen <weiwu.chen@intel.com>
Signed-off-by: Qiming Shi <qiming.shi@intel.com>
2014-01-28 11:54:01 -08:00
Qiming Shi
4041b13c20 bionic: Do not use magic number for portability
Do not use the magic number 0xFFFFFFFFU to represent the max value of an address
as it's not correct on 64bit platform. We should use UINTPTR_MAX instead.

Change-Id: I1fc6f5864a651b2eddea2333cb0788f9d9223270
Signed-off-by: Qiming Shi <qiming.shi@intel.com>
Signed-off-by: Weiwu Chen <weiwu.chen@intel.com>
2014-01-27 14:51:07 -08:00
Colin Cross
d1973ca513 bionic: rename aarch64 target to arm64
Rename aarch64 build targets to arm64.  The gcc toolchain is still
aarch64.

Change-Id: Ia92d8a50824e5329cf00fd6f4f92eae112b7f3a3
2014-01-23 18:35:39 -08:00
Elliott Hughes
a4aafd1560 Make it possible for code to query the dynamic linker's default search path.
We're not going to have init(1) set LD_LIBRARY_PATH globally on 64-bit.
This patch makes it possible for libnativehelper to set LD_LIBRARY_PATH
in each Java VM (to support System.loadLibrary) without also hard-coding
the default search path there.

Change-Id: If13961fae976e06dd80d5ef522f31e8b7eb01154
2014-01-13 16:37:47 -08:00
Elliott Hughes
7ff07ad321 Add -Bsymbolic to the ld flags when linking the dynamic linker.
We don't need this on architectures other than aarch64, and
we're still investigating why we need it on aarch64, but it
doesn't seem unreasonable to have this flag set when linking
the dynamic linker anyway; it's clearly the intended behavior.

Change-Id: I4fa1b4ae543a818979934bf818eabac03bb9154f
2014-01-13 13:33:01 -08:00
Elliott Hughes
1272dbd1d7 Add NT_PRSTATUS to <elf.h>.
Needed by aarch64.

Bug: 12476126
Change-Id: I7764664459a06cf4f2a60e707bd968d321a78430
2014-01-09 15:45:07 -08:00
Elliott Hughes
54a7494f17 Regenerate the NOTICE files.
Also standardize the orthography in a few places to reduce near-duplicates
in the NOTICE files.

Change-Id: I347c75e817be61ec1b9c5b4b96226feedc8d09ab
2014-01-07 13:46:11 -08:00
Elliott Hughes
b93702a046 Improve dynamic linker diagnostics for internal errors.
If the linker can't resolve its own internal references to symbols,
we currently exit silently (albeit with EXIT_FAILURE). Not very helpful.

Change-Id: I1614fc970dee4560b38832ede1987b65a8e53a1e
2013-12-22 19:38:42 +00:00
Marcus Oakland
e365f9d654 AArch64: Linker64 support for AArch64
Addition of support for AArch64 in the linker64 target.

Change-Id: I8dfd9711278f6706063e91f626b6007ea7a3dd6e
Signed-off-by: Marcus Oakland <marcus.oakland@arm.com>
2013-12-17 15:02:43 -08:00
Pavel Chupin
5407eed84b Fix debugging issues in vdso handling
Under valgrind ehdr_vdso is null and causing segfault.
Adding debug info for vdso producing plenty of issues on debugging
through gdbserver, removing it. It doesn't seem it should be here.

Unwinding through vdso test still works.

Change-Id: I1a7e233c493f2268d725fa8d7279822d07decc49
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-12-12 11:18:46 -08:00
Sergey Melnikov
ebd506c69e Fix linker crashes during unknown symbol lookup
Integration of kernel VDSO into internal bionic data structures using
common functions.
Fix for dl_iterate_phdr function: the function provides incorrect
address of object in case of nonzero virtual and base addresses.
Location in address space of a particular program header should be
calculated using the formula:  addr = base_addr + virtual_addr.

Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com>
Change-Id: Ie2ab4257fd456242aab8afed0bd5bd6b29e81d6d
2013-10-31 15:06:20 -07:00
Elliott Hughes
74ce45972d Update <sys/exec_elf.h> to get the DF_* flags.
Change-Id: Ia9e785f6b95122f94ee3b01a312db1d5bb91a72e
2013-10-28 14:59:41 -07:00
Elliott Hughes
e4d792adb8 Don't allow text relocations on 64-bit.
I've also updated our <sys/exec_elf.h> to match upstream.

Change-Id: I52f9fce3167541811208d273ff23ceaa112f7135
2013-10-28 14:34:56 -07:00
Elliott Hughes
4eeb1f12a8 Clean up linker architecture macros.
We don't need our own architecture macros; the standard ones will do.

This patch also fixes some __x86_64__ tests to be USE_RELA tests instead,
because they're not actually x86_64-specific.

I've cleaned up architecture-specific code slightly so where possible
all the code corresponding to a particular architecture is together.

This patch also fixes a bug in LP64 DT_PLTGOT handling, which should be
an error rather than falling through into DT_DEBUG! There was another #ifdef
bug where we'd only report unexpected DT_ entries on MIPS.

Change-Id: Id1d04e372611f641c1aa278a18e379f28af9eaf5
2013-10-28 11:02:49 -07:00
Elliott Hughes
60d5b06ece Simplify defining the linker architecture macro.
Like the new TODO says, though, do we need this at all? Wouldn't we be better
off just using the regular architecture-specific macros? This is a dynamic
linker, so there's never a possibility of cross-linking.

Change-Id: I7be6b8663f5e585c4024a49aae383430c86a3c1b
2013-10-24 23:18:13 -07:00
Elliott Hughes
b8b0b6b412 Revert "Don't warn about x86 text relocations. They're too prevalent."
This reverts commit 5be2c5998c.

Change-Id: I3fc8ca530cdbd74c834fb9cfabe812c9386419fc
2013-10-24 22:58:28 +00:00
Elliott Hughes
5be2c5998c Don't warn about x86 text relocations. They're too prevalent.
We should fix this (and disallow it for x86_64), but for now let's get CTS
running again.

libdvm.so and libcutils.so are the main problems.

$ scanelf -qT out/target/product/generic_x86/symbols/system/lib/libcutils.so
  libcutils.so: (memory/data?) [0x4125] in (optimized out: previous android_memset16) [0x4100]
  libcutils.so: (memory/data?) [0x424F] in (optimized out: previous android_memset16) [0x4100]
  libcutils.so: (memory/data?) [0x42F8] in (optimized out: previous android_memset16) [0x4100]
  libcutils.so: (memory/data?) [0x4349] in (optimized out: previous android_memset16) [0x4100]
  libcutils.so: (memory/data?) [0x4406] in (optimized out: previous android_memset16) [0x4100]
  libcutils.so: (memory/data?) [0x45AC] in (optimized out: previous android_memset32) [0x4590]
  libcutils.so: (memory/data?) [0x4650] in (optimized out: previous android_memset32) [0x4590]
  libcutils.so: (memory/data?) [0x46F9] in (optimized out: previous android_memset32) [0x4590]
  libcutils.so: (memory/data?) [0x474A] in (optimized out: previous android_memset32) [0x4590]
  libcutils.so: (memory/data?) [0x4807] in (optimized out: previous android_memset32) [0x4590]

Bug: 11353056
Change-Id: Id4a76b310be7fe858a8a60d0d260b09913b66be9
2013-10-23 13:45:01 -07:00
Nick Kralevich
3d4470c14a change wording on text relocation message.
The current message is too alarmist.

Change-Id: I53e8eadca239f867b4e6b9c193eba96e267950c3
2013-10-22 12:06:36 -07:00
Elliott Hughes
2258347f3b Build the linker with the same -std flags as the rest of bionic.
Change-Id: I5bdb28ecfdf78a90f6b072077a1c5ffd63f5d2ae
2013-10-17 13:06:20 -07:00
Elliott Hughes
41b87c6512 Merge "x86_64: Add R_X86_64_64 relocation handling" 2013-10-17 19:51:11 +00:00
Elliott Hughes
c7e9b23317 Fix sigaction(3) for 64-bit.
Also clean up <signal.h> and revert the hacks that were necessary
for 64-bit in linker/debugger.cpp until now.

Change-Id: I3b0554ca8a49ee1c97cda086ce2c1954ebc11892
2013-10-17 11:36:55 -07:00
Pavel Chupin
c075c18537 x86_64: Add R_X86_64_64 relocation handling
Change-Id: I86ffc56fa6a9053bed44e92a579530c2beb8eb2c
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-10-16 19:13:58 +04:00
Pavel Chupin
1a57f9f75c x86_64: Rename 64-bit linker to linker64
That's for having both on the same system.

Change-Id: Ic2bc2c015e6486e8b6a7576f7b28d2d027534368
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
2013-10-09 16:50:30 -07:00
Elliott Hughes
eb847bc866 Fix x86_64 build, clean up intermediate libraries.
The x86_64 build was failing because clone.S had a call to __thread_entry which
was being added to a different intermediate .a on the way to making libc.so,
and the linker couldn't guarantee statically that such a relocation would be
possible.

  ld: error: out/target/product/generic_x86_64/obj/STATIC_LIBRARIES/libc_common_intermediates/libc_common.a(clone.o): requires dynamic R_X86_64_PC32 reloc against '__thread_entry' which may overflow at runtime; recompile with -fPIC

This patch addresses that by ensuring that the caller and callee end up in the
same intermediate .a. While I'm here, I've tried to clean up some of the mess
that led to this situation too. In particular, this removes libc/private/ from
the default include path (except for the DNS code), and splits out the DNS
code into its own library (since it's a weird special case of upstream NetBSD
code that's diverged so heavily it's unlikely ever to get back in sync).

There's more cleanup of the DNS situation possible, but this is definitely a
step in the right direction, and it's more than enough to get x86_64 building
cleanly.

Change-Id: I00425a7245b7a2573df16cc38798187d0729e7c4
2013-10-09 16:00:17 -07:00
Elliott Hughes
2a0b873065 Fix __errno for LP64 and clean up __get_tls.
If __get_tls has the right type, a lot of confusing casting can disappear.

It was probably a mistake that __get_tls was exposed as a function for mips
and x86 (but not arm), so let's (a) ensure that the __get_tls function
always matches the macro, (b) that we have the function for arm too, and
(c) that we don't have the function for any 64-bit architecture.

Change-Id: Ie9cb989b66e2006524ad7733eb6e1a65055463be
2013-10-09 13:39:13 -07:00
Elliott Hughes
011bc0ba45 Use /system/lib64 and /vendor/lib64 for 64-bit libraries.
Change-Id: I4886aeb3070bf97b4cfe8053388ecb1bda288017
2013-10-08 14:27:10 -07:00
Elliott Hughes
0f395b7ba0 Make logging fall back to /dev/stderr if we're on the host.
Otherwise you get no logging, which sucks.

Change-Id: Iea1e8f996461afbb217a55711b7967005c39cfcb
2013-10-08 13:19:00 -07:00
Elliott Hughes
d7398f146d Use linker64 for the 64-bit linker.
Change-Id: I13fc7f93274f99e4cf99b077afdf5293e7233f39
2013-10-08 10:05:05 -07:00
Elliott Hughes
afac15d686 Use C99 structure initializer designator style.
clang warns about using the GCC style of designator.

Change-Id: I86ec79f06c8774618082859f48d7d1f576520e32
2013-10-08 10:01:09 -07:00
Elliott Hughes
c00f2cb587 x86_64 linker.
Based on I8dc3e2cb596f75dc58ae82e4dc58f8c177dd3323 by
Pavel Chupin <pavel.v.chupin@intel.com>.

Change-Id: Icd582d277cbe273477b450f2848343d72c86ec9f
2013-10-08 09:57:01 -07:00
Stephen Hines
99f0e1a329 Fix Clang warning since KernelArgumentBlock is actually a class.
Change-Id: Id72868d80feffbbc5f7d1e43beaed5d4e4d95f52
2013-10-08 00:08:13 -07:00
Elliott Hughes
c620059479 Remove 32-bit assumptions from the ELF code.
Change-Id: I2c1f3d34c33685799aade8866eec44479ff9f963
2013-09-30 18:43:46 -07:00
Christopher Ferris
24053a461e Add the dl_iterate_phdr function to libdl for arm.
Bug: 8410085

Merge from internal master.

(cherry-picked from cb491bc66d)

Change-Id: I94ed51bc5d4c626df7552c0e85c31ccee2d6568f
2013-09-06 09:53:54 -07:00
Brian Carlstrom
87c358524e Make mips_relocate_got tolerate a missing got
Bug: 10094803

(cherry picked from commit 7ee26878065abb494600595349ce58b2b2db3709)

Change-Id: Ib15bccecaee421dc463d46a3956b054051708759
2013-08-21 10:20:13 -07:00
Brian Carlstrom
0e79b91962 Add more information to error due to truncated Elf32_Ehdr
Change-Id: I24f30bd0c1120bcf85d77f5c4e69f0fefe9a2478
2013-08-14 15:47:46 -07:00
Elliott Hughes
cbf07a2514 am 2be511d4: Merge "Improve stack overflow diagnostics (take 2)."
* commit '2be511d405d47eccc61a6e3c338d1877bf33b4fa':
  Improve stack overflow diagnostics (take 2).
2013-07-17 13:50:15 -07:00
Elliott Hughes
84114c8dd5 Improve stack overflow diagnostics (take 2).
This reverts commits eb1b07469f and
d14dc3b87f, and fixes the bug where
we were calling mmap (which might cause errno to be set) before
__set_tls (which is required to implement errno).

Bug: 8557703
Change-Id: I2c36d00240c56e156e1bb430d8c22a73a068b70c
2013-07-17 13:33:19 -07:00
Guang Zhu
6f08b8659a am 2cf5a6f6: Merge "Revert "Improve stack overflow diagnostics.""
* commit '2cf5a6f6627549842c0c840ff3615ae942a90ea3':
  Revert "Improve stack overflow diagnostics."
2013-07-16 20:18:57 -07:00
Guang Zhu
d14dc3b87f Revert "Improve stack overflow diagnostics."
This reverts commit aa754dca90.

Change-Id: Ifa76eee31f7f44075eb3a48554315b2693062f44
2013-07-17 03:17:05 +00:00
Elliott Hughes
10a954dea6 am 026867c7: Merge "Improve stack overflow diagnostics."
* commit '026867c7dcce7828212dcd4a61806146908e9039':
  Improve stack overflow diagnostics.
2013-07-16 15:31:40 -07:00
Elliott Hughes
aa754dca90 Improve stack overflow diagnostics.
We notify debuggerd of problems by installing signal handlers. That's
fine except for when the signal is caused by us running off the end of
a thread's stack and into the guard page.

Bug: 8557703
Change-Id: I1ef65b4bb3bbca7e9a9743056177094921e60ed3
2013-07-16 13:14:24 -07:00
Elliott Hughes
d31287d601 am 7d624e9a: Merge "Kernel dso support for \'dl_iterate_phdr\' function"
* commit '7d624e9aff4c6addea7f2275fe58ff0815d95c70':
  Kernel dso support for 'dl_iterate_phdr' function
2013-06-25 13:17:37 -07:00
Sergey Melnikov
c45087bffa Kernel dso support for 'dl_iterate_phdr' function
Kernel provides virtual DSO for stack unwinding/exception handlind info for
signal usage case. Stack unwinding routines use 'dl_iterate_phdr' function
for additional DWARF info gathering from DSOs. Patch enables virtual DSO
enumeration via dl_iterate_phdr function.

Signed-off-by: Sergey Melnikov <sergey.melnikov@intel.com>
Change-Id: Ic2882b28f40b456a088bc1e63c50cbfda7e4a102
2013-06-25 13:12:39 -07:00
Nick Kralevich
100d678438 am 53ddcc90: Merge "linker: Emit a warning on text relocations"
* commit '53ddcc90701d86c7d809a84cf4710c651066e3c7':
  linker: Emit a warning on text relocations
2013-06-21 15:39:21 -07:00
Nick Kralevich
c9084427aa linker: Emit a warning on text relocations
Text relocations unnecessarily mark pages as dirty, preventing them
from being swapped out, wasting memory. Also, text relocations
prevent the code from running on certain hardened systems.

Print a message in logcat and stderr when we see a text relocation,
to encourage developers to fix their code.

Change-Id: I6051a7463911e090ae5727a355397d539669d5b9
2013-06-21 15:33:15 -07:00
Elliott Hughes
45ef218bde am 6807af77: Merge "Make LD_PRELOAD failures just warnings."
* commit '6807af773f862750efb6860e00402580a5f463f3':
  Make LD_PRELOAD failures just warnings.
2013-06-18 13:27:16 -07:00
Elliott Hughes
7e5a8cc523 Make LD_PRELOAD failures just warnings.
This matches glibc and makes life easier for developers who want to
sometimes preload a library from init (which has no conditionals); they
can simply move/remove the library to disable.

Change-Id: I579b8633f958235af6e46bb53b378b9e363afb1f
2013-06-18 13:15:00 -07:00
Brian Carlstrom
d978d21d19 am 8252b8e4: Merge "Honor p_vaddr if set"
* commit '8252b8e4b730b13623f31dc66396e000586d1c58':
  Honor p_vaddr if set
2013-06-10 15:41:19 -07:00
Brian Carlstrom
e7dffe150b Honor p_vaddr if set
(cherry picked from commit 88ff15c2c279d2bbe3569101b36cd2aa0931a0a9)

Change-Id: I4aabbe911d30aea8ace69e29bb6e980a4e89de90
2013-06-07 12:47:58 -07:00
Brian Carlstrom
81bfade818 am 06713930: Merge "Small cleanup of soinfo_elf_lookup."
* commit '0671393072a78e75a726c58aa3ca718e55eeac3e':
  Small cleanup of soinfo_elf_lookup.
2013-06-03 20:21:04 -07:00
Christopher Ferris
6bec5b792a Small cleanup of soinfo_elf_lookup.
- Remove unnecessary line.
- Move declarations to first use.

Change-Id: I1d8398d6c13f7cb86bffe0b68af849e35a4b234d
2013-06-03 20:15:14 -07:00
Brian Carlstrom
46bf467a15 am f5f29de6: Merge "Fix bionic linker to support segments with zero p_filesz"
* commit 'f5f29de6ae5a0b74234f111b5691a1e5588671cb':
  Fix bionic linker to support segments with zero p_filesz
2013-05-21 17:23:09 -07:00
Brian Carlstrom
82dcc7910d Fix bionic linker to support segments with zero p_filesz
(cherry picked from commit 96362fb9d11beef6233aa03db396f25688e70860)

Change-Id: Ib075a6dfc45d5d0746d8b278f317dd9b8d772f2a
2013-05-21 16:57:55 -07:00
Elliott Hughes
58f3dbdacd am 98f7659d: Merge "Don\'t fail to run DT_INIT and DT_INIT_ARRAY constructors if a shared library has DT_PREINIT_ARRAY constructors."
* commit '98f7659d7e3a7d75c68a41299f6ee55d7d35c27b':
  Don't fail to run DT_INIT and DT_INIT_ARRAY constructors if a shared library has DT_PREINIT_ARRAY constructors.
2013-05-09 17:53:38 -07:00
Elliott Hughes
8147d3c284 Don't fail to run DT_INIT and DT_INIT_ARRAY constructors if a shared library has DT_PREINIT_ARRAY constructors.
The GNU dynamic linker silently ignores a DT_PREINIT_ARRAY section
in a shared library. We had ineffectual code that tried to report
an error, which I tried to fix but got wrong --- my version still
wouldn't report the error to the caller, but would prevent us from
continuing to call constructors.

Bug: 8825226
Change-Id: I4fd8450ecc44d8767a1cb808aeecfbfbfc77c070
2013-05-09 15:29:54 -07:00
Nick Kralevich
ed572aaa0d am 5f28fde8: Merge "linker: only re-open std* for setuid programs."
* commit '5f28fde8aeee047a70e344c9da937695dc51a3ba':
  linker: only re-open std* for setuid programs.
2013-04-25 17:01:41 -07:00
Nick Kralevich
8d3e91d4f8 linker: only re-open std* for setuid programs.
get_AT_SECURE() was getting called before linker_env_init() had
been called, and returning the default value ("true"). This was
causing us to reopen closed stdin, stdout, and stderr for ALL
processes, not just privileged (setuid) processes.

Calling path:
  - __linker_init
    - soinfo_link_image
      - get_AT_SECURE
    - __linker_init_post_relocation
      - linker_env_init

This change restores the intended behavior of only re-opening
stdin, stdout, and stderr for privileged processes.

Change-Id: I8b085ea6597710ac4c1a3c93f1bf8b81eecb08c0
2013-04-25 13:15:24 -07:00
Elliott Hughes
9c7b510a40 am 240fb862: Merge "Make abort messages available to debuggerd."
* commit '240fb8623b1fe027d0d33a9d4c41d99ceb385b58':
  Make abort messages available to debuggerd.
2013-04-05 11:43:37 -07:00
Elliott Hughes
0d787c1fa1 Make abort messages available to debuggerd.
This adds __libc_fatal, cleans up the internal logging code a bit more,
and switches suitable callers over to __libc_fatal. In addition to logging,
__libc_fatal stashes the message somewhere that the debuggerd signal handler
can find it before calling abort.

In the debuggerd signal handler, we pass this address to debuggerd so that
it can come back with ptrace to read the message and present it to the user.

Bug: 8531731
Change-Id: I416ec1da38a8a1b0d0a582ccd7c8aaa681ed4a29
2013-04-05 11:24:19 -07:00
Elliott Hughes
3077d88347 am c48968d2: am 4453c51c: Merge "Drop unnecessary execution permission for .cpp/.c/.h"
* commit 'c48968d268820ee64986f738e227910b29290eab':
  Drop unnecessary execution permission for .cpp/.c/.h
2013-03-21 19:40:15 -07:00
Kito Cheng
8f7120bbac Drop unnecessary execution permission for .cpp/.c/.h
Change-Id: I9ac2b9d8f6bdb4fab8962210c5ec8f9c3e8c0ebf
2013-03-22 10:28:15 +08:00
Elliott Hughes
12ea800566 am 5f829205: am c1416647: Merge "Clean up internal libc logging."
* commit '5f8292050fc07f4bf9e70f37a807ad028e3cfc87':
  Clean up internal libc logging.
2013-03-15 16:36:37 -07:00
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