Commit graph

168 commits

Author SHA1 Message Date
Elliott Hughes
37ad959783 More missing _unlocked <stdio.h> functions.
Also simplify trivial one-liners like perror/puts/fputs, and clean up
fread/fwrite slightly.

Fix perror to match POSIX.

Add basic perror and *_unlocked tests.

Bug: N/A
Test: ran tests
Change-Id: I63f83c8e0c15c3c4096509d17421ac331b6fc23d
2017-10-31 13:23:41 -07:00
Elliott Hughes
cc3d04f03a Add null checks to <dirent.h> functions.
Move all the new checks over to the existing __fortify_fatal.

Bug: http://b/67455242
Test: ran tests
Change-Id: Idb899c58c32d52d3b423caf1a91feb7defcba9b3
2017-10-26 16:16:33 -07:00
Elliott Hughes
fa386e0d1e Add POSIX swab.
Surprisingly to me, there are actual uses of `swab` in the codebases
I have available to search, including one with a #ifndef __ANDROID__
around it.

Bug: N/A
Test: ran tests
Change-Id: Ic91b78ae22bb65c346cb46dd38916f48d979abe0
2017-10-18 13:34:32 -07:00
Josh Gao
0e0e370154 Add libc_nopthread.
Add a static library containing the non-pthread dependent parts of
libc.

Bug: http://b/64400027
Test: sailfish boots
Test: bionic-unit-tests32/64, no new failures
Test: bionic-unit-tests-static32/64, no new failures
Change-Id: I93dc3811acddad7936d11b369b98cefd945ee2d5
2017-10-16 21:31:37 -07:00
Elliott Hughes
ddd6436df2 Merge "Unified sysroot: kill arch-specific include dirs." 2017-10-12 22:23:58 +00:00
Elliott Hughes
d4ca231ae2 Unified sysroot: kill arch-specific include dirs.
<machine/asm.h> was internal use only.

<machine/fenv.h> is quite large, but can live in <bits/...>.

<machine/regdef.h> is trivially replaced by saying $x instead of x in
our assembler.

<machine/setjmp.h> is trivially inlined into <setjmp.h>.

<sgidefs.h> is unused.

Bug: N/A
Test: builds
Change-Id: Id05dbab43a2f9537486efb8f27a5ef167b055815
2017-10-12 13:19:51 -07:00
Elliott Hughes
14e3ff9f09 Implement <spawn.h>.
As described here:

  http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_spawn.html

And here:

  http://man7.org/linux/man-pages/man3/posix_spawn.3.html

Bug: N/A (but mentioned in my inbox since 2013)
Test: ran tests
Change-Id: I0b27b2919b660779e3bd8a25fb429527c16dc621
2017-10-11 14:57:49 -07:00
Christopher Ferris
93ea09f65c Add directives to force stop unwinding.
On aarch64/x86/x86_64 add a macro that inserts a cfi directive that will
stop unwinding.

For arm, clang doesn't allow emitting .cantunwind, so add a comment and
leave it the same as it current is.

Add this macro to __libc_init and __start_thread.

Also, remove duplicate compilation of libc_init_static.cpp that already
includes the static library that includes that file.

Bug: 15469122

Test: Did unwinds using new unwinder tool (unwind) and debuggerd -b
Test: and verified new unwinder works on aarch64/x86/x86_64.
Test: Verified that it works on old unwinder for aarch64/x86, but
Test: x86_64 doesn't work properly, but as well as before.
Change-Id: I77302e8f6c7ba1549d98a4a164106ee82c9ecadc
2017-10-05 15:18:47 -07:00
Elliott Hughes
f1c568d1ea Add <glob.h>.
This is the FreeBSD implementation, plus some tests. The FreeBSD
implementation includes the GNU extensions and seems to be what
iOS is using too, which should provide bug compatibility for app
developers.

The code unfortunately uses a lot of stack, and uses FreeBSD locale
implementation that we don't have, but it does seem better maintained
than the other BSDs.

Bug: http://b/29251134
Test: ran tests
Change-Id: Ie477b45e42a6df1319b25712098519d2b33adf67
2017-09-26 18:46:09 -07:00
Dan Willemsen
7ccc50d2e4 Use an embedded linker for host bionic
The linux kernel requires that the ELF interpreter (runtime linker)
that's referenced by PT_INTERP be either an absolute path, or a relative
path from the current working directory. We'd prefer a relative path
from the binary, similarly to how we handle looking up shared libraries,
but that's not supported.

Instead, extract the LOAD segments from the runtime linker ELF binary
and embed them into each host bionic binary, omitting the PT_INTERP
declaration. The kernel will treat it as a static binary, and we'll use
a special entry point (linker_wrapper) to fix up the arguments passed by
the kernel before jumping to the embedded linker. From the linker's
point of view, it looks like the kernel loaded the linker like normal.

Bug: 31559095
Test: Enable host bionic, build and run libdemangle_test
Change-Id: I1753401ef91eecbf0ae3376faca31eec1c53842b
2017-09-20 13:59:13 -07:00
Treehugger Robot
7e6f98b93d Merge "Remove clang: true" 2017-09-11 21:39:41 +00:00
Lennart Wieboldt
2286b9f5ae Remove clang: true
clang is the default compiler since Android nougat

Test: mma & verified it´s still build with clang
Change-Id: Id8b5361d18c1b2febb2dc6cc44502feaa08f605c
Signed-off-by: Lennart Wieboldt <lennart.1997@gmx.de>
2017-09-11 21:43:58 +02:00
Elliott Hughes
4c9d528a25 Merge "Finish <search.h>." 2017-09-11 18:39:30 +00:00
Jayant Chowdhary
ab2f79c0da For devices which are not treble enabled, return the system shell.
For treble enabled devices, still return the appropriate shell depending
on whether the process is a vendor process or a system one.

Test: Manual testing: on a bullhead device, ran test programs from
      /vendor/bin which used popen() and system(). The calls succeeded.

Bug: 65054230

Bug: 64516799

Merged-In: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e
Change-Id: I15dfdbb107cfca7c0f92f337c9bb46b9876eb38e
(cherry picked from commit 1e52871773)
2017-09-07 17:19:21 -07:00
Elliott Hughes
5702c6ff45 Finish <search.h>.
I'm unable to find a bug, but we've had requests for this internally
once or twice (though I pointed those folks at the STL), and there's
code we build for the host or in our bootloaders that would use this,
and there's reasonable-looking FreeBSD implementation ready and waiting.

Bug: N/A
Test: ran tests
Change-Id: I6ddee4b71bea4c22ed015debd31d3eaac4fcdd35
2017-08-31 17:38:51 -07:00
Elliott Hughes
a648733cb7 Implement <iconv.h>.
Bug: http://b/32978596
Test: ran tests
Change-Id: I56b6ae3d9c5a3a56d2b4afba33fb8f9e964bf7b9
2017-08-25 08:47:41 -07:00
Sandeep Patil
9b1ca569db libc: Add support to allow library calls to find appropriate shell executable for a process
Library calls like system() and popen() invoke the shell executable
pointed to by '_PATH_BSHELL' in order to run the command passed into the
function. The _PATH_BSHELL points to /system/bin/sh by default and thus
breaks any vendor process trying to use system() / popen(), as they are
denied access to system shell by selinux.

This CL make necessary changes, so the implmentations of system() and popen()
can use the appropriate shell (e.g. /vendor/bin/sh for processes running
out of /vendor partition). Also, changes the implementation of system()
and popen().

Bug: 64832610
Test: Manual, Using a test program running from /system/bin and
      /vendor/bin to ensure correct shell is being used.

Change-Id: Ie7168d69decb1ae98284446ae7db34dec930dc33
Merged-In: Ie7168d69decb1ae98284446ae7db34dec930dc33
Signed-off-by: Sandeep Patil <sspatil@google.com>
(cherry picked from commit aa3e32422c)
2017-08-22 10:17:28 -07:00
Tom Cherry
ac49cedc7e Always use CLOCK_MONOTONIC for pthreads and semaphores
pthread's and semaphore's default behavior is to use CLOCK_REALTIME,
however this behavior is essentially never intended, as that clock is
prone to change discontinuously.

What users really intend is to use CLOCK_MONOTONIC, however only
pthread_cond_timedwait() provides this as an option and even there, a
large amount of existing code does not opt into CLOCK_MONOTONIC.

We have seen numerous bugs directly attributable to this difference.
Therefore, we provide this general workaround to always use
CLOCK_MONOTONIC for waiting, regardless of what the input timespec
is.

Specifically this impacts the below APIs:
pthread_mutex_timedlock()
pthread_cond_timedwait()
pthread_rwlock_timedrdlock()
pthread_rwlock_timedwrlock()
sem_timedwait()

Test: boot bullhead, boot sailfish
Test: bionic pthread/semaphore unit tests
Test: check that pthread_cond_timedwait() timeouts are uneffected by
      CLOCK_REALTIME time changes

Bug: 64694413
Bug: 64623895
Bug: 35756266
Bug: 35678943
Change-Id: Ibba98f5d88be1c306d14e9b9366302ecbef6d534
2017-08-18 09:11:05 -07:00
Treehugger Robot
1db06faa38 Merge "libc: Split FORTIFY into its own headers" 2017-08-01 02:03:52 +00:00
Elliott Hughes
bafa1985ec Merge "Implement wcwidth(3) in terms of icu4c." 2017-07-28 21:42:13 +00:00
Elliott Hughes
c41b560f5f Implement wcwidth(3) in terms of icu4c.
Based on com.google.i18n.CharWidth by the icu-team folks.

Bug: N/A
Test: ran tests
Change-Id: Ia9d818ec4ae60f2f3978533195330d00699397c5
2017-07-27 17:08:24 -07:00
George Burgess IV
b97049c039 libc: Split FORTIFY into its own headers
This patch cleans up our standard headers by moving most of the FORTIFY
cruft out in to its own sandbox. In order to include the *_chk and
*_real declarations, you can either enable FORTIFY, or `#define
__BIONIC_DECLARE_FORTIFY_HELPERS`.

Both sys/select.h and strings.h are explicitly ignored by this patch.
Both of these files have very small __BIONIC_FORTIFY blocks, and don't
define any actual FORTIFY'ed functions (just macros, and 3 *_chk
functions).

This patch also makes the versioner ignore the FORTIFY implementation
headers, since we're guaranteed to pick the FORTIFY'ed headers up when
looking at the regular headers. (...Not to mention that making the
FORTIFY'ed headers freestanding would be annoying to do and maintain for
~no benefit).

We bake the knowledge of where FORTIFY headers live directly into the
versioner. We could go with a more general approach (e.g. adding an -X
IGNORED_FILE flag that tells the versioner to ignore
$HEADER_PATH/$IGNORED_FILE), but we'd then have to repeat that for every
test, every manual invocation of the versioner, etc. for no benefit
that's obvious to me.

Bug: 12231437
Test: m checkbuild on bullhead internal master + CtsBionicTestCases. no
new errors.

Change-Id: Iffc0cc609009b33d989cdaddde0a809282131a5b
2017-07-27 17:00:13 -07:00
Elliott Hughes
82e950c9fb Actually turn on -Werror for crtbegin.
And then -Wno-gcc-compat in the right place this time. (But leaving the
other one because I don't care in the non-crtbegin code either.)

Bug: N/A
Test: builds without warnings now
Change-Id: Id2cfa3392ee80c045644ebfdf92c6d341db90964
2017-07-27 16:39:02 -07:00
Treehugger Robot
4f36cabd8d Merge "libc: Move FORTIFY into one file; make style fixups" 2017-07-26 02:44:21 +00:00
George Burgess IV
d34b0a946c libc: Move FORTIFY into one file; make style fixups
This addresses post-commit feedback from
I88c39ca166bacde0b692aa3063e743bb046a5d2f. With this, our FORTIFY impl
now sits in one file.

Bug: 12231437
Test: mma; no new CtsBionicTestCases failures on bullhead internal
master.
Change-Id: I6f9ff81c3e86cf9d6a0efa650eb5765f1e2fa09c
2017-07-25 17:39:21 -07:00
Treehugger Robot
9306889509 Merge "Build crtbegin with clang too." 2017-07-25 21:03:26 +00:00
Elliott Hughes
b348d5cda8 Build crtbegin with clang too.
If _start_main is static, clang optimizes it out and then generates an
undefined reference from the inline assembler, so let's explicitly tell
the compiler it's used.

Bug: N/A
Test: ran tests
Change-Id: Iba3d9c63abae9a0dc32f236b01783515f0190956
2017-07-25 11:54:33 -07:00
Treehugger Robot
086b1b5a22 Merge "Split our FORTIFY implementation into libc_fortify" 2017-07-25 18:05:42 +00:00
George Burgess IV
6cb0687932 Split our FORTIFY implementation into libc_fortify
As requested in the bug. This also rips __memcpy_chk out of memcpy.S,
which lets us cut down on copypasta (all of the implementations look
identical).

Bug: 12231437
Test: mma on aosp_{arm,arm64,mips,x86,x86_64} internal master;
checkbuild on bullhead internal master; CtsBionicTestCases on bullhead.
No new failures.
Change-Id: I88c39ca166bacde0b692aa3063e743bb046a5d2f
2017-07-24 14:20:16 -07:00
Elliott Hughes
bff8da308f Merge "Replace fmemopen." 2017-07-24 20:36:16 +00:00
Elliott Hughes
57ad09278f Merge "Replace killpg." 2017-07-24 20:16:40 +00:00
Treehugger Robot
fd80e39546 Merge "Switch to FreeBSD for wcsstr and wmemcpy." 2017-07-24 19:23:36 +00:00
Elliott Hughes
3a4c45499e Replace fmemopen.
A new implementation starting from the FreeBSD fmemopen rather than the
OpenBSD one we used to use.

The tests were arrived at by translating each sentence in
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fmemopen.html,
plus http://man7.org/linux/man-pages/man3/fmemopen.3.html for historical
GNU bugs.

Bug: http://b/31304889
Test: ran tests
Change-Id: Id8b168c9ecde638e9cdedbc3b8a0982fc83c7048
2017-07-24 10:48:42 -07:00
Elliott Hughes
697f42afdb Hide various mbstate implementation details.
...by inlining them.

Also fix a couple of harmless bugs in passing. I've added tests, but in
both cases I don't think it was actually possible to hit the bad behavior:
we'd hit another test and fail immediately after in an externally
indistinguishable way.

Bug: N/A
Test: readelf
Change-Id: I8466050b0bfe2b7b94c76b383cf10c1d9d28debd
2017-07-14 17:00:05 -07:00
Elliott Hughes
20f3399956 Switch to FreeBSD for wcsstr and wmemcpy.
Almost all of our w* functions come from FreeBSD already. The one downside is
that we can't take all our w* functions from FreeBSD because FreeBSD handles
locales very differently from us.

Bug: N/A
Test: ran tests
Change-Id: I177b4332499992babd5d5afe5b3f469f8c4345a5
2017-07-13 09:45:00 -07:00
Dan Albert
2d585e0070 Merge changes from topic 'locale-android-support'
* changes:
  Add a non-TLS slot implementation of locale.cpp.
  Move non-locale.h APIs out of locale.cpp.
2017-07-13 08:34:57 +00:00
Dan Albert
e2fd01035b Move non-locale.h APIs out of locale.cpp.
libandroid_support only needs the locale.h stuff.

Test: make checkbuild
Bug: None
Change-Id: I0c53fe9d2df4f9ff4b99771727034508bc89cb32
2017-07-12 12:41:47 -07:00
Elliott Hughes
7532b32627 Replace killpg.
Upstream's killpg is diverging further from glibc behavior, so let's just fork.

Bug: N/A
Test: ran tests
Change-Id: I70a3543018bc0a5c0bbf019ac527043b90568fda
2017-07-11 15:00:17 -07:00
Victor Khimenko
0a0743f864 Move environ valiable into it's own file
Test: build statically the example program below

  char** environ;
  int main() {
  }

Change-Id: I3f01652da1d5063d92ba7cbff7fb09bd0a89325c
2017-07-10 21:44:17 +02:00
Stephen Crane
f4b1cbda4a Disable stack protector for __libc_preinit
__libc_preinit sets up the stack protector global cookie value, and thus
cannot intialize a stack protector cookie for itself in the function
prologue. LTO compilation can inline functions requiring a stack
protector into __libc_preinit. This patch disables stack protection for
__libc_preinit and forces all potentially inlined functions into a
helper that can have a stack protector.

Test: run bionic-unit-tests

Change-Id: I45911611190f216c91eb6feff722967214c5f99f
2017-06-21 23:53:46 +00:00
Elliott Hughes
5059939c87 Enable exporting the non-uapi scsi headers.
Callers are supposed to #include <scsi/sg.h> but if we tell soong to add
bionic/libc/kernel/android/ to the include path, the uapi headers in there
would be (unintentionally) accessible as either <linux/name.h> or
<uapi/linux/name.h>.

Bug: N/A (hit while upgrading strace to 4.17)
Test: builds
Change-Id: I8d47dd51da688c38f747a255d401dfb2c209c805
2017-05-25 19:17:55 -07:00
Elliott Hughes
94072fbb4e Switch to inline assembler in crtbegin.
Using __builtin_frame_address was clever, but didn't work for arm64 (for
reasons which were never investigated) and the ChromeOS folks claim it
causes trouble for x86 with ARC++ (though without a reproduceable test case).

Naked functions turn out to be quite unevenly supported: some architectures
do the right thing, others don't; some architectures warn, others don't (and
the warnings don't always match the platforms that _actually_ have problems).

Inline assembler also removes the guessing games: everyone knows what the
couple of instructions _ought_ to be, and now we don't have to reason about
what the compiler will actually do (yet still keep the majority of the code
in C).

Bug: N/A
Test: builds, boots
Change-Id: I14207ef50ca46b6eca273c3cb7509c311146a3ca
2017-05-23 14:47:16 -07:00
Christopher Ferris
94bd274551 Add support for cortex-a73.
Bug: 37647380

Test: Built target with cortex-a73 for both 32 bit/64 bit.
Test: Built target with cortex-a53.cortex-a57 for both 32 bit/64 bit.
Test: Ran bionic unit tests, ran art target tests.

(cherry picked from commit 6fca047b53)

Change-Id: I2c48e1bc7f4a3c4548d1c66f87eab19c8618a0b8
2017-05-15 12:44:58 -07:00
Christopher Ferris
7a3681e5b6 Move libc_log code into libasync_safe.
This library is used by a number of different libraries in the system.
Make it easy for platform libraries to use this library and create
an actual exported include file.

Change the names of the functions to reflect the new name of the library.

Run clang_format on the async_safe_log.cpp file since the formatting is
all over the place.

Bug: 31919199

Test: Compiled for angler/bullhead, and booted.
Test: Ran bionic unit tests.
Test: Ran the malloc debug tests.
Change-Id: I8071bf690c17b0ea3bc8dc5749cdd5b6ad58478a
2017-05-03 08:50:43 -07:00
Elliott Hughes
2fad0d5927 Include the libc/kernel/android/scsi headers in the NDK.
We have some non-upstream (but Android common kernel) scsi headers to include
in the NDK.

Bug: N/A
Test: checked out/soong/ndk/sysroot
Change-Id: If7611e1e554ada63f266ec99d95dfedb99562ae9
2017-04-27 16:26:55 -07:00
Jake Weinstein
04d99df80d libc: ARM: Add 32-bit Kryo memcpy
* Memcpy is based on Scorpion due to Qualcomm's
  128-bit cache line size optimizations.

* PLDOFFSET and PLDSIZE are from the ARM64 Kryo memcpy routine.

Below are the results of the benchmark, tested on a OnePlus 3 with MSM8996.

Before:
BM_string_memcpy/8                          1000k          8    0.934 GiB/s
BM_string_memcpy/64                         1000k         11    5.785 GiB/s
BM_string_memcpy/512                        1000k         25   19.918 GiB/s
BM_string_memcpy/1024                         50M         42   23.938 GiB/s
BM_string_memcpy/8Ki                          10M        473   17.291 GiB/s
BM_string_memcpy/16Ki                          5M        565   28.976 GiB/s
BM_string_memcpy/32Ki                       1000k       1105   29.631 GiB/s
BM_string_memcpy/64Ki                       1000k       2194   29.864 GiB/s

After:
BM_string_memcpy/8                          1000k          6    1.145 GiB/s
BM_string_memcpy/64                         1000k          7    8.560 GiB/s
BM_string_memcpy/512                        1000k         18   27.370 GiB/s
BM_string_memcpy/1024                         50M         33   30.340 GiB/s
BM_string_memcpy/8Ki                          10M        266   30.770 GiB/s
BM_string_memcpy/16Ki                          5M        553   29.599 GiB/s
BM_string_memcpy/32Ki                       1000k       1121   29.219 GiB/s
BM_string_memcpy/64Ki                       1000k       2208   29.678 GiB/s

Test: make otapackage
Test: Ran bionic unit tests on Pixel device. Verified memcpy wins on
Test: Pixel device.

Change-Id: Id7a9c37ef75a306dd5cf8d374d79d0fe83f8a3ba
2017-04-13 11:18:56 -07:00
Jake Weinstein
4d114f9e21 libc: use Cortex-A7/A53 memset on Kryo
Tested on OnePlus 3 with MSM8996

Before (Krait):
BM_string_memset/8                          1000k          7    1.071 GiB/s
BM_string_memset/64                         1000k          9    6.720 GiB/s
BM_string_memset/512                        1000k         19   26.699 GiB/s
BM_string_memset/1024                       1000k         29   34.214 GiB/s
BM_string_memset/8Ki                          10M        184   44.302 GiB/s
BM_string_memset/16Ki                          5M        351   46.656 GiB/s
BM_string_memset/32Ki                          5M        686   47.744 GiB/s
BM_string_memset/64Ki                       1000k       1355   48.342 GiB/s

After (A7/A53):
BM_string_memset/8                          1000k          7    1.017 GiB/s
BM_string_memset/64                         1000k          7    8.039 GiB/s
BM_string_memset/512                        1000k         13   37.976 GiB/s
BM_string_memset/1024                       1000k         21   47.595 GiB/s
BM_string_memset/8Ki                          10M        150   54.354 GiB/s
BM_string_memset/16Ki                         10M        285   57.336 GiB/s
BM_string_memset/32Ki                          5M        555   59.016 GiB/s
BM_string_memset/64Ki                       1000k       1097   59.720 GiB/s

Test: make otapackage
Test: Verified this wins in all dimensions on a Pixel device.

Change-Id: I4cb72cc0363877de7c41d6f991149fda42fd0b4b
2017-04-12 14:58:29 -07:00
Treehugger Robot
21d4a9ac6b Merge "Move localtime.c over to CachedProperty." 2017-04-12 18:15:53 +00:00
Dan Willemsen
230a7a44ce Mark CRT objects as vendor available
This will build separate copies of the CRT for vendor vs system when
BOARD_VNDK_VERSION is set. We'll be able to change crtbrand / etc as
needed with #ifdef __ANDROID_VNDK__ and similar.

Bug: 36426473
Bug: 36079834
Test: Put #ifdef __ANDROID_VNDK__ into crtbrand.S, see changes
Change-Id: I7db0cccfe94d144f072e7cef23832884f3c066f0
2017-04-12 00:06:47 +00:00
Elliott Hughes
0e8616a37a Move localtime.c over to CachedProperty.
Since localtime.c is C, this entails pulling our code out into its own
C++ file, which we should probably have done years ago anyway.

Bug: N/A
Test: ran tests, and manually tested via Settings
Change-Id: Ifc787a553e8f739a87641a2d35321aca40a47286
2017-04-11 14:44:51 -07:00