Commit graph

1543 commits

Author SHA1 Message Date
Mitch Phillips
3d577a836d Merge "Add the recoverable GWP-ASan feature." 2023-02-03 18:35:08 +00:00
Mitch Phillips
a493fe4153 Add the recoverable GWP-ASan feature.
GWP-ASan's recoverable mode was landed upstream in
https://reviews.llvm.org/D140173.

This mode allows for a use-after-free or a buffer-overflow bug to be
detected by GWP-ASan, a crash report dumped, but then GWP-ASan (through
the preCrashReport() and postCrashReportRecoverableOnly() hooks) will
patch up the memory so that the process can continue, in spite of the
memory safety bug.

This is desirable, as it allows us to consider migrating non-system apps
from opt-in GWP-ASan to opt-out GWP-ASan. The major concern was "if we
make it opt-out, then bad apps will start crashing". If we don't crash,
problem solved :). Obviously, we'll need to do this with an amount of
process sampling to mitigate against the 70KiB memory overhead.

The biggest problem is that the debuggerd signal handler isn't the first
signal handler for apps, it's the sigchain handler inside of libart.
Clearly, the sigchain handler needs to ask us whether the crash is
GWP-ASan's fault, and if so, please patch up the allocator. Because of
linker namespace restrictions, libart can't directly ask the linker
(which is where debuggerd lies), so we provide a proxy function in libc.

Test: Build the platform, run sanitizer-status and various test apps
with recoverable gwp-asan. Assert that it doesn't crash, and we get a
debuggerd report.
Bug: 247012630

Change-Id: I86d5e27a9ca5531c8942e62647fd377c3cd36dfd
2023-02-02 15:35:25 -08:00
Vincent Donnefort
2efa017409 linker: Fallback to argv[0] to get the executable info
Enable linking on a system without /proc mounted by falling back to
reading the executable paths from argv[0] when /proc/exe/self can't be
found.

Bug: 254835242
Change-Id: I0735e873fa4e2f439688722c4a846fb70ff398a5
2023-01-25 16:34:43 +00:00
Florian Mayer
eae797db66 Merge "Plumb scudo_ring_buffer_size to debuggerd_process_info" 2023-01-10 21:23:33 +00:00
Florian Mayer
347dc623ec Plumb scudo_ring_buffer_size to debuggerd_process_info
This is a no-op but will be used in upcoming scudo changes that allow to
change the buffer size at process startup time, and as such we will no
longer be able to call __scudo_get_ring_buffer_size in debuggerd.

Bug: 263287052
Change-Id: I18f166fc136ac8314d748eb80a806defcc25c9fd
2023-01-05 14:07:22 -08:00
huangchaochao
bdc3796a87 linker: Fix memory leak for reserved memory
When loading a dynamic library, reserved memory is successful, but fail in other steps, such as loading segments, which will generate a memory leak. Because the reserved memory is not released in time.

Bug: https://issuetracker.google.com/issues/263713888

Change-Id: I556ee02e37db5259df0b6c7178cd9a076dab9725
Signed-off-by: huangchaochao <huangchaochao@bytedance.com>
2022-12-29 15:48:41 +08:00
Jooyung Han
57b03decd1 linker_namespace: move sonames instead of copying
android_namespace_link_t::shared_lib_sonames_ is unorderd_set<string>.
When initializing, it's copied a few times unnecessarily.
- when add_linked_namespace is called
- when android_namespace_link_t() is called
- when push_back is called.

Now, it's moved around after the initial creation.

Bug: n/a
Test: atest --test-mapping .
Change-Id: I283954bb0c0bbf94ebd74407137f492e08fd41bd
2022-12-01 16:23:03 +09:00
Martin Stjernholm
4c4015b3cc Remove stale TODO.
As of https://r.android.com/2304013 classloader namespaces are no
longer called "classloader-namespace". However, this whole TODO is
stale - it was supposed to be addressed in O and it only applies to
compat code for SDK < 24, so there is no use fixing it now.

Test: N/A - comment change only
Bug: 258340826
Change-Id: Id09e262191cea236224196a4a4268331d5cf84c6
2022-11-18 13:54:14 +00:00
Ulya Trafimovich
b973c756a0 Correctly print RISC-V arch name on error when verifying ELF header.
Test: enable debug logging, observe EM_RISCV printed in dlopen error
message instead of default EM_???.

Change-Id: Ieed5bd3eecc5d4093ffcb40558c554bb747e7a4b
2022-11-15 15:18:33 +00:00
Elliott Hughes
3e4f603c7f riscv64: build the linker.
The only meaningful change from alibaba's version is jr instead of jalr.

Also fix the comment that's in all the begin.S files while we're here.

Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
Signed-off-by: Xia Lifang <lifang_xia@linux.alibaba.com>
Signed-off-by: Chen Guoyin <chenguoyin.cgy@linux.alibaba.com>
Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
Signed-off-by: Lu Xufan <luxufan@iscas.ac.cn>
Test: ran mksh
Change-Id: I2645c78bd700b8a55bde363600d7f8b87de641a1
2022-10-22 03:57:11 +00:00
Elliott Hughes
43462707a1 riscv64 TLS support.
Signed-off-by: Mao Han <han_mao@linux.alibaba.com>
Signed-off-by: Xia Lifang <lifang_xia@linux.alibaba.com>
Signed-off-by: Chen Guoyin <chenguoyin.cgy@linux.alibaba.com>
Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
Signed-off-by: Lu Xufan <luxufan@iscas.ac.cn>
Test: treehugger
Change-Id: I14efb4a03a3dc2ec736d7e47a3f8859c886eb9d6
2022-10-10 20:30:24 +00:00
Martin Stjernholm
964b14c299 Improve a debug message to log a more useful namespace.
The two namespaces are often the same, but if they aren't the old
message could be confusing and not very helpful.

#codehealth

Test: Build and boot with `LinkerLogger::flags_ = kLogDlopen` and check
      logcat
Change-Id: I61a78d40f1eb5c074772e3c113a1055d3e915cb1
2022-09-30 20:52:58 +01:00
Jiyong Park
7157dfbfe7 Use liblog_for_runtime_apex instead of liblog
liblog_for_runtime_apex is a static variant of liblog which is
explicitly marked as available to the runtime APEX. Any static
dependency to liblog from inside the runtime APEX is changed from liblog
to liblog_for_runtime_apex.

Previously, to support the need for using liblog inside the runtime
APEX, the entire (i.e. both static and shared variants) liblog module
was marked as available to the runtime APEX, although in reality only
the static variant of the library was needed there. This was not only
looking dirty, but also has caused a problem like b/241259844.

To fix this, liblog is separated into two parts. (1) liblog and (2)
liblog_for_runtime_apex. (1) no longer is available to the runtime APEX
and is intended to be depended on in most cases: either from the
non-updatable platform, or from other APEXes. (2) is a static library
which is explicitly marked as available to the runtime APEX and also
visible to certain modules that are included in the runtime APEX.

Bug: 241259844
Test: m and check that liblog depends on stub library of libc
Change-Id: Ib21f6e64da0c7592341b97b95ca8485d7c29ac4d
2022-08-19 13:09:18 +09:00
Christopher Ferris
d37df2b638 Add the .debug_frame for arm32.
As with libc.so, add the debug frame into the linker for arm32
to make any crashes unwindable.

Bug: 242162222

Test: Forced a crash on wembley where an unwind failed before and
Test: verified it unwinds properly with the debug frame.
Change-Id: I2b904af63f670b038d169f5a7d907637b352ab4e
2022-08-11 17:39:43 -07:00
Treehugger Robot
39de8b944e Merge "Basic support for MTE stack tagging." 2022-05-27 02:15:53 +00:00
Evgenii Stepanov
f9fa32acf3 Basic support for MTE stack tagging.
Map all stacks (primary, thread, and sigaltstack) as PROT_MTE when the
binary requests it through the ELF note.

For the reference, the note is produced by the following toolchain changes:
https://reviews.llvm.org/D118948
https://reviews.llvm.org/D119384
https://reviews.llvm.org/D119381

Bug: b/174878242
Test: fvp_mini with ToT LLVM (more tests in a separate change)

Change-Id: I04a4e21c966e7309b47b1f549a2919958d93a872
2022-05-26 16:18:53 -07:00
Suchang Woo
119765415a Fix it to call the lambda function
The lambda function is converted to bool instead of being called. So,
get_transparent_hugepages_supported() returns always true.

Test: check whether /sys/kernel/mm/transparent_hugepage/enabled is
accessed via strace.
Bug: http://b/233137490
Signed-off-by: Suchang Woo <suchang.woo@samsung.com>
Change-Id: I88b0d18d8ceb2300482043391eed4ae7041866ca
2022-05-19 02:13:39 +00:00
Jiyong Park
2bac1f81c1 Deprecate "/apex/<name>/ld.config.txt
The file is a manually created linker config file for the binaries in
the APEX. This is discouraged since such a manually created linker
config is error-prone and hard to maintain. Since the per-APEX
linker config file is automatically created by the linkerconfig tool as
/linkerconfig/<name>/ld.config.txt, we can safely deprecated the
fallback path.

There currently are two APEXes using these hand-crafted configs. They
can (and should) keep the configs for backwards compatibility; in case
when they run on older devices where the auto-generated configs are not
available. But for newer platforms, the files are simply ignored and no
new APEX should be using that.

Bug: 218933083
Test: m
Change-Id: I84bd8850b626a8506d53af7ebb86b158f6e6414a
2022-04-05 14:07:48 +09:00
Florian Mayer
6e8f3a76ee Extempt calculate_gnu_hash_neon from hwasan.
Bug: 227630703
Change-Id: I525c99796c87252050b46faffb3058f7e8b5866c
2022-03-31 22:46:54 +00:00
Ryan Prichard
df41909cf6 Merge "Always process TLS relocs using general code path" 2022-03-28 19:19:12 +00:00
Ryan Prichard
8ea6af53e2 Always process TLS relocs using general code path
This is important for enabling the error about unsupported TLS
relocations to local symbols. The fast path tends to skip this error,
because it fails during lookup_symbol(). Add a test for this error.

I didn't see a performance regression in the linker_relocation
benchmark.

Bug: http://b/226978634
Test: m bionic-unit-tests
Change-Id: Ibef9bde2973cf8c2d420ecc9e8fe2c69a5097ce2
2022-03-25 15:51:11 -07:00
Treehugger Robot
8397fadb2e Merge "Add DF_1_ORIGIN to SUPPORTED_DT_FLAGS_1." 2022-03-22 20:25:30 +00:00
Peter Collingbourne
7aa3abc781 Add DF_1_ORIGIN to SUPPORTED_DT_FLAGS_1.
This flag means "$ORIGIN processing required", and since we always
do that, we can claim support for it.

Change-Id: If60ef331963f6bc1e1818d7fa2ee57c1aa8fa343
2022-03-21 19:02:26 -07:00
Colin Cross
da446cc5cc Tweak linux_glibc properties for musl builds in bionic
For convenience, builds against musl libc currently use the
linux_glibc properties because they are almost always linux-specific
and not glibc-specific.  In preparation for removing this hack,
tweak the linux_glibc properties by either moving them to host_linux,
which will apply to linux_glibc, linux_musl and linux_bionic, or
by setting appropriate musl or linux_musl properties.  Properties
that must not be repeated while musl uses linux_musl and also still
uses the linux_glibc properties are moved to glibc properties, which
don't apply to musl.  Whether these stay as glibc properties or get
moved back to linux_glibc later once the musl hack is removed is TBD.

Bug: 223257095
Test: m checkbuild
Test: m USE_HOST_MUSL=true host-native
Change-Id: I809bf1ba783dff02f6491d87fbdc9fa7fc0975b0
2022-03-08 15:07:57 -08:00
Eric Miao
08cf949855 Change default block size alignment to be 4 for memory saving on 32-bit arch
For a 32-bit userspace, `struct LinkedListEntry` takes 8 bytes for
storing the two pointers, a default block allocator size alignment of
16-bytes would waste 50% of memory. By changing the alignment to size
of a pointer, it saves >1MB memory postboot on wembley device.

Bug: http://b/206889551
Test: bionic-unit-tests
Change-Id: Ie92399c9bb3971f631396ee09bbbfd7eb17dc1a7
2022-02-03 16:55:37 -08:00
Eric Miao
fbee3177af Keep allocation of tail_ outside of LinkedList
This change is to allocate `head_` and `tail_` outside of LinkedList
and only keep a readonly pointer there. By doing this, all updates
of the list touches memory other than the LinkedList itself, thus
preventing copy-on-write pages being allocated in child processes
when the list changes.

The other approach is to make the LinkedList a singly-linked list,
however, that approach would cause a full list traversal to add
one item to the list. And preliminary number shows there are ~60K
calls to `soinfo::add_secondary_namespace` during Android bootup
on a wembley device, where a singly-linked approach could be
hurting performance.

NOTE: the header is allocated and initialized upon first use instead
of being allocated in the constructor, the latter ends up in crash.
This is likely caused by static initialization order in the linker,
e.g. g_soinfo_list_allocator is a static object, and if this linked
list is embedded into some other static objects, there's no guarantee
the allocator will be available.

Bug: http://b/206889551
Test: bionic-unit-tests
Change-Id: Ic6f053881f85f9dc5d249bb7d7443d7a9a7f214f
2022-02-01 21:32:30 -08:00
Yi Kong
e20a1d9060 Move linker from sampling PGO to AFDO pipeline
Sampling PGO is being replaced by AFDO.

Test: presubmit
Change-Id: I23e4dace5f2c2d1f2499daba99a28b2a1bc0f22d
2022-01-25 03:19:58 +08:00
Yi Kong
9e33b76c67 Re-enable LTO for linker
Clang cannot build ifunc with LTO. This is a KI: https://bugs.llvm.org/show_bug.cgi?id=46488

Move the LTO: never down to libc itself, so that we can have LTO for the
rest of linker.

Test: m GLOBAL_THINLTO=true linker
Change-Id: I483fc3944e340638a664fb390279e211c2ae224b
2021-11-04 01:03:11 +08:00
Christopher Parsons
39c2776fff Merge "Remove bazel_module stanzas from bionic/linker" 2021-10-01 22:11:52 +00:00
Chris Parsons
ebe5e5f7d4 Remove bazel_module stanzas from bionic/linker
This also effectively re-enables linker_wrapper, which may have been
independently fixed some time ago.

Test: mixed_droid.sh
Change-Id: I9bc7e099fe3c5da1c4da12c79128baf6f807354a
2021-10-01 16:06:38 -04:00
Colin Cross
0cc60afa33 Add more tests to TEST_MAPPING
Test: treehugger
Change-Id: I1d7dd32fd7f90a20d61de4701293527f83dc4ec4
2021-10-01 09:25:36 -07:00
Peter Collingbourne
563e60e32a Merge "Reland "Use the dynamic table instead of __rela?_iplt_* to find the linker's IRELATIVE relocs." with a fix." 2021-08-26 22:11:31 +00:00
Peter Collingbourne
1583cd286e Reland "Use the dynamic table instead of __rela?_iplt_* to find the linker's IRELATIVE relocs." with a fix.
A recent change to lld [1] made it so that the __rela?_iplt_*
symbols are no longer defined for PIEs and shared libraries. Since
the linker is a PIE, this prevents it from being able to look up
its own relocations via these symbols. We don't need these symbols
to find the relocations however, as their location is available via
the dynamic table. Therefore, start using the dynamic table to find
the relocations instead of using the symbols.

Previously landed in r.android.com/1801427 and reverted in
r.android.com/1804876 due to linux-bionic breakage. This time,
search .rela.dyn as well as .rela.plt, since the linker may put the
relocations in either location (see [2]).

[1] f8cb78e99a
[2] https://reviews.llvm.org/D65651

Bug: 197420743
Change-Id: I5bef157472e9893822e3ca507ef41a15beefc6f1
2021-08-26 11:48:19 -07:00
Treehugger Robot
957d6d513e Merge "Revert "Use the dynamic table instead of __rela?_iplt_* to find the linker's IRELATIVE relocs."" 2021-08-26 02:03:28 +00:00
ycheo
e5570c5dfe Revert "Use the dynamic table instead of __rela?_iplt_* to find the linker's IRELATIVE relocs."
This reverts commit 65bdf655c4.

Reason for revert: checking the failure of avd/avd_boot_test
Bug: 197781964
Change-Id: I70eb03b45cdfbd87ef6edb03b74ad6d1970dc08c
2021-08-26 00:31:51 +00:00
Treehugger Robot
9f99a046b9 Merge "Export memalign to linker" 2021-08-25 02:14:15 +00:00
Peter Collingbourne
65bdf655c4 Use the dynamic table instead of __rela?_iplt_* to find the linker's IRELATIVE relocs.
A recent change to lld [1] made it so that the __rela?_iplt_*
symbols are no longer defined for PIEs and shared libraries. Since
the linker is a PIE, this prevents it from being able to look up
its own relocations via these symbols. We don't need these symbols
to find the relocations however, as their location is available via
the dynamic table. Therefore, start using the dynamic table to find
the relocations instead of using the symbols.

[1] f8cb78e99a

Change-Id: I4a12ae9f5ffd06d0399e05ec3ecc4211c7be2880
2021-08-20 12:07:53 -07:00
Matthew Maurer
2411a5e789 Export memalign to linker
In order to support demangling of rust symbols by the linker, we are
adding a small Rust component. Rust expects `memalign` to be present in
hosted environments, and it doesn't appear costly to enable it.

Bug: 178565008
Test: m, killall -11 keystore2 produced mangled names in tombstone
Change-Id: I8fc749000fa02a3b760c8cc55be3348b9964d931
2021-08-17 15:08:49 -07:00
Colin Cross
331b3887f4 Remove host_bionic_inject
Now that linker_wrapper.o does not use objcopy --prefix-symbols=__dlwrap_
it can reference the _start symbol of the original binary without
colliding with its own __dlwrap__start symbol, which means
host_bionic_inject is no longer necessary.

Test: build and run host bionic binary
Change-Id: I1752efa39fa73a092fab039771bf59c99b7b5974
2021-06-14 12:25:05 -07:00
Colin Cross
a0a591a714 Don't use prefix_symbols for host bionic linker wrapper
The only symbol that actually needs a prefix to avoid a collision is
_start, and that can be handled with a copy of begin.S that uses a
"#define" to rename _start to __dlwrap__start. Removing the prefixed
symbols will also allow simplifying the host bionic build process by
letting it directly reference the real _start.

Test: build and run host bionic binary
Change-Id: I50be786c16fe04b7f05c14ebfb74f710c7446ed9
2021-06-14 12:24:25 -07:00
Collin Fijalkovich
13d267e77e Merge "Add cc_defaults for hugepage alignment of shared libraries" 2021-05-11 16:13:58 +00:00
Collin Fijalkovich
47d27aa79c Bionic: Mark PMD aligned text segments huge page eligible
To take advantage of file-backed huge pages for the text segments of key
shared libraries (go/android-hugepages), the dynamic linker must load
candidate ELF files at an appropriately aligned address and mark
executable segments with MADV_HUGEPAGE.

This patches uses segments' p_align values to determine when a file is
PMD aligned (2MB alignment), and performs load operations accordingly.

Bug: 158135888
Test: Verified PMD aligned libraries are backed with huge pages on
supporting kernel versions.

Change-Id: Ia2367fd5652f663d50103e18f7695c59dc31c7b9
2021-05-06 13:15:11 -07:00
Collin Fijalkovich
c9521e08ce Add cc_defaults for hugepage alignment of shared libraries
Introduces a cc_defaults category hugepage_aligned that passes the
requisite linker flags to produce shared object files with 2MB-aligned
sections. This enables supporting platforms to back the text segments of
these libraries with hugepages.

Bug: 158135888
Test: Built and confirmed ELF layout
Change-Id: I5c8ce35d8f8bf6647ec19d58398740bd494cc89c
2021-04-29 11:32:43 -07:00
Jingwen Chen
c57947860d bp2build: remove some bp2build_available props, use package_allowlist instead.
Test: build/bazel/scripts/milestone-2/demo.sh full

Test: bazel query //bionic/...
Change-Id: I737574766be898279d8bf6f3f0adb43dcc40c220
2021-03-19 02:06:27 -04:00
Peter Collingbourne
03e961e392 Merge "Teach debuggerd to pass the secondary ring buffer to __scudo_get_error_info()." 2021-03-11 01:15:49 +00:00
Peter Collingbourne
6ba27e04df Merge "Add some slack at the end of large allocations when target SDK level < S." 2021-03-09 01:15:54 +00:00
Peter Collingbourne
2659d7b6c2 Add some slack at the end of large allocations when target SDK level < S.
This works around buggy applications that read a few bytes past the
end of their allocation, which would otherwise cause a segfault with
the concurrent Scudo change that aligns large allocations to the right.

Because the implementation of
android_set_application_target_sdk_version() lives in the linker,
we need to introduce a hook so that libc is notified when the target
SDK version changes.

Bug: 181344545
Change-Id: Id4be6645b94fad3f64ae48afd16c0154f1de448f
2021-03-05 14:29:17 -08:00
Pete Bentley
557308c732 Ignore LD_LIBRARY_PATH when determining file type in ldd.
Otherwise if a 32bit copy of a library used by Toybox
exists on LD_LIBRARY_PATH then file(1) will fail.

Bug: 181666541
Test: Manually copied to device and verified correct behaviour
Change-Id: I7d729927b1b433ec953c266920489613fc096e03
2021-03-02 16:56:39 +00:00
Bob Badour
aa7d835fdd Add LOCAL_LICENSE_KINDS to bionic
Added SPDX-license-identifier-Apache-2.0 to:
  apex/Android.bp
  libdl/Android.bp
  tools/Android.bp
  tools/versioner/Android.bp
  tools/versioner/src/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  benchmarks/Android.bp
  benchmarks/linker_relocation/gen/Android.bp
  libc/malloc_debug/Android.bp
  libc/system_properties/Android.bp
  tests/Android.bp
  tests/libs/Android.bp
  tests/libs/Android.build.dlext_testzip.mk
  tests/make_fortify_compile_test.mk

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-ISC SPDX-license-identifier-MIT
    legacy_notice legacy_unencumbered
to:
  libc/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-MIT legacy_unencumbered
to:
  libm/Android.bp

Added SPDX-license-identifier-Apache-2.0 legacy_unencumbered
to:
  libc/tools/Android.bp

Added SPDX-license-identifier-BSD
to:
  benchmarks/linker_relocation/Android.bp
  benchmarks/spawn/Android.bp
  libc/async_safe/Android.bp
  libc/malloc_hooks/Android.bp
  libfdtrack/Android.bp
  linker/Android.bp
  tests/headers/Android.bp
  tests/headers/posix/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all
Exempt-From-Owner-Approval: janitorial work
Change-Id: Ib05bcaa276b3aa71a7654ccbe8e67e1f16aec9f3
2021-02-19 23:38:28 +00:00
Rupert Shuttleworth
a7e29a8823 Rename ldd input file to ldd.sh to make Bazel conversion easier.
Test: m and bp2build write; bazel build ...
Change-Id: Ic8a4ad6ac81f034ac8b9736d99a322c48598619e
2021-02-18 23:41:55 +00:00
Elliott Hughes
332065d57e Merge "Fix/update notices." 2021-02-17 17:51:06 +00:00
Bob Badour
22801c7c8d Merge "Revert "[LSC] Add LOCAL_LICENSE_KINDS to bionic"" 2021-02-17 01:59:45 +00:00
Elliott Hughes
aa8db1b9d1 Fix/update notices.
Auto-generate NOTICE files for all the directories, and for each one
individually rather than mixing libc and libm together.

Test: N/A
Change-Id: I7e251194a8805c4ca78fcc5675c3321bcd5abf0a
2021-02-16 15:06:50 -08:00
Elliott Hughes
5e44c22ebf Revert "[LSC] Add LOCAL_LICENSE_KINDS to bionic"
This reverts commit 48d43034d7.

Reason for revert: bionic is multiple projects, not just one.

Change-Id: Ib31e1bb8888cc85c6e7736c4e2a1d4652fd23935
2021-02-16 20:02:47 +00:00
Rupert Shuttleworth
a4583b7af3 Mark ldd as executable for Bazel builds to work.
Test: bazel build ...
Change-Id: I15f23804ab1ef44cc0a68b66c408dd88366f8098
2021-02-16 15:28:25 +00:00
Bob Badour
48d43034d7 [LSC] Add LOCAL_LICENSE_KINDS to bionic
Added SPDX-license-identifier-Apache-2.0 to:
  libdl/Android.bp
  tools/versioner/src/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD to:
  benchmarks/Android.bp
  libc/malloc_debug/Android.bp
  libc/system_properties/Android.bp
  linker/Android.bp
  tests/Android.bp
  tests/libs/Android.bp
  tests/libs/Android.build.dlext_testzip.mk
  tests/make_fortify_compile_test.mk

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-ISC SPDX-license-identifier-MIT
    legacy_notice legacy_unencumbered
to:
  Android.bp
  libc/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-ISC SPDX-license-identifier-MIT
    legacy_unencumbered
to:
  tools/Android.bp
  tools/versioner/Android.bp

Added SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-BSD
    SPDX-license-identifier-MIT legacy_unencumbered
to:
  libm/Android.bp

Added SPDX-license-identifier-Apache-2.0 legacy_unencumbered
to:
  libc/tools/Android.bp

Added SPDX-license-identifier-BSD
to:
  benchmarks/linker_relocation/Android.bp
  benchmarks/spawn/Android.bp
  libc/async_safe/Android.bp
  libc/malloc_hooks/Android.bp
  libfdtrack/Android.bp
  tests/headers/Android.bp
  tests/headers/posix/Android.bp

Added legacy_notice
to:
  apex/Android.bp
  benchmarks/linker_relocation/gen/Android.bp

Bug: 68860345
Bug: 151177513
Bug: 151953481

Test: m all

Exempt-From-Owner-Approval: janitorial work
Change-Id: I76cad00578b9b99180ee5dd1e04b4646d5c5fedf
2021-02-12 17:51:24 -08:00
Peter Collingbourne
2753fc8ee5 Teach debuggerd to pass the secondary ring buffer to __scudo_get_error_info().
With this change we can report memory errors involving secondary
allocations. Update the existing crasher tests to also test
UAF/overflow/underflow on allocations with sizes sufficient to trigger
the secondary allocator.

Bug: 135772972
Change-Id: Ic8925c1f18621a8f272e26d5630e5d11d6d34d38
2021-02-12 12:30:52 -08:00
Rupert Shuttleworth
344b8da46a Mark sh_binary target as being bp2build_available.
Test: build/bazel/scripts/bp2build-sync.sh write.
Change-Id: I8e8c3c95aa2c7ff6d7db3d92291f224bdf7cf255
2021-02-09 11:53:36 +00:00
Ryan Prichard
ef1478765d Fix -Wl,--exclude-libs typo: x86->i686
These lines shouldn't actually matter, because the DSOs are using
version scripts to allow-list exported symbols.

Bug: none
Test: bionic unit tests
Change-Id: I39d3df8c4f8053624f862b3c6994e30c693e928c
2021-01-28 15:41:47 -08:00
Ryan Prichard
058eb8fa4e Ensure same order of global group members in all NS's
During "step 1" of find_libraries, the linker finds the transitive
closure of dependencies, in BFS order. As it finds each library, it
adds the library to its primary namespace (so that, if some other
library also depends on it, find_loaded_library_by_soname can find the
library in the process of being loaded).

LD_PRELOAD libraries are automatically marked DF_1_GLOBAL, and any
DF_1_GLOBAL library is added to every linker namespace. Previously,
this secondary namespace registration happened after step 1. The result
is that across different namespaces, the order of libraries could vary.
In general, a namespace's primary members will all appear before
secondary members. This is undesirable for libsigchain.so, which we
want to have appear before any other non-preloaded library.

Instead, when an soinfo is added to its primary namespace, immediately
add it to all the other namespaces, too. This ensures that the order of
soinfo objects is the same across namespaces.

Expand the dl.exec_with_ld_config_file_with_ld_preload and
dl.exec_with_ld_config_file tests to cover the new behavior. Mark
lib1.so DF_1_GLOBAL and use a "foo" symbol to mimic the behavior of a
signal API interposed by (e.g.) libsigchain.so and a ASAN preload.

Test: bionic unit tests
Bug: http://b/143219447
Change-Id: I9fd90f6f0d14caf1aca6d414b3e9aab77deca3ff
2021-01-22 03:27:43 -08:00
Ryan Prichard
fcd9c78534 Merge "Switch libc.so and linker to prebuilt LLVM libunwind" 2021-01-20 00:10:58 +00:00
Elliott Hughes
01be44d2f8 Inline call_array for clearer stack traces.
No-one seems to understand that a crash in a random .so from call_array()
in the linker isn't a linker bug. They _seem_ to understand (or at least
claim to) when we explain that this is just the linker calling their ELF
constructors --- despite the fact that the caller of call_array() is
call_constructors().

One experiment we can try though is to inline call_array() to elide that
frame from the crash dumps. I do also wonder whether renaming
call_constructors() to call_elf_constructors() would help/hinder/make no
difference. For now I'm leaning toward "hinder" because I suspect most
people don't understand "ELF constructor" and C++ folks at least will
probably be influenced in a not wholly incorrect direction when they
hear "constructor" (whereas "ELF constructor" might mislead them back in
the direction of "strange linker magic, not my fault" again)...

(The reformatting is clang-format's decision, not mine.)

Test: treehugger
Change-Id: I65ab95ceb2e988fd053c48c66f51afba17ccfa61
2021-01-19 09:47:50 -08:00
Ryan Prichard
cdf7175fa5 Switch libc.so and linker to prebuilt LLVM libunwind
For libc.so, use a special build of libunwind.a whose symbols aren't
hidden ("libunwind-exported"), because libc.so exports the _Unwind_*
APIs.

Bug: http://b/153025717
Test: bionic unit tests
Change-Id: I7435e076ec8cc4410e3e6086d3cf5d2c6011c80c
2021-01-14 17:35:05 -08:00
Ryan Prichard
bb1e37358f Delay setting linker soname until post-reloc and post-ctor
Setting the linker's soname ("ld-android.so") can allocate heap memory
now that the name uses an std::string, and it's probably a good idea to
defer doing this until after the linker has relocated itself (and after
it has called C++ constructors for global variables.)

Bug: none
Test: bionic unit tests
Test: verify that dlopen("ld-android.so", RTLD_NOLOAD) works
Change-Id: I6b9bd7552c3ae9b77e3ee9e2a98b069b8eef25ca
2021-01-13 17:48:05 -08:00
Elliott Hughes
f9dd1a760a Store soname as a std::string.
Once upon a time (and, indeed, to this very day if you're on LP32) the
soinfo struct used a fixed-length buffer for the soname. This caused
some issues, mainly with app developers who accidentally included a full
Windows "C:\My Computer\...\libfoo.so" style path. To avoid all this we
switched to just pointing into the ELF file itself, where the DT_SONAME
is already stored as a NUL-terminated string. And all was well for many
years.

Now though, we've seen a bunch of slow startup traces from dogfood where
`dlopen("libnativebridge.so")` in a cold start takes 125-200ms on a recent
device, despite no IO contention. Even though libnativebridge.so is only
20KiB.

Measurement showed that every library whose soname we check required
pulling in a whole page just for the (usually) very short string. Worse,
there's readahead. In one trace we saw 18 pages of libhwui.so pulled
in just for `"libhwui.so\0"`. In fact, there were 3306 pages (~13MiB)
added to the page cache during `dlopen("libnativebridge.so")`. 13MiB for
a 20KiB shared library!

This is the obvious change to use a std::string to copy the sonames
instead. This will dirty slightly more memory, but massively improve
locality.

Testing with the same pathological setup took `dlopen("libnativebridge.so")`
down from 192ms to 819us.

Bug: http://b/177102905
Test: tested with a pathologically modified kernel
Change-Id: I33837f4706adc25f93c6fa6013e8ba970911dfb9
2021-01-11 09:57:46 -08:00
Evgenii Stepanov
8564b8d9e6 Use ELF notes to set the desired memory tagging level.
Use a note in executables to specify
(none|sync|async) heap tagging level. To be extended with (heap x stack x
globals) in the future. A missing note disables all tagging.

Bug: b/135772972
Test: bionic-unit-tests (in a future change)

Change-Id: Iab145a922c7abe24cdce17323f9e0c1063cc1321
2021-01-06 16:08:18 -08:00
Yi Kong
6f6daaae9d linker: Enable PGO
linker-reloc-bench shows 1.2% improvement on flame.

                        PGO         No PGO
BM_linker_relocation/
real_time_mean          52215 us    52916 us

Test: linker-reloc-bench --benchmark_repetitions=25
Bug: 175205560
Change-Id: I6abbbd51912f86fcf8112c024d1cf2519056bea7
2020-12-09 19:03:53 +00:00
Elliott Hughes
658b938700 linker: add ld.config.txt parse time to systrace.
Bug: http://b/172640358
Test: treehugger
Change-Id: I9d6b7c1e200d2effb737508d3c282063edefa888
2020-11-06 09:28:16 -08:00
Yifan Hong
02bee7182e Merge "Make vendor_ramdisk_available." 2020-10-29 17:17:29 +00:00
Yifan Hong
b04490d7e5 Make vendor_ramdisk_available.
Test: pass
Bug: 156098440
Change-Id: I8fe2deb8fa3b24c227202be02d8af648629cffeb
2020-10-27 17:06:45 -07:00
Yi Kong
a7e363f873 No global ThinLTO for linker
Previous CL aosp/1432874 missed one project to exclude.

Test: make
Change-Id: Ib39e6a86c410e35141cba17948a0f30e197ea9a3
2020-10-01 04:10:01 +08:00
Yi Kong
15a05a77b4 No global ThinLTO for bionic
There are multiple build breakages with bionic when we enable ThinLTO
globally. Opt bionic out of ThinLTO for now.

#global-thinlto-opt-out

Test: TreeHugger
Bug: 169004486
Change-Id: I546a8074f9c3e0ddbd01d3b7cd730e215e3c0c49
2020-09-29 17:24:04 +00:00
Tamas Petz
8d55d1872a Enable BTI in bionic linker
This patch adds support to load BTI-enabled objects.

According to the ABI, BTI is recorded in the .note.gnu.property section.
The new parser evaluates the property section, if exists.
It searches for .note section with NT_GNU_PROPERTY_TYPE_0.
Once found it tries to find GNU_PROPERTY_AARCH64_FEATURE_1_AND.
The results are cached.

The main change in linker is when protection of loaded ranges gets
applied. When BTI is requested and the platform also supports it
the prot flags have to be amended with PROT_BTI for executable ranges.
Failing to add PROT_BTI flag would disable BTI protection.
Moreover, adding the new PROT flag for shared objects without BTI
compatibility would break applications.

Kernel does not add PROT_BTI to a loaded ELF which has interpreter.
Linker handles this case too.

Test: 1. Flame boots
      2. Tested on FVP with BTI enabled

Change-Id: Iafdf223b74c6e75d9f17ca90500e6fe42c4c1218
2020-09-23 17:53:28 -07:00
Jiyong Park
3b47d603fa Add arm64 source to linker_wrapper
As we enable arm64-based Bionic host target (linux_bionic_arm64),
linker_wrapper is added with the corresponding source.

Bug: 159685774
Test: HOST_CROSS_OS=linux_bionic HOST_CROSS_ARCH=arm64 m
Test: copy out/soong/host/linux_bionic_arm64/ to an ARM64 emulator
running Linux and execute the binaries

Change-Id: I4f367a349f7e0015318352cb7f2870fc856eab05
2020-09-22 11:28:22 +09:00
Vy Nguyen
d500751443 Add a thread-properties API
(Based on proposal at https://sourceware.org/glibc/wiki/ThreadPropertiesAPI)

This includes API to:
 - locate static and dynamic TLS
 - register thread-exit and  dynamic TLS creation/destruction callbacks

Change-Id: Icd9d29a5b2f47495395645e19d3b2c96826f19c8
2020-08-11 16:51:43 +00:00
Ryan Prichard
aff9a34bd8 Rename linker greylist to exempt-list
Update a comment in android-changes-for-ndk-developers.md about the
removed debug.ld.greylist_disabled system property.

Update language to comply with Android's inclusive language guidance

  #inclusivefixit

See https://source.android.com/setup/contribute/respectful-code for reference

Bug: http://b/162536543
Test: bionic-unit-tests
Change-Id: I760ee14bce14d9d799926c43d2c14fd8ffbc6968
2020-08-03 16:17:00 -07:00
Treehugger Robot
0f4bdb04fb Merge "linker: Cleanup for Android's inclusive language guidance" 2020-08-02 14:48:01 +00:00
Luke Huang
30f2f053f2 linker: Cleanup for Android's inclusive language guidance
1. Cleanup for #inclusivefixit. (whitelisted -> allowed_libs)
2. Support the old term for backwards compatibility. (Also update test.)
3. Fix the formatting errors found by clang-format.

See https://source.android.com/setup/contribute/respectful-code
for reference.

Bug: 161896447
Test: atest linker-unit-tests linker-benchmarks
Change-Id: I19dbed27a6d874ac0049cb7b67d2cb0f75369c1b
2020-07-31 11:37:28 +08:00
Ryan Prichard
238609328f Remove debug.ld.greylist_disabled property
This property provided a way to disable the greylist, for testing
whether an app targeting < 24 still works. Instead of turning off the
greylist, though, an app developer should simply target a newer API.

(If app developers really need this property for testing, they can
still use it on versions of Android between N and R, inclusive.)

Update language to comply with Android's inclusive language guidance

See https://source.android.com/setup/contribute/respectful-code for reference

#inclusivefixit

Bug: http://b/162536543
Test: bionic-unit-tests
Change-Id: Id1eb2807fbb7436dc9ed7fe47e15b7d165a26789
2020-07-30 19:29:17 -07:00
Elliott Hughes
68ae6ad12e Changes for #inclusivefixit.
Test: treehugger
Change-Id: I7ff0496c5c2792a41781e74634247f55b0548213
2020-07-21 16:34:58 -07:00
Evgenii Stepanov
e0848bbf89 Pagetable-friendly shared library address randomization.
Add inaccessible gaps between shared libraries to make it harder for the
attackers to defeat ASLR by random probing.

To avoid excessive page table bloat, only do this when a library is
about to cross a huge page boundary, effectively allowing several
smaller libraries to be lumped together.

Bug: 158113540
Test: look at /proc/$$/maps
Change-Id: I39c0100b81f72447e8b3c6faafa561111492bf8c
2020-07-16 13:57:20 -07:00
Evgenii Stepanov
b5f301eaaf Merge "Revert "Add randomized padding around shared library mappings."" 2020-07-06 22:18:45 +00:00
Evgenii Stepanov
474f2f5c8b Revert "Add randomized padding around shared library mappings."
This reverts commit a8cf3fef2a.

Reason for revert: memory regression due to the fragmentation of the page tables
Bug: 159810641
Bug: 158113540

Change-Id: I6212c623ff440c7f6889f0a1e82cf7a96200a411
2020-07-06 19:27:55 +00:00
Kiyoung Kim
46e731caf5 Disable warning message for missing linker config in some cases
There are some special cases - such as init process - when linker
configuration is not expected to exist. This change disables warning
message that generated linker configuration does not exist in those
cases.

Bug: 158800902
Test: Tested from cuttlefish that warning message is not generated from
init

Change-Id: Ie2fbb5210175cf1e6f2b7e638f57c3b74d395368
2020-06-30 09:21:07 +09:00
Evgenii Stepanov
a8cf3fef2a Add randomized padding around shared library mappings.
Improve ASLR by increasing the randomly sized gaps between shared
library mappings, and keep them mapped PROT_NONE.

Bug: 158113540
Test: look at /proc/$$/maps
Change-Id: Ie72c84047fb624fe2ac8b7744b2a2d0d255ea974
2020-06-17 17:28:28 -07:00
Evgenii Stepanov
071416b700 Use PROT_NONE on the unused parts of CFI shadow.
This replaces a single 2Gb readable memory region with a bunch of tiny
regions, and leaves the bulk of 2Gb mapped but unaccessible. This makes
it harder to defeat ASLR by probing for the CFI shadow region.

Sample CFI shadow mapping with this change:
7165151000-716541f000 ---p 00000000 00:00 0                              [anon:cfi shadow]
716541f000-7165420000 r--p 00000000 00:00 0                              [anon:cfi shadow]
7165420000-71654db000 ---p 00000000 00:00 0                              [anon:cfi shadow]
71654db000-71654dc000 r--p 00000000 00:00 0                              [anon:cfi shadow]
71654dc000-71654dd000 r--p 00000000 00:00 0                              [anon:cfi shadow]
71654dd000-71654f0000 ---p 00000000 00:00 0                              [anon:cfi shadow]
71654f0000-71654f1000 r--p 00000000 00:00 0                              [anon:cfi shadow]
71654f1000-71e5151000 ---p 00000000 00:00 0                              [anon:cfi shadow]

This change degrades CFI diagnostics for wild jumps and casts (i.e. when
the target of a CFI check is outside of any known library bounds). This
is acceptable, because CFI does not have much to tell about those cases
anyway. Such bugs will show up as SEGV_ACCERR crashes inside
__cfi_slowpath in libdl.so from now on.

Bug: 158113540
Test: bionic-unit-tests/cfi_test.*
Test: adb shell cat /proc/$PID/maps | grep cfi

Change-Id: I57cbd0d3f87eb1610ad99b48d98ffd497ba214b4
Merged-In: I57cbd0d3f87eb1610ad99b48d98ffd497ba214b4
2020-06-12 12:22:32 -07:00
Elliott Hughes
3205cddff0 linker: CHECK() or async_safe_fatal() rather than abort().
In particular, add the strerror() output if mprotect() fails.

Fix the CHECK macro so that you can make assertions involving operator%
without that being confused for a printf format specifier.

Bug: https://issuetracker.google.com/158645318
Test: treehugger
Change-Id: I6817f8ca5f094c52dc2c9067bfac90385a8743f5
2020-06-10 14:49:28 -07:00
Jooyung Han
61a9a4016c Make .whitelisted property "append"-able
.whitelisted is a list of sonames seperated by ":" just like
.shared_libs and .paths properties. It makes sense to make it appendable
using += as well ass .shared_libs and .paths.

Bug: n/a
Test: atest linker-unit-tests
Change-Id: If61cc553c8080e8a58de8a3a6051c1853f7bfe5f
2020-06-02 16:05:01 +09:00
Victor Khimenko
9b3e026c8f Refactor translateSystemPathToApexPath
This is more efficient and easier to read.

Test: bionic-unit-tests --gtest_filter=*icu*

Change-Id: Iddeed7cd4a1d48d8968f97951a9af004ccce52e8
2020-05-19 02:32:07 +02:00
Victor Khimenko
01790fdc69 Allow native_bridge linker to use different APEX from native one
Bug: http://b/156397945

Test: dlfcn.dlopen_system_libicuuc_android_api_level_28 with native_bridge

Change-Id: I3ecd929a0c31dda8cd424795f21f6ef472776557
2020-05-15 20:56:22 +00:00
Victor Khimenko
d15229df76 Copy translateSystemPathToApexPath to linker_translate_path.cpp
Bug: http://b/156397945

Test: m

Change-Id: I33f11b8a6a41475b6cdd65e1ff49b2084c33b197
2020-05-14 22:17:45 +02:00
vichang
10bad3e882 Merge "Move libicuuc.so into com.android.i18n module." 2020-05-11 11:37:06 +00:00
Victor Chang
f248d2de84 Move libicuuc.so into com.android.i18n module.
Change the location set in the linker

Bug: 130219528
Bug: 138994281
Test: atest CtsBionicTestCases
Test: atest CtsJniTestCases
Change-Id: I215a8e023ccc4d5ffdd7df884c809f8d12050c8f
2020-05-07 23:15:01 +00:00
Peter Collingbourne
144a6ab341 Merge "Introduce a new heap tagging level, M_HEAP_TAGGING_LEVEL_SYNC." 2020-05-07 17:51:51 +00:00
Peter Collingbourne
d3060019de Introduce a new heap tagging level, M_HEAP_TAGGING_LEVEL_SYNC.
The SYNC tagging level enables stack trace collection for allocations and
deallocations, which allows allocation and deallocation stack traces to
appear in tombstones when encountering a tag check fault in synchronous tag
checking mode.

Bug: 135772972
Change-Id: Ibda9f51b29d2c8e2c993fc74425dea7bfa23ab1e
2020-05-05 13:28:16 -07:00
Martin Stjernholm
82d84bcd7e Make Bionic and kernel system includes explicit in the blueprints.
Before this Soong added hardcoded system include paths to
bionic/libc/{include,kernel}, which won't work when Bionic libs are
packaged up as prebuilts in an SDK module snapshot.

Test: Build and boot
Test: Check in out/verbose.log.gz that a C file doesn't get any bionic
  include path for linux_glibc.
Bug: 153590472
Change-Id: I13c8eb3dd7150d6e0fee001b290b53fcebebcfea
2020-05-05 13:34:14 +01:00
Ryan Prichard
172611f5ce __loader_cfi_fail: acquire g_dl_mutex
CfiFail calls find_containing_library, which searches the linker's
internal soinfo list, which could be modified by another thread.

Bug: http://b/150372650
Test: bionic-unit-tests
Change-Id: I59024a0a47913caa75702f15ec058b0a360727b5
2020-04-20 18:14:51 -07:00
Ryan Prichard
c2a93792fc android_get_exported_namespace: acquire g_dl_mutex
android_get_exported_namespace searches g_exported_namespaces, which
isn't modified after process initialization, but it does the search
using a new std::string object, and the linker's malloc/free functions
aren't thread-safe. (They're protected by the same lock (g_dl_mutex) as
the rest of the linker's state.)

Bug: http://b/150372650
Test: bionic-unit-tests
Change-Id: Iafd12e5ab36ae61f0642aad59939f528d31bda16
2020-04-20 17:59:43 -07:00
Ryan Prichard
df3dc8039d Merge changes Ia359d9f2,Ibabbf559,I1b542e47,I4b6f48af,I82e442f0
* changes:
  Fix bootstrap linker library searching
  Remove dangling soinfo* from elf_readers_map_
  Fix DL_WARN_documented_change URL
  remove search_linked_namespaces param
  Refactor linker lookup code a bit
2020-03-31 21:02:18 +00:00
Peter Collingbourne
aed48830ac Merge "Switch to debugger_process_info in bionic." 2020-03-30 21:36:41 +00:00
Ryan Prichard
40494406b8 Fix bootstrap linker library searching
For the bootstrap linker, insert /system/${LIB}/bootstrap in front of
/system/${LIB} in any namespace search path.

Bug: http://b/152572170
Test: bionic unit tests
Change-Id: Ia359d9f2063f4b6fff3f79b51b500ba968a18247
2020-03-27 18:46:28 -07:00
Ryan Prichard
4fa6d9978a Remove dangling soinfo* from elf_readers_map_
If ElfReader::Read fails, then it is hazardous to leave the invalid
ElfReader in the soinfo*->ElfReader table, because a future soinfo
object could happen to have the same address, then reuse the invalid
ElfReader. I'm not sure whether this can break anything, because the
linker would call ElfReader::Read on the invalid object and overwrite
its previous value.

Test: bionic unit tests
Bug: none
Change-Id: Ibabbf559443441b9caeacc34ca165feaafe5e3a7
2020-03-27 18:46:28 -07:00
Ryan Prichard
146620b644 Fix DL_WARN_documented_change URL
The doc_link argument is really a URL fragment within the
android-changes-for-ndk-developers.md document, not a filename at the
root of the bionic repository.

Test: manual
Bug: none
Change-Id: I1b542e47aca132ce43ba1d50d83db1bf3c7b10c6
2020-03-27 18:46:28 -07:00
Ryan Prichard
323d7dfe90 remove search_linked_namespaces param
The search_linked_namespaces parameter to find_library_internal is
always true.

Bug: none
Test: bionic tests
Change-Id: I4b6f48afefca4f52b34ca2c9e0f4335fa895ff34
2020-03-27 18:46:28 -07:00
Ryan Prichard
aa2db969dc Refactor linker lookup code a bit
Add a few _Nonnull / _Nullable annotations. Clang may use them to issue
warnings but violating the annotation isn't undefined behavior.

Bug: none
Test: bionic tests
Change-Id: I82e442f06a2c59c69bc0008f0f686785695cdd02
2020-03-27 18:46:28 -07:00
Treehugger Robot
2a069b24df Merge "Revert "Statically link libdl.a to linker"" 2020-03-18 16:05:54 +00:00
Jooyung Han
274e21fdb6 Revert "Statically link libdl.a to linker"
This reverts commit 8dba7fefb0.

Reason for revert: This workaround is not necessary with ag/10700799

Merged-In: I2bf469bfe00f3a70e67085abfb3822db6908d522
Change-Id: If351aedfce23d60582f0c5ff965f94356d1900d9
Bug: 150860940
2020-03-18 08:45:25 +00:00
Peter Collingbourne
de9c34601a Switch to debugger_process_info in bionic.
Bug: 135772972
Change-Id: I2b4eae107fc7f62a5ad7ead3a8cfa26e444532d4
2020-03-17 14:35:09 -07:00
Kiyoung Kim
8bc0353dbc Update linkerconfig missing message to warning
Update message that generated linker configuration is missing to from
into to warning again. Also do not raise this message from host
environment which is expected.

Bug: 146386369
Test: m -j passed
Change-Id: Ia5c2969d77fbc70e0406fbb449920080989a1ea8
2020-03-17 09:52:55 +09:00
Jiyong Park
8dba7fefb0 Statically link libdl.a to linker
When libbase is built for an APEX, it uses dlsym to reflectively access
liblog symbols that are added in R. This is because the APEX where
libbasse is packaged into might be running in pre-R devices where the
symbols don't exist in liblog.so.

This however causes a problem for a static executable in an APEX. Since
it is in an APEX, the dlsym is used. But libdl.so which provides dlsym
is not available to static executable. Currently, the dynamic linker is
the only executable in an APEX that all of its dependencies are
statically linked. Fixing the issue by providing fake dlsym by
statically linking to libdl.a.

Exempt-From-Owner-Approval: cherry-pick rvc-dev

Bug: 149569129
Test: m

Merged-In: I2e9e45d9876c2d6c878e541715389e6d1ef56996
(cherry picked from commit ec829ed4ea)
Change-Id: I2e9e45d9876c2d6c878e541715389e6d1ef56996
2020-03-11 07:53:47 +00:00
Treehugger Robot
ae35f675bb Merge "Delete definitions of __aeabi_unwind_cpp_pr0." 2020-03-10 18:30:30 +00:00
Chih-Hung Hsieh
fa658eb094 Fix bugprone-macro-parentheses warnings
Bug: 150783705
Test: WITH_TIDY=1 make
Change-Id: If47b7adaa5f3ba3c518fb0be48f0ffdc81d204b2
2020-03-04 13:22:05 -08:00
Mitch Phillips
4c9293f29a [GWP-ASan] Export GWP-ASan regions to libdebuggerd.
Exports GWP-ASan allocator information callbacks to libdebuggerd so that
tombstoned can get information from the GWP-ASan allocator in the case
of a crash.

Bug: 135634846
Test: atest bionic-unit-tests

Change-Id: Ie16426af55602fb2a76c4e69217773354c365843
2020-02-19 09:01:27 -08:00
Kiyoung Kim
47ddeb1ae4 Merge "Deprecate sys.linker.use_generated_config property" 2020-02-18 00:52:59 +00:00
Kiyoung Kim
1878690fdd Deprecate sys.linker.use_generated_config property
sys.linker.use_generated_config property was introduced at the beginning
of linkerconfig development to skip this generated configuration if it
does not work properly during dev. However, linkerconfig development is
now completed and is working properly from most of devices, so this
property is no longer in use. Therefore deprecating this property as
this would not be used.

Bug: 149335054
Test: m -j passed
Test: No linking error from Cuttlefish and Crosshatch
Change-Id: I0a1b3f36b69872862196b1613718a75d482e0a92
2020-02-15 04:35:37 +09:00
Ivan Lozano
c65b55cded Merge "Remove XOM properties." 2020-02-14 14:42:49 +00:00
Elliott Hughes
14798930ec Remove unused mips/mips64 code from the linker.
Test: treehugger
Change-Id: I42f1e4c492ac644cf78e7c1196ba9b3518f9c8f8
2020-02-13 15:58:48 -08:00
Ivan Lozano
3e928edc77 Remove XOM properties.
XOM is no longer supported by the build system, so remove these
properties.

Bug: 123034666
Bug: 147300048
Test: Build succeeds.
Change-Id: I77efc98241f45b1a78b1cca5560f64eef5ef22f4
2020-02-13 14:20:44 -05:00
Roland Levillain
57e6b8612a Adjust the documentation of get_ld_config_file_apex_path.
Test: n/a
Bug: 147987608
Change-Id: I479a63a2fa7e0975db80fcfdda78d2ee154c53cb
2020-02-12 17:34:20 +00:00
Kiyoung Kim
a399ede44e Merge "Use generated linker config for APEX binaries" 2020-02-07 03:25:42 +00:00
Ryan Prichard
22fa3dde07 Ignore symbols of imported libs' dependencies
When a library is present in a namespace via the secondary_namespaces
list (i.e. the executable, LD_PRELOAD, DF_1_GLOBAL, or
android_create_namespace inheritance), then we want to search that
library's symbols, but not the symbols of its dependencies. Otherwise,
we want to search the dependencies to handle cross-NS dependency.

Bug: http://b/148569846
Test: bionic unit tests
Change-Id: If798d69de28ed5c0f1a155e4ff85c7e08934e531
2020-02-03 14:20:40 -08:00
Kiyoung Kim
fb58744f6b Use generated linker config for APEX binaries
LinkerConfig will start to generate linker configuration for APEX
binaries. Linker should check if this generated file exists first, and
use it if exists and otherwise use ld.config.txt under APEX etc.

Bug: 147987608
Test: m -j passed
Test: Tested with adbd and SWCodec from Cuttlefish and Crosshatch
Change-Id: I5a0c28ee1a427adface3e67c8af062e1b2ef6197
2020-02-03 10:27:56 +09:00
Ryan Prichard
e503383c92 Comment two linker namespace functions
Test: it builds
Change-Id: I4dee0d4da230bd559319317b504e2c597f814f50
2020-01-31 14:48:35 -08:00
Ryan Prichard
272458ee9f Rename dlsym_handle_lookup:6 to dlsym_handle_lookup_impl
Rearrange a function to remove a forward declaration.

Test: m linker
Change-Id: I014eac3319bd6f4c10f8bba50f8006f96bb33dce
2020-01-31 14:48:19 -08:00
Elliott Hughes
1d8f6f2f5d Merge "Modernize SHT_RELR support." 2020-01-27 18:10:13 +00:00
Elliott Hughes
6663f5525d Modernize SHT_RELR support.
Until now we've only supported RELR with our own OS-private-use
constants. Add support for the official numbers (while maintaining
support for the historical numbers).

Add tests to ensure we continue to support both indefinitely.

We can't yet flip the build system over to using the official constants
because the old GNU binutils objcopy we still use in most cases (for the
mini-debug section) only supports the historical constants.

Bug: http://b/147452927
Test: treehugger
Change-Id: If214fce7fade4316115947e90b78ab40864b61f2
2020-01-24 15:39:01 -08:00
Yifan Hong
29546b9133 Merge "Make ramdisk_available." 2020-01-24 22:39:41 +00:00
Ryan Prichard
928c2492a3 Remove an unused code path
A static analyzer is complaining that num_valid_bits could be 64, and if
it were 64, then two later accesses would be out-of-bounds. is_nul_u64
can't be zero, though, because we only exit the loop when part of is_nul
is non-zero.

Bug: none
Test: manual
Change-Id: I75c3f70b600aa5478cb32fdf4ca0ae1173b69524
2020-01-22 13:59:15 -08:00
Yifan Hong
5a39cee1ce Make ramdisk_available.
Test: pass
Bug: 147347110
Change-Id: I142311a7558a19d209bcd63207a88e12cf6f130e
2020-01-22 12:09:33 -08:00
Peter Collingbourne
39d9156bdc Merge "Export the unwinder implementation from libc." 2020-01-21 21:28:44 +00:00
Ryan Prichard
0bf9aed92e Merge "Neon-optimized version of the GNU symbol calculation" 2020-01-17 20:48:14 +00:00
Ryan Prichard
4f140695d9 Restore handling of R_GENERIC_NONE relocations
Previously, the linker was ignoring the symbol of the R_GENERIC_NONE
relocation, so continue ignoring it. This is a little unfortunate because
it requires adding an extra condition on the fast path for relocation
handling.

I tried benchmarking this change, and I can't tell whether it has no
effect or is a regression of up to 1%. It might be possible to refactor
this code (e.g. do the lookup anyway, but avoid reporting an error), or by
changing the linker behavior, but this simple change gets the linker
working again.

Bug: http://b/147719203
Test: verify that the broken app works again
Change-Id: I7589b65705fec522d5fbadc05136dd5489833aea
2020-01-15 15:19:17 -08:00
Ryan Prichard
129f7a1d8e Neon-optimized version of the GNU symbol calculation
On 64-bit walleye, improves the linker relocation benchmark from 71.9ms to
70.7ms (1.7% of the run-time).

On a 32-bit device, it improves the linker relocation benchmark from
205.5ms to 201.2ms (2.1% of the run-time).

$ adb shell taskset 10 /data/benchmarktest64/linker-benchmarks/linker-benchmarks --benchmark_repetitions=100 --benchmark_display_aggregates_only
--------------------------------------------------------------------
Benchmark                          Time             CPU   Iterations
--------------------------------------------------------------------
BM_gnu_hash_simple_mean        15232 ns        15212 ns          100
BM_gnu_hash_simple_median      15176 ns        15159 ns          100
BM_gnu_hash_simple_stddev        111 ns          110 ns          100
BM_gnu_hash_neon_mean          10265 ns        10252 ns          100
BM_gnu_hash_neon_median        10261 ns        10249 ns          100
BM_gnu_hash_neon_stddev         28.1 ns         23.9 ns          100

Bug: none
Test: linker-unit-tests
Test: linker-benchmarks
Change-Id: I3983bca1dddc9241bb70290ad3651d895f046660
2020-01-13 13:29:25 -08:00
Ryan Prichard
339ecef22d Optimize GNU hash linking for large inputs
Symbol lookup is O(L) where L is the number of libraries to search (e.g.
in the global and local lookup groups). Factor out the per-DSO work into
soinfo_do_lookup_impl, and optimize for the situation where all the DSOs
are using DT_GNU_HASH (rather than SysV hashes).

To load a set of libraries, the loader first constructs an auxiliary list
of libraries (SymbolLookupList, containing SymbolLookupLib objects). The
SymbolLookupList is reused for each DSO in a load group. (-Bsymbolic is
accommodated by modifying the SymbolLookupLib at the front of the list.)
To search for a symbol, soinfo_do_lookup_impl has a small loop that first
scans a vector of GNU bloom filters looking for a possible match.

There was a slight improvement from templatizing soinfo_do_lookup_impl
and skipping the does-this-DSO-lack-GNU-hash check.

Rewrite the relocation processing loop to be faster. There are specialized
functions that handle the expected relocation types in normal relocation
sections and in PLT relocation sections.

This CL can reduce the initial link time of large programs by around
40-50% (e.g. audioserver, cameraserver, etc). On the linker relocation
benchmark (64-bit walleye), it reduces the time from 131.6ms to 71.9ms.

Bug: http://b/143577578 (incidentally fixed by this CL)
Test: bionic-unit-tests
Change-Id: If40a42fb6ff566570f7280b71d58f7fa290b9343
2020-01-13 13:29:25 -08:00
Peter Collingbourne
f2b1e03606 Export the unwinder implementation from libc.
This supports the soong commit which causes most platform binaries to stop
statically linking against the unwinder implementation. The soong commit
message has more motivation for this change.

ARM32 uses LLVM libunwind, while all other platforms use libgcc as the
unwinder implementation. This matches the current choices of unwinders on
the various architectures, but means that apps which were directly linking
against the libc.so unwinder symbols on ARM32 are now using LLVM libunwind
instead of libgcc.

Set libc_headers sdk_version to 1 so that libunwind_llvm can depend on it,
and stop statically linking libunwind into libc_malloc_debug.

Bug: 144430859
Change-Id: I52c7f7893d93f500383aeb0b76086c3b6f1935a5
2020-01-10 19:07:59 -08:00
Ryan Prichard
a04764bd28 Merge changes I578d36a1,Id17508ab,I385f312b
* changes:
  Create linker_log[_va_list] functions
  Validate defined versions in prelink_image
  Prelink each library only once
2020-01-10 22:21:15 +00:00
Peter Collingbourne
27c1e22036 Delete definitions of __aeabi_unwind_cpp_pr0.
These are no longer necessary now that LLVM no longer emits references to
this symbol on Android.

Bug: 144430859
Change-Id: I6c43338f755ce5a79e2df36bd3f2006a748fab27
2020-01-10 10:40:43 -08:00
Ryan Prichard
cec75e3303 Merge "Do not add duplicate soinfos to g_default_namespace" 2020-01-07 20:18:14 +00:00
Ryan Prichard
551565e87c Create linker_log[_va_list] functions
A later linker CL defines a function that needs to forward a printf format
and argument list to TRACE(), but there is no version of the TRACE macro
that works with a va_list. The CL also needs to check the verbosity level,
using a slow path if tracing is enabled, so define LINKER_VERBOSITY_xxx
macros.

Bug: none
Test: bionic unit tests
Change-Id: I578d36a12dc40f9a651956b4b09adc1a7c644e24
2020-01-06 16:06:37 -08:00
Ryan Prichard
0e12ccedd4 Validate defined versions in prelink_image
Validate the list of defined versions explicitly, during library
prelinking, rather than implicitly as part of constructing the
VersionTracker in soinfo::link_image.

Doing the validation upfront allows removing the symbol lookup failure
code paths, which only happen on a library with invalid version
information.

Helps on the walleye 64-bit linker relocation benchmark (146.2ms ->
131.6ms)

Bug: none
Test: bionic unit tests
Change-Id: Id17508aba3af2863909f0526897c4277419322b7
2020-01-06 16:06:37 -08:00
Ryan Prichard
ae320cde07 Prelink each library only once
Previously, during a find_libraries call that loaded a library, a
library was prelinked once for each DT_NEEDED reference to the library.

This CL has a negligible effect on the linker relocation benchmark
(146.9ms -> 146.2ms).

Bug: none
Test: bionic unit tests
Change-Id: I385f312b8acf8d35aa0af9722131fe367b5edd9b
2020-01-02 17:40:32 -08:00
NIEJuhu
e2871bd0d8 Do not add duplicate soinfos to g_default_namespace
The soinfo instances of linker and vdso have been added to g_default_namespace
before init_default_namespace() is called. So init_default_namespace() don't
have to add them a second time.

Test: manual
Change-Id: I29b3da782b1e9445509f45a7698561fc3e19e9a1
2019-12-27 11:32:29 +08:00
Elliott Hughes
5e2ac29165 Merge "Stop using the __ANDROID_API_x__ constants." 2019-12-23 03:26:37 +00:00
Elliott Hughes
95c6cd753f Stop using the __ANDROID_API_x__ constants.
Historically we've made a few mistakes where they haven't matched the
right number. And most non-Googlers are much more familiar with the
numbers, so it seems to make sense to rely more on them. Especially in
header files, which we actually expect real people to have to read from
time to time.

Test: treehugger
Change-Id: I0d4a97454ee108de1d32f21df285315c5488d886
2019-12-20 13:26:14 -08:00
Elliott Hughes
fa8774462f Make the linker NOTICE file match the linker source.
Test: eyeball
Change-Id: I3e10bd813eff5cc05fc9c4f50a75777b82df9a5c
2019-12-20 12:29:39 -08:00
Kiyoung Kim
19f95dd872 Do not DL_WARN when failed to find generated linker config
DL_WARN message when failed to find generated linker config makes some
of the ART tests fail. Lowering log level as ART test does not have
linkerconfig generated for the test.

Bug: 146386369
Test: Cuttlefish boot succeeded without any error
Test: run_build_test_target.py art-linux-bionic-x64-zipapex passed
Change-Id: I4f876c3ac5c30d32d51346d4cd16b5205da8f1bf
2019-12-17 13:59:57 +09:00
Evgeny Eltsin
ff43ec0147 Prefer arch-specific linker config when available
New linker configuration from /linkerconfig is not suitbale for emulated
architectures. But as of now, native_bridge linkers pick it up as well
and thus fail to find the libraries for emulated architectures.

This is a (temporary) fix so native_bridge linker still picks up
configuration from old location.

Bug: 138920271
Test: native_bridge linker works
Change-Id: I0abbd3e95f9e6830385b0f19db0688e6183030b9
2019-12-16 19:22:07 +01:00
Kiyoung Kim
838ca10715 Merge "Enable linker configuration from generator by default" 2019-12-16 01:55:44 +00:00
Kiyoung Kim
ef04c80bf6 Enable linker configuration from generator by default
Current linker configuration is only enabled from fully treblelized
devices. This change will allow linker to first check generated linker
configuration even for non-treblelized devices and recovery.

Bug: 139638519
Test: Tested from cuttlefish
Change-Id: I655b1ab807cd8db5696d07fd2bdd00ce0558901d
2019-12-13 13:59:00 +09:00
Elliott Hughes
cdb52fc147 Make private/bionic_page.h available as platform/bionic/page.h.
Bug: http://b/145825270
Test: treehugger
Change-Id: I52958f370c0df2c02cb8250e2cf0705d4e93e908
2019-12-12 15:26:14 -08:00