aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Klyubin <klyubin@google.com>2015-12-04 17:10:01 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-12-04 17:10:01 +0000
commit7f1eda800d8cdb793b521e20798eaacb3fe410ad (patch)
tree19c920d1bf748ed7095ce03de80bc78b60501776
parentb275dd1623ca5256d9dfb8542cd324c624c6e9fe (diff)
parentdbb5527a9ef27f292794d1e51ae56d1df68c328b (diff)
downloadbuild-7f1eda800d8cdb793b521e20798eaacb3fe410ad.tar.gz
Merge "Make signapk align .so entries to 4096 bytes."
am: dbb5527a9e * commit 'dbb5527a9ef27f292794d1e51ae56d1df68c328b': Make signapk align .so entries to 4096 bytes.
-rw-r--r--tools/signapk/SignApk.java21
1 files changed, 20 insertions, 1 deletions
diff --git a/tools/signapk/SignApk.java b/tools/signapk/SignApk.java
index 740a34354a..397f8cca55 100644
--- a/tools/signapk/SignApk.java
+++ b/tools/signapk/SignApk.java
@@ -476,7 +476,7 @@ class SignApk {
* more efficient.
*/
private static void copyFiles(Manifest manifest, JarFile in, JarOutputStream out,
- long timestamp, int alignment) throws IOException {
+ long timestamp, int defaultAlignment) throws IOException {
byte[] buffer = new byte[4096];
int num;
@@ -515,6 +515,7 @@ class SignApk {
offset += 4;
firstEntry = false;
}
+ int alignment = getStoredEntryDataAlignment(name, defaultAlignment);
if (alignment > 0 && (offset % alignment != 0)) {
// Set the "extra data" of the entry to between 1 and
// alignment-1 bytes, to make the file data begin at
@@ -555,6 +556,24 @@ class SignApk {
}
}
+ /**
+ * Returns the multiple (in bytes) at which the provided {@code STORED} entry's data must start
+ * relative to start of file or {@code 0} if alignment of this entry's data is not important.
+ */
+ private static int getStoredEntryDataAlignment(String entryName, int defaultAlignment) {
+ if (defaultAlignment <= 0) {
+ return 0;
+ }
+
+ if (entryName.endsWith(".so")) {
+ // Align .so contents to memory page boundary to enable memory-mapped
+ // execution.
+ return 4096;
+ } else {
+ return defaultAlignment;
+ }
+ }
+
private static class WholeFileSignerOutputStream extends FilterOutputStream {
private boolean closing = false;
private ByteArrayOutputStream footer = new ByteArrayOutputStream();