Commit graph

221 commits

Author SHA1 Message Date
Will Newton
b61103dff4 libc/arch-arm/bionic/memcpy.a9.S: memcpy from cortex-strings.
This memcpy code uses NEON/VFP to achieve very good performance
on ARMv7-A processors. It is specifically tuned for A15 but should
provide good performance on A9 also. It is equivalent to the code
in cortex-strings rev 116.

This patch is a follow up the existing gerrit change:

I7f6f77995f3ca903ad9c66d14261441667a2a935

But this version includes a tweak for performance on misaligned
buffers.

Change-Id: I285abac0068f8ae29a1cbf7862ea8590aadaf0a7
Signed-off-by: Will Newton <will.newton@linaro.org>
2013-07-01 11:15:27 +01:00
Ben Cheng
7e6ce1a3c5 Fix abort(3) to raise SIGABRT rather than causing SIGSEGV.
tgkill() needs the .save stack unwinding directive to get the complete
stack trace.

BUG: https://code.google.com/p/android/issues/detail?id=16672

Change-Id: Ifb447dca2147a592c48baf32769dfc175d8aea72
2013-06-10 17:17:46 -07:00
Ben Cheng
a123b5d319 Use bl instead of blx to support interworking properly.
(cherry picked from commit 9e1905794b in
master)

Change-Id: I9b8c35ea9e201e00f84315f9f105013c23c94d85
2013-05-31 14:39:23 -07:00
Andrew Hsieh
e8f46e8edd Remove redundant space within square brackets
The new "as" in binutils-2.23 (with gcc4.8) is more picky:
it expects register right after [

Change-Id: I876124841582070ab2083ffafe38bc333b5812d0
2013-04-25 15:05:03 +08:00
Elliott Hughes
8794ece296 Replace unnecessary ARM uses of <sys/linux-syscalls.h> with <asm/unistd.h>.
For some reason, socketcalls.c was only being compiled for ARM, where
it makes no sense. For x86 we generate stubs for the socket functions
that use __NR_socketcall directly.

Change-Id: I84181e6183fae2314ae3ed862276eba82ad21e8e
2013-03-21 23:07:11 -07:00
Elliott Hughes
5c2772f59d The SYS_ constants should cover all __NR_ values.
<sys/linux-syscalls.h> only contains constants for the syscalls
we're generating stubs for. We want all the syscalls available
on the architecture in question.

Keep using <sys/linux-syscalls.h> on ARM for now because the
__NR_ARM_set_tls and __NR_ARM_cacheflush values aren't in <asm/unistd.h>.

Change-Id: I66683950d87d9b18d6107d0acc0ed238a4496f44
2013-03-21 22:26:20 -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
9aceab5015 Use the kernel's MAX_ERRNO in the syscall stubs.
Bug: http://code.google.com/p/android/issues/detail?id=53104
Change-Id: Iaabf7025b153e96dc5eca231a33a32d4cb7d8116
2013-03-12 17:43:58 -07:00
Ben Cheng
14283004f5 Add stack unwinding directives to memcpy.
Also include some Android specific header files.

Change-Id: Idbcbd43458ba945ca8c61bfbc04ea15fc0ae4e00
2013-03-01 14:56:04 -08:00
Greta Yorsh
eb149e954e Adding strcmp tuned for Cortex-A15.
The attached patch provides a new implementation of strcmp for ARM,
using LDRD instead of LDR whenever possible.

For older architectures that do not support LDRD, this implementation
uses the same algorithm as before.

Testing and benchmarking:
* Validation: successfully passes a test that compares different strings
of length 1-128 and offsets 0-8 from a word boundary. Checked on
qemu/A15/A9, ARM/Thumb mode, Big/Little Endian.
* Integration with gcc: no regression on qemu for arm-none-eabi --with-cpu
a15/a9 --with-mode arm/thumb.

Change-Id: I9e230e1b99dbdc9119b69ee858a89038c516a4ea
Signed-off-by: Vassilis Laganakos <vasileios.laganakos@arm.com>
2013-03-01 10:41:01 +00:00
Greta Yorsh
5b349fc22e Adding memcpy tuned for Cortex-A15.
The strategy for large block sizes is LDRD and STRD with offset addressing,
where the main loop copies 64 bytes in every iteration, (i.e., 8 calls to
LDRD and STRD pairs), interleaving load and stores (i.e., the pairs of LDRD
and STRD of the same data are consecutive instructions), and the writeback
of an updated address is a separate instruction, which allows us to write
back the accumulated update once per iteration.

This strategy is implemented in memcpy.S. In some configurations, a plain
version of memcpy (included from memcpy-stub.c) is used instead of the
optimized one.

Validation:
* Correctness: checked memcpy using a test harness for block sizes
ranging between 1 to 128, and source and destination buffers alignment
ranging in { 0,1,2,3,4,8,12 } bytes each.
* Performance: benchmarking on Cortex-A15 FPGA indicates that this strategy
is better for A15 than the strategy used by glibc and even slightly better
than using NEON. Benchmarking on Cortex-A9 bare metal and Linux shows
that the proposed strategy is reasonable: not as fast as the version of
memcpy from glibc (which is the best open source strategy for A9), but
comparable with csl and bionic.
* Integration with GCC: no regression for arm-none-eabi --with-cpu
cortex-a15 and cortex-a9.

Change-Id: Ied56354d8992c62ae3e02d582a2bd55585d814b9
Signed-off-by: Vassilis Laganakos <vasileios.laganakos@arm.com>
2013-03-01 10:40:50 +00:00
Elliott Hughes
40eabe24e4 Fix the pthread_setname_np test.
Fix the pthread_setname_np test to take into account that emulator kernels are
so old that they don't support setting the name of other threads.

The CLONE_DETACHED thread is obsolete since 2.5 kernels.

Rename kernel_id to tid.

Fix the signature of __pthread_clone.

Clean up the clone and pthread_setname_np implementations slightly.

Change-Id: I16c2ff8845b67530544bbda9aa6618058603066d
2013-02-15 12:08:59 -08:00
Elliott Hughes
6719500dbd Add a bunch more missing ENDs to assembler routines.
This isn't everything; I've missed out those x86 files that are

Change-Id: Idb7bb1a68796d6c0b70ea2b5c3300e49da6c62d2
2013-02-13 15:12:32 -08:00
Elliott Hughes
73964c592c Everyone has CLZ.
Even armv5 had CLZ.

Change-Id: I51bc8d1166d09940fd0d3f4c7717edf26977082c
2013-02-13 14:40:48 -08:00
Elliott Hughes
9f878c2fca Really set errno if __pthread_clone fails.
If r0 == 0, we're the child. If r0 > 0, we're the parent.
Otherwise set errno.

The __bionic_clone code I copy & pasted was wrong. This patch
fixes both.

Bug: 3461078
Change-Id: Ibb7d6cc7e54e666841f2f0dc59a141a0b31982e4
2013-02-12 16:07:06 -08:00
Elliott Hughes
d7a3a403c1 Use ENTRY/END in ARM __get_sp.
Change-Id: If2f159b266f5fa4ad9d188a17d4cd318b605e446
2013-02-11 16:58:34 -08:00
Elliott Hughes
5e3fc43dde Fix __pthread_clone on ARM to set errno on failure.
MIPS and x86 appear to have been correct already.

(Also fix unit tests that ASSERT_EQ with errno so that the
arguments are in the retarded junit order.)

Bug: 3461078
Change-Id: I2418ea98927b56e15b4ba9cfec97f5e7094c6291
2013-02-11 16:39:10 -08:00
Elliott Hughes
f94fd3ccc6 Clean up ARM assembler files to use ENTRY/END.
We also don't need legacy syscall support (non-"swi 0").

Change-Id: Id1012e8ca18bf13f3f4e42200f39ba0e2e632cbf
2013-02-11 15:36:59 -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
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
Ben Cheng
35f5385aa5 Add __aeabi_idiv to the dummy reference list.
If the platform code is compiled with -mcpu=cortex-a15, then without this
change prebuilt libraries built against -march=armv7 cannot resolve the
dependency on __aeabi_idiv (provided by libgcc.a).

Bug: 7961327

cherry-picked from internal master.

Change-Id: I8fe59a98eb53d641518b882523c1d6a724fb7e55
2013-01-14 15:33:40 -08:00
Henrik Smiding
884e4f839b Add optimized version of memset for Cortex A9
Adds new code to function memset, optimized for Cortex A9.

Copyright (C) ST-Ericsson SA 2010

Added neon implementation

Author: Henrik Smiding henrik.smiding@stericsson.com for ST-Ericsson.

Change-Id: Id3c87767953439269040e15bd30a27aba709aef6
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
2012-11-09 15:05:32 -08:00
Henrik Smiding
6d0bcdc832 Add optimized version of memcpy for Cortex A9
Adds new code to memcpy function, optimized for Cortex A9.
Adds new ARM-only loop, for operations where source and
destination are aligned.

Copyright (C) ST-Ericsson SA 2010

Modified neon implementation to fit Cortex A9 cache line size,
for those running 32 bytes L2 cache line size.
Also split the implementation in aligned and unaligned access,
for those that allows unaligned memory access with Neon.
For totally aligned operations, arm-only code is used.

Change-Id: I95ebf6164cd6486b12a7e3e98e369db21e7e18d2
Author: Henrik Smiding henrik.smiding@stericsson.com for ST-Ericsson.
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
2012-11-08 18:02:14 -08:00
Elliott Hughes
c213291515 Merge "Add optimized version of memcmp for Cortex A9" 2012-11-08 17:48:19 -08:00
Andrew Hsieh
048569be54 Rename __dso_handle_so.c to __dso_handle_so.h
Also chang libc/arch-arm/bionic/crtbegin_so.c to include it
as a header.

Change-Id: Ib91b0b8caf5c8b936425aa8a4fc1a229b2b27929
2012-09-07 12:49:41 +08:00
Elliott Hughes
b2c5bd543d Merge "ARM: warn about atexit() calls from legacy shared libraries" 2012-09-05 10:18:43 -07:00
Elliott Hughes
26f2e4a163 Merge "ARM: make CRT_LEGACY_WORKAROUND work as intended" 2012-09-05 09:43:35 -07:00
Nick Kralevich
069c64cdf2 Merge "ARM: make sure __on_dlclose() actually gets called" 2012-08-28 13:04:22 -07:00
Nick Kralevich
e026b1d89a Merge "ARM: remove dummy entries from .so init_array/fini_array" 2012-08-28 12:49:46 -07:00
Ard Biesheuvel
144c291866 ARM: warn about atexit() calls from legacy shared libraries
Legacy ARM shared libraries use this generic version of atexit(),
which queues exit functions for invocation at program exit, at
which time the library may have been dlclose()'d, causing the
program to crash.

Change-Id: I41ae153c23268daa65ede7fb8966fc3e9caec369
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-08-28 11:23:06 +02:00
Ard Biesheuvel
f3cfcd869d ARM: make CRT_LEGACY_WORKAROUND work as intended
To properly support legacy ARM shared libraries, libc.so needs
to export the symbols __dso_handle and atexit, even though
these are now supplied by the crt startup code.

This patch reshuffles the existing CRT_LEGACY_WORKAROUND
conditionally compiled code slightly so it works as the
original author likely intended.

Change-Id: Id6c0e94dc65b7928324a5f0bad7eba6eb2f464b9
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-08-28 10:27:02 +02:00
Ard Biesheuvel
c23092887f ARM: remove dummy entries from .so init_array/fini_array
The runtime linker parses the ELF section headers to
discover the size of the init_array and fini_array, so
there is no point in putting NULL terminators at the end.

Change-Id: I3246cd585efce9314155600277dd829e9f37d04f
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-08-28 09:55:51 +02:00
Ard Biesheuvel
0a150ead18 libc: remove ctors/dtors sections
None of the supported ARCHs actually populate these sections,
so there is no point in keeping them in the binaries.

Change-Id: I21a364f510118ac1114e1b49c53ec8c895c6bc6b
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-08-22 20:45:26 +02:00
Ard Biesheuvel
404e28ff8c hardening: remove pointless ARM __get_pc() function
Useful if you're trying to defeat ASLR, otherwise not
so much ...

Change-Id: I17ebb50bb490a3967db9c3038f049adafe2b8ea7
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-08-22 20:38:54 +02:00
Ard Biesheuvel
5ed48a4d7f ARM: make sure __on_dlclose() actually gets called
Change-Id: I280e5428b0543cccf17ca36baee4865395928cdb
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@gmail.com>
2012-08-21 12:56:05 +02: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
Nick Kralevich
6eee1fc68f crtend*: Add GNU_STACK note
Add a GNU_STACK marker to crtend* files. This tells the linker
that these files do not require an executable stack.

When linking, a missing GNU_STACK marker in any .o file can prevent
the compiler from automatically marking the final executable as NX
safe (executable stack not required).  In Android, we normally work
around this by adding -Wa,--noexecstack / -Wl,-z,noexecstack.
For files like crtend.S / crtend_so.S, which are included in every
executable / shared library, it's better to add the GNU_STACK note
directly to the assembly file.  This allows the compiler to
automatically mark the final executable as NX safe without any
special command line options.

References: http://www.gentoo.org/proj/en/hardened/gnu-stack.xml

Change-Id: I07bd058f9f60ddd8b146e0fb36ba26ff84c0357d
2012-08-10 14:12:00 -07:00
Peter Enderborg
3460db9490 bionic: Stack pointer/signal race condition.
Move the stackpointer so a captured signal does not corrupt
stack variables needed for __thread_entry.

Change-Id: I3e1e7b94a6d7cd3a07081f849043262743aa8064
2012-07-27 15:11:01 +02:00
Nick Kralevich
9d40326830 arm: rewrite crtbegin* as C files.
Rewrite
 crtbegin.S     -> crtbegin.c
 crtbegin_so.S  -> crtbegin_so.c

This change allows us to generate PIC code without relying
on text relocations.

As a consequence of this rewrite, also rewrite
  __dso_handle.S    -> __dso_handle.c
  __dso_handle_so.S -> __dso_handle_so.c
  atexit.S          -> atexit.c

In crtbegin.c _start, place the __PREINIT_ARRAY__, __INIT_ARRAY__,
__FINI_ARRAY__, and __CTOR_LIST__ variables onto the stack, instead of
passing a pointer to the text section of the binary.

This change appears sorta wonky, as I attempted to preserve,
as much as possible, the structure of the original assembly.
As a result, you have C files including other C files, and other
programming uglyness.

Result: This change reduces the number of files with text-relocations
from 315 to 19 on my Android build.

Before:
  $ scanelf -aR $OUT/system | grep TEXTREL | wc -l
  315

After:
  $ scanelf -aR $OUT/system | grep TEXTREL | wc -l
  19

Change-Id: Ib9f98107c0eeabcb606e1ddc7ed7fc4eba01c9c4
2012-06-01 14:41:27 -07:00
Nick Kralevich
83a73d1afe crtbegin: eliminate duplicate code
crtbegin_dynamic and crtbegin_static are essentially identical,
minus a few trivial differences (comments and whitespace).

Eliminate duplicates.

Change-Id: Ic9fae6bc9695004974493b53bfc07cd3bb904480
2012-05-30 11:45:12 -07:00
Henrik Smiding
3ebd31c0a1 Add optimized version of memcmp for Cortex A9
Adds new code to function memcmp, optimized for Cortex A9.

Copyright (C) ST-Ericsson SA 2010

Added neon optimization

Change-Id: I8864d277042db40778b33232feddd90a02a27fb0
Author: Henrik Smiding henrik.smiding@stericsson.com for ST-Ericsson.
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
2012-05-19 14:04:59 +02: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
Iliyan Malchev
8034415ddd resolved conflicts for merge of 08e72d01 to jb-dev-plus-aosp
Change-Id: If00e354a5953ed54b31963d4f8ea77e1603c321e
2012-05-10 09:19:59 -07:00
Prajakta Gudadhe
08e72d0161 bionic: add support for non-NEON memcpy() on NEON SoCs
Some SoCs that support NEON nevertheless perform better with a non-NEON than a
NEON memcpy().  This patch adds build variable ARCH_ARM_USE_NON_NEON_MEMCPY,
which can be set in BoardConfig.mk.  When ARCH_ARM_USE_NON_NEON_MEMCPY is
defined, we compile in the non-NEON optimized memcpy() even if the SoC supports
NEON.

Change-Id: Ia0e5bee6bad5880ffc5ff8f34a1382d567546cf9
2012-05-09 13:34:31 -07:00
Ben Cheng
da0d8534f1 am 08b51e2c: Implement the "abort" stub in assembly for ARM.
* commit '08b51e2c091d036c124259ae59eb7be6bbe346af':
  Implement the "abort" stub in assembly for ARM.
2012-05-09 01:48:40 -07:00
Ben Cheng
eda7be454d Implement the "abort" stub in assembly for ARM.
So that we can always get the full stack trace regardless of gcc's handling
of the "noreturn" attribute associated with abort().

(Cherry pick of Id264a5167e7cabbf11515fbc48f5469c527e34d4.)

Bug: 6455193

Conflicts:

	libc/Android.mk

Change-Id: I568fc5303fd1d747075ca933355f914122f94dac
2012-05-08 14:47:20 -07:00
Ben Cheng
08b51e2c09 Implement the "abort" stub in assembly for ARM.
So that we can always get the full stack trace regardless of gcc's handling
of the "noreturn" attribute associated with abort().

[cherry-picked from master]

BUG:6455193
Change-Id: I0102355f5bf20e636d3feab9d1424495f38e39e2
2012-05-08 14:39:35 -07:00
Elliott Hughes
e636e1f2c1 am 8657eafc: Merge "Adjust memcpy for ARM Cortex A9 cache line size"
* commit '8657eafc3552f36c176667c1591beab255308da6':
  Adjust memcpy for ARM Cortex A9 cache line size
2012-05-07 13:59:58 -07:00
Henrik Smiding
fe6338da91 Adjust memcpy for ARM Cortex A9 cache line size
ARM Cortex A8 use 64 bytes and ARM Cortex A9 use 32 bytes cache line
size.

The following patch:
  Adds code to adjust memcpy cache line size to match A9 cache line
  size.
  Adds a flag to select between 32 bytes and 64 bytes cache line
  size.

  Copyright (C) ST-Ericsson SA 2010
    Modified neon implementation to fit Cortex A9 cache line size
    Author: Henrik Smiding henrik.smiding@stericsson.com for
            ST-Ericsson.

Change-Id: I8a55946bfb074e6ec0a14805ed65f73fcd0984a3
Signed-off-by: Christian Bejram <christian.bejram@stericsson.com>
2012-05-07 14:18:02 +02:00
Evgeniy Stepanov
4a9d6e50bb Fix segv when unwinding stack past __libc_init.
This change mirrors cd15bac for statically-linked binaries.

Change-Id: Id870832a50b37f0ef3e79e1ed03ed31390bfc9ef
2012-04-18 12:59:38 +04:00
Elliott Hughes
d5099016f7 Merge "Fix segv when unwinding stack past __libc_init." 2012-04-12 11:52:44 -07:00
Kenny Root
470835b215 Move end of __on_dlclose up
The END macro was put too far down which made the linker complain about
it. Move up to the end of the code.

Change-Id: Ica71a9c6083b437d2213c7cefe34b0083c78f16b
2012-04-11 14:24:28 -07:00
Kenny Root
03273f8fc0 __on_dlclose should be aligned
Marking segments read-only was pushing the alignment of __on_dlclose by
2 bytes making it unaligned. This change makes sure the ARM code is
aligned to the 4 byte boundary.

Bug: 6313309
Change-Id: Ic2bf475e120dd61225ec19e5d8a9a8b1d0b7f081
2012-04-10 17:53:11 -07:00
Evgeniy Stepanov
cd15bacf33 Fix segv when unwinding stack past __libc_init.
This change fixes a segmentation fault in the libc unwinder when it goes
past __libc_init.

Unwind instructions for __libc_init direct it to grab the return address from
the stack frame. Without this change, the unwinder gets a wild address and
looks up further unwind instructions for the routine at that address. If it's
unlucky enough to hit an existing function, it will try to unwind it. Bad
things happen then.

With this change, the return address always points to the _start function,
which does not have unwind instructions associated with it. This stop the
unwind process.

__libc_init never returns, so this does not affect program execution, other
than adding 4 bytes on the main thread stack.

Change-Id: Id58612172e8825c8729cccd081541a13bff96bd0
2012-04-10 16:45:54 +04:00
Kenny Root
be101bf39a Revert "Reference __dso_handle in PIC way"
This reverts commit 93cb308137
2012-03-05 10:45:31 -08:00
Kenny Root
93cb308137 Reference __dso_handle in PIC way
Use the same pattern in atexit.S to reference __dso_handle in a way that
doesn't require a TEXTREL flag to be set.

Change-Id: Id69d20863ee203d2b2f7ef0db230f9b548657741
2012-03-02 13:09:36 -08:00
Andrew Hsieh
4fc1273459 Merge "Trivial fix in comment" 2012-02-29 09:40:49 -08:00
Dima Zavin
f1a17e762b libc: Add __aeabi_llsl and __aeabi_llsr to libgcc_compat
Some platform libraries built for ICS do not work with master
because of some refactoring in frameworks/base.

Make sure that these libgcc symbols are always present in our libc

Change-Id: Ib8d345878be0ba711f051082a778f5cc1f1b3a19
Signed-off-by: Dima Zavin <dima@android.com>
2012-02-22 15:18:56 -08:00
Andrew Hsieh
58b2c1616b Trivial fix in comment
Very, very trivial fix for minor typo in comment about how it works

Change-Id: Ia08d332366837dec8f7e91b9728732c5edea223e
2012-02-21 15:09:32 -08:00
David 'Digit' Turner
f1a39dce60 libc: Fix typo that broke NDK compatibility.
The function must be named __atomic_cmpxchg, not __android_cmpxchg.
This typo broke existing prebuilt binaries (they couldn't be loaded
at runtime anymore).

Change-Id: I25ca7d18329817f0056e616a0409113269ad7b1f
2011-11-23 14:38:36 +01:00
David 'Digit' Turner
de44d0b2bd Merge "libc: provide atomic operations will full barriers for NDK apps." 2011-11-22 02:10:06 -08:00
Jeff Brown
10c8ce59a4 Add tgkill syscall.
Use tgkill instead of tkill to implement pthread_kill.
This is safer in the event that the thread has already terminated
and its id has been reused by a different process.

Change-Id: Ied715e11d7eadeceead79f33db5e2b5722954ac9
2011-11-18 16:40:48 -08:00
David 'Digit' Turner
0fec6b9d88 libc: provide atomic operations will full barriers for NDK apps.
__atomic_cmpxchg and other related atomic operations did not
provide memory barriers, which can be a problem for non-platform
code that links against them when it runs on multi-core devices.

This patch does two things to fix this:

- It modifies the existing implementation of the functions
  that are exported by the C library to always provide
  full memory barriers. We need to keep them exported by
  the C library to prevent breaking existing application
  machine code.

- It also modifies <sys/atomics.h> to only export
  always-inlined versions of the functions, to ensure that
  any application code compiled against the new header will
  not rely on the platform version of the functions.

  This ensure that said machine code will run properly on
  all multi-core devices.

This is based on the GCC built-in sync primitives.

The end result should be only slightly slower than the
previous implementation.

Note that the platform code does not use these functions
at all. A previous patch completely removed their usage in
the pthread and libstdc++ code.

+ rename arch-arm/bionic/atomics_arm.S to futex_arm.S
+ rename arch-x86/bionic/atomics_x86.S to futex_x86.S
+ remove arch-x86/include/sys/atomics.h which already
  provided inlined functions to the x86 platform.

Change-Id: I752a594475090cf37fa926bb38209c2175dda539
2011-11-16 17:37:15 +01: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
Evgeniy Stepanov
487b613e57 Use ENTRY and EXIT macros for strcmp, memcpy, atexit.
Without this change strcmp size is zero (not set), and it gets
ignored by Valgrind. Changes to memcpy and atexit don't affect the
generated binary in any way.

Change-Id: I05818cb5951f75901dc8c0eef02807a2e83a9231
2011-10-11 12:12:05 +04:00
David 'Digit' Turner
58246b7067 libc: Add __aeabi_f2uiz to libgcc_compat.c
This patch ensure that __aeabi_f2uiz is embedded in our C library.
This is needed to avoid breaking certain applications when they are
loaded in ICS. It is likely that the issue is due to mis-linked
binaries generated with the stand-alone toolchain (the problem
should not exist if you use ndk-build), but this fix is easier
than asking all app developers to fix their custom build system.

If you want more technical details, read the comments inside
libgcc_compat.c

Change-Id: I59ac1fc781ecb70b90b5573c5a3c67560ca8f270
2011-08-22 19:53:10 +02:00
David Turner
b489666086 am 1c0a0381: Merge "Enable functional DSO object destruction"
* commit '1c0a0381dfb3648ffadef9537ec9383d63d62473':
  Enable functional DSO object destruction
2011-06-23 05:28:13 -07:00
Bruce Beare
3964084282 Enable functional DSO object destruction
Unfortunately, legacy .so files for ARM don't have a correct crtbegin file.
Consequently, we have to grandfather the old __dso_handle behaviour.
Add some ifdefs for ARM to allow it to use the old code until we can work
out a transition.

Change-Id: I6a28f368267d792c94e1d985d8344023bc632f6f
Author: H.J. Lu <hongjiu.lu@intel.com>
Signed-off-by: Bruce Beare <bruce.j.beare@intel.com>
2011-06-20 14:44:44 -07:00
David Turner
a9e409a035 am a7a9dddb: Merge "bionic: Add ARM optimized strcmp()"
* commit 'a7a9dddb5dfe783d65fec4d3b0dee9f734345a29':
  bionic: Add ARM optimized strcmp()
2011-05-17 04:47:09 -07:00
Jim Huang
f50e9be593 bionic: Add ARM optimized strcmp()
Reference results of the experiments on TI OMAP3430 at 600 MHz

$ bench_strcmp -N "strcmp_1k" -s 1k -I 200

[original C code]
             prc thr   usecs/call      samples   errors cnt/samp     size
strcmp_1k      1   1     10.38000          102        0    15000     1024

[ARM optimized code]
             prc thr   usecs/call      samples   errors cnt/samp     size
strcmp_1k      1   1      3.08840           88        0    15000     1024

The work was derived from ARM Ltd, contributed to newlib, and reworked
for Android by Linaro.

Change-Id: Ib0d5755e1eb9adb07d80ef0252f57a5c4c57a425
Signed-off-by: Jim Huang <jserv@0xlab.org>
2011-04-20 15:39:43 +08:00
David Turner
3224c08bd7 Merge changes I8c481c89,I791406f8,I5f09cef8
* changes:
  libc: ARM: update syscalls with new script
  libc: ARM: add size info to gensyscalls
  Add function marks and size indications
2011-02-18 15:22:27 -08:00
Kenny Root
420878c690 Add function marks and size indications
Add a macro to annotate function end and start using both ENTRY and END
for each function. This allows valgrind (and presumably other debugging
tools) to use the debug symbols to trace the functions.

Change-Id: I5f09cef8e22fb356eb6f5cee952b031e567599b6
2011-02-17 09:07:25 -08:00
Kenny Root
0233509c16 Amend previous commit with needed include
Change-Id: Idae8daaf095d90513820e05f423144ffed4ba913
2011-02-17 07:50:36 -08:00
Kenny Root
3a3c1853ac Use CLZ on ARMv5 and newer
Change-Id: Ia5aa6974c0343ae43fbcb91304501213048e9ec0
2011-02-16 16:40:08 -08:00
Jean-Baptiste Queru
24dc936346 resolved conflicts for merge of 1bc98ccb to gingerbread-plus-aosp
Change-Id: Ief9ec3d0472660e26864e082e03c26e09a043b9d
2010-11-22 13:34:59 -08:00
Jim Huang
73c04b3269 bionic: Add ARM optimized strcpy()
Reference results of the experiments on Qualcomm MSM7x25 (524MHz):

[original C code]
             prc thr   usecs/call      samples   errors cnt/samp
size
strcpy_1k      1   1     14.56159           99        0     1000
1024

[ARM optimized code]
             prc thr   usecs/call      samples   errors cnt/samp
size
strcpy_1k      1   1      3.46653           99        0     1000
1024

The work was derived from ARM Ltd.

Change-Id: I906ac53bb7a7285e14693c77d3ce8d4ed6f98bfd
2010-11-22 13:01:32 -08:00
Jim Huang
a172709259 bionic: Rename _ARM_HAVE_LDREX_STREX to __ARM_HAVE_LDREX_STREX for consistency
The patch follows the naming manner in existing macros with prefix
__ARM_HAVE.

Change-Id: I6763ce2bf3ee85fd1da112c719543061d8d19bf4
2010-08-09 05:35:11 +08:00
Dima Zavin
18c5bcc66a Revert "Set SA_RESTORER in sigaction()"
This reverts commit e4fa46e75c.
2010-07-29 19:12:04 -07:00
David 'Digit' Turner
3b43f87d29 Allow dlclose() to properly call static C++ destructors.
With this patch _and_ an upcoming build/ patch, the destruction
of static C++ objects contained in shared libraries will happen
properly when dlclose() is called.

Note that this change introduces crtbegin_so.S and crtend_so.S which
are currently ignored by the build system.

+ move definition of __dso_handle to the right place
(before that, all shared libraries used the __dso_handle
global variable from the C library).

Note that we keep a 'weak' __dso_handle in aeabi.c to avoid
breaking the build until the next patch to build/core/combo/
appears. We will be able to remove that later.

+ move bionic/aeabi.c to arch-arm/bionic/ (its proper location)

NOTE: The NDK will need to be modified to enable this feature in
         the shared libraries that are generated through it.

Change-Id: I99cd801375bbaef0581175893d1aa0943211b9bc
2010-07-01 23:09:28 -07:00
David 'Digit' Turner
6a9b888d7c Allow static C++ destructors to be properly called on dlclose().
With this patch, _and_ an upcoming build/ patch, the destruction
of static C++ objects contained in shared libraries will happen
properly when dlclose() is called.

Note that this change introduces crtbegin_so.S and crtend_so.S which
are currently ignored by the build system.

+ move definition of __dso_handle to the right place
  (before that, all shared libraries used the __dso_handle
   global variable from the C library).

  Note that we keep a 'weak' __dso_handle in aeabi.c to avoid
  breaking the build until the next patch to build/core/combo/
  appears. We will be able to remove that later.

+ move bionic/aeabi.c to arch-arm/bionic/ (its proper location)

Change-Id: Ie771aa204e3acbdf02fd30ebd4150373a1398f39
NOTE: The NDK will need to be modified to enable this feature in
      the shared libraries that are generated through it.
2010-06-18 16:07:10 -07:00
David 'Digit' Turner
b8e6c50cfa Fix setjmp()/longjmp() to save FP registers on ARMv7. - DO NOT MERGE
Change-Id: I3a0c2c05e295ac05ed51a531dabda668be204ca0
2010-06-09 13:18:29 -07:00
Andy McFadden
fcd00ebbdf Atomic/SMP update, part 3.
Update ARM atomic ops to use LDREX/STREX.  Stripped out #if 0 chunk.

Insert explicit memory barriers in pthread and semaphore code.

For bug 2721865.

Change-Id: I0f153b797753a655702d8be41679273d1d5d6ae7
2010-05-28 16:12:01 -07:00
Andy McFadden
4fdbadde92 Atomic/SMP update.
Added an underscore to _ARM_HAVE_LDREX_STREX to make it match the others.

Added __ARM_HAVE_DMB and __ARM_HAVE_LDREXD when appropriate.

Fixed some typos.

Change-Id: I2f55febcff4aeb7de572a514fb2cd2f820dca27c
2010-05-20 15:59:32 -07:00
The Android Open Source Project
4aef0ae660 merge from open-source master
Change-Id: I2be62bce462ee53fe9519f433523bd7a44a73d40
2010-05-13 14:31:02 -07:00
Matt Fischer
e4fa46e75c Set SA_RESTORER in sigaction()
GDB looks for specific opcode sequences when trying to recognize a stack
frame as a signal trampoline.  The sequences it looks for happen to be those
created when SA_RESTORER is set, since glibc always sets a restorer.  This
patch does the same here, so that the trampolines can be correctly identified.

Change-Id: I0ac574a68818cb24d939c3527f3aaeb04b853d04
2010-05-12 14:18:36 -05:00
David 'Digit' Turner
88f06cd84a Use private futexes for pthread_mutex_t.
This does not change the implementation of conditional variables
since we're waiting for other system components to properly use
pthread_condattr_init/setpshared before that.

Also remove an obsolete x86 source file.

Change-Id: Ia3e3fbac35b87a534fb04d4381c3c66b975bc8f7
2010-03-18 17:13:41 -07:00
Fabrice Di Meglio
8641833b62 Revert "bionic: pthread: use private futexes by default for mutexes and condvars"
This reverts commit ba9c6f0989.
2010-03-11 14:47:47 -08:00
David 'Digit' Turner
ba9c6f0989 bionic: pthread: use private futexes by default for mutexes and condvars
Private futexes are a recent kernel addition: faster futexes that cannot be
shared between processes. This patch uses them by default, unless the PROCESS_SHARED
attribute flag is used when creating a mutex and/or conditional variable.

Also introduces pthread_condattr_init/destroy/setpshared/getpshared.

Change-Id: I3a0e2116f467072b046524cb5babc00e41057a53
2010-03-11 11:48:38 -08:00
Colin Cross
ecede40222 Only use NEON memcpy if __ARM_NEON__ is defined
Change-Id: I32e6b9385d46efeec15dee8e395a82eef24ba3ea
2010-03-09 16:23:51 -08:00
David 'Digit' Turner
97cf7f3394 Implement clone() C library function properly.
Only provide an implementation for ARM at the moment, since
it requires specific assembly fragments (the standard syscall
stubs cannot be used because the child returns in a different
stack).
2010-01-25 11:18:30 -08:00
Doug Kwan
d548a265ca Add missing symbol type directives. 2009-12-03 16:26:04 -08:00
Mathias Agopian
ecac54db21 am 3ba822cc: am 199f9d92: Improve memcpy performance from 290 MiB/s to 340 MiB/s (17% improvment)
Merge commit '3ba822cc3f0a252db73cf63cb8390e46fc0ceb0a' into eclair-mr2-plus-aosp

* commit '3ba822cc3f0a252db73cf63cb8390e46fc0ceb0a':
  Improve memcpy performance from 290 MiB/s to 340 MiB/s (17% improvment)
2009-10-29 19:53:39 -07:00
Mathias Agopian
47c5e30b61 am 199f9d92: Improve memcpy performance from 290 MiB/s to 340 MiB/s (17% improvment)
Merge commit '199f9d923804d74e021dd80e48ec75c0a96dba77' into eclair-plus-aosp

* commit '199f9d923804d74e021dd80e48ec75c0a96dba77':
  Improve memcpy performance from 290 MiB/s to 340 MiB/s (17% improvment)
2009-10-29 02:44:15 -07:00
Mathias Agopian
199f9d9238 Improve memcpy performance from 290 MiB/s to 340 MiB/s (17% improvment)
use 64 bytes cache lines, reduce the main loop to 64-bytes instead of
128 bytes and adjust the prefetch distance to the optimal value.
2009-10-28 03:17:02 -07:00
Mathias Agopian
581f43056b am 76ef331c: am 7e7d6c48: use local symbols in memset so it doesn\'t screw up profiling
Merge commit '76ef331cd6967ca8f5af779d25c8b634f8cdd2b6' into eclair-mr2-plus-aosp

* commit '76ef331cd6967ca8f5af779d25c8b634f8cdd2b6':
  use local symbols in memset so it doesn't screw up profiling
2009-10-19 17:19:37 -07:00
Mathias Agopian
214dec2811 am 7e7d6c48: use local symbols in memset so it doesn\'t screw up profiling
Merge commit '7e7d6c48a064af82f0ec39f47b9eb803a6e1df4c' into eclair-plus-aosp

* commit '7e7d6c48a064af82f0ec39f47b9eb803a6e1df4c':
  use local symbols in memset so it doesn't screw up profiling
2009-10-19 17:09:51 -07:00
Mathias Agopian
7e7d6c48a0 use local symbols in memset so it doesn't screw up profiling 2009-10-19 16:34:38 -07:00
David 'Digit' Turner
1f2a381e84 am fdc5c1f5: Re-enable ARMv7 memcpy implementation.
Merge commit 'fdc5c1f56f9d21034badb8e4b092c47098f19613' into eclair-plus-aosp

* commit 'fdc5c1f56f9d21034badb8e4b092c47098f19613':
  Re-enable ARMv7 memcpy implementation.
2009-10-07 11:48:11 -07:00
David 'Digit' Turner
5be45ce0cf am 1e40783d: Fix armv7-user builds by disabling the ARMv7-optimized memcpy.
Merge commit '1e40783d9ad29c88a4d547774e05080fc4327a2e' into eclair-plus-aosp

* commit '1e40783d9ad29c88a4d547774e05080fc4327a2e':
  Fix armv7-user builds by disabling the ARMv7-optimized memcpy.
2009-10-07 11:42:33 -07:00
David 'Digit' Turner
fdc5c1f56f Re-enable ARMv7 memcpy implementation.
Do not submit this patch before the one that modifies the Android emulator to
work-around a weird ARMv7 emulation issue. This is done to temporarily re-allow
the -user builds needed for QA.
2009-10-05 14:25:10 -07:00
David 'Digit' Turner
1e40783d9a Fix armv7-user builds by disabling the ARMv7-optimized memcpy.
This is required to work-around some corny bugs in ARMv7 emulation.

The emulation itself is required to run the dex pre-optimization pass
for -user builds.
2009-10-02 19:13:27 -07:00
David 'Digit' Turner
0893d49187 am 7a9e06fa: Merge change I2a7ad975 into eclair
Merge commit '7a9e06fa7e4e533074cde314f25dff3024f34a5d' into eclair-plus-aosp

* commit '7a9e06fa7e4e533074cde314f25dff3024f34a5d':
  Fix ABI breakage in libc.so and libm.so between 1.6 and Eclair.
2009-09-29 15:13:15 -07:00
Android (Google) Code Review
7a9e06fa7e Merge change I2a7ad975 into eclair
* changes:
  Fix ABI breakage in libc.so and libm.so between 1.6 and Eclair.
2009-09-29 18:04:51 -04:00
David 'Digit' Turner
2a7ad97539 Fix ABI breakage in libc.so and libm.so between 1.6 and Eclair.
For a detailed description of the problem and why this fix is
needed, plrease read the comments in libgcc_compat.c
2009-09-29 14:43:38 -07:00
Mathias Agopian
2d77d4dbd6 am ee223d02: NEON optimized memcpy.
Merge commit 'ee223d02d96815c989b62043ff1237b1cd4e14b0' into eclair-plus-aosp

* commit 'ee223d02d96815c989b62043ff1237b1cd4e14b0':
  NEON optimized memcpy.
2009-09-29 13:31:57 -07:00
Mathias Agopian
ee223d02d9 NEON optimized memcpy.
372 MB/s for large transfers, 440 MB/s for smaller ones down to 1KB. 130 MB/s for very small transfers ( < 32 bytes )
Performance is similar with non-congruent buffers.
2009-09-28 19:08:18 -07:00
David 'Digit' Turner
dfa87a200f am f355096a: Remove NEON optimizations for memcpy
Merge commit 'f355096a64b74c8e869527de55f7e908873e3128' into eclair-plus-aosp

* commit 'f355096a64b74c8e869527de55f7e908873e3128':
  Remove NEON optimizations for memcpy
2009-09-27 07:19:59 -07:00
David 'Digit' Turner
f355096a64 Remove NEON optimizations for memcpy 2009-09-27 07:08:46 -07:00
Ben Cheng
b8a18d059b am bd192b47: Add stack unwinding directives to assembly leaf functions.
Merge commit 'bd192b470b69e00e9313680b70c5572a609e535d' into eclair-plus-aosp

* commit 'bd192b470b69e00e9313680b70c5572a609e535d':
  Add stack unwinding directives to assembly leaf functions.
2009-09-15 14:51:10 -07:00
Ben Cheng
bd192b470b Add stack unwinding directives to assembly leaf functions.
So that the real culprit of native crashes can surface in the stack trace.
2009-09-15 13:41:14 -07:00
Jean-Baptiste Queru
cdeb4c8afa merge from open-source master 2009-09-15 07:51:39 -07:00
vinay harugop
76ec6891e2 ARM architecture reference manuals for ARMv6 & ARMv7 state that the use of 'swp' instruction is deprecated
ARMv6 onwards. These architectures provide the load-linked, store-conditional pair of ldrex/strex whose use
is recommended in place of 'swp'. Also, the description of the 'swp' instruction in the ARMv6 reference
manual states that the swap operation does not include any memory barrier guarantees.This fix attempts to
address these issues by providing an atomic swap implementation using ldrex/strex under _ARM_HAVE_LDREX_STREX
macro.  This Fix is verified on ST Ericsson's U8500 platform and Submitted on behalf of a third-party:
Surinder-pal SINGH from STMicroelectronics.
2009-09-09 21:01:46 +05:30
David 'Digit' Turner
1bbc56cd22 Neon-optimized versions of memcpy.
This optimization come from the external 0xdroid repository.
Original patch can be found here:

ebafe41c2c
2009-09-02 23:21:52 +02:00
David 'Digit' Turner
3a654b1e04 Revert "Fix the C library initialization to avoid calling static C++ constructors twice."
This reverts commit 03eabfe65e.
2009-06-03 19:32:37 +02:00
David 'Digit' Turner
03eabfe65e Fix the C library initialization to avoid calling static C++ constructors twice.
The problem was due to the fact that, in the case of dynamic executables,
the dynamic linker calls the DT_PREINIT_ARRAY, DT_INIT and DT_INIT_ARRAY
constructors when loading shared libraries and dynamic executables,
*before* calling the executable's entry point (i.e. arch-$ARCH/bionic/crtbegin_dynamic.c)
which in turns call __libc_init() in libc.so, as defined by bionic/libc_init_dynamic.c

The latter did call these constructors array again, mistakenly.

The patch also updates the documentation of many related functions.

Also adds a new section to linker/README.TXT explaining restrictions on
C library usage.

The patch has been tested on a Dream for stability issues with
proprietary blobs:

- H264 decoding works
- Camera + Video recording works
- GPS works
- Sensors work

The tests in system/extra/tests/bionic/libc/common/test_static_cpp_mutex.cpp has been
run and shows the static C++ constructor being called only once.
2009-06-02 23:27:44 +02: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
6d6c82c7a0 auto import from //branches/cupcake/...@125939 2009-01-09 17:50:54 -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