Commit graph

372 commits

Author SHA1 Message Date
Colin Cross
90d0500699 Merge changes I59b7a32a,Ida7bc75a am: 0329f2398c
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1406259

Change-Id: I9b2b709c59630394aa528c64b4fbe60b52d50be5
2020-09-03 00:21:49 +00:00
Bill Peckham
945441c09a Add exclude_from_vendor_snapshot property, related logic
When building a vendor snapshot, the general rule the
build system uses to select a module for inclusion into
the vendor snapshot is if it's a framework module.
However, there are cases where a partner may modify the
framework module, thereby assuming control of that
module.

This change adds the exclude_from_vendor_snapshot
property allowing the partner to mark a module that
would normally be included in the vendor snapshot for
exclusion. This module is then built from source when
building the vendor image against the vendor snapshot.

Bug: 165705527
Test: m nothing
Test: build partner code against vendor snapshot
Change-Id: I6c5c15f13eeeb8f29717a4abd84b65fa72096889
2020-09-02 22:27:45 +00:00
Xin Li
65cb5c69ea Merge Android R (rvc-dev-plus-aosp-without-vendor@6692709)
Bug: 166295507
Merged-In: Ifca7b65f4e27bf14cdc30f72f790b0de90130bae
Change-Id: I3a39be5f0b8736de4822c6a14072c78d4e4ad89d
2020-08-29 01:17:45 -07:00
Colin Cross
42507337e5 Only request image and version variations for device SDK dependencies
AddFarVariationDependencies was broken, which allowed sdk modules to
request dependencies using image and version variations, even for
host modules that do not have image or version variations.  Make
the image and version variations conditional on device sdk modules.

Test: go test ./sdk
Change-Id: I59b7a32a3782254fd5feb828a5258ee13d4db812
2020-08-26 11:51:51 -07:00
Pirama Arumuga Nainar
84ce8d8d89 Merge "[cc/sanitize] Deprecate blacklist sub-property of sanitize" 2020-08-11 21:24:16 +00:00
Inseob Kim
eaebec1312 Merge changes from topic "cfi_vendor_snapshot"
* changes:
  Add cfi static libraries to vendor snapshot
  Refactor vendor snapshot modules
2020-08-07 01:48:10 +00:00
Mitch Phillips
8dc2af873b Merge "Added write only sanitizer for ASAN and HWASAN" 2020-08-06 21:17:12 +00:00
Inseob Kim
c42f2f2e9d Add cfi static libraries to vendor snapshot
CFI modules can't link against non-CFI static libraries, and vice versa.
So without capturing both CFI and non-CFI static libraries, vendor
modules won't be able to use CFI, which will be a critical security
hole.

This captures both CFI and non-CFI variants of all static libraries for
vendor snapshot, except for those whose cfi are explicitly disabled.

For example, suppose that "libfoo" is defined as follows.

cc_library_static {
    name: "libfoo",
    vendor_available: true,
}

As it doesn't have cfi disabled, two libraries "libfoo.a" and
"libfoo.cfi.a" will be captured. When installed, vendor snapshot module
for "libfoo" will look like:

vendor_snapshot_static {
    name: "libfoo",
    src: "libfoo.a",
    cfi: {
        src: "libfoo.cfi.a",
    },
}

The build system will recognize the "cfi" property, and will create both
CFI and non-CFI variant, allowing any modules to link against "libfoo"
safely, no matter whether CFI is enabled or not.

Two clarification:

1) The reason why we don't create separate modules is that DepsMutator
runs before sanitize mutators. CFI and non-CFI variant of a library
should exist in a single module.

2) We can't capture CFI variant if the source module explicitly disables
cfi variant by specifying the following.

sanitize: {
    cfi: false,
}

In this case, only non-CFI variant will be created for the vendor
snapshot module.

Bug: 65377115
Test: m dist vendor-snapshot && install && build against snapshot
Change-Id: Idbf3e3205d581800d6093c8d6cf6152374129ba4
2020-08-06 19:47:57 +00:00
Treehugger Robot
8c69770ff0 Merge changes from topic "soong_sanitize_fix"
* changes:
  Separate lists of soong sanitize modules
  Move image mutator things to image.go
2020-08-06 00:48:16 +00:00
Inseob Kim
74d255698b Separate lists of soong sanitize modules
Dependencies of makefile modules are being redirected according to
SOONG_CFI_STATIC_LIBRARIES and SOONG_HWASAN_STATIC_LIBRARIES. But the
variables are shared among all variants (e.g. core, vendor, product,
arch), which can cause build error.

This splits the Makefile variables into several lists, one list per each
arch and each image variant, to correctly make the redirection.

Bug: 162476652
Test: build and inspect ninja
Change-Id: Icc753382f1c53de8468cc85243a6954e1986297a
2020-08-05 04:47:41 +00:00
Pirama Arumuga Nainar
c02c98b8f5 [cc/sanitize] Deprecate blacklist sub-property of sanitize
All uses of this property have been migrated to 'blocklist' instead.

Update language to comply with Android’s inclusive language guidance

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

Bug: 161896447
Bug: 162245450

Test: TH
Change-Id: I4b83b41ad5a4b2caf1166b1acece9537f545aaad
2020-07-30 22:17:22 -07:00
Colin Cross
6e511a9a9f Add libraryDependencyTag to track dependencies on static and shared libraries
dependencyTag uses a set of predefined tags to identify different types
of dependencies.  There are already multiple bits of metadata stored
in the dependency tag (Library, Shared, ReexportFlags), and supporting
them all requires a combinatorial explosion of predefined tags and
causes issues when using equality comparisons if a new bit of metadata
is added.

Add a new libraryDependencyTag type that will contain the metadata
bits, and replace the quality comparisons with checks on the metadata
bits.

There are 5 TODOs where modifying the checks identified problems with
the existing checks.  These were left in place to produce identical
build output and will be fixed separately.

Bug: 162437057
Test: no change to build.ninja or {Android,make_vars,late}-${TARGET_PRODUCT}.mk
Change-Id: I72d4207dcf381c07c92e00e5a03968ebb5ed8d30
2020-07-29 13:22:30 -07:00
Jasraj Bedi
bb4511df94 Added write only sanitizer for ASAN and HWASAN
Bug: 162024969
Test: Successfully builds targets for both host and device

"writeonly" flag in SANITIZE_(HOST|TARGET) enables it with "address"
and "hwaddress"

Change-Id: Ia89d43230deef15a67dee09ed015fea14f0717ff
2020-07-29 20:13:53 +00:00
Pirama Arumuga Nainar
eda8499a3c Merge "[cc/sanitize] Add Blocklist property" 2020-07-28 17:21:59 +00:00
Pirama Arumuga Nainar
6c4ccca7b7 [cc/sanitize] Add Blocklist property
This will eventually replace the Blacklist property.

Update language to comply with Android’s inclusive language guidance

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

Bug: 161896447
Bug: 162245450
Test: build topic
Change-Id: I3c2609c791c27b8ba3bcb55f79304b78bce1f518
2020-07-27 13:37:05 -07:00
Pirama Arumuga Nainar
eb8d403273 Rename CFI blocklist files.
Update language to comply with Android’s inclusive language guidance

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

Bug: 161896447
Test: build
Change-Id: I3de274e58135660e102c276a9822a2ef2cd7cba8
2020-07-27 18:37:48 +00:00
Mitch Phillips
7df01cc05a Merge "[HWASan] Disable GlobalISel/FastISel w/ HWASan." into rvc-dev am: 13b85a4792
Original change: https://googleplex-android-review.googlesource.com/c/platform/build/soong/+/11959173

Change-Id: I986f605a95a5627c42ff6195138c65843f6938f5
2020-06-30 18:38:19 +00:00
Mitch Phillips
b1c574fd13 [HWASan] Disable GlobalISel/FastISel w/ HWASan.
Bug: 159343917
Test: See upstream testing at https://reviews.llvm.org/D82249
Change-Id: Ib644a857caa048d7fc3dd5e5f20553e0b4a47d43
2020-06-30 17:35:56 +00:00
Christopher Ferris
f70926eef0 Remove libc_scudo references.
Test: Builds and boots.
Change-Id: Iad97159e6193f7afffd8fbc9456427eee5d150e3
Merged-In: Iad97159e6193f7afffd8fbc9456427eee5d150e3
(cherry picked from commit 1f16b27511)
2020-06-22 15:27:56 -07:00
Jooyung Han
8ce8db9ed6 apex: install hwasan lib if depended on libc
There're two ways to enable hwasan:
- global setting: TARGET_SANITIZE=hwaddress
- individual setting: sanitize: { hwaddress: true }

This change covers both cases by looking up if com.android.runtime is
hwaddress santized or not.

Bug: 156678661
Test: m (soong test added)
Change-Id: I67c382c3e76a06f4b27f221eebd153c698647227
2020-05-15 19:12:38 +09:00
Dan Willemsen
b5b2aba43b Don't tell make about modules in other namespaces
This was causing build breaks when different devices moved to Android.bp
at different times.

Bug: 150878976
Test: build *_hwasan targets
Change-Id: I68912bb6a5696809c318d1ec816a1bcfbe2df245
Merged-In: I68912bb6a5696809c318d1ec816a1bcfbe2df245
(cherry picked from commit 7b6af23db6)
2020-05-04 00:05:47 -07:00
Dan Willemsen
7b6af23db6 Don't tell make about modules in other namespaces
This was causing build breaks when different devices moved to Android.bp
at different times.

Bug: 150878976
Test: build *_hwasan targets
Change-Id: I68912bb6a5696809c318d1ec816a1bcfbe2df245
2020-05-03 21:30:43 -07:00
Evgenii Stepanov
96fa3dd0af Revert "Reenable the new pass manager in hwasan builds."
This reverts commit 259eaab3b3.

Reason for revert: breaks hwasan + gcov

Bug: 135298400
Change-Id: Ie8574753f9237a55ad1618783bd5150ffb646015
2020-03-27 19:42:01 +00:00
Evgenii Stepanov
259eaab3b3 Reenable the new pass manager in hwasan builds.
Also remove a deprecated flag -fsanitize-hwaddress-abi=platform.

Switching to the new pass manager reduces size of the "lib64" directory
by almost 6%.

Bug: 135298400
Test: objdump -d path/to/symbols/system/lib64/*.so | grep __hwasan_check_
Test: adb shell sanitizer-status

Change-Id: I327ee982e20c02b3b2126d93189048d9f4bfb301
2020-03-23 14:56:03 -07:00
Elliott Hughes
cc868de8a7 Merge "Remove unused mips workarounds." 2020-03-16 21:06:13 +00:00
Ivan Lozano
9d790c78da Disable CFI only on incompatible variants.
Only disable CFI on incompatible variants rather than the base module.

Bug: 142157676
Test: Manual llvm-cfi-verify checks
Change-Id: I999e1dbcccc1ffb102b2fe01c47f1bda4df5e601
Merged-In: I999e1dbcccc1ffb102b2fe01c47f1bda4df5e601
(cherry picked from commit 4774a81c0f)
2020-03-13 11:59:07 -04:00
Ivan Lozano
438d379eb6 Merge "Disable CFI only on incompatible variants." 2020-03-13 15:57:08 +00:00
Ivan Lozano
fadd6358c1 Fix UBSanitized host binaries missing runtime.
Host binaries by default use the UBSan runtime whether or not
diagnostics are requested in the module definition. The rest of the code
assumes the runtime is only needed when diag properties are set.

This makes sure to add the runtime to the dependency graph of host
binaries that are UBSanitized.

Bug: 150336284
Test: ./art/tools/dist_linux_bionic.sh com.android.art.host
Test: runtime appropriately identified as a dependency of libziparchive
Change-Id: I2704aaba4abc7f4e6d96747917c77b5147fd1d56
Merged-In: I2704aaba4abc7f4e6d96747917c77b5147fd1d56
(cherry picked from commit f3b190f8e7)
2020-03-12 14:14:27 -04:00
Ivan Lozano
f3b190f8e7 Fix UBSanitized host binaries missing runtime.
Host binaries by default use the UBSan runtime whether or not
diagnostics are requested in the module definition. The rest of the code
assumes the runtime is only needed when diag properties are set.

This makes sure to add the runtime to the dependency graph of host
binaries that are UBSanitized.

Bug: 150336284
Test: ./art/tools/dist_linux_bionic.sh com.android.art.host
Test: runtime appropriately identified as a dependency of libziparchive
Change-Id: I2704aaba4abc7f4e6d96747917c77b5147fd1d56
2020-03-11 20:40:21 -04:00
Ivan Lozano
4774a81c0f Disable CFI only on incompatible variants.
Only disable CFI on incompatible variants rather than the base module.

Bug: 142157676
Test: Manual llvm-cfi-verify checks
Change-Id: I999e1dbcccc1ffb102b2fe01c47f1bda4df5e601
2020-03-10 16:27:38 -04:00
Elliott Hughes
da3a071eaa Remove unused mips workarounds.
This was never really finished, and hasn't been supported for years.

Test: treehugger
Change-Id: I21d4c3112aa8cf0c56e59f0cc19ff8725ef714b9
2020-03-06 18:15:44 -08:00
Colin Cross
dc7319df2b Convert cc to AndroidMkEntries
Use AndroidMkEntries so the next patch can use ExtraFooters, which
doesn't exist in AndroidMkData.

Bug: 149591522
     the bug is not exactly related to this change, but it is the bug
     that the follow-up changes are trying to fix.
Test: manually diff out/soong/Android.aosp_x86_64.mk
Merged-In: Ia3006b6747813693cf7e2b536030b21f3109f538
Change-Id: Ia3006b6747813693cf7e2b536030b21f3109f538
(cherry picked from commit d80cbca76d)
2020-03-05 14:40:43 +09:00
Colin Cross
d80cbca76d Convert cc to AndroidMkEntries
Use AndroidMkEntries so the next patch can use ExtraFooters, which
doesn't exist in AndroidMkData.

Test: manually diff out/soong/Android.aosp_x86_64.mk
Change-Id: Ia3006b6747813693cf7e2b536030b21f3109f538
2020-02-25 19:53:04 -08:00
Ivan Lozano
9ac32c7674 Allow Linux hosts to use ubsan runtime sanitizers.
Linux host prebuilts for UBSan runtime are available now, so we can
enable these. There's a bit more work to be done for Windows/Darwin
support, so that's left to another CL.

Bug: 148289941
Test: Build host binary with integer overflow sanitization enabled.
Test: ./art/test/testrunner/run_build_test_target.py art-linux-bionic-x64

Change-Id: Ie98979116fa3bb8accb23d1788adcc28330a9530
2020-02-20 20:27:35 +00:00
Inseob Kim
eec88e1de8 Add vendor snapshot modules
This implements four modules (static/shared/header libraries, and
binaries) for vendor snapshot. These modules will override source
modules if BOARD_VNDK_VERSION != current.

Bug: 65377115
Test: 1) VNDK_SNAPSHOT_BUILD_ARTIFACTS=true m dist vndk vendor-snapshot
Test: 2) install snapshot under source tree
Test: 3) set BOARD_VNDK_VERSION and boot cuttlefish
Change-Id: I24ddb4c3aa6abeab60bbfd31bcbd8753e2592dc5
2020-02-07 02:59:24 +09:00
Inseob Kim
8471cdaced Implement vendor snapshot
Vendor snapshot can be captured with "m dist vendor-snapshot". With
vendor snapshot and vndk snapshot, older version of /vendor and newer
version of /system will be able to be built together by setting
BOARD_VNDK_VERSION to past vendor's version.

Only vendor modules under AOSP are to be captured. In detail, modules
under following directories are ignored:
- device/
- vendor/
- hardware/, except for interfaces/, libhardware/, libhardware_legacy/,
  and ril/

Test modules (cc_test, etc.) and sanitized modules are also ignored.

Bug: 65377115
Test: m dist vendor-snapshot
Change-Id: If7a2f6de7f36deee936930c0ccf7c47c4a0cebf6
2020-02-07 02:58:29 +09:00
Yifan Hong
1b3348d50a Add ramdisk image.
It is similar to recovery image.
Test: m nothing -j

Change-Id: I11389777c6bfb0c0d73bbb4c70091c1e70f44077
2020-01-22 16:54:18 -08:00
Mitch Phillips
734b4cb62f Add $ORIGIN to fuzzer-coverage sanitized .so's.
Build fuzzer-sanitized libraries with an $ORIGIN DT_RUNPATH. Android's linker
uses DT_RUNPATH, not DT_RPATH. When we deploy cc_fuzz targets and their
libraries to /data/fuzz/<arch>/lib, any transient shared library gets the
DT_RUNPATH from the shared library above it, and not the executable, meaning
that the lookup falls back to the system. Adding the $ORIGIN to the DT_RUNPATH
here means that transient shared libraries can be found colocated with their
parents.

This may have some interesting consequences if:

 1. Your fuzz target depends on a shared library which has `sanitize.fuzzer:
 false` (as the DT_RUNPATH won't have `$ORIGIN`, and so you may get missing
 libraries).
 2. A `SANITIZE_TARGET=fuzzer` platform has a shared object in two
 different directories (like system vs. ndk) and is depending on the linker
 implementation details to resolve this in some manner.

I don't believe either of these instances should reasonably happen in
practise.

Fixes: 145973404
Fixes: 145988908
Test: m example_fuzzer
Change-Id: I94cbf628fc1ce15c43283d72bdabd9817de1fef8
2019-12-10 17:35:55 +00:00
Treehugger Robot
e643cd2b61 Merge "Add -instcombine-lower-dbg-declare to hwasan flags." 2019-12-03 02:19:08 +00:00
Evgenii Stepanov
64bee4decf Add -instcombine-lower-dbg-declare to hwasan flags.
This is a workaround to improve hwasan reports involving stack
variables.

Bug: 112437883
Test: SANITIZE_TARGET=hwaddress, build and boot

Change-Id: I21ea2fdd2d1f04e2bb9b9847785c00a951030c74
2019-11-22 18:40:07 -08:00
Colin Cross
7228ecd5e3 Move cc.imageMutator into the android package
Prepare for making the image mutator available to all modules and
moving it between the os and arch mutators by moving it into the
android package and using an interface implemented by the module
types to control it.

Bug: 142286466
Test: No unexpected changes to out/soong/build.ninja
Change-Id: I0dcc9c7b5ec80edffade340c367f6ae4da34151b
2019-11-20 15:21:32 -08:00
Colin Cross
4af21ed26f Split local and global cflags
Native compiler flags are currently applied in approximately:
global cflags
local cflags
local include dirs
global include dirs
global conlyflags
local conlyflags
global cppflags
local cppflags

This means that a flag that is enabled in the global cppflags
cannot be disabled in the local cflags, and an Android.bp author
must know to disable it in the local cppflags.  A better order
would be:
global cflags
global conlyflags
global cppflags
local cflags
local conlyflags
local cppflags
local include dirs
global include dirs

We are mixing both the global and local cflags into a single
variable, and similar for conlyflags and cppflags, which
prevents reordering them.  This CL prepares to reorder them
by splitting the global and local cflags into separate variables.

Bug: 143713277
Test: m native
Change-Id: Ic55a8c3516c331dc5f2af9d00e59ceca9d3e6c15
2019-11-07 15:27:58 -08:00
Jooyung Han
0302a84ddc Soong generates vndk-related .libraries.txt files
This is a follow-up CL of I9a24f6975bd4b226a94f61a13d43857dcdce6b88

Generated files are passed to make via MakeVars:
- SOONG_LLNDK_LIBRARIES_FILE
- SOONG_VNDKCORE_LIBRARIES_FILE
- SOONG_VNDKSP_LIBRARIES_FILE
- SOONG_VNDKPRIVATE_LIBRARIES_FILE
- SOONG_VNDKCOREVARIANT_LIBRARIES_FILE
- SOONG_VNDK_LIBRARIES_FILE

Previously filenames were "guessed" from module names. Now VndkMutator
stores filenames as well and generate those files with them.

Bug: 142963962
Bug: 141450808
Test: m && device boots && TH
Change-Id: I0c248b707188f904df60ead50059fefe90bfd17f
2019-11-01 04:35:21 +09:00
Ivan Lozano
52767be335 Add support for Rust C libraries.
Adds the ability for rust modules to be compiled as C libraries, and
allows cc modules to depend on these rust-generated modules. This also
means that soong-rust should not have any dependencies on soong-cc aside
from what's required for testing.

There's a couple small fixes included as well:

 - A bug in libNameFromFilePath that caused issues when library's had
 "lib" in their name.
 - VariantName is removed from rust library MutatedProperties since this
 was unused.

Bug: 140726209
Test: Soong tests pass.
Test: Example cc_binary can include a rust shared library as a dep.
Test: m crosvm.experimental
Change-Id: Ia7deed1345d2423001089014cc65ce7934123da4
2019-10-28 22:09:01 -07:00
Ivan Lozano
183a3218e2 Add a common interface for cc linkable libraries.
Adds an interface, CcLinkableInterface, for cc linkable dependencies
which come from other toolchains such as Rust.

Bug: 140726209
Test: Soong tests pass, rust modules still compile.
Change-Id: I7378a46fad94fd0b735746aaf4e265fd2c2c04d8
2019-10-28 13:45:12 -07:00
Ryan Prichard
b49fe1bde7 Stop linking libdl.a into static bins
libdl.a has a no-op dlopen, which breaks static libraries that need a real
dlopen. Instead of automatically linking libdl.a into static executables,
make it optional.

Until recently, the libunwind_llvm.a unwinder, used on arm32, needed the
no-op dladdr, but it's now built using -D_LIBUNWIND_USE_DLADDR=0.

The HWASan run-time uses dlsym and dladdr, so add a libdl dependency for
HWASan-built static binaries. We could also remove the dependency from
libclang_rt.hwasan_static-*.a, but this is also easy to do.

Bug: http://b/141485154
Test: bionic unit tests, device boots, verify that static and dynamic
   executables can throw/catch an exception
Test: verify that a static executable using dlopen doesn't link (unless it
   adds an explicit dependency on libdl)

Change-Id: Ic52c3f336b671b4ed335e99c94a64dfe8614b618
2019-10-24 22:25:54 -07:00
Colin Cross
ad4a597c79 Merge "Add method to determine variations from a Target" 2019-10-17 18:52:20 +00:00
Colin Cross
0f7d2ef3ac Add method to determine variations from a Target
The arch variants are hardcoded in every module type.  Refactor
them out into a Target.Variations() method in preparation for
splitting the arch mutator into two, which will require using
different variations.

Test: m checkbuild
Change-Id: I28ef7cd5168095ac888fe77f04e27f9ad81978c0
2019-10-16 14:52:30 -07:00
Mitch Phillips
b8e593d600 Workaround unexported sancov symbols. Fix multiple sanitizer RT deps.
Fuzz targets currently have dependencies on multiple libclang_rt runtime
libraries when building with ASan/HWAsan on device. This is an error.

This happens as Soong adds the dependency on the ASan/HWASan shared
runtime library. These libraries should provide the required UBSan
components. The clang driver was previously being passed
-fsanitize=fuzzer-no-link at link time, and as it doesn't know about the
already-established dependency on ASan/HWASan, it mistakenly thinks that
there is not runtime providing the UBSan components.

This patch fixes that problem by not adding -fsanitize=fuzzer-no-link to
the link-time flags.

This revealed a underlying issue in the upstream runtime compilation.
Android uses emulated TLS, which changes the symbol names from
<my_symbol_name> to __emutls_v._<my_symbol_name>. In particular, this
fails to account for the '__sancov_lowest_stack' symbol, as it no longer
matches the linker script rule for '__sancov*', and the symbol is no
longer exported in the shared library variant of ASan/HWASan.

This patch works around the discovered issue, which is being tracked in
the linked bug. It disables stack depth instrumentation, and we no
longer depend on this symbol. This means we get a missing sanitizer
coverage feature when fuzzing, but shouldn't be too detrimental.

Bug: 142430592
Test: SANITIZE_TARGET=hwaddress m example_fuzzer && \
readelf -d example_fuzzer # ensure only ONE libclang_rt dep (in this
case, hwasan)

Change-Id: Iea6df55d592a801732511c9b690134367429d62a
2019-10-10 10:53:48 -07:00
Peter Collingbourne
1c648b8936 Allow sanitize attribute on cc_objects and propagate sanitize attributes into them.
Without this change, we can end up failing to sanitize parts of libraries
that are compiled as cc_objects, such as bcm_object.o in boringssl. This
is normally harmless (except that the sanitizer would fail to detect bugs
in unsanitized code), however boringssl in particular needs to be compiled
with HWASAN enabled in all translation units in order to avoid link errors
with newer toolchains that support HWASAN global instrumentation.

Change-Id: Ib8bd325f76b7852cab435bff79d6945768298a5c
2019-09-26 12:35:06 -07:00
Mitch Phillips
586b8a2042 Merge "Disable FORTIFY for fuzzer builds."
am: 1e7f14b1d5

Change-Id: Ifa6d2c356181af8005e8df12801141b17e5b99ae
2019-08-29 10:10:17 -07:00
Mitch Phillips
b9b3e79096 Disable FORTIFY for fuzzer builds.
Disables FORTIFY for fuzz target builds. We generally build with a
sanitizer and want the sanitizer to handle the bugs and provide us with
a nice stack trace.

Bug: 140187921
Test: m example_fuzzer && $ANDROID_HOST_OUT/fuzz/example_fuzzer (note
that you get a proper ASan report instead of a fortify crash)

Change-Id: I15a117b26c401a03785fb44c0f796588f366bc55
2019-08-28 12:41:07 -07:00
Yi Kong
e4a824d378 Merge "Switch to clang-r365631"
am: bdefa541d9

Change-Id: I4f8b4e9ce9e0a355b247b11effc5bb1e5ba07f63
2019-08-22 11:56:05 -07:00
Yi Kong
bdefa541d9 Merge "Switch to clang-r365631" 2019-08-22 18:35:54 +00:00
Yi Kong
5006a72ec9 Merge "Revert "Re-enable ASAN globals instrumentation for devices.""
am: 20cf012ad1

Change-Id: Ibffe87ad95d7336c9ffdd78eb67fd81ab4b3e1b1
2019-08-21 21:09:52 -07:00
Yi Kong
20cf012ad1 Merge "Revert "Re-enable ASAN globals instrumentation for devices."" 2019-08-22 03:43:51 +00:00
Yi Kong
da069087bf Revert "Re-enable ASAN globals instrumentation for devices."
This reverts commit cba311bcfc.

The build is actually still broken with ASAN globals instrumentation.
We accidentally suppressed ASAN by turning on the new pass manager and
the build breakage was not discovered.

Bug: 137312732
Bug: 139747256
Change-Id: I8110e1413468c4d760a59a8de816a72c9852a7c8
2019-08-22 00:46:36 +00:00
Yi Kong
55d2d90ea4 Merge "Disable new pass manager for ASAN build"
am: 5724333e22

Change-Id: I670af9bab9dca4284420cda4bca5ed5884e7d6a6
2019-08-21 14:47:29 -07:00
Yi Kong
20233a43db Disable new pass manager for ASAN build
ASAN build has some weird issues with the new pass manager, keep using
the legacy pass manager for now.

Test: presubmit
Bug: 139747256
Change-Id: I345afbf6bc4043f274a4e7545a895b59c65641b0
2019-08-21 20:38:51 +00:00
Yi Kong
d255c7bc2f Switch to clang-r365631
Test: build, boot, bionic-unit-test
Test: For Googlers, go/clang-r365631-testing
Bug: 131328001
Change-Id: Ib357d9044a72e41f6bde1e5ec2db34e90706124d
2019-08-15 04:47:34 +00:00
Jiyong Park
72969547dc Merge "Fix sanitizer dep"
am: e49256e564

Change-Id: I2199bff441c53410030ccf7f48fc386a7e123c4f
2019-08-11 10:45:55 -07:00
Treehugger Robot
e49256e564 Merge "Fix sanitizer dep" 2019-08-11 17:12:47 +00:00
Jiyong Park
1d1119f4bd Fix sanitizer dep
This change fixes a problem in sanitizerMutator where a module is linked
with of non-sanitized variant of a lib at build-time, but is linked with
the sanitized variant of the lib at run-time.

This happened because, for each sanitizer type, every shared libs are
split into non-sanitized and sanitized variants, and then either of the
variants are suppressed from Make so that it isn't installed to the
device.

This change fixes the problem by NOT splitting for shared libs; only the
sanitized variant is created if needed. Header libs, static libs and
shared libs for a few sanitizer types (asan/fuzzer) are however split
into two. This is because the static and headers libs become part of the
depending module, and asan/fuzzer require that the depending module and
the dependant module should be compiled for the same sanitizer.

Bug: 138103882
Bug: 138426065
Test: m com.android.runtime.debug
Check that libziparchive exists under both
/system/apex/com.android.runtime/[lib|lib64]

Change-Id: Ia447785c485c0d049e19477b32bc638bfe6f1608
2019-08-08 01:51:26 +09:00
Mitch Phillips
cead9bad66 Merge "Disable LTO when building with fuzzer support."
am: df7d2cc9f8

Change-Id: Ie4f0e1c6266cca662c4eb133ce2bd9ce85b1dcd9
2019-08-05 11:39:28 -07:00
Mitch Phillips
34b493fec5 Disable LTO when building with fuzzer support.
Bug: 131771163

LTO is currently broken when building with SANITIZE_TARGET=fuzzer. The
compiler bug is currently being addressed upstream (see linked bug), but
we have applied a local workaround in the build system to disable LTO
when building using the fuzzer config.

There is a bug here however. In the sanitizer mutator we explicitly
remove -flto and add -fno-lto. The sanitizer mutator runs after the LTO
mutator, so (in general) this works just fine. The problem exists when a
target specifies an explicit 'lto: { ... }' flag in their Android.bp. In
this case, the sanitizer mutator disables LTO, then the flags are parsed
from the Android.bp, re-enabling LTO.

This patch fixes this issue. If the sanitizer mutator has added the
-fsanitize=fuzzer-no-link flags, then the LTO mutator won't add the LTO
flags after this fact.

Test: Build a target with SANITIZE_TARGET=fuzzer (or a cc_fuzz target),
where there is an explitiy 'lto: { ... }' and watch it now succeed in
building.

Change-Id: I6643909417f666539c23469816926b806e204b06
2019-08-02 16:57:55 -07:00
Dan Albert
233d006ef7 Merge "Remove asanLibs."
am: 6303423549

Change-Id: I4c5bc78924613aa6c61399400f468f7ff7353a53
2019-07-22 11:29:26 -07:00
Dan Albert
55a18ba71a Remove asanLibs.
We already link the shared prebuilt from the toolchain. This is
redundant and the wrong version.

Test: make checkbuild
Bug: http://b/74067984
Change-Id: I4b5d23514158eebfb4eea2aa6761e076131c3224
2019-07-19 12:53:27 -07:00
Mitch Phillips
88cddcf297 Merge "Re-enable ASAN globals instrumentation for devices."
am: 68c9eed6b2

Change-Id: I8a29cd64cd1c9a60adcc1bc8858163a1589cc20e
2019-07-12 13:20:19 -07:00
Mitch Phillips
cba311bcfc Re-enable ASAN globals instrumentation for devices.
ASan globals instrumentation apparently broke the build in the pass.
This is now a customer feature to get this up and running, let's see if
it works.

Bug: 137312732

Test: Build the platform, deploy and run an asan-ified test (maybe
resolv_integration_test?).

Change-Id: Ic4ee0db617c290d8a3fec52db4b90bc4772696b8
2019-07-11 17:16:58 -07:00
Colin Cross
e0318dec1b Merge changes Ia77090da,I95a57f76 am: e264f22bec
am: 0240f5cea1

Change-Id: I61e3e45e533cb62c548fcd09b2bf5eb3890e0a38
2019-06-21 10:51:45 -07:00
Colin Cross
e264f22bec Merge changes Ia77090da,I95a57f76
* changes:
  Fix data races in finder_test.go
  Optimize sanitizerRuntimeDepsMutator
2019-06-21 17:01:23 +00:00
Mitch Phillips
a87c8005b4 Merge "Remove experimental pass manager for fuzzer builds." am: c4be0815d8
am: 07c9775cef

Change-Id: I333316ff6041b6139b86bed5469885b42b6be96d
2019-06-20 18:17:19 -07:00
Treehugger Robot
c4be0815d8 Merge "Remove experimental pass manager for fuzzer builds." 2019-06-21 00:51:26 +00:00
Colin Cross
0b90833ea8 Optimize sanitizerRuntimeDepsMutator
sanitizerRuntimeDepsMutator only modifies the currently visited
module, it can visit modules in parallel.

Also, stop recursing into modules that are not static dependencies,
and stop recursing if the module already has all modifications that
the mutator could make.

Test: m checkbuild
Change-Id: I95a57f763a91940f1854ba3c587a2f70e8baba97
2019-06-20 15:23:41 -07:00
Mitch Phillips
74384758a6 Remove experimental pass manager for fuzzer builds.
Sanitizer coverage is currently broken with the experimental pass
manager. See b/133876586 for more information. The patch is currently
being worked on upstream (https://reviews.llvm.org/D62888), but is not
ready yet. Hence, we disable it here (similar to the LTO bug).

Bug: 133876586
Test: Build anything with SANITIZE_TARGET='fuzzer', verify that it has
'sancov' symbols.

Change-Id: I4302a8cf05300015aaff137f40b61d5685dc3fea
2019-06-17 10:33:52 -07:00
Evgenii Stepanov
d7344ad0ca Disable new LLVM pass manager for HWASan. am: 1c69e83030
am: b85d386af5

Change-Id: I443bdbf313216591841272cbe51491fd6bd51fbd
2019-06-15 14:13:04 -07:00
Evgenii Stepanov
1c69e83030 Disable new LLVM pass manager for HWASan.
Current Android toolchain does not support hwasan with new pm.

Bug: 135298400
Test: manual, inspect the binaries for calls to __hwasan_init
Change-Id: I126c59e6ecabc3a1699e1bf34c546568b6e8a21f
2019-06-14 18:39:59 -07:00
Mitch Phillips
bfeade6424 Fix fuzzer builds [#2].
- Updates the fuzzer builds to use SANITIZE_TARGET='fuzzer' instead of
'coverage'.
- Removed an old dependency that made fuzzer builds without ASan
an error.
- Fixed up the build flags to allow fuzzers to be built. Previously, the
coverage flags were manually provided. As the toolchain has moved on,
these flags are no longer compatible with libFuzzer, and so I've updated
them to use the correct, compatible flags.
- Added a dependency mutator for fuzzer coverage.

Bug: 121042685
Test: With all patches in the bug merged, build a fuzzer using
'SANITIZE_TARGET=fuzzer mmma <your_fuzzer>'.

Change-Id: Ib6246980f77bc4babe587b1e88038aa12228fa83
Merged-In: Ib6246980f77bc4babe587b1e88038aa12228fa83
2019-05-30 16:49:42 +00:00
Mitch Phillips
5a6ea6cf3b Fix fuzzer builds [#2].
- Updates the fuzzer builds to use SANITIZE_TARGET='fuzzer' instead of
'coverage'.
- Removed an old dependency that made fuzzer builds without ASan
an error.
- Fixed up the build flags to allow fuzzers to be built. Previously, the
coverage flags were manually provided. As the toolchain has moved on,
these flags are no longer compatible with libFuzzer, and so I've updated
them to use the correct, compatible flags.
- Added a dependency mutator for fuzzer coverage.

Bug: 121042685
Test: With all patches in the bug merged, build a fuzzer using
'SANITIZE_TARGET=fuzzer mmma <your_fuzzer>'.

This is the qt-dev-plus-aosp cherrypick of aosp/954925. See the AOSP
commit for further information.

Change-Id: Ib6246980f77bc4babe587b1e88038aa12228fa83
2019-05-28 15:46:11 -07:00
Evgenii Stepanov
6c8b9a0296 Disable malloc fill in HWASan.
am: 2c6484e334

Change-Id: I84cd62a3cc76006c968136b69bf4d88137b2f934
2019-05-15 15:28:45 -07:00
Evgenii Stepanov
2c6484e334 Disable malloc fill in HWASan.
HWASan has a feature to fill malloc() memory with non-zero pattern.
This has found a bug or two in the past, but it also keep causing hard
to debug issues. The main problem is lack of diagnostics - use of
pattern-initialized memory is not an immediate crash. More often than
not it manifests as a subtle change in system behavior.

Having MemorySanitizer on Android would be nice...

This change does not affect any shipping configuration, but improves
stability of testing-only SANITIZE_TARGET=hwaddress build.

Bug: 132803232
Bug: 132652537
Bug: 131438232
Bug: 132810685
Test: SANITIZE_TARGET=hwasan on crosshatch successfully boots in ~100%
      attempt (up from ~99% currently).

Change-Id: I7dcbcdf1b8a5b8556e32690327b32f04879e5db1
2019-05-15 13:53:37 -07:00
Christopher Ferris
422687005a Merge "Remove libc_scudo library when building asan." am: d7e66d9e7c
am: 486b170bbc

Change-Id: Ifd1c9021bad87c4a74104be311a04ba73a4419b6
2019-05-13 17:30:56 -07:00
Christopher Ferris
d7e66d9e7c Merge "Remove libc_scudo library when building asan." 2019-05-14 00:12:33 +00:00
Inseob Kim
c012b19eb0 Merge "Attach global variables to Context" am: a1591ab08c
am: 66c5cac22b

Change-Id: Icaf7aa78580459fd76605ec66b5bbaac13a30c9e
2019-05-09 19:42:18 -07:00
Christopher Ferris
753d4a69d5 Remove libc_scudo library when building asan.
Running any executable built with asan and libc_scudo results in crashes.

Bug: 131810078

Test: Built the media processes with the sanitizer enabled verifying
Test: that the libc_scudo.so shared library is not listed in the
Test: mediaextractor and the mediaswcodec binaries.
Test: Build the media processes without the sanitizer enabled verifying
Test: that the libc_scudo.so shared library is listed in the
Test: mediaextractor and the mediaswcodec binaries.
Change-Id: Ie55a0414088787ec11d85fffcb04592ed4f23c57
2019-05-09 13:35:37 -07:00
Inseob Kim
9516ee9556 Attach global variables to Context
Global variables make testing difficult, and they should attached to
Context.

Bug: N/A
Test: m
Change-Id: Ic671dda755e99d036c7ddce0eed114496374d7ec
2019-05-09 12:29:58 +09:00
Evgenii Stepanov
d98ccb44f2 Disable hwasan memory stats.
Disable a debugging feature in hwasan that seems to be causing flaky selinux
denials in the boot test:

05-02 12:11:11.360  1663  1663 I auditd  : type=1400 audit(0.0:8): avc: denied { read } for comm="iptables-wrappe" path="/proc/1015/statm" dev="proc" ino=30968 scontext=u:r:netutils_wrapper:s0 tcontext=u:r:netmgrd:s0 tclass=file permissive=0

I could not reproduce this locally, but this feature has no users and
I've verified that things keep working without it.

This does not affect any shipped product.

Bug: 131438232
Bug: 112438058
Bug: 131845076
Test: crosshatch_hwasan boot test
Change-Id: I08d46d19151e6d5221cdd56fd6864dae224fae25
2019-05-02 12:52:32 -07:00
Peter Collingbourne
e726ba56ac Pass -fsanitize-hwaddress-abi=platform when building with hwasan.
Reduces size of walleye_hwasan-userdebug system.img by another 4.5MB.

Bug: 122363025
Change-Id: I6d15c237dc5f330ad574a73147b2b2c712fe125e
2019-03-21 16:22:00 -07:00
Peter Collingbourne
967511a4e8 Pass -hwasan-allow-ifunc when building with hwasan.
Now that the toolchain and bionic both support ifuncs in
static executables, we can turn this on. Reduces size of
walleye_hwasan-userdebug system.img by 11MB.

Change-Id: I2f19b22518153328eee3fdca79d0c851cc513c3a
2019-03-20 19:42:42 +00:00
Peter Collingbourne
bd19db0da6 Remove workarounds for old compiler versions.
LLVM r349610 was released, so these workarounds are no longer required.

Bug: 112907825
Change-Id: Ia6ba0034881f2ab657d8420df3047c21757c7d9b
2019-03-06 10:48:36 -08:00
Jiyong Park
f97782b18c Remove prefer_sanitize.* properties
The properties are no longer required as an APEX module is mutated with
required sanitizers which are gathered by scanning the sanitizers that
are enabled for its direct dependencies.

Bug: 124128094
Test: m on marlin
The extractor libs are found under /system/apex/com.android.media

Merged-In: I55961d400dcbac067a5c0dcecb90e399d4991a70
Change-Id: I55961d400dcbac067a5c0dcecb90e399d4991a70
(cherry picked from commit abda0eb76b)
2019-02-14 12:30:49 +09:00
Colin Cross
571cccfcbc Prepare for a type-safe OnceKey
Add an opaque OnceKey type and use it for all calls to Once in
build/soong.  A future patch will convert the arguments to
Once* to OnceKey once users outside build/soong have been updated.

Test: onceper_test.go
Change-Id: Ifcb338e6e603e804e507203c9508d30ffb2df966
2019-02-06 01:52:41 +00:00
Kostya Kortchinsky
d5275c8657 Add option to disable Scudo globally [Soong]
This adds an option in Soong to turn off Scudo globally.

Bug: 123228023
Test: enable Scudo for tombstoned, lunch marlin_svelte-eng && m -j, and
make sure that Scudo is not linked in
out/target/product/marlin/system/bin/tombstoned
Test: enable Scudo for tombstoned, lunch marlin-userdebug && m -j, and
make sure that Scudo is linked in
out/target/product/marlin/system/bin/tombstoned

Change-Id: I0b0992446953fc4074bde94507b66f92764c8143
Merged-In: I0b0992446953fc4074bde94507b66f92764c8143
2019-02-04 12:29:17 -08:00
Jiyong Park
a2aca28750 Use bootstrap linker for asan build
This change the asan version of
https://android-review.googlesource.com/c/platform/build/soong/+/879237

Bug: 123725034
Test: forrest run on asan_cf_x86_pasan
Test: SANITIZE_TARGET=address m init_second_stage
inspect /system/bin/init with readelf
DT_INTERP is set to /system/bin/bootstrap/linker_asan

Change-Id: I0fabe08cc63126aadec18ca8e9f2973c33411a4f
2019-02-02 13:28:57 +09:00
Evgenii Stepanov
93c3f5368d [hwasan] Remove deprecated compiler flag (NFC)
-hwasan-with-ifunc=0 matches the default value of the flag, and there
are no plans to change that.

Test: SANITIZE_TARGET=hwaddress keeps working
Change-Id: Ie46ffa6ae3c42a9677c3a9a3b5cdc6fb62c2c2f0
2019-02-01 22:56:03 +00:00
Jiyong Park
8222663f1b Fix: runtime apex is not instrumented with sanitizer
Fixing the problem that IsSanitizerEnabled always returns false due to
the different sanitizer names from config.SanitizerDevice() and
sanitizerType.String().

Bug: 123708856
Test: SANITIZE_TARGET=hwaddress m com.android.runtime.release
$ ls -al out/soong/.intermediates/art/build/apex/com.android.runtime.release/android_common_hwasan_com.android.runtime.release/image.apex/lib | wc -l
34
$ ls -al out/soong/.intermediates/art/build/apex/com.android.runtime.release/android_common_hwasan_com.android.runtime.release/image.apex/lib64 | wc -l
35
$ ls -al out/target/product/blueline/apex/com.android.runtime.release/lib | wc -l
34
$ ls -al out/target/product/blueline/apex/com.android.runtime.release/lib64 | wc -l
35

Test: inspect out/soong/build.ninja
- Variant of com.android.runtime.release is "android_common_hwasan_com.android.runtime.release"
- Dependencies of com.android.runtime.release are hwasan variants: e.g.,
  out/soong/.intermediates/bionic/libc/libc/android_arm64_armv8-2a_kryo385_core_shared_hwasan_com.android.runtime.release/libc.so

Test: ls out/soong/.intermediates/art/build/apex/com.android.runtime.release/android_common_hwasan_com.android.runtime.release/image.apex/lib64/*.so  | xargs readelf -d | grep libclang_rt.hwasan | wc -l
29

Change-Id: Idbb1f68a3ea6bdd02351d6f6048c3eedb9cf32d2
2019-02-01 11:26:04 +09:00
Jiyong Park
3b1746a212 Fix: deps to sanitizer runtime libs are with correct 'image' variant
This change fixes a bug that sanitizer runtime libs for non-core variant
(e.g. recovery, vendor, etc.) are not installed. It happened because the
dependency to the sanitizer runtime lib was without 'image' variant,
which in most case caused only the core variant - which is the first in
the image variants - of the lib to be installed.

Fixing the issue by correctly selecting image variant depending on the
location of the lib having dependency to the runtime lib.

Bug: 123525879
Test: SANITIZE_TARGET=hwaddress m out/target/product/blueline/boot.img
Test: SANITIZE_TARGET=address m out/target/product/blueline/boot.img
libclang_rt.*.so is under
out/target/product/blueline/root/recovery/system/lib64

Change-Id: Iea7d718d4971e36521f0a3f712a454de944cd7ac
2019-01-31 01:58:26 +09:00
Jiyong Park
388ef3f5aa Create sanitizer variants of APEX only when SANITIZE_TARGET is set
This fixes a problem that APEX is unconditionally mutated for all
sanitizer types. This can make an APEX to include sanitized version
of a lib even when SANITIZE_TARGET is not set. It can happen when lib X
is directly depended on by an APEX (e.g. via native_shared_libs) and X
has a sanitized variant due to the dependency from another library Y
which is force sanitized (via 'sanitize' property). In that case,
regardless of lib Y is in the APEX or not, the APEX chooses the
sanitized variant of lib X since the dependency from APEX to the lib is
created with AddFarVariationDependency.

Fixing this problem by mutating the APEX for a sanitizer type only when
the device is requested to be sanitized.

Bug: 122717287
Test: add libnetd_client to com.android.runtime APEX.
Inspect build.ninja to verify that libnetd_client.so in the runtime APEX
is not a sanitized one.

Change-Id: I918bc8407137d74c5456142b3a29de13df68c0b3
2019-01-29 07:10:31 +09:00
Jiyong Park
64a44f231d Make sure that ASAN runtime lib is the first DT_NEEDED one
Introduce a new tag earlySharedDepTag which is added in front of the
ordinary sharedDep dependencies. Dependency to the ASAN runtime lib is
added with the new tag.

Bug: 120894259
Bug: 121038155
Test: m; SANITIZE_TARGET=address m
Use readelf -d to see if the runtime lib is in the first DT_NEEDED one.

Change-Id: I90de6ab95df734a99995532d826564b13fe05316
2019-01-25 14:05:51 +09:00
Pirama Arumuga Nainar
6aa210243c Revert "Revert "Fix: sanitizerRuntimeMutator is not run for host""
Bug: http://b/123254047

This reverts commit 84757ea7ea.

Reason for revert: veridex asan failure is fixed.

Change-Id: Id03180b8d3d1dc1386fd7e4f800d64dc8578139c
2019-01-25 00:21:02 +00:00
Doug Horn
c32c6b0d79 Support building for Fuchsia.
This CL adds configs for the arm64 and x64 fuchsia
device targets, sets up the necessary linker flags,
and disables some functionality that is not currently
supported on Fuchsia.

Bug: 119831161
Test: Compile walleye, internal validation against
fuchsia_arm64-eng and fuchsia_x86_64-eng.
Change-Id: I2881b99d2e3a1995e2d8c00a2d86ee101a972c94
2019-01-24 18:59:29 +00:00
Dan Albert
84757ea7ea Revert "Fix: sanitizerRuntimeMutator is not run for host"
This reverts commit 1c29b0e6ec.

Reason for revert: Broke aosp_x86_64

Change-Id: I581200f1c271c3e1a39d5cdad84c782977b13054
2019-01-23 23:33:25 +00:00
Jiyong Park
1c29b0e6ec Fix: sanitizerRuntimeMutator is not run for host
Bug: 123254047
Test: m ASAN_OPTIONS=detect_leaks=0 SANITIZE_HOST=address
FORCE_BUILD_LLVM_COMPONENTS=true out/host/linux-x86/bin/adb
nm -an out/host/linux-x86/bin/adb  | grep -c asan
shows non-zero value

Change-Id: I030e08bd0db38585b1fdaecd00220406f1e8b371
2019-01-23 23:37:45 +09:00
Jiyong Park
379de2fab0 APEXes can be sanitized
This change first introduces the interface "Sanitizeable" that
module types other than cc.Module can use to be handled by the sanitizer
mutator. APEX module, by implementing the interface, gets sanitizer
variants.

In doing so, sanitizer.go is refactored so that modules have explicit
dependencies to the runtime sanitizer libraries. This allows the runtime
library to be packaged into the APEX when required. This also completes
the dependency graph; updating the prebuilt sanitizer runtime will
trigger rebuilding of modules using the runtime.

Bug: 120894259
Bug: 121038155
Test: SANITIZE_TARGET=hwaddress m apex.test
Test: TARGET_FLATTEN_APEX=true SANITIZE_TARGET=address m
Change-Id: Ia91576ff48cda3c996350308b75bf83fcf7c23d7
2019-01-13 00:48:47 +09:00
Evgenii Stepanov
3c5a52a477 [hwasan] Reduce history size to save memory.
Bug: 112437883
Test: adb shell echo $HWASAN_OPTIONS
Change-Id: Ifc4ab10e37efb1a0ce7ea77ad691947d24c2da2b
2018-12-18 17:02:44 -08:00
Ivan Lozano
7929bba218 Add option to avoid recovering with diagnostics.
Add a no_recover option that allows specifying which sanitizers in
diagnostics modes shouldn't recover. This can help debugging as we test
enabling sanitizers in new libraries since it'll cause tombstones to be
generated along with the diagnostics information.

Bug: 80195448
Bug: 110791537
Test: Compiled test module with this flag, checked compiler command.
Test: Test module crashed, tombstone contained diagnostics information.
Change-Id: Ie938923ef95716c2d49d6cd719ee223ad62755c6
2018-12-12 10:01:16 -08:00
Evgenii Stepanov
0a87b664c3 Disable hwasan frame descriptions.
Current implementation does not play nice with -gc-sections.

Bug: 120673911
Test: make SANITIZE_TARGET=hwaddress recovery-persist
Change-Id: I36cd37fb41c0c26c7e747e2c1dd5fadf7a31f4e7
2018-12-07 15:33:24 -08:00
Chih-Hung Hsieh
3567e62f97 Switch to clang-r346389.
* Add -fno-sanitize=implicit-integer-sign-change when
  there is any integer related sanitizer, and this check
  is not explicitly specified.
  Android core does not boot with this new sanitizer yet.
* Filter out -fno-sanitize=implicit-integer-sign-change
  from tooling flags.

Bug: 119329758
Bug: 119557795
Test: make checkbuild, boot, go/clang-r346389-testing
Change-Id: I709de569cb73d070fc4958e2b4387f4041bc5438
2018-12-04 19:50:45 +00:00
Evgenii Stepanov
98f5b0642c Add sanitizer runtime library to recovery when needed.
Make sanitized targets in recovery depend on ".recovery" flavor of
sanitizer runtime library. This forces installation of the runtime
library in recovery image as long as at least one target depends on it.

Test: hwasan build can boot into recovery
Bug: 112438058
Bug: 119582521
Change-Id: I1b7f9fa4ff5f29acb03c27074512ea24467a3d37
2018-11-29 23:22:20 +00:00
Peter Collingbourne
8c7e6e2626 Add an "scs" flag for enabling shadow call stack on targets.
Shadow call stack (SCS) is a security mitigation that uses a
separate stack (the SCS) for return addresses.

The effect of setting sanitize.scs on a shared library is to build
the library and all of its static library dependencies with SCS. This
is similar to CFI and the other sanitizers.

Bug: 112907825
Bug: 119557795
Change-Id: I82fb2b38b10eac911c4d2d120b74fea4af0622ad
2018-11-19 17:39:23 -08:00
Evgenii Stepanov
1e79844f15 Apply HWASan to libc-in-recovery.
HWASan is disabled in recovery strictly for code size, not for
correctness. With this change, HWASan binaries and libraries can be
used in recovery.

The real reason is the make build system which has no idea of the big
picture, and makes it hard to disable HWASan in _all_ recovery modules
recursively. A few static libraries have sneaked in.

Bug: 119582521
Test: sideload an OTA onto a hwasan device
Change-Id: I6536cc7bf5bfb37f939b585545a23c2068fbd47f
2018-11-15 17:34:18 -08:00
Peter Collingbourne
abde584fd1 Stop passing the gold plugin path to llvm-ar.
llvm-ar takes a --plugin argument but it is ignored for compatibility,
so passing it has no effect.

Change-Id: I4fc51d226d66cf2a43462d3d4ccc12e6e5ebb226
2018-11-08 20:13:16 -08:00
Yi Kong
8c3c0f50d0 Revert "Prevent clang from using the x18 register on arm64."
This reverts commit 98d8580c3a.

Change no longer needed with the new LLVM toolchain update.

Bug: 112907825
Bug: 111759196
Change-Id: Ife3ce47a602dd850ac84bb51abc70c0ca157776e
2018-11-08 21:07:08 +00:00
Peter Collingbourne
98d8580c3a Prevent clang from using the x18 register on arm64.
This is achieved via the compiler flag -ffixed-x18 for non-LTO builds
and the linker flag -plugin-opt -mattr=+reserve-x18 for LTO builds.

This change should be reverted once we upgrade past LLVM r340889
which does this by default on Android.

Bug: 112907825
Bug: 111759196
Change-Id: I05473ddbb98319d87d442425b4d715647eae3a38
2018-10-24 23:40:49 +00:00
Evgenii Stepanov
109029fb5c Define HWADDRESS_SANITIZER_GLOBAL_OPTIONS.
It will be exported in device environment as HWASAN_OPTIONS.

Bug: 112438058
Test: none
Change-Id: I574b46060b3193c9f2351116a91ebc35470ae803
2018-10-12 18:18:13 +00:00
Kostya Kortchinsky
ad73b2e18a Scudo minimal runtime support for Soong
Scudo is now compatible with the -fsanitize-minimal-runtime, and offers a new
dynamic library that doesn't bundle UBSan.

This patch adds support for this new library in Soong, preferring it over the
full one, unless a UBSan or diagnostic dependency is found.

Test: aosp compiled with m -j
Test: local test enabling Scudo for tombstoned
Change-Id: I17794131db148b33f8a8710ac43302cadf1af314
2018-10-11 11:55:16 -07:00
Ivan Lozano
ae6ae1d880 Apply minimal runtime to the rest of ubsan.
Make sure that the minimal runtime gets applied to the rest
of the sanitizers we might use from ubsan.

Bug: 80195448
Test: Build success and checked build flags.
Change-Id: I31b211b80bb1068c153a9b65454a2605933c9568
2018-10-09 08:05:27 -07:00
Dan Willemsen
8536d6b3b7 Remove GCC checks
Clang is always used now, so we can remove all the GCC checks. Removing
GCC-specific configuration will happen in the next CL.

Test: m
Change-Id: I4835ecf6062159315d0dfb07b098e60bff033a8a
2018-10-09 02:16:58 +00:00
Evgenii Stepanov
dbf1d4f884 (soong) Add -fsanitize= argument to assembly flags.
It allows use of sanitizer preprocessor macros (like __has_feature())
in assembly files.

Bug: 112438058
Test: SANITIZE_TARGET=hwaddress
Change-Id: Id3fed5492ab9473cbb13cd6c0485302412e8b1de
2018-09-07 10:23:07 -07:00
Evgenii Stepanov
d97a6e9483 Add "hwaddress" sanitizer.
This is a new sanitizer similar to ASan, but with a few differences
from the build system perspective:
* Only runs on AArch64.
* Supports static binaries.
* Bionic itself will be built with HWASan.
* Does not have any "if a library is sanitized than the binary must
  be, too" requirements unlike ASan. Even better, individual static
  libraries can be freely sanitized or not. We propagate "nosanitize"
  from binaries to static libraries anyway, because otherwise there
  is no good way to disable hwasan on a binary as a whole.

Same a CFI, we export a list of sanitized static libraries to make.
In fact, we export separate lists for vendor and regular libraries,
because it is possible for one to be sanitized without the other
(i.e. there can be mylib.hwasan.vendor w/o mylib.hwasan or vice
versa).

Bug: 112438058, 112709969
Test: manual, part of a bigger patch set

Change-Id: Ie4fdeb522ac03cf9684526882e84dfee3807b6a7
2018-08-16 13:18:47 -07:00
Pirama Arumuga Nainar
b6682c47b8 Merge "Do not enable sanitizers on Windows"
am: d7e5c05eac

Change-Id: I7398e6b08154c5bc7fad0507bd9e1dae8c14da0a
2018-06-26 17:05:30 -07:00
Pirama Arumuga Nainar
83d716c413 Do not enable sanitizers on Windows
Bug: http://b/69933068

Test: m native-host-cross SANITIZE_HOST=address
Change-Id: Ia9ff941fb569b0a2e9c4eef604fd165f94bca31a
2018-06-26 14:18:16 -07:00
Colin Cross
e98238b3ab Merge "Use WalkDeps instead of VisitDepsDepthFirst"
am: cbafd0fb48

Change-Id: Ic22ffa9ac8a5e3b5c29cd5e85664acb1afebc04f
2018-06-22 17:14:31 -07:00
Colin Cross
6b75360cbc Use WalkDeps instead of VisitDepsDepthFirst
VisitDepsDepthFirst is almost never correct, as it can't query
dependency tags of multiple dependencies between the same two modules.
Replace VisitDepsDepthFirst with WalkDeps in sanitize.go and
python.go.  Also verify the dependency tag before continuing to
recurse to ensure that they don't recurse through genrules and into
unrelated modules.

Test: m checkbuild
Change-Id: I2f7560126f56b51a40ec39dfbdcc18b5891489f7
2018-06-22 12:44:35 -07:00
Kostya Kortchinsky
9cba8204b1 Soong support for Scudo
am: d18ae5ce98

Change-Id: I0c0fcf29ccd99575de573a915c7da5d51b14cd45
2018-06-19 13:11:58 -07:00
Kostya Kortchinsky
d18ae5ce98 Soong support for Scudo
Scudo is a hardened usermode allocator that is part of LLVM's compiler-rt
project (home of the Sanitizers). clang allows for -fsanitize=scudo as a
possible command line option to link the shared Scudo library to a binary.

This patch add Scudo as a potential sanitize option. Scudo is not compatible
with ASan and TSan and will be disabled if either is enabled.

Bug: 72112048
Test: aosp compiled with m -j
Test: local experiment with scudo: true to ensure that a test target
(tombstoned) could be linked with scudo.

Change-Id: I76bb6c60891d4782f6665a112c4c2bf7c31645da
2018-06-19 09:46:09 -07:00
Vishwath Mohan
722b64e0ad Don't enable diagnostics for CFI when setting the CFI sanitizer. am: 05b002dea0
am: dc55e621bb

Change-Id: I04214a9fcb50363bd5d82362b366e5bf69355183
2018-05-31 11:03:56 -07:00
Vishwath Mohan
05b002dea0 Don't enable diagnostics for CFI when setting the CFI sanitizer.
The SetSanitizer() method in cc/sanitize.go was also enabling
diagnostics for CFI when invoked from the sanitizer mutator. We
shouldn't be doing this, so this CL disables that.

Bug: 79785496
Test: strings libziparchive.so | grep 'ubsan'
Change-Id: Iffe0d4e9c333ac5dfbec3f48e381c232ce5d4463
2018-05-30 20:52:39 -07:00
Vishwath Mohan
4cac067ca1 Disable CFI for vendor variants of all components
am: 9ccbba0200

Change-Id: I6a6a839475f58f92180bfd391035dd538df71a50
2018-05-29 16:36:13 -07:00
Vishwath Mohan
9ccbba0200 Disable CFI for vendor variants of all components
The current VNDK ABI snapshot expects that CFI is disabled for
components that either in the include paths (from cfi-common.mk) OR
enabled directly in the makefile/blueprint. However, on non-arm64
architectures, the build system was only disabling CFI for vendor
components in the include paths.

This topic corrects it by (a) removing the include paths check to
disable CFI for vendor variants (this CL), and (b) inheriting the CFI
include paths in all product configs to ensure that when we update the
ABI we're able to move to relying exclusively
on (PRODUCT_)CFI_INCLUDE_PATHS.

Bug: 66301104
Test: ABI matches for all architectures.
Change-Id: I648edf13346b18fd88b623682e8590ed44709e0d
2018-05-28 13:57:48 -07:00
Vishwath Mohan
40aaea2321 Restrict CFI_INCLUDE_PATHS to Arm64
am: 1c54f66bd5

Change-Id: I379932454f8f18d7029f3fa3eb1654f4f36997c1
2018-05-25 00:24:53 -07:00
Vishwath Mohan
1c54f66bd5 Restrict CFI_INCLUDE_PATHS to Arm64
This CL restricts CFI_INCLUDE_PATHS and PRODUCT_CFI_INCLUDE_PATHS to
Arm64 only.

Bug: 66301104
Test: x86 targets do not respect the include paths variables
Change-Id: I66ec2fb05435535aaf5d59fdfc7a170a4fdd4f26
2018-05-24 18:36:18 -07:00
Vishwath Mohan
9b87f812ea Disable CFI for vendor variants of VNDK libraries
am: 7589c82eec

Change-Id: I3d44d7c66d777df15ce8ecbd7f4577eaf293affb
2018-05-24 14:43:32 -07:00
Vishwath Mohan
7589c82eec Disable CFI for vendor variants of VNDK libraries
Enabling CFI changes the VNDK ABI from the frozen snapshot, so the
only solution for now is to temporarily disable CFI on all vendor
variants for the sake of compatibility.

Bug: 66301104
Test: ABI is consistent.
Change-Id: Ie7dca41e0f647808b08adede09a30f3c746e6bda
2018-05-23 23:39:38 -07:00
Vishwath Mohan
165e01b744 Merge "Allow abi diffs sanitized variants of vndk libraries on production devices." into pi-dev 2018-05-23 17:47:38 +00:00
Ivan Lozano
1838ef9be4 Don't export UBSan minimal runtime symbols.
When linking in the UBSan minimal runtime, don't export the symbols.
This was resulting in an edge case where symbols were sometimes
undefined at runtime on address sanitized builds if static library
dependencies were integer overflow sanitized.

Bug: 78766744
Test: readelf on libraries show either inclusion of the shared library
or no undefined symbols related to the minimal runtime.

Change-Id: Ide85c8c6b53b400ce9166ccaf96d250797fe4b24
Merged-In: Ide85c8c6b53b400ce9166ccaf96d250797fe4b24
(cherry picked from commit 59fdea2ac2)
2018-05-16 10:42:39 -07:00
Ivan Lozano
59fdea2ac2 Don't export UBSan minimal runtime symbols.
When linking in the UBSan minimal runtime, don't export the symbols.
This was resulting in an edge case where symbols were sometimes
undefined at runtime on address sanitized builds if static library
dependencies were integer overflow sanitized.

Bug: 78766744
Test: readelf on libraries show either inclusion of the shared library
or no undefined symbols related to the minimal runtime.

Change-Id: Ide85c8c6b53b400ce9166ccaf96d250797fe4b24
2018-05-15 08:37:18 -07:00
Jayant Chowdhary
f267f715eb Allow abi diffs sanitized variants of vndk libraries on production devices.
Previously abi diffs were allowed only on unsanitized variants of vndk
libraries. This CL allows them on all sanitized variants which go onto
production devices, eg: cfi variants.

Bug: 66301104

Test: Without this change, for arm64 libstagefright_foundation doesn't
      get an lsdump file since we don't build an unsanitized variant
      (aosp_arm64_ab).

Test: With this change, for arm64 libstagefright_foundation does
      get an lsdump file (aosp_arm64_ab)

Merged-In: I94f82fd84fc898e4980c3f3619df9677ed723c32
Change-Id: I94f82fd84fc898e4980c3f3619df9677ed723c32
(cherry picked from commit b7e08ca830)
2018-05-14 18:34:40 -07:00
Jayant Chowdhary
b7e08ca830 Allow abi diffs sanitized variants of vndk libraries on production devices.
Previously abi diffs were allowed only on unsanitized variants of vndk
libraries. This CL allows them on all sanitized variants which go onto
production devices, eg: cfi variants.

Bug: 66301104

Test: Without this change, for arm64 libstagefright_foundation doesn't
      get an lsdump file since we don't build an unsanitized variant
      (aosp_arm64_ab).

Test: With this change, for arm64 libstagefright_foundation does
      get an lsdump file (aosp_arm64_ab)

Change-Id: I94f82fd84fc898e4980c3f3619df9677ed723c32
2018-05-10 15:32:18 -07:00
Ivan Lozano
a9255a8378 Support integer_overflow static lib diagnostics.
This extends the minimal runtime dependency mutator to allow signed
and unsigned integer overflow diagnostics in static libraries and
binaries. This also enables the integer_overflow flag for static
libraries and binaries.

Note compilation will fail if the static library is a dependency
of a Make module that does not also have diagnostics enabled.

Bug: 66952339
Bug: 73283972
Test: make SANITIZE_TARGET{,_DIAG}=integer_overflow
Test: Enabled diagnostics in a static lib, saw results in logcat.
Test: Checked showcommands output for ubsan runtime library inclusion.

Change-Id: Ic52881a0f74cdcac0e4a15335df493b59b002ae5
2018-04-02 12:54:52 -07:00
Vishwath Mohan
3af8ee0288 Revert "Change PRODUCT_CFI_INCLUDE_PATHS to opt-out (Soong)"
This reverts commit 289d548c3e.

Change-Id: Ic284687157d5cb4122899c84a37c5db507aaee2a
2018-03-30 02:55:23 +00:00
TreeHugger Robot
be6b6a63f8 Merge "Fix data race on cfiExportsMap" into pi-dev 2018-03-29 04:52:31 +00:00
Vishwath Mohan
289d548c3e Change PRODUCT_CFI_INCLUDE_PATHS to opt-out (Soong)
This CL changes PRODUCT_CFI_INCLUDE_PATHS to be included in all
product configs by default. To maintain the status quo, the sanitizer
logic has been modified to only respect this product config for Arm64
devices (where this was previously enabled).

Bug: 63926619
Test: m -j60 # the device still has CFI enabled thanks to the default
opt-in

Change-Id: Ia613aec545ad3e544dea41a6dbdb4112aef4afab
2018-03-28 20:30:05 -07:00
Colin Cross
fe6edc9a70 Fix data race on cfiExportsMap
cfiExportsMap was reinitialized for every module, which caused
data races.  Create the path from the string on each use
instead.

Bug: 77234104
Test: m nothing with race detector turned on
Change-Id: Ibca3149dcbe8a9d4d9f7ec6dd0b164697e7ae5cd
Merged-In: Ibca3149dcbe8a9d4d9f7ec6dd0b164697e7ae5cd
(cherry picked from commit 1218a19f0d)
2018-03-28 19:18:07 -07:00
Colin Cross
1218a19f0d Fix data race on cfiExportsMap
cfiExportsMap was reinitialized for every module, which caused
data races.  Create the path from the string on each use
instead.

Bug: 77234104
Test: m nothing with race detector turned on
Change-Id: Ibca3149dcbe8a9d4d9f7ec6dd0b164697e7ae5cd
2018-03-28 16:19:50 -07:00
Chih-Hung Hsieh
3ede294729 Switch to clang 7.0
* Suppress more noisy new warnings at global level.
* Add -no-pie to partial link .o files, with -r.
* Revert workaround of b/72706604, no need of
  -Wl,-plugin-opt,-emulated-tls
* Filter out clang 7.0 unknown flag "-Wno-extended-offsetof"

Bug: 72706604
Bug: 72412006
Test: make checkbuild
Change-Id: I7ff45465c4bd771991f42b40f68dc35586045656
2018-03-26 18:04:47 -07:00
Ivan Lozano
954f430e97 Add minimal-runtime support for integer overflows.
Adds Soong support for -fsanitze-minimal-runtime when using
the integer overflow sanitizers. This makes the crashes due to these
sanitizers less mysterious.

Bug: 64091660
Test: Compiled and checked the generated compiler commands
Test: Checked program that overflows for the abort reason

Change-Id: Ieeceaf6c35c8371592952d3b8b977aefc11601c5
Merged-In: Ieeceaf6c35c8371592952d3b8b977aefc11601c5
(cherry picked from commit 30c5db2f47)
2018-03-21 10:04:53 -07:00
Ivan Lozano
30c5db2f47 Add minimal-runtime support for integer overflows.
Adds Soong support for -fsanitze-minimal-runtime when using
the integer overflow sanitizers. This makes the crashes due to these
sanitizers less mysterious.

Bug: 64091660
Test: Compiled and checked the generated compiler commands
Test: Checked program that overflows for the abort reason

Change-Id: Ieeceaf6c35c8371592952d3b8b977aefc11601c5
2018-03-07 18:41:20 -08:00
Zhizhou Yang
51be632b95 Fix llvm-ar error caused by using lto and sanitizer together
LLVM-AR does not allow passing --plugin options more than once. The
--plugin ARFLAGS that lto want to add, may already exist if sanitizer is
also turned on.

Fixed this by adding a new bool Flags.ArGoldPlugin. Set this variable to
true whenever LLVM gold plugin is needed for ArFlags. In function
TransformObjToStaticLib(), add this option to arFlags using global value
${config.LLVMGoldPlugin} if the bool value is true.

Bug: http://b/73160350
Test: build the image with make and succeeded.

Change-Id: I62785829b0a4b663225926e4aed98defc1b6da2c
(cherry picked from commit 4917049f6e)
2018-02-14 21:21:14 +08:00
Zhizhou Yang
4917049f6e Fix llvm-ar error caused by using lto and sanitizer together
LLVM-AR does not allow passing --plugin options more than once. The
--plugin ARFLAGS that lto want to add, may already exist if sanitizer is
also turned on.

Fixed this by adding a new bool Flags.ArGoldPlugin. Set this variable to
true whenever LLVM gold plugin is needed for ArFlags. In function
TransformObjToStaticLib(), add this option to arFlags using global value
${config.LLVMGoldPlugin} if the bool value is true.

Bug: http://b/73160350
Test: build the image with make and succeeded.

Change-Id: I62785829b0a4b663225926e4aed98defc1b6da2c
2018-02-09 13:47:52 -08:00
Ryan Prichard
3ed1f70414 Enable emutls with -flto for Android sanitize=cfi
-fsanitize=cfi requires LTO. Normally, the Clang driver automatically
enables emutls, but it's broken with -flto, so work around it by passing
-Wl,-plugin-opt=-emulated-tls.

See https://buganizer.corp.google.com/issues/72706604#comment15

Enable the workaround with ctx.Device(), which is the same condition used
in the existing I18acac41aac885fc6635fbd55f96ba7c845eb5e7 workaround.

Bug: b/72706604
Bug: https://github.com/android-ndk/ndk/issues/498
Test: m libaudioflinger (on internal master); \
  readelf -sW symbols/system/lib64/libaudioflinger.so | grep tlNBLogWriter
  check that __emutls_t.tlNBLogWriter exists
  check that no symbols of type TLS exist

Change-Id: I2cf65574c52476843cc017ee176a7d6777e2ce0b
2018-02-06 15:11:38 -08:00
Dan Albert
7d1eecf3cc Fix static_ndk_lib for sanitized libraries.
Test: build-ndk-prebuilts.sh with libc/libm included in the NDK
Bug: https://github.com/android-ndk/ndk/issues/272
Change-Id: Ic398f541036f6c16f7dc58b9af984c60ed948495
2018-01-22 12:40:13 -08:00
Ivan Lozano
b7d0f52337 Revert "Support enabling overflow sanitization by path."
This reverts commit 17df3c1b76.

Change-Id: Id5dab777da591c24113c3048b8606547a661afdd
2018-01-20 01:44:38 +00:00
Ivan Lozano
17df3c1b76 Support enabling overflow sanitization by path.
Handle paths variable provided from Make about where integer overflow
sanitization should be enabled by default, and prepare to enable minimal
runtime diagnostics for integer overflow sanitizers in userdebug/eng builds.

This provides Soong support for on-by-default paths from Make for
integer overflow sanitization.

Bug: 30969751
Bug: 63927620
Test: Include paths passed from Make are being sanitized.
Test: Compilation succeeds with and without diagnostics enabled.
Test: See Make patch for further test notes.

Change-Id: I803a75646cc27ef5b4b5b74b8eb2981c39f8a6a3
2018-01-18 14:16:47 -08:00
Colin Cross
6510f91a1c Replace ModuleContext.AConfig() with Config()
AConfig() now duplicates Config().  Replace the uses of AConfig()
with Config().  Leave AConfig() for now until code in other
projects is cleaned up.

Test: m checkbuild
Change-Id: Ic88be643049d21dba45dbd1a65588ed94bf43bdc
2017-11-30 00:44:18 +00:00
Jeff Gaston
7276539d6a Sort cfi static libs to make them consistent
To make it easier to diff the ninja files with diff_build_graphs.sh
Bug: b/69133815
Test: m -j

Change-Id: Ic08094f7dc3adb773ebb64a7d34125fc24641bf3
2017-11-28 16:39:12 -08:00
Vishwath Mohan
e712879d5d Reduce how often both mutated variants are needed.
This CL rolls back how often we bubble up both sanitized and
un-sanitized variants of a component. With this change only
CFI-enabled target static libraries will do this, all other cases
suppress one of the two variants (both from being installed and from
being exposed to Make for make-embedded builds).

This means we shouldn't need a separate sanitizer suffix for ASAN at
all (.asan), and similarly for non static-lib CFI components (.cfi),
so this CL changes that as well.

Lastly, because the version of ar meant for the host is not built
with plugin support (which CFI requires), this CL disables CFI for
host targets.

This CL should fix the following 2 issues:
(1) Removing warnings about multiple rules existing for the same
installable target.

(2) Fixing VTS packaging, which had been broken by the generation of
the .asan suffix.

Bug: 69172424, 69059192, 67507323
Test: m -j40 # Soong generated .mk file does not have duplicate rules.
Test: SANITIZE_TARGET="address" m -j40 libstagefright # installed
correctly.

Change-Id: Ib90fdbc8a6ad3924fc2a691b7277a8a1bc67cda8
2017-11-21 14:09:09 -08:00
Vishwath Mohan
1fa3ac552d CFI include/exclude path support (Soong)
This CL adds the ability to centrally enable or disable CFI for
components using either an environment or product config
variable. This is a better, nore manageable option that enabling CFI
across each component individually.

Bug: 67507323
Test: CFI_INCLUDE_PATHS= system/nfc m -j40
Test: CFI_EXCLUDE_PATHS = frameworks/av m -j40

Change-Id: I38b77946759121aec99ab25f31aaee2e5d993f73
2017-11-08 18:56:10 -08:00
Nan Zhang
0007d810e2 Change bool, and string properties to *bool, and *string for cc
there's no use case for prepending/appending to bool, and string
properties within module struct. Declearing "*bool" and "*string" almost
cover everything user need.

I did see one case that user specify relative_install_path as
path prefix in cc_defaults, and concatenate with the one in real module
to get the final relative install path in Android.bp <bionic/tests/libs>.

Test: m -j checkbuild
Bug: b/68853585
Change-Id: If3a7a2689c3fc307aae136af6bc9c57f27a1e1a0
2017-11-07 15:57:16 -08:00
Pirama Arumuga Nainar
bdb17f068c Remove CFI-related WARs that seem no longer necessary
Bug: http://b/33678192

Clang has been updated past the revisions mentioned in the work arounds.
So these seem no longer necessary.

Test: Build

Change-Id: I08fee0db7c5785836a1ad0104688245435865cb7
2017-11-02 23:37:28 -07:00
Vishwath Mohan
e21fe42662 Don't install both variants for host or non-make builds.
This CL ensures that only one of the two generated variants are
installed for non-make builds and for host binaries.

Bug: 30227045
Test: OUT_DIR=/tmp/ndk build/soong/scripts/build-ndk-prebuilts.sh
Change-Id: I7ca78af51ea6bd3ae1107a69331abd6ff68f2150
2017-11-02 03:03:50 -07:00
Vishwath Mohan
b743e9c16a Revert "Revert "Build system changes for CFI (Soong)""
This reverts commit 33c252c2f1.

I have a fix to the crashes that this CL set was causing, and have
uploaded it as a patchset to this revert.

This also contains a partial fix that was initially submitted
separately as
https://android-review.googlesource.com/#/c/platform/build/soong/+/524295/

Bug: 30227045
Test: ./art/test/testrunner/run_build_test_target.py -j110 art-asan #no
build errors
Test: m -j50 ASAN_OPTIONS=detect_leaks=0 SANITIZE_HOST=address # no
build errors

Change-Id: I3e53549fa03413d35d9a952f04de1e7629e1f06d
2017-11-01 12:50:01 -07:00
Orion Hodson
33c252c2f1 Revert "Build system changes for CFI (Soong)"
This reverts commit d4b484b070.

Rationale: second in group of commits that left aosp_x86_64 not
building. (See https://android-build.googleplex.com/builds/
submitted/4426589/aosp_x86_64-eng/latest/logs/build_error.log)

Bug: 30227045
Test: builds
Change-Id: I38ab5284c614d6ee68e7359219bd75c7d50131be
2017-10-31 21:01:00 +00:00
Orion Hodson
da11d7422f Revert "Hide mutated variant in non-make builds."
This reverts commit 6147c6972a.

Rationale: first in group of commits that left aosp_x86_64 not
building. (See https://android-build.googleplex.com/builds/
submitted/4426589/aosp_x86_64-eng/latest/logs/build_error.log)

Bug: 30227045
Test: builds
Change-Id: I632869d13d09b43e2040da187d7ced4f05c332de
2017-10-31 20:47:44 +00:00
Vishwath Mohan
6147c6972a Hide mutated variant in non-make builds.
This CL hides (using Module.Properties.PreventInstall) either the
sanitized or stock variant for non-make embedded builds (based on
whether a sanitizer is enabled or not) so we don't have duplicate
rules for installing the same target.

Bug: 30227045
Test: OUT_DIR=out build/soong/scripts/build-ndk-prebuilts.sh # no
longer generates a duplicate build error.

Change-Id: I0b2dbb0afd5d426b32da67f951e2a4f9fbb3f3b9
2017-10-30 20:33:41 -07:00
Vishwath Mohan
d4b484b070 Build system changes for CFI (Soong)
This CL makes multiples changes in preparation for platform-wide CFI.

(a) Adds a second -version-script=... to the command line
when building components that use a version script. This ensures that
__cfi_check is also exported, and allows CFI to be enabled for these
components.

(b) Adds both topdown and bottom up mutators for CFI to help propagate
dependencies correctly for components that may need CFI disabled.

(c) Fixes an issue with the mutators to correctly apply settings to
both generated variants

(d) Fixes issues when components have more than a single visibility
flag.

Bug: 30227045
Test: SANITIZE_TARGET=cfi m -j40 # dependencies are correctly built
                                 # with/without CFI

Change-Id: I44793cc03bcbcdaa957cc49c7240b87d7c9db327
2017-10-30 01:42:31 -07:00
Colin Cross
d11fcda940 Convert Visit*Deps from blueprint.Module to android.Module
Also adds checks that the dependencies are android.Modules and
are not disabled.

Test: m checkbuild
Change-Id: I05e945f38915d49cd3c0ab72a86576949bc7eff2
2017-10-24 13:01:03 -07:00
Yabin Cui
6be405ef69 Support tsan in Android.bp.
Bug: http://b/25392375
Test: build a unit test with tsan.

Change-Id: Ifbd30e41e3a9558a8f106750c2a08778db5d5c81
2017-10-19 15:53:02 -07:00
Jeff Gaston
af3cc2d23c Some clarifications in preparation to automatically order linker dependencies
Test: Browse the code and determine whether it's easier to understand
Bug: 66260943
Change-Id: I88c24a8a31ef68f428919087d206433659265684
2017-10-18 18:06:02 +00:00
Jeff Gaston
7b6118be6b Revert "Some clarifications in preparation to automatically order linker dependencies"
This reverts commit 2370af0e23.

Reason for revert: New Build Breakage: aosp-master/aosp_arm64_ab-userdebug @ 4376965

Change-Id: Ibe4b819c4292457c454bf42e6d94fba3071ec04b
2017-10-04 21:07:42 +00:00
Jeff Gaston
2370af0e23 Some clarifications in preparation to automatically order linker dependencies
Test: Browse the code and determine whether it's easier to understand
Bug: 66260943
Change-Id: Ia3fdb8f38e83ad8225a72c8de2804db23a90ef9b
2017-10-03 17:18:01 -07:00
Dan Willemsen
27991b7652 Add -lm to the default libs for Linux & Darwin
libm is a default library for device builds, so default it for host
builds as well.

Also removes duplicate additions of -ldl, -lpthread, -lm and -lrt.

Test: m host
Change-Id: I8f7e799d48a1f427e48dcfb1d0ccba93c5f9780b
2017-09-26 20:25:09 -07:00
Zach Riggle
06bbd89c16 Enhance coverage options to include those needed by Honggfuzz for coverage-driven fuzzing
Test: make m
Bug: 64903541
Change-Id: Id5f10b6d7c122444f875134883f7c0a95d71e12d
2017-08-24 19:25:05 +00:00
Colin Cross
ef88ae2369 Make libdl.so be loaded after libc.so
Make sure that libdl is always after libc on the command line.
Simplifies the logic to always support system_shared_libs for
sdk and vndk builds.

For backwards compatibility without updating lots of Android.bp
files, allow libdl to be listed in shared_libs as long as it
is also in system_shared_libs or libc is not in system_shared_libs.

Remove all the places that libdl is added as a dependency, since
it will always be present unless explicitly removed now.

Bug: 62815515
Test: m -j checkbuild
Change-Id: I0233178ffea87a2f0b82190746022476304a68e2
2017-08-23 12:54:54 +09:00
Colin Cross
27a4b05441 Remove error from AndroidMkData.Extra
It's never anything except nil, and it unnecessarily complicates
the implementations.

Test: m -j checkbuild
Change-Id: I8a117a86aa39aeb07d9d8d0686ef869c52784f19
2017-08-11 15:24:11 -07:00
Vishwath Mohan
952293044f Revert "Fix ASAN mutator."
This reverts commit 12758d0cec.

Change-Id: I475e63d7e56ff166c2046fc423a1729ed098ff66
2017-08-11 00:56:44 +00:00
Vishwath Mohan
e615345f28 Revert "Don't apply sanitizer mutators to host modules."
This reverts commit bba1927bde.

Change-Id: Ie895d8eae5abb533468b836639e0835e7adbf8c9
2017-08-11 00:52:44 +00:00
Vishwath Mohan
bba1927bde Don't apply sanitizer mutators to host modules.
This CL blocks modules intended for the host from having the bottom up
sanitizer mutator applied. We only maintain a single copy of host
binaries, so generating variants doesn't make sense
anyway. Additionally, the existing logic was causing an error with
builds not embedded in make (eg: aosp-build-tools which uses
soong_ui.bash) where the wrong variant was installed on the host. This
change should fix that.

Bug: 64536751
Test: m -j40 && SANITIZE_TARGET="address" m -j40
Test: aosp-build-tools build breakage is fixed.
Change-Id: Ia79b4661f69ce26a7be17c4339c18ca0f397d760
2017-08-10 11:05:00 -07:00
Vishwath Mohan
12758d0cec Fix ASAN mutator.
This CL fixes a bug in the ASAN top down mutator which was incorrectly
checking (and setting) SanitizeDep to true only for the parent module
and not for the visited child modules.

Fixing this also requires some changes to the variant creation logic
to ensure that the correct variant is passed to make for
installation. This will eventually be replaced by logic that appends
an appropriate suffix to sanitized libraries (eg: libc++.asan), which
will allow both variants to be passed to make.

Bug: 64536751
Test: m -j40 && SANITIZE_TARGET="address" m -j40
Change-Id: Id5e5a5946192adf07418dd433bca503047177007
2017-08-09 16:58:36 -07:00
Jiyong Park
27b188bc86 .vendor suffix is added only for libs having core/vendor variants
When the lib is vendor-only, then .vendor suffix is not added.
Furthermore, this change correctly adds .vendor suffix even to the names
listed in LOCAL_SHARED_LIBRARIES so that we don't need to add the suffix
in the make world.

This also allows us to use the original name (without the .vendor
suffix) of the vendor-only modules in make (e.g. in PRODUCT_PACKAGES or
as a make target).

Bug: 37480243
Test: BOARD_VNDK_VERSION=current m -j <name> is successful, where <name>
is one of the vendor-only libraries in Soong. (i.e.
android.hardware.renderscript@1.0-impl)
Test: m -j does not break anything

Change-Id: I203e546ff941878a40c5e7cfbb9f70b617df272d
2017-07-27 08:54:52 +09:00
liuchao
c5996de4ce Enable ubsan check flag in build
Ubsan is currently support ARM/ARM64,
so It's OK to enable the build Flag

Test: build test module with flags in Android.bp:
      sanitize: {
          all_undefined: true,
          diag: {
              undefined: true,
          },
      },
BUG:38250996
Change-Id: I37a01b4610132f58315e68335b3c3cdfb148357d
2017-07-21 02:31:37 +00:00
Ivan Lozano
5f59553bca Allow integer_overflow sanitizer path exclusion.
Add support for excluding paths from having integer_overflow applied to
them when using SANITIZE_TARGET=integer_overflow via an
INTEGER_OVERFLOW_EXCLUDE_PATHS make variable. This covers the soong side
of the change.

Bug: 30969751
Test: Build with SANITIZE_TARGET=integer_overflow
SANITIZE_TARGET_DIAG=integer_overflow
INTEGER_OVERFLOW_EXCLUDE_PATHS=<path> and confirmed this was no
longer being applied to binaries in that path.

Change-Id: I298b772f5425da28dff1cf007825be19558db3a8
2017-07-18 13:38:20 -07:00
Ivan Lozano
0c3a1efae4 Add integer_overflow sanitization build option.
Adds the SANITIZE_TARGET=integer_overflow build option to apply signed and
unsigned integer overflow sanitization globally. This implements the
Soong side of the build option.

An additional build option is provided to control whether or not to run
in diagnostics mode, controlled by SANITIZE_TARGET_DIAG. This works the
same way that SANITIZE_TARGET does and currently only supports
'integer_overflow' as an option.

A default sanitizer blacklist is added to avoid applying sanitization
to functions that are likely to exhibit benign overflows.

Bug: 30969751
Test: Building with and without the new flags, device boot-up, tested
various permutations of controlling the new flags from build files.

Change-Id: Ibc8a8615d3132f1a23faaf1cb4861f24c5ef734a
2017-07-07 09:52:23 -07:00
Dan Austin
8241abba87 Update coverage sanitizer flags in soong
Update the coverage sanitizer flags in soong to use the new
flavor of coverage sanitization.

Bug: 63108942

Test: Fuzzer runs with coverage guards.
Change-Id: I2e817a5282cf7dab49aee6985743defd4fb74628
2017-06-29 08:55:13 -07:00
Jayant Chowdhary
9677e8c6ad Black-list for clang LibTooling Cflags.
Add a list of flags which are not understood by clang LibTooling tools
and filter them out of the Cflags the tools are invoked with.

Test: In frameworks/av, make libmedia vendor_available (this invokes
header-abi-dumper on this module), mm -j64.

Bug: 62447349

Change-Id: I46f017212b89f4331145c999103d0ed44da0abaf
2017-06-19 19:43:03 -07:00
Ivan Lozano
651275ba90 Add support for misc_undefined diagnostics
Setting Sanitize.Diag.Undefined to true does not enable diagnostics for
all possible UBSan sanitizers that might be declared in Sanitize.Misc_undefined
(specifically unsigned-integer-overflow and nullability-*). This adds an
equivalent Sanitize.Diag.Misc_undefined string array to allow diagnostics to
be enabled in these sanitizers.

Bug: 62546512
Test: make works and device boots.
Test: Tested an Android.bp generated binary with the new field enabling
unsigned-integer-overflow diagnostics.

Change-Id: I9aa7cb2555ab4f94ae1aa290715a617718d936ff
2017-06-19 10:11:56 -07:00
Evgenii Stepanov
c6482d69c2 Don't add -lrt on Darwin for sanitized targets.
Bug: 34719251

Change-Id: Iff81c4d891a2341a8152e5603391b55b0222ebd7
2017-06-07 16:19:17 -07:00
Evgenii Stepanov
76cee23144 Fix -fsanitize=integer not passed for soong builds.
Also filter out -Wl,--no-undefined for all host sanitizers, not just ASan.
UBSan on host defaults to no-trap (i.e. diagnostic mode), and that requires
the runtime library and runs into the same problem with undefined symbols as ASan.

Bug: 34719251
Test: Misc_undefined: ["integer"] on a soong target
Change-Id: I1fb4781f663a11f5f427d50c0bf9beb8e181cd5e
Merged-In: I1fb4781f663a11f5f427d50c0bf9beb8e181cd5e
(cherry picked from commit fe9bc1dccb)
2017-06-07 11:01:02 -07:00
Andreas Gampe
9707116867 Soong: Change Sanitize.Recover order
Add Sanitize.Order cflags after the general sanitizer options, so
it can override the global -fno-sanitize-recover=all.

Bug: 38128476
Test: m SANITIZE_HOST=address
Test: manual test
Change-Id: Ied5600507b66bd25d9d2a8bba428162ed4eb01e4
2017-05-08 23:37:51 +00:00
Colin Cross
8ff9ef4c30 Declare dependency on sanitizer runtime libraries
Moving the last users of a sanitizer runtime library to soong was
causing the runtime library to stop getting installed.  Declare
the dependency so make keeps installing it.

Test: builds
Change-Id: Ieeb9ad5c04ac8df0d1a74239da393dac5cab2b03
2017-05-08 15:57:05 -07:00
Vishwath Mohan
8f4fdd8f76 Disable CFI for ASAN targets. (Soong)
This CL disables CFI if both CFI and ASAN flags are enabled. This
allows ASAN to take precedence where needed, preventing build errors
that would otherwise arise.

Bug: 30227045
Test: SANITIZE_TARGET="address" m -j40
Change-Id: Id336bf2bf5498d4c3ea6492e36b366c76c06376e
2017-04-20 08:06:09 -07:00
Vishwath Mohan
1dd8839286 Refactor sanitized library on-disk layout - Soong.
This CL moves the location of ASAN-ified libraries on disk in the
following manner:
/data/lib* --> /data/asan/system/lib*
/data/vendor/* --> /data/asan/vendor/*

There are a couple of advantages to this, including better isolation
from other components, and more transparent linker renaming and
SELinux policies.

Bug: 36574794
Bug: 36674745
Test: m -j40 && SANITIZE_TARGET="address" m -j40 and the device
boots. All sanitized libraries are correctly located in /data/asan/*.

Change-Id: I06bf459260ec451d4495a02562f640ad622f34c2
2017-03-31 01:03:56 +00:00
Vishwath Mohan
7a5b46db91 Add ar flags for CFI enabled components in Soong.
CFI enabled components need ar to use the gold linker. This CL adds
that.

Bug: 36290748
Test: Enabling CFI for a Soong component builds without error.
Change-Id: Icbf78fa1ca0d845350516b4dd345b54fbb7ef847
2017-03-16 16:36:16 -07:00
Vishwath Mohan
f3918d37fb Blacklist code for CFI.
Adds the -fsanitize-blacklist option for CFI, using the built in
blacklist at external/compiler-rt/lib/cfi/cfi_blacklist.txt.

Also refactors the CFI cflags and ldflags into cc/makevars.go to
ensure they're consistent across Soong and make projects.

Bug: 30227045
Test: ENABLE_CFI=true m -j40 builds and boots.
Test: The blacklist prevents runtime errors that otherwise occur.
Change-Id: I91c5420478e7290061d89338a86abdef69c67fe2
2017-02-15 12:46:52 -08:00
Vishwath Mohan
6d67e6e68e Disble CFI for ARM32 processes.
This CL disables CFI for 32-bit ARM processes, which is broken due to
a compiler error in the most recent version of clang.

Bug: 35157333
Test: ENABLE_CFI=true m -j40 does not enable CFI for 32-bit processes
Change-Id: I52ccf60d91ff1a2af4cf024376b7d70f87040674
2017-02-08 19:46:27 -08:00
Evgenii Stepanov
a83fdacf7c Disable CFI on Mips and add -march to linkflags on ARM.
Mips toolchain does not have ld.gold.
ARM change is a workaround for LLVM r290384.

Bug: 33678192
Test: make ENABLE_CFI=1
Change-Id: I189ffd42760f0ea8d151717337b9355b37cb207b
2017-02-03 23:50:28 +00:00
Evgenii Stepanov
cb3f890263 Remove duplicate code.
Test: NFC
Change-Id: I63a1b1ee244c2ab015914e1879aefc3ba8f886b0
2017-02-03 13:25:03 -08:00
Evgenii Stepanov
774cb81796 Disable global coverage when a module disables asan.
With SANITIZE_TARGET="address coverage", if a module disables ASan
(address: false), it is left with just coverage, which is not
supported. In that case, disable coverage as well.

Bug: 33091541
Test: see above
Change-Id: Idcd04dad8cab7c7e2644d2408b1b8a381490e5af
2017-01-24 20:55:11 +00:00
Evgenii Stepanov
7ebf9fa3c9 Force Thumb for CFI targets.
Bug: 22033465
Test: bionic device tests
Change-Id: I672ccc970309631fa895b7134a32c0d403a2151e
2017-01-20 14:13:32 -08:00
Vishwath Mohan
1b017a76e1 Hide CFI behind a global flag.
This CL ensures that locally enabling CFI in a .bp file is not honored
unless it is enabled globally using ENABLE_CFI=true first, effectively
hiding it behind a flag.

Bug: 30227045
Bug: 22033465
Test: m -j40 works and device boots
Test: cfi is correctly honored only when the global flag is set.
Change-Id: Iccc6e4bf5e7828ab8ce6056f3e40922712faa0d8
2017-01-19 14:40:34 -08:00