Commit graph

58 commits

Author SHA1 Message Date
Treehugger Robot
5a1a88ee93 Merge "LinuxBionic supports arm64" 2020-09-14 15:59:16 +00:00
Ivan Lozano
6d45a9863a rust: Pass lld flags from cc to rust linker args.
Rust is not passing the sysroot flag to Clang when invoking it as the
linker. This means files from the host may leak in, and host targets
may fail if sysroot files are not available from the host.

This patch prepends the lld flags from cc into rust linkargs. This
pulls in the sysroots flag, and also ensures that we remain in sync
with linkage flags used in cc.

The '-Wl,--no-undefined-version' from cc is overridden to avoid
missing version assignment errors for rust's generated alloc
functions.

Bug: 167690054
Test: cd external/rust; mma
Test: strace -f -e %file <host libstd.dylib.so build command> pulls
      from correct sysroots.
Change-Id: Ic40597f546f3b112012155614056afed487c6ca1
2020-09-09 14:20:00 -04:00
Jiyong Park
4afa2e2682 LinuxBionic supports arm64
LinuxBionic now supports arm64 architecture in addition to the existing
x86_64 arch. This is to make it possible to build host tools like adb,
fastboot, crosvm, etc. for Linux/ARM on regular Linux/x86 machines.

The arm64 target can be selected in various ways in Android.bp files:

   - target.host (because this is still considered as a host target)
   - target.linux (provided that the module is also enabled for host)
   - target.linux_bionic (use the OS name directly)
   - target.linux_bionic_arm64 (OS name + arch combo)
   - target.linux_arm64 (provided that the module is also for host)
   - target.not_windows
   - arch.arm64

The toolchain for the new target is almost the same as the toolchain
config for Android/ARM64. One notable difference is that the clang
triple is aarch64-linux instead of aarch64-linux-android, so that
__ANDROID__ is not defined for the new OS type.

Bug: 134795810
Test: HOST_CROSS_OS=linux_bionic HOST_CROSS_ARCH=arm64 m nothing

Change-Id: If4300583edfb6d75bd4d984b38f73b6a406b4447
2020-09-09 21:57:10 +09:00
Thiébaud Weksteen
682c9d7b25 Rename ccConfig to cc_config
Follow up from aosp/1413495 to set a consistent name throughout the
package.

Test: m
Change-Id: Idafcd973e7d874cd97599ac419c2972a8a5cd0b4
2020-08-31 10:06:16 +02:00
Thiébaud Weksteen
19e1c6c8e7 rust: enable use-android-relr-tags
Bug: 153430439
Test: m
Change-Id: I1873a180f0646cd1dba9e1756fd68bd788d4f725
2020-08-28 10:47:11 +02:00
Jeffrey Vander Stoep
2e8a617bca Merge "Rust: use 1.45.2 prebuilts" 2020-08-20 17:14:19 +00:00
Treehugger Robot
2d815963ba Merge "Add AIDL compiler to allowed Rust paths" 2020-08-18 22:00:42 +00:00
Thiébaud Weksteen
2346b014eb Merge "rust: modify linting properties" 2020-08-17 07:01:14 +00:00
Jeff Vander Stoep
3a9d80a60c Rust: use 1.45.2 prebuilts
Test: TH
Change-Id: I2eab5af0a822673ca1f5bb2f63c88edc2c7830ff
2020-08-14 13:53:38 +02:00
Matthew Maurer
61ca6a39cc Merge "Add Rust Binder crate to allowed list" 2020-08-13 21:13:57 +00:00
Thiébaud Weksteen
9e8451e524 rust: modify linting properties
Move the linting properties to an enum with 4 possible options:
"default", "android", "vendor" or "none". The previous logic for
default, based on the module's location, is kept. It is now possible to
force the upgrade to a certain lint level for some modules (e.g.
external/[...]/android). Update the unit tests and documentation.

Bug: 163400111
Test: m
Change-Id: I8e464b04401158ed2d3c518a9b72f145a9835c99
2020-08-13 15:58:09 +02:00
Stephen Crane
fb67ab5152 Add Rust Binder crate to allowed list
Test: m libbinder_rs
Change-Id: I5c6b6216376a8b68c4fc7a30490c035c4fae54ff
2020-08-10 19:41:24 +00:00
Thiébaud Weksteen
95647739aa Merge "rust: fully disable all lints when no_lint is set" 2020-08-10 07:56:19 +00:00
Yi Kong
91c3e4ec1a [rust] Add profcollectd to allowed list
Test: none
Change-Id: I9c9b4ce10d5349d9a0e0759aeb6d8941b0d9fa65
2020-08-08 01:30:17 +00:00
Andrei Homescu
834152c033 Add AIDL compiler to allowed Rust paths
Change-Id: I10864f72ff5099ccd522ff31636ee61981dcdc4b
2020-08-07 22:07:43 +00:00
Thiébaud Weksteen
4318e1c650 rust: fully disable all lints when no_lint is set
If the no_lint attribute is set, we now explicitly disable any warning
or error.

Bug: 162897623
Test: cd external/selinux; mma; check the build log for warnings
Change-Id: I5338bda77ab25ded7cc43cc3afd29419fcbd9808
2020-08-07 13:56:35 +02:00
Janis Danisevskis
8b7eb8d86a Rust: allow system/security
Bug: 160623310
Test: None
Change-Id: I00ddb0fb26e7e67f832fb321186f7313209c2669
2020-08-03 21:27:41 +00:00
Jeff Vander Stoep
6e97a7b4a1 rust: Use host linker when building for Mac host.
This behavior is non-hermetic, but matches the behavior of the C++
support. On Linux, using lld works, but on OSX, this fails because lld
does not support Apple's new .tbd files.

Bug: 155302034
Test: On both Linux and Mac hosts:
    cd external/rust; mma

Change-Id: I0ad489113d720bdb9c3b7a67cce9d1e72266f428
2020-07-15 22:02:18 +02:00
Ivan Lozano
33c05281a5 Fix incorrect Rust dylib extension on darwin.
rustc expects Rust dylibs to have a .dylib extension on darwin.

Bug: 155302034
Test: rust_library_host outputs have correct extension on darwin.
Change-Id: I17b0d7eaf0f42f8186185e3f14c3a8e992c74fde
2020-07-15 11:35:30 -04:00
Matthew Maurer
2ae0513a8e rust: Change default variants
rust_library now produces only rlib and dylib variants.
rust_library_foreign now produces static and shared variants.

This change was made because both are common cases, but all four
together essentially never happens. This allows us to have fewer repeat
module definitions.

Bug: 143217452
Test: cd external/rust; mma
Change-Id: Iaf69e8da38f7c12710331c51464699cf7cbbb656
2020-07-01 11:27:12 -07:00
Thiébaud Weksteen
8e46efac71 Explicitly define Rust default lints
Add documentation on how lints are defined and used in Android. Merge
the deny_warnings attribute with a new attribute (no_lint) which can be
used to disable the default linting parameters.
Explicitly allow all lints for external/ and prebuilts/, which remove
any warning when building sysroot for the devices.

Test: cd external/rust/crates; mma
Test: add dummy internal Rust module; mma
Change-Id: I62be1c41aeda4068fb9e288038727c1de5ffe547
2020-07-01 17:11:58 +02:00
Matthew Maurer
85a08fc454 Merge "Add clippy-driver build rule" 2020-06-26 20:33:37 +00:00
Jeff Vander Stoep
530dccb8c5 Update rustc to 1.44.0
Test: Treehugger
Change-Id: Ib940bc5afbbbec6b16ed7c2879ad31438e58907d
2020-06-26 15:26:49 +02:00
Thiébaud Weksteen
92f703b084 Add clippy-driver build rule
Depending on the location of the repository (e.g. external/, vendor/), a
different set of lints will be enabled. Add the clippy property to the
rust_* modules. This property can be used to overwrite the default
behaviour.

Test: m checkbuild
Bug: 157238651
Change-Id: Ife0f723ef4a74abb102597f8486a7b9f30e7d351
2020-06-26 13:31:21 +02:00
Colin Cross
440e0d0542 Use inclusive language in build/soong
Test: m checkbuild
Change-Id: Id07890b7cbc2397291a658ca00e86b43c743aafc
2020-06-11 15:33:16 -07:00
Jaewoong Jung
4b79e98a6e Soong package structure refactoring
Give prebuilt_etc and sh_binary their own packages and split the
gigantic main Android.bp up to small, per-package ones.

Test: m nothing, TreeHugger
Bug: 156980228
Change-Id: I7b00cd344b9f16861f1ff39edf0029f016b853d0
2020-06-01 13:44:48 -07:00
Ivan Lozano
c0ccb6b443 Fix darwin shared library and proc macro suffixes.
Darwin builds aren't using the correct suffix for shared libraries or
proc macros (.dylib). This fixes that.

Bug: 155302034
Test: "cd external/rust; mma" no longer indicates wrong extension.
Change-Id: I5093e0bcc78dbb2dd9fcf39069f326101bb8f411
2020-05-29 13:08:27 +00:00
Matthew Maurer
e7fe2527f6 Merge "Switch rustc to 1.43.0" 2020-05-05 16:43:47 +00:00
Matthew Maurer
f5be9a6ad4 Switch rustc to 1.43.0
Bug: 154947284
Test: cd external/rust/crates; mm
Change-Id: I684e9ee5d44029806d48a271970f8ef28e793195
2020-04-29 13:33:40 -07:00
Ivan Lozano
9d1df10e2a Provide 32-bit and 64-bit Rust libs by default.
CC libraries which depend on Rust libraries get missing dependency
errors when building 32-bit variants dependent on Rust modules which
don't explicitly have "multilib: both" declared.

Because CC libraries use MultilibBoth by default, Rust should do the
same.

This also fixes a bug where the ARM32 toolchain incorrectly embedded
toolchain64Bit instead of toolchain32Bit.

Bug: 154730212
Test: Rust libraries provide both variants by default.
Change-Id: Ia545fe069d3c6b77c3d18f4f10267e2c72ee0bab
2020-04-29 15:31:34 -04:00
Matthew Maurer
1f434b26c1 Merge "Update Android's rustc version 1.40.0->1.42.0" 2020-04-23 16:53:41 +00:00
Matthew Maurer
e972e8822b Update Android's rustc version 1.40.0->1.42.0
Test: cd external/rust/crates; mm
Bug: 152633654
Change-Id: Ic7cbc1869fdffa332033cecd4c4596775946d0e9
2020-04-22 13:22:25 -07:00
Ivan Lozano
78e5ee0b8d Remove rust execute-only memory linker flag.
With kernel support being removed for execute-only memory layouts,
remove support for XOM until there's kernel support again.

Bug: 153457617
Test: Rust binaries no longer have execute-only text sections.
Change-Id: I19cfb5b347a1f44394a619e17bb0c057c09e76a9
2020-04-09 09:40:50 -04:00
Lingfeng Yang
0f8c5b4ac8 Add minijail to whitelist.go
The latest version of crosvm refers to minijail as a separate crate:

2dae56768c%5E%21/#F1

The current version of minijail in aosp crosvm-master isn't a crate,
but minijail in aosp master is a crate and builds with crosvm.

This allows the latest version of crosvm to build in the Android tree
and use minijail in the same tree.

Change-Id: I2231149f1488727754430183d04072c5cc0f570a
2020-02-20 07:27:15 -08:00
Elliott Hughes
c5960d61cd Always use RELR for Rust.
Rust has no backwards compatibility concerns, so no need to use
--use-android-relr-tags here.

Bug: http://b/147452927
Test: treehugger
Change-Id: I94de40bfad1ff2dcbc4241b944db90e0891bf9f3
2020-01-28 17:30:16 -08:00
Matthew Maurer
e7d7b6d924 Remove libterm from implicit crates
This is no longer shipped by rustc, and wasn't really intended to be
implicitly available in the first place.

Bug: 147432625
Test: Built a sample rust device binary
Change-Id: I3c33ac3726c788debe14ed39a9ecbae7a7449351
2020-01-09 12:24:58 -08:00
Matthew Maurer
bd73c4d06b Update rustc version to 1.40.0
Bug: 146571186
Test: m crosvm.experimental; atest unicode-xid_device_tests_unicode_xid
Change-Id: If7142a4cd31295a04eb485ee3d7cada5dc6be185
2020-01-02 15:07:18 -08:00
Nick Desaulniers
894cdee30a Merge changes from topic "separate_code"
* changes:
  soong: use -Wl,-z,separate-code w/ -Wl,--execute-only
  Revert "Revert "soong: upgrade Android platform to clang-r370808""
2019-12-16 21:13:28 +00:00
Nick Desaulniers
dcee1e5c54 soong: use -Wl,-z,separate-code w/ -Wl,--execute-only
The clang-r370808 upgrade contains a change to LLD allow PT_LOAD
segments to reside at non-multiples of the page size in the resulting
object file.  https://reviews.llvm.org/rL369344

While this helps reduce the alignment waste and resulting image size, it
has interesting implications for execute only memory (XOM): The runtime
loader will now load code or data from other segments into pages with
different protections than intended.

This would partially defeat execute only (XOM) text sections as the
segment could now overlap with previous and following sections. This
might allow for code or data from the preceding and following sections
(like .eh_frame, and .data.rel.ro) to be executable, and either ends of
.text to be readable.

When the runtime loader (linker[64]) `mmap`s segments from *.so files,
the file offset parameter (see `man 2 mmap`) MUST be a multiple of the
page size.  Since the updated LLD can now pack segments in a file (which
helps minimize resulting object file size) (previously, the segment
offsets were page aligned), this has interesting implications.

To appreciate the current bug, consider the following output from
`readelf` before this patch is applied, but after the toolchain upgrade:

```
$ readelf -lSW $OUT/symbols/apex/com.android.runtime/lib64/bionic/libc.so
...
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
...
  [13] .eh_frame         PROGBITS        000000000002e7c0 02e7c0 013374 00   A  0   0  8
  [14] .text             PROGBITS        0000000000042b40 041b40 09ecb4 00  AX  0   0 64
  [15] .plt              PROGBITS        00000000000e1800 0e0800 001f30 00  AX  0   0 16
  [16] .data.rel.ro      PROGBITS        00000000000e4740 0e2740 005208 00  WA  0   0 32
...
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  PHDR           0x000040 0x0000000000000040 0x0000000000000040 0x000230 0x000230 R   0x8
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x041b34 0x041b34 R   0x1000
  LOAD           0x041b40 0x0000000000042b40 0x0000000000042b40 0x0a0bf0 0x0a0bf0   E 0x1000
  LOAD           0x0e2740 0x00000000000e4740 0x00000000000e4740 0x006720 0x006720 RW  0x1000
...
   01     .note.android.ident .note.gnu.build-id .dynsym .gnu.version .gnu.version_d .gnu.version_r .gnu.hash .dynstr .rela.dyn .rela.plt .rodata .eh_frame_hdr .eh_frame
   02     .text .plt
   03     .data.rel.ro .fini_array .init_array .dynamic .got .got.plt
...

The above output tells us:
1. .text will wind up in the third (02) segment.
2. The third segment will be (LOAD)'ed as (E)xecutable.
3. Because the file (Offset) of the first segment (0x41b40) is NOT a
   multiple of the page size, it cannot be passed as the `offset` to
   `mmap`. As such it will be rounded down to the first multiple of the
   page size, 0x41000.
4. The preceding section (.eh_frame) will be loaded in the preceding
   segment (01). It occupies file (Off)set range [(0x2e7c0):0x41b34].
   0x41b34 is not explicit in the output, instead you must use the
   formula:
     Off     + Size    == End
   ie.
     0x2e7c0 + 0x13374 == 0x41b34
   (This happens to match (FileSiz) of the second segment, which makes
   sense as .eh_frame is the final section in the second segment.)
5. mmap'ing file offset 0x41000 when loading the second segment will
   include 0x4c0 bytes (0x42000 - 0x41b40) from .text, now mapped as
   readable (oops). Suddenly code from .text is now readable (and thus
   scannable for gadgets for ROP chains).
6. mmap'ing file offset 0x41000 when loading the third segment will
   include 0xb34 bytes (0x41b34 - 0x41000) from .eh_frame, now mapped as
   executable (oops). Suddenly data from .eh_frame is now executable
   (and thus a potential gadget for ROP chains).
7. mmap'ing file offset 0xe2000 when loading the third segment will
   include 0x8CO bytes (0xe3000 - 0xe2740) from .data.rel.ro, now mapped
   as executable (oops). Suddenly data from .data.rel.ro is now
   executable (and thus a potential gadget for ROP chains).
8. mmap'ing file offset 0xe2000 when loading the fourth segment will
   include 0x730 bytes (0xe0800 + 0x1f30 - 0xe2000) from .plt, now
   mapped as readable (oops). Suddenly data from .plt is now readable
   (and thus scannable for gadgets for ROP chains).

All these oops' could be avoided if the linker placed .text+.plt at page
size aligned file offsets, which is what `-Wl,-z,separate-code` code
does.  After this patch, we have:

```
$ readelf -lSW $OUT/symbols/apex/com.android.runtime/lib64/bionic/libc.so
...
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  PHDR           0x000040 0x0000000000000040 0x0000000000000040 0x000230 0x000230 R   0x8
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x041b34 0x041b34 R   0x1000
  LOAD           0x042000 0x0000000000042000 0x0000000000042000 0x0a0be0 0x0a0be0   E 0x1000
  LOAD           0x0e3000 0x00000000000e3000 0x00000000000e3000 0x006720 0x006720 RW  0x1000
```

In the future, we could go back to tightly packing segments in the
binary if the runtime loader was improved to detect the previously
stated problem, and `memset` over the problematic ranges of the freshly
`mmap`ed pages (implying additional startup cost for reduced binary
size). This might save ~6 KB from each native binary, which adds up to
~17 MB for an AOSP image.

Also, prefer
-Wl,--execute-only
rather than
-Wl,-execute-only

Bug: 139945549
Bug: 146144180
Test: readelf -lSW $OUT/symbols/apex/com.android.runtime/lib64/bionic/libc.so
Change-Id: I64527e034ca3c71565ea52ed06f81f75d5216627
Reported-by: Ryan Prichard <rprichard@google.com>
Suggested-by: Fangrui Song <maskray@google.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
2019-12-16 09:55:37 -08:00
Chih-Hung Hsieh
1f202e9bbb Add x86 device output for Rust
* Copy current configuration from
  rust/config/x86_64_device.go and
  cc/config/x86_device.go.

Bug: 145608833
Test: build rust modules for aosp_x86-userdebug
Change-Id: Ie4951dd4703596f8e503d813a6c4ac03c1f20980
2019-12-12 19:18:06 -08:00
Ivan Lozano
31b095d071 Add rust default compilation flags.
Bug: 140725928
Test: m -j crosvm.experimental
Change-Id: I1674f099659957f024cce70341a6a69610118a69
2019-11-20 10:14:33 -08:00
Treehugger Robot
fcc157a150 Merge "Add new module types to the rust whitelist." 2019-11-15 03:47:33 +00:00
Ivan Lozano
8a34287fad Add new module types to the rust whitelist.
Bug: 144490046
Test: make rust modules
Change-Id: Ib7122bcc20aa2cde2f48788431055fe986918dd0
2019-11-14 07:36:22 -08:00
Matthew Maurer
51feafad57 Enable x86_64 device support
Now that we have sysroots built in Soong, we can enable these devices
and they just work.

Bug: 141251907
Bug: 141381044
Change-Id: I562256fee372d331db883f7c1b46405945295c24
2019-11-13 17:46:24 -08:00
Matthew Maurer
99020b04fb Build Rust Device Sysroots in Soong
In order to ensure we are using current platform Bionic for any platform
Rust binaries, we need to build the sysroot in Soong. This will also
enable us too hook the "test" crate if necessary.

While both a dynamic and static sysroot are available, on device only a
dynamic sysroot will be injected. On host, we continue using the sysroot
used to build the compiler as before.

Bug: 139486496
Change-Id: I127377e5b056610ceb5015a34d266250320fbc31
2019-11-13 17:46:19 -08: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
Chih-Hung Hsieh
c74d723c09 Allow rust code in external/rust.
Test: mm in all rust enabled directories
Change-Id: I3454c840adb7a9823637f0ae874355e4df995b66
2019-10-25 10:08:57 -07:00
Ivan Lozano
1c2ff86225 Add Rust darwin host support.
Support for building Rust modules on darwin hosts.

Bug: 140640858
Test: m libremain works on darwin
Change-Id: Ieb1ff9167de34cffbebebab31fa48da07081c8a6
2019-10-21 13:15:10 -07:00
Chih-Hung Hsieh
961a30c714 Fix defaults of BaseCompilerProperties
* Edition and Deny_warnings should not be set when
  constructing a BaseCompilerProperties, or the
  initialized values will reject values inherited from rust_defaults.
* Use getEdition and getDenyWarnings to retrieve those properties
  with defaults from config.

Bug: 141699953
Test: mm in rust projects
Change-Id: Id1ae357caeaf656cd33732bf4e54920e206f4ead
2019-10-03 09:47:06 -07:00
Joel Galenson
724286c957 Pass --remap-path-prefix to Rust builds.
We need to pass --remap-path-prefix to Rust builds to ensure that they
are reproducible across different paths.  This adds that for both host
and device builds.

Test: Verify host and device builds are reproducible with different
directories.

Change-Id: I68ba31537b2332fd05613aa0fb00a1502d78e410
2019-10-01 11:12:15 -07:00