Commit graph

230 commits

Author SHA1 Message Date
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
Nick Kralevich
8c4f3ce8d0 linker: surround "debug_verbosity" by "#if LINKER_DEBUG"
Avoid executing useless code when we're not compiled
with debugging support.

Change-Id: Iea1821b241acacdf65d1a91d743356058dfef273
2012-04-04 12:43:32 -07:00
Nick Kralevich
3a7ea52f17 linker: enable -fvisibility=hidden
Compile the linker with -fvisibility=hidden. This reduces the number
of symbols that show up in the .dynsym section of the linker.
These symbols are never exported to other applications.

In particular, this fixes a problem with setting -DLINKER_DEBUG=1
introduced in 468319ce4f.
Because the symbols "debug_verbosity" and "format_log" have not been
resolved before the linker links itself, any attempt to call
PRINT / INFO / TRACE / WARN / ERROR will result in a segfault.
This change allows the static linker to produce a relative reference
to these symbols rather than relying on relocation.

This also has a nice side effect of making the linker slightly smaller
and slightly more optimized.

The following symbols no longer in the .dynsym section of the linker
after this change:

-addr_to_name
-call_constructors_recursi
-calloc
-debugger_init
-debugger_signal_handler
-debug_verbosity
-dladdr
-dlclose
-dlerror
-dl_lock
-dlopen
-dlsym
-dl_unwind_find_exidx
-find_containing_library
-find_containing_symbol
-find_library
-format_buffer
-free
-libdl_info
-linker_env_get
-linker_env_init
-linker_env_secure
-linker_env_unset
-linker_get_error
-__linker_init
-lookup
-lookup_in_library
-malloc
-notify_gdb_of_libraries
-notify_gdb_of_load
-notify_gdb_of_unload
-realloc
-rtld_db_dlactivity
-unload_library
-vsnprintf

Bug: 5827809
Change-Id: I5e8cd7dcf48c1d6831a970a67f63f24916c5e437
2012-04-04 11:13:51 -07:00
Nick Kralevich
aac0dc97a9 Merge "linker: fix off-by-one error in GNU_RELRO handling" 2012-03-20 10:52:42 -07:00
Nick Kralevich
d73b5cafa0 linker: fix off-by-one error in GNU_RELRO handling
Fix a bug where the GNU_RELRO end address could be exactly
the end of the loadable segment.

Change-Id: If6c43acabc06e9aff9217c0f6016e158b28bb41f
2012-03-20 09:24:58 -07:00
Nick Kralevich
6625986f3a linker: initially reserved memory as PROT_NONE
When the dynamic linker loads a shared library into memory, it
initially allocates a chunk of memory. The memory is then carved
into smaller chunks for each LOAD region, and appropriate memory
protections applied.

Modify the initial memory allocation so that the pages are mapped
as PROT_NONE, rather than PROT_READ / PROT_EXEC. This ensures that
gaps between LOAD regions are not inadvertantly readable / executable.

(Long term, we should munmap() these gaps entirely)

Change-Id: If128a203ccc6fe12dcbbd2bfe0cf13a2045675af
2012-03-16 13:06:12 -07:00
Andy McFadden
ca9a0712b8 Re-throw signals
If we catch a fatal signal that won't automatically re-throw when
the thread resumes, re-throw it manually.  (Common examples are
SIGPIPE and the SIGFPE from integer division by zero.)

Change-Id: I329e6d4db907047c555957b42cbd09c50fc808e7
2012-03-08 11:14:37 -08:00
Marco Nelissen
e5cf8166dc Merge "Log the thread id and name for fatal signals." 2012-03-07 13:09:36 -08:00
Marco Nelissen
3df3e672f5 Log the thread id and name for fatal signals.
This adds the thread id and name to the "Fatal signal" logging,
making it easier to track down where in process it actually crashed.

Change-Id: I17a365042b2f10b161debe98bc2e7070af055dfb
2012-03-07 12:32:15 -08:00
Nick Kralevich
9ec0f03a0d Add relro support
Add support for PT_GNU_RELRO. This allows the static linker to
indicate that certain regions of memory should be marked as
"read-only" after dynamic linking is complete.

See:
  * http://www.akkadia.org/drepper/nonselsec.pdf (section 6)
  * http://tk-blog.blogspot.com/2009/02/relro-not-so-well-known-memory.html

Note that this change has no effect on Android right now, because
we don't compile our code with relro enabled.

Change-Id: I6541f8775367e8558b4388f7d105b1ae6e8f046b
2012-03-05 16:44:42 -08:00
Jean-Baptiste Queru
76ab561b4d am 49a05c06: am 62daffe1: am f9c5afb1: Merge "Redesign dlopen() locks to be recursive per thread."
* commit '49a05c060acd4d3e17b2819f00a694271bf40977':
  Redesign dlopen() locks to be recursive per thread.
2012-02-23 11:20:49 -08:00
Pavel Chupin
e19d702b8e Redesign dlopen() locks to be recursive per thread.
That is to fix the bug:
dlxxx functions can't be called recursively.
For example, if we use dlopen() to use open one library whose constructor
also calls dlopen() in order to open another library, then the thread is
dead-blocked.

By changing the dl_lock from a non-recursive lock to a recursive lock, we can
prevent the thread from dead-blocked by recursive dlxxx calls in the same
thread context.

Change-Id: I1018b41c82f4641cc009c0a2eda31f5a47a534f9
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
Signed-off-by: Jack Ren <jack.ren@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2012-02-21 14:57:26 -08:00
David 'Digit' Turner
9db064a0d3 am 5d7181a7: am 68fc85ff: am 177a7706: linker: fix x86 build
* commit '5d7181a71c0b066fe6c19b9c5906bd694a399a59':
  linker: fix x86 build
2012-02-01 11:24:29 -08:00
David 'Digit' Turner
177a77067b linker: fix x86 build
Change-Id: I47d76a0f50515013c37ccef89accba03cc69529d
2012-02-01 10:47:04 -08:00
Jean-Baptiste Queru
25b7a16a6e Merge c4cb87f3
Change-Id: I4cc14eba43fde75a7702fdc7ad07d3d949e9c092
2012-02-01 09:46:08 -08:00
David 'Digit' Turner
70b1668a76 remove obsolete SuperH support
We don't have a toolchain anymore, we don't have working original
kernel headers, and nobody is maintaining this so there is really
no point in keeping this here. Details of the patch:

- removed code paths from Android.mk files related to the SuperH
  architecture ("sh")

- removed libc/arch-sh, linker/arch-sh, libc/kernel/arch-sh

- simplified libc/SYSCALLS.TXT

- simplified the scripts in libc/tools/ and libc/kernel/tools

Change-Id: I26b0e1422bdc347489e4573e2fbec0e402f75560

Signed-off-by: David 'Digit' Turner <digit@android.com>
2012-01-31 20:28:23 +01:00
Jesse Hall
f5d1693e3c Fix recursive ELF constructor check
The flag to avoid calling ELF constructors recursively (in the case
of recursive .so dependencies) was being set after the dangerous
recursive constructor call had already been made.

This fixes the libc's debug malloc implementation.

Change-Id: I5e601f0ea19ab1df81b8b1ad4df25c3eab0ccda4
2012-01-30 15:39:57 -08:00
Andy McFadden
1fc51769de Log debuggerd connection failures
Write a message to the log file if the signal handler is not able
to connect to debuggerd.  This is especially handy if the failure
was caused by running out of file descriptors, since there's some
chance that the lack of fds relates to the crash.

Sample:

 F libc    : Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1)
 F libc    : Unable to open connection to debuggerd: Too many open files

Bug 5926330

Change-Id: I0ff210d82ab1db39b08f328bae5e08f67a69e5d7
2012-01-26 13:40:38 -08:00
Jean-Baptiste Queru
f20d59e691 am c83c1da5: am cee8425f: Merge "Move variable declaration on its own line"
* commit 'c83c1da54831ef1c9ff59cf9df8d5c0173893ee5':
  Move variable declaration on its own line
2012-01-20 17:23:52 -08:00
Jean-Baptiste Queru
c3650d6a4b am 5b44655f: am 7e6a5773: Merge "Use the AT_SECURE auxv flag to determine whether to enable secure mode."
* commit '5b44655f22dd05c7cd8afcd218102616a6f5f4da':
  Use the AT_SECURE auxv flag to determine whether to enable secure mode.
2012-01-20 17:23:51 -08:00
Stephen Smalley
bb44055d0a Move variable declaration on its own line
Change-Id: Ied54ffabccdc867ea4e124a0f0324a217270d6e7
2012-01-20 10:59:15 -08:00
Stephen Smalley
861b42a2d8 Use the AT_SECURE auxv flag to determine whether to enable secure mode.
The Linux kernel provides an AT_SECURE auxv flag to inform userspace
whether or not a security transition has occurred.  This is more reliable
than directly checking the uid/gid against the euid/egid, because it covers
not only setuid/setgid but also file capabilities, SELinux, and AppArmor
security transitions.  It is also a more efficient test since it does
not require any additional system calls.

Change-Id: I9752a4f6da452273258d2876d13b05e402fb0409
2012-01-20 13:35:57 -05:00
Evgeniy Stepanov
e83c56dfbb Execute .preinit_array before any shared object initialization functions.
This change makes linker handling of .preinit_array compliant with the
System V ABI:

"These [pre-initialization] functions are executed after the dynamic linker has
built the process image and performed relocations but before any shared object
initialization functions."
http://www.sco.com/developers/gabi/latest/ch5.dynamic.html#init_fini

Change-Id: Iebfee22bb1ebe1d7c7e69cb4686e4ebae0dfc4bb
2012-01-10 13:30:41 +04:00
Nick Kralevich
253b763160 get rid of unused "main" function.
confuses gdb.

Change-Id: I1c64357ce122fe5a2564ee96bb4caa32b733f6ea
2011-12-05 16:09:30 -08:00
Zhenghua Wang
0e0bd58631 am 1ad08626: am 897815a1: bionic: add machine type check
* commit '1ad08626a143dc684e92f56754c7176cc4914ce8':
  bionic: add machine type check
2011-11-30 10:50:57 -08:00
Zhenghua Wang
897815a1fe bionic: add machine type check
android linker doesn't check machine type, it may load some
libraries which it doesn't support sometimes.

Author: Zhenghua Wang <zhenghua.wang@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-11-29 17:01:08 -08:00
Nick Kralevich
7e2daefe6c Merge "Make the linker relocatable." 2011-11-16 10:43:56 -08:00
David 'Digit' Turner
8180b08fb2 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
2011-11-15 17:17:28 +01:00
Nick Kralevich
468319ce4f 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
2011-11-11 18:01:53 -08:00
Nick Kralevich
7939908c83 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
2011-11-04 10:22:55 -07:00
Nick Kralevich
8e8a7b1f0f Revert "Make the linker relocatable."
This reverts commit 994e9a5ed1.

Broke x86 build.
2011-11-03 09:25:06 -07:00
Nick Kralevich
994e9a5ed1 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: I90d064743abdd29450ac0482ed28752b2196286c
2011-11-02 16:20:06 -07:00
Nick Kralevich
d9ad62343c 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
2011-10-22 13:19:23 -07:00
Mathias Agopian
bda5da074e fix prototype of dladdr
this breaks C++ source code in particular.

Change-Id: Ie06b5d31d23b5455e6950c470adc64dd5e7784df
2011-09-28 12:17:34 -07:00
David 'Digit' Turner
96e5faccdc am 91966c30: am 0acdbe08: am 89ea107d: Merge "linker: allow debugging of constructors"
* commit '91966c30efbdc7feecd6c45a46ab488e715c0a35':
  linker: allow debugging of constructors
2011-08-30 09:50:54 -07:00
David 'Digit' Turner
91966c30ef am 0acdbe08: am 89ea107d: Merge "linker: allow debugging of constructors"
* commit '0acdbe0892105d01a38de9baf4e34eef22b8259c':
  linker: allow debugging of constructors
2011-08-29 18:01:05 -07:00
Nick Kralevich
38bccb271f linker.h: don't change the soinfo structure
In 48527c3f74, we modified the soinfo
structure to remove an unnecessary variable. However, third party
programs seem to be relying on the structure not changing.
Add a dummy variable back into place to preserve structure.

Bug: 5064106

Change-Id: I3014dda1a46e624644b09e156c3e9381ba3729bd
2011-08-29 13:52:18 -07:00
David 'Digit' Turner
e5ea45547e linker: allow debugging of constructors
This patch allows the debugging of constructors in shared
libraries and executables. It does so by ensuring that the
corresponding binary is visible to gdb before running the
constructors.

Change-Id: I0a3df726a04ad109944c834dcbba672b85d3991e
2011-08-27 10:21:01 +02:00
Andy McFadden
ec92af8fe5 Log signal info at time of receipt
When a fatal signal is received, we now write a message to the log
that looks like this:

  F/libc    ( 1540): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1)

This is useful for debugging fatal signals that turn out not to be
fatal.  This also changes the signal reset from SIG_IGN to SIG_DFL,
so that future non-fatal fatal signals are fatal.

The code that blocked SIGUSR1 to avoid being interrupted by the GC
has been removed.

Also, fix minor issues in format_buffer().

Bug 5035703

Change-Id: I8940af47297b5dcf3cf33537e3483ca5334ed565
2011-08-04 14:48:15 -07:00
Shih-wei Liao
48527c3f74 Revert "Revert "linker: get rid of the buddy allocator""
This reverts commit f9a9cda23a.
This revert is promised once b/5039224, b/5036755, b/5036610 are resolved.
2011-07-17 12:32:43 -07:00
Nick Kralevich
f9a9cda23a Revert "linker: get rid of the buddy allocator"
This reverts commit 7059b1f02e.
Bug: 5036610
2011-07-15 16:12:45 -07:00
Nick Kralevich
7059b1f02e linker: get rid of the buddy allocator
Currently, the Android linker is placing shared libraries into
a well-known spot in memory.  This is interfering with the kernel's
ASLR support.

This change stops forcing non-prelinked libraries into a particular
address space.

Also, get rid of FLAG_PRELINKED.  As best I can tell, this flag
is never used.

Change-Id: I527af12fb54f821c2b5ca7693dbf63d022f8f4ae
2011-07-14 13:48:13 -07:00
Martijn Coenen
a903811819 Revert "x86: Enable -fstack-protector"
This reverts commit e0b4844a20,
causes netd to crash.
2011-06-07 17:19:12 +02:00
David Turner
65fb884d28 am 204d1f65: am b2c7e0c1: Merge "x86: Enable -fstack-protector"
* commit '204d1f65dbfc6d5a14a90627d9d1efcfce8261ee':
  x86: Enable -fstack-protector
2011-06-06 12:57:08 -07:00
David Turner
204d1f65db am b2c7e0c1: Merge "x86: Enable -fstack-protector"
* commit 'b2c7e0c18b7ab04cfe306277c79165de0612a2d1':
  x86: Enable -fstack-protector
2011-06-06 11:32:49 -07:00
Bruce Beare
e0b4844a20 x86: Enable -fstack-protector
Change-Id: Ib69514c3afcb4c1f5e5f3f8cd91acfd145a0866c
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-05-24 13:32:14 -07:00
David Turner
c2af2c075f am 1af88c97: am d004dc99: Merge "Use MAP_FIXED when allocating prelinked shared library regions"
* commit '1af88c97432c88ec5b39d155e8c296d2a6eb1225':
  Use MAP_FIXED when allocating prelinked shared library regions
2011-05-02 13:30:03 -07:00
David Turner
1af88c9743 am d004dc99: Merge "Use MAP_FIXED when allocating prelinked shared library regions"
* commit 'd004dc9957cd8944d3db8ed92544c8ee65b117ca':
  Use MAP_FIXED when allocating prelinked shared library regions
2011-05-02 12:34:57 -07:00
Iliyan Malchev
368070454b bionic: remove LOCAL_PRELINK_MODULE
Change-Id: Iad65ae18446b20d2aace7b8fe19b1a032b616e9c
Signed-off-by: Iliyan Malchev <malchev@google.com>
2011-03-14 14:25:58 -07:00
Chris Dearman
db4bce0549 Use MAP_FIXED when allocating prelinked shared library regions
Prelinked libraries must be mapped to a fixed address. MAP_FIXED is ignored
for non-prelinked libraries (si->base==0)

Signed-off-by: Raghu Gandham <raghu@mips.com>
2011-03-10 10:48:14 -08:00
David 'Digit' Turner
81d79f9fb3 am 962dcb22: am fed58049: Merge "libc: Fix PTHREAD_RWLOCK_INITIALIZER"
* commit '962dcb22218a1a6d4ebd05e4fc4a69875d037234':
  libc: Fix PTHREAD_RWLOCK_INITIALIZER
  Proxy getnameinfo through netd
  Updated gcc 4.4.3 IA toolchain doesn't require the .ctors list
  Convert cname lenght before use
2011-03-10 01:55:35 -08:00
Bruce Beare
48e1feaa9d Updated gcc 4.4.3 IA toolchain doesn't require the .ctors list
Change-Id: Ia840a19a45257128eccdcf25d105f500f2d90741
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-02-16 17:50:23 -08:00
Kenny Root
72f9a5c374 Increase SO_MAX to accomodate valgrind
system_server loads up 87 shared libraries upon start. Running under
valgrind pushes this just over the edge of 96. Increase SO_MAX to 128 to
give us some more headroom.

Change-Id: Iadceb14ab6d9621bdccd292570d50867828057d9
2011-02-10 17:02:23 -08:00
tedbo
b67c1bacd0 Fix bug in linker environment variable lookup.
The linker_env_get() method that is used to match an environment
variable was failing due to an incorrect equality check.

This  was introduced in git change
be5755969d.

The bug was causing the linker to ignore environment variables such
as LD_LIBRARY_PATH. This issue also affects the linker_env_secure()
path that removes unsafe environment variables, since it would
not match any in the unsecure variable list.

Change-Id: I14228df9252010e9fb4c1862bed5735f23e97aec
2011-01-21 21:15:08 +01:00
tedbo
b3cdf7fef8 Fix bug in linker environment variable lookup.
The linker_env_get() method that is used to match an environment
variable was failing due to an incorrect equality check.

This  was introduced in git change
be5755969d.

The bug was causing the linker to ignore environment variables such
as LD_LIBRARY_PATH. This issue also affects the linker_env_secure()
path that removes unsafe environment variables, since it would
not match any in the unsecure variable list.

Change-Id: I169024de4a005321e768accd38246fc1d717271b
2011-01-20 20:44:44 -08:00
Glenn Kasten
1f353828c3 Fix typos
Change-Id: Ia02baba53be7034903f325258205441e5c193f7b
2011-01-18 09:36:38 -08:00
David 'Digit' Turner
be5755969d linker: Remove unsecure env. variable for setuid programs.
This removes several unsecure environment variables from the
environment block when the program being loaded is setuid. The
list of env. variables is the same than what GLibc uses at this
point.

Change-Id: I456d3ea0880fe0d4de0d3c5dd51871dd36e87fd6
2010-12-20 12:06:45 +01:00
Brian Swetland
fedbcde6ef add /vendor support
- add /vendor/lib to front of default library search path
- remove long-obsolete /lib from default library search path

Change-Id: I7d33bf899be018e7cc4c213d5790bbd991023a62
2010-09-19 03:39:13 -07:00
Dima Zavin
a716190241 linker: fix overwriting the real linker error string
Change-Id: Ia9165fd9aa1951b2bb81d0ac8f5bb3057aded8bd
Signed-off-by: Dima Zavin <dima@android.com>
2010-08-17 15:57:55 -07:00
David 'Digit' Turner
6774809b62 linker: Support dlopen(NULL, ...) properly.
Change-Id: Icba37823cb350c34848cc466d144c3a0af87c94c
2010-07-23 12:16:15 -07:00
David 'Digit' Turner
8bff9a31aa linker: remove libcutils dependency by re-implementing simpler socket_local_client.
Change-Id: I87f29fd59454d713b9ddfb13e6cf114822f52efd
2010-06-10 22:58:22 -07:00
Jean-Baptiste Queru
f439445830 fix build
Change-Id: I243c98e20a250e0d40d481f16af481ff070219fd
2010-05-12 10:05:59 -07:00
The Android Open Source Project
bb7928ccda merge from open-source master
Change-Id: Iecfd2bd3069f70bbe508042cc249fcf7ff24800d
2010-05-12 09:22:50 -07:00
Matt Fischer
4fd42c1dc0 Added support for LD_PRELOAD
The LD_PRELOAD environment variable allows the user to specify a list of
libraries which should be unconditionally loaded before any others.  This
makes possible some useful tricks, such as library interposers.

Change-Id: I433d775ab08ef63a5fbe7b21f87a5642954fc32f
2010-05-10 15:09:19 -07:00
The Android Open Source Project
5ef5272be9 merge from open-source master
Change-Id: I518bb4ae9d7269957365561d4d609f22cde519db
2010-04-21 09:10:08 -07:00
Matt Fischer
1698d9ebfc Fixed support for RTLD_NEXT in dlsym()
The previous implementation of this flag was broken--it behaved identically
to RTLD_DEFAULT.  This adds a proper implementation, which examines the address
of the calling function, and uses it to determine which library to use to begin
the symbol search process.

Change-Id: I2ad2b46363f68932af63a3828a22f9c7987eea67
2010-04-08 10:14:47 -05:00
The Android Open Source Project
d046725133 merge from open-source master
Change-Id: I483fedf77d978b1c6e52d73eebc14f011bb9f809
2010-03-31 14:19:51 -07:00
Min-su, Kim
3cab22c8cf linker: fix the undefined weak symbols issue 2010-03-29 15:43:09 -07:00
The Android Open Source Project
377d4c979d merge from open-source master
Change-Id: I70266ee8c520b216773f267e46c8273d2334c31d
2010-03-22 15:55:09 -07:00
Matt Fischer
e2a8b1fd19 Added support for dladdr()
dladdr() is a GNU extension function, which allows the caller to retrieve
symbol information for a specified memory address.  It is useful for things
like generating backtrace information at runtime.

Change-Id: I3a1def1a6c9c666d93e1e97b7d260dfa5b9b79a9
2010-03-17 16:11:37 -05:00
David 'Digit' Turner
5c734644ee Fix debug output in the dynamic linker.
This provides a mini-printf implementation that reduces the
size of the dynamic linker by 25 KB, by preventing the drag of
formatting-related routines from the C library.

Also allow traces to be sent to the log, instead of stdout.

NOTE: You now need to modify Android.mk to enable/disable debug
      output.
2010-02-11 10:46:48 -08:00
Iliyan Malchev
e100f52f4a bionic/linker: rename ba_prelink to ba_nonprelink
-- fixes b/2432550
-- ba_prelink is used to manage non-prelinked libraries, hence ba_nonprelink is
   a more appropriate name for it

Signed-off-by: Iliyan Malchev <malchev@google.com>
2010-02-10 19:14:35 -08:00
Doug Kwan
90f82e5868 Fix typo in a comment. 2010-01-25 11:09:31 -08:00
Doug Kwan
1a2917ca95 Align TEXT section to 4K boundary so that we can use both ld and gold. 2010-01-25 10:24:50 -08:00
Gary King
278d157f43 Use correct TLS codepath for linker
Replicate ARM libc build's HAVE_ARM_TLS_REGISTER preprocessor definition
logic, to ensure that the runtime linker uses the correct codepath for
accessing the TLS address
2010-01-12 17:37:44 -08:00
David 'Digit' Turner
a3de55c831 am fe62de1a: Add support for R_ARM_REL32 to the dynamic linker.
Merge commit 'fe62de1ad036a1417df44b7b1a7c65cc79dc7091' into eclair-plus-aosp

* commit 'fe62de1ad036a1417df44b7b1a7c65cc79dc7091':
  Add support for R_ARM_REL32 to the dynamic linker.
2009-12-02 11:17:29 -08:00
David 'Digit' Turner
fe62de1ad0 Add support for R_ARM_REL32 to the dynamic linker.
Merged from eclair-mr2
2009-12-02 10:54:53 -08:00
David 'Digit' Turner
83d3d7491a am ebf3ea00: am 34ea5117: Add support for R_ARM_REL32 to the dynamic linker.
Merge commit 'ebf3ea006e5367fff93d2491eec24c4b1a633805'

* commit 'ebf3ea006e5367fff93d2491eec24c4b1a633805':
  Add support for R_ARM_REL32 to the dynamic linker.
2009-11-17 16:16:52 -08:00
David 'Digit' Turner
ebf3ea006e am 34ea5117: Add support for R_ARM_REL32 to the dynamic linker.
Merge commit '34ea5117dbeba41ae5dfdfb2c2ec8cae23388b66' into eclair-mr2-plus-aosp

* commit '34ea5117dbeba41ae5dfdfb2c2ec8cae23388b66':
  Add support for R_ARM_REL32 to the dynamic linker.
2009-11-17 16:06:26 -08:00
David 'Digit' Turner
34ea5117db Add support for R_ARM_REL32 to the dynamic linker. 2009-11-17 14:56:26 -08:00
Jean-Baptiste Queru
b152dde4ca am 83362689: merge from open-source master
Merge commit '83362689f5b1f6393d376d242fe29541b63ead2d'

* commit '83362689f5b1f6393d376d242fe29541b63ead2d':
  added and modified linker to support SuperH architecture
  Add the BSD sys_signame array.
  added and modified bionic code to support SuperH architecture
2009-11-09 12:07:54 -08:00
Jean-Baptiste Queru
83362689f5 merge from open-source master 2009-11-09 08:04:48 -08:00
Jean-Baptiste Queru
10be95cffc merge from open-source master 2009-11-08 16:09:17 -08:00
Shin-ichiro KAWASAKI
ad13c57298 added and modified linker to support SuperH architecture 2009-11-06 10:36:37 +09:00
Doug Kwan
e823807dc2 Add weak symbol support. Also fix a bug caused by a typo. 2009-10-26 12:05:23 -07:00
Iliyan Malchev
f1729553e3 am 9e78de3e: am 70bba516: am 763ac283: Merge changes Ibcba4b4f,I9af341e1 into eclair
Merge commit '9e78de3e3c90ec3c2970431d8eae7378fdc0dac6'

* commit '9e78de3e3c90ec3c2970431d8eae7378fdc0dac6':
  bionic/linker: make the buddy allocator compute max_order on its own
  bionic/linker: change the buddy allocator to take a handle to the managed area
2009-10-23 18:58:19 -07:00
Iliyan Malchev
9e78de3e3c am 70bba516: am 763ac283: Merge changes Ibcba4b4f,I9af341e1 into eclair
Merge commit '70bba5160f83ecd6251c4539f747ae39e9ed469c' into eclair-mr2-plus-aosp

* commit '70bba5160f83ecd6251c4539f747ae39e9ed469c':
  bionic/linker: make the buddy allocator compute max_order on its own
  bionic/linker: change the buddy allocator to take a handle to the managed area
2009-10-23 18:49:14 -07:00
Iliyan Malchev
53b32f8b7e am 763ac283: Merge changes Ibcba4b4f,I9af341e1 into eclair
Merge commit '763ac28357f604e0e4196e0a7ad5b0f5cdcf274a' into eclair-plus-aosp

* commit '763ac28357f604e0e4196e0a7ad5b0f5cdcf274a':
  bionic/linker: make the buddy allocator compute max_order on its own
  bionic/linker: change the buddy allocator to take a handle to the managed area
2009-10-23 18:39:30 -07:00
Iliyan Malchev
70bba5160f am 763ac283: Merge changes Ibcba4b4f,I9af341e1 into eclair
Merge commit '763ac28357f604e0e4196e0a7ad5b0f5cdcf274a' into eclair-mr2

* commit '763ac28357f604e0e4196e0a7ad5b0f5cdcf274a':
  bionic/linker: make the buddy allocator compute max_order on its own
  bionic/linker: change the buddy allocator to take a handle to the managed area
2009-10-23 18:38:35 -07:00
Doug Kwan
943043583a Clean up some linker code. 2009-10-23 18:11:40 -07:00
Iliyan Malchev
bb9eedeff4 bionic/linker: make the buddy allocator compute max_order on its own
Signed-off-by: Iliyan Malchev <malchev@google.com>
2009-10-19 18:10:35 -07:00
Iliyan Malchev
af7315acf6 bionic/linker: change the buddy allocator to take a handle to the managed area
-- rename struct ba_info to struct ba
-- move the static ba descriptor from ba.c to linker.c and rename it ba_prelink
-- ba_init, ba_allocate, ba_free, ba_start_addr, and ba_len all take a pointer
   to struct ba

Signed-off-by: Iliyan Malchev <malchev@google.com>
2009-10-19 18:10:35 -07:00
David 'Digit' Turner
b3cfdb6220 am eeaf6544: Merge change I7934a799 into eclair-mr2
Merge commit 'eeaf6544b676f68ccdd70a3fa78f44789a1bf69c' into eclair-mr2-plus-aosp

* commit 'eeaf6544b676f68ccdd70a3fa78f44789a1bf69c':
  Prevent spurious EINTR to freeze process debugging
2009-10-19 15:03:31 -07:00
Android (Google) Code Review
eeaf6544b6 Merge change I7934a799 into eclair-mr2
* changes:
  Prevent spurious EINTR to freeze process debugging
2009-10-19 17:55:08 -04:00
David 'Digit' Turner
5d436ddcae am 8213d5c3: am ff7b46b8: Merge change I3c998761 into eclair
Merge commit '8213d5c3c072b23f5cc1922d232efe7338091d9b' into eclair-mr2-plus-aosp

* commit '8213d5c3c072b23f5cc1922d232efe7338091d9b':
  Allow the dynamic linker to relocate references to thumb symbols in NDK libraries.
2009-10-16 12:46:51 -07:00
David 'Digit' Turner
cd23098828 am ff7b46b8: Merge change I3c998761 into eclair
Merge commit 'ff7b46b87c4d85881d88c2105a94be6c6accb628' into eclair-plus-aosp

* commit 'ff7b46b87c4d85881d88c2105a94be6c6accb628':
  Allow the dynamic linker to relocate references to thumb symbols in NDK libraries.
2009-10-16 12:36:27 -07:00
David 'Digit' Turner
7934a799e1 Prevent spurious EINTR to freeze process debugging 2009-10-16 12:14:04 -07:00
Jean-Baptiste Queru
73981476a3 merge from open-source master 2009-10-14 08:18:23 -07:00
David 'Digit' Turner
3c99876116 Allow the dynamic linker to relocate references to thumb symbols in NDK libraries.
The lowest bit of the symbol's value should be ignored when looking at UNDEF symbols
for correctness. It is used as an ARM/Thumb flag by the linker.
2009-10-13 16:55:18 -07:00
Iliyan Malchev
4a9afcb101 bionic/linker: allow resolving of symbols from library back to executable
Signed-off-by: Iliyan Malchev <malchev@google.com>
2009-09-29 14:33:46 -07:00
Iliyan Malchev
9ea64da6c5 bionic/linker: change lookup() to return soinfo, not base 2009-09-29 14:33:46 -07:00
Iliyan Malchev
6ed80c8814 Revert "Revert "bionic/linker: fix symbol lookup during relocations""
This reverts commit 33acbf0719.
2009-09-29 14:33:46 -07:00
Mathias Agopian
33acbf0719 Revert "bionic/linker: fix symbol lookup during relocations"
This reverts commit 8d0c0334f1.
2009-09-27 22:04:15 -07:00
Iliyan Malchev
8d0c0334f1 bionic/linker: fix symbol lookup during relocations
When resolving relocations while loading a library, the linker used to find
symbols by looking them up in the list of all linked libraries for the current
process, as opposed to following just the library's DT_NEEDED entries.  This
can cause a problem where the symbol is picked up from the wrong library.

Signed-off-by: Iliyan Malchev <malchev@google.com>
2009-09-27 17:18:06 -07:00
Thinker K.F Li
5cf640c926 Fill l_ld of linkmaps with value from soinfo::dynamic.
GDB will try to read l_ld of linkmaps and compare the value to vma of
.dynamic sections from shared objects.  Since linker does not assign l_ld,
GDB will complain about and re-compute l_addr from l_ld.  And, GDB will get a
wrong value.
2009-09-15 17:05:55 -07:00
Erik Gilling
30eb40241c bionic: linker: add error message if link failed due to previous error
Signed-off-by: Erik Gilling <konkers@android.com>
2009-08-13 16:18:07 -07:00
Erik Gilling
fde8642fc4 bionic/linker: keep track of opened libraries by basename
Prior to this change, the dynamic loader kept track of opened libraries
either by their base name (i.e., libfoo.so instead of /system/lib/libfoo.so)
when the shared library was loaded through the DT_NEEDED tag in an ELF header,
or by whatever name was passed to dlopen(). This created a number of problems,
among which:

1. dlopen("libfoo.so") and dlopen("/path/to/libfoo.so") would open the same
library twice;
2. dlopen("/path/to/libfoo.so") and then dlopen("libbar.so"), where libbar.so
depends on libfoo.so, would open libfoo.so twice.

This patch makes the dynamic loader keep track of each loaded library by
basename, which resolves the above ambiguity. The patch also enforces
library lookup by base name, which means that it will refuse to load another
library that has the same name.

Thanks for the inspiration Iliyan.

Signed-off-by: Erik Gilling <konkers@android.com>
Cc: Iliyan Malchev <malchev@google.com>
2009-07-28 20:36:47 -07:00
Erik Gilling
d00d23a9d4 linker: remove newlines from DL_ERR so that dlerror works correctly
Signed-off-by: Erik Gilling <konkers@android.com>
2009-07-22 17:10:39 -07:00
David 'Digit' Turner
ef0bd18570 Pass the elfdata pointer in a slot of the temporary TLS area.
This is needed to properly initialize the C runtime when libc.so
is loaded by the dynamic linker.

Move the temporary TLS setup before the first system call, just
in case something really horrible happens, we won't crash when
trying to write an error code in 'errno'

Remove the broken TLS_SLOT_THREAD_ID setup. First, this slot
should normally receive the address of a pthread_internal_t,
not a kernel thread identifier. Second, it is never used by
the linker anyway.

Also remove an obsolete comment.
2009-07-17 17:55:01 +02:00
David Bartley
bc3a5c26f1 Add LD_LIBRARY_PATH support to bionic's linker 2009-06-15 21:36:03 -07:00
Dima Zavin
0353195f34 linker: Give more context for failures during library dependency resolution.
Signed-off-by: Dima Zavin <dima@android.com>
2009-06-01 12:55:48 -07:00
Dima Zavin
2e85579c34 linker: Make the errors reported by dlopen/dlsym be more useful.
Changed it so that when the linker generates error messages, they are
scribbled away into a buffer that dlfcn and friends can read from.

Since the error messages are generetad with snprintf, and snprintf
MAY call malloc during some code paths, we now link against a version
of libc that does not contain malloc/free/realloc/calloc. We then define
malloc and friends in the dynamic loader, and make them abort() if they
are ever called.

Signed-off-by: Dima Zavin <dima@android.com>
2009-05-27 20:16:19 -07:00
David 'Digit' Turner
8215679b35 Fix the parsing of the .fini_array in the dynamic linker (it should happen in reverse order).
Also add a small design overview document for the linker. The latter contains details on
how the initialization/finalization is supposed to work.
2009-05-26 11:16:28 +02:00
Dima Zavin
d1b40d8c69 linker: Compute symbol name before lookup so we can also use it for error msg
Signed-off-by: Dima Zavin <dima@android.com>
2009-05-12 10:59:09 -07:00
James Dong
ba52b3092f Increase the limit of loaded shared libraries from 64 to 96 This change is required for OpenCORE 2.0
This is the same as Change 71 in master branch.
2009-04-30 20:37:36 -07:00
Iliyan Malchev
5e12d7ec70 Automated import from //branches/donutburger/...@140950,140950 2009-03-24 19:02:00 -07:00
The Android Open Source Project
1dc9e472e1 auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00
The Android Open Source Project
1767f908af auto import from //depot/cupcake/@135843 2009-03-03 18:28:13 -08:00
The Android Open Source Project
a799b53f10 auto import from //depot/cupcake/@132589 2009-03-03 14:03:51 -08:00
The Android Open Source Project
fe5745033a auto import from //depot/cupcake/@137055 2009-03-02 22:54:14 -08:00
The Android Open Source Project
6f04a0f4c7 auto import from //branches/cupcake/...@132276 2009-02-19 10:57:29 -08:00
The Android Open Source Project
9f65adf2ba auto import from //branches/cupcake/...@130745 2009-02-10 15:43:56 -08:00
The Android Open Source Project
e5cc1f386b auto import from //branches/cupcake/...@126645 2009-01-15 16:12:07 -08:00
The Android Open Source Project
4e468ed2eb Code drop from //branches/cupcake/...@124589 2008-12-17 18:03:48 -08:00
The Android Open Source Project
a27d2baa0c Initial Contribution 2008-10-21 07:00:00 -07:00