forked from Grouper-AOSP/platform_manifest
-
Notifications
You must be signed in to change notification settings - Fork 13
/
bionic.patch
578 lines (556 loc) · 18.9 KB
/
bionic.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
diff --git a/libc/arch-arm/arm.mk b/libc/arch-arm/arm.mk
index 76f465e81..21b615236 100644
--- a/libc/arch-arm/arm.mk
+++ b/libc/arch-arm/arm.mk
@@ -1,6 +1,7 @@
# 32-bit arm.
libc_bionic_src_files_arm += \
+ arch-arm/generic/bionic/memchr.S \
arch-arm/generic/bionic/memcmp.S \
arch-arm/generic/bionic/memcpy.S \
arch-arm/generic/bionic/memset.S \
@@ -13,7 +14,8 @@ libc_bionic_src_files_exclude_arm += \
bionic/__memset_chk.cpp \
libc_openbsd_src_files_exclude_arm += \
- upstream-openbsd/lib/libc/string/strcpy.c \
+ upstream-openbsd/lib/libc/string/memchr.c \
+ upstream-openbsd/lib/libc/string/strcpy.c
#
# Inherently architecture-specific code.
diff --git a/libc/arch-arm/generic/bionic/memchr.S b/libc/arch-arm/generic/bionic/memchr.S
new file mode 100644
index 000000000..490cdb7b0
--- /dev/null
+++ b/libc/arch-arm/generic/bionic/memchr.S
@@ -0,0 +1,200 @@
+/* Copyright (c) 2015 ARM Ltd.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Linaro nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+
+#include <private/bionic_asm.h>
+
+ .syntax unified
+ .arch armv7-a
+ .fpu neon
+ .text
+ .thumb
+ .thumb_func
+ .p2align 4,,15
+ .align 4
+
+/* Arguments */
+#define srcin r0
+#define chrin r1
+#define cntin r2
+
+/* Retval */
+#define result r0 /* Live range does not overlap with srcin */
+
+/* Working registers */
+#define src r1 /* Live range does not overlap with chrin */
+#define tmp r3
+#define synd r0 /* No overlap with srcin or result */
+#define soff r12
+
+/* Working NEON registers */
+#define vrepchr q0
+#define vdata0 q1
+#define vdata0_0 d2 /* Lower half of vdata0 */
+#define vdata0_1 d3 /* Upper half of vdata0 */
+#define vdata1 q2
+#define vdata1_0 d4 /* Lower half of vhas_chr0 */
+#define vdata1_1 d5 /* Upper half of vhas_chr0 */
+#define vrepmask q3
+#define vrepmask0 d6
+#define vrepmask1 d7
+#define vend q4
+#define vend0 d8
+#define vend1 d9
+
+/*
+ * Core algorithm:
+ *
+ * For each 32-byte chunk we calculate a 32-bit syndrome value, with one bit per
+ * byte. Each bit is set if the relevant byte matched the requested character
+ * and cleared otherwise. Since the bits in the syndrome reflect exactly the
+ * order in which things occur in the original string, counting trailing zeros
+ * allows to identify exactly which byte has matched.
+ */
+
+ENTRY(memchr)
+ .cfi_sections .debug_frame
+ /* Use a simple loop if there are less than 8 bytes to search. */
+ cmp cntin, #7
+ bhi .Llargestr
+
+.Lsmallstr:
+ subs cntin, cntin, #1
+ blt .Lnotfound /* Return not found if reached end. */
+ ldrb tmp, [srcin], #1
+ cmp tmp, chrin
+ bne .Lsmallstr /* Loop again if not found. */
+ /* Otherwise fixup address and return. */
+ sub result, result, #1
+ bx lr
+
+.Llargestr:
+ vdup.8 vrepchr, chrin /* Duplicate char across all lanes. */
+ /*
+ * Magic constant 0x8040201008040201 allows us to identify which lane
+ * matches the requested byte.
+ */
+ movw tmp, #0x0201
+ movt tmp, #0x0804
+ lsl soff, tmp, #4
+ vmov vrepmask0, tmp, soff
+ vmov vrepmask1, tmp, soff
+ /* Work with aligned 32-byte chunks */
+ bic src, srcin, #31
+ ands soff, srcin, #31
+ beq .Lloopintro /* Go straight to main loop if it's aligned. */
+
+ /*
+ * Input string is not 32-byte aligned. We calculate the syndrome
+ * value for the aligned 32 bytes block containing the first bytes
+ * and mask the irrelevant part.
+ */
+ vld1.8 {vdata0, vdata1}, [src:256]!
+ sub tmp, soff, #32
+ adds cntin, cntin, tmp
+ vceq.i8 vdata0, vdata0, vrepchr
+ vceq.i8 vdata1, vdata1, vrepchr
+ vand vdata0, vdata0, vrepmask
+ vand vdata1, vdata1, vrepmask
+ vpadd.i8 vdata0_0, vdata0_0, vdata0_1
+ vpadd.i8 vdata1_0, vdata1_0, vdata1_1
+ vpadd.i8 vdata0_0, vdata0_0, vdata1_0
+ vpadd.i8 vdata0_0, vdata0_0, vdata0_0
+ vmov.32 synd, vdata0_0[0]
+
+ /* Clear the soff lower bits */
+ lsr synd, synd, soff
+ lsl synd, synd, soff
+ /* The first block can also be the last */
+ bls .Lmasklast
+ /* Have we found something already? */
+ cbnz synd, .Ltail
+
+.Lloopintro:
+ vpush {vend}
+ /* 264/265 correspond to d8/d9 for q4 */
+ .cfi_adjust_cfa_offset 16
+ .cfi_rel_offset 264, 0
+ .cfi_rel_offset 265, 8
+ .p2align 3,,7
+
+.Lloop:
+ vld1.8 {vdata0, vdata1}, [src:256]!
+ subs cntin, cntin, #32
+ vceq.i8 vdata0, vdata0, vrepchr
+ vceq.i8 vdata1, vdata1, vrepchr
+ /* If we're out of data we finish regardless of the result. */
+ bls .Lend
+ /* Use a fast check for the termination condition. */
+ vorr vend, vdata0, vdata1
+ vorr vend0, vend0, vend1
+ vmov synd, tmp, vend0
+ orrs synd, synd, tmp
+ /* We're not out of data, loop if we haven't found the character. */
+ beq .Lloop
+
+.Lend:
+ vpop {vend}
+ .cfi_adjust_cfa_offset -16
+ .cfi_restore 264
+ .cfi_restore 265
+
+ /* Termination condition found, let's calculate the syndrome value. */
+ vand vdata0, vdata0, vrepmask
+ vand vdata1, vdata1, vrepmask
+ vpadd.i8 vdata0_0, vdata0_0, vdata0_1
+ vpadd.i8 vdata1_0, vdata1_0, vdata1_1
+ vpadd.i8 vdata0_0, vdata0_0, vdata1_0
+ vpadd.i8 vdata0_0, vdata0_0, vdata0_0
+ vmov.32 synd, vdata0_0[0]
+ cbz synd, .Lnotfound
+ bhi .Ltail
+
+.Lmasklast:
+ /* Clear the (-cntin) upper bits to avoid out-of-bounds matches. */
+ neg cntin, cntin
+ lsl synd, synd, cntin
+ lsrs synd, synd, cntin
+ it eq
+ moveq src, #0 /* If no match, set src to 0 so the retval is 0. */
+
+.Ltail:
+ /* Count the trailing zeros using bit reversing */
+ rbit synd, synd
+ /* Compensate the last post-increment */
+ sub src, src, #32
+ /* Count the leading zeros */
+ clz synd, synd
+ /* Compute the potential result and return */
+ add result, src, synd
+ bx lr
+
+.Lnotfound:
+ /* Set result to NULL if not found and return */
+ mov result, #0
+ bx lr
+
+END(memchr)
diff --git a/libc/arch-arm/include/machine/cpu-features.h b/libc/arch-arm/include/machine/cpu-features.h
index fc8c80dc7..8e7f95095 100644
--- a/libc/arch-arm/include/machine/cpu-features.h
+++ b/libc/arch-arm/include/machine/cpu-features.h
@@ -33,7 +33,9 @@
* so try to guess it.
*/
#ifndef __ARM_ARCH__
-# if defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ || \
+# if defined __ARM_ARCH_8__ || defined __ARM_ARCH_8A__
+# define __ARM_ARCH__ 8
+# elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ || \
defined __ARM_ARCH_7R__ || defined __ARM_ARCH_7M__
# define __ARM_ARCH__ 7
# elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ || \
diff --git a/libc/bionic/jemalloc.h b/libc/bionic/jemalloc.h
index fceb323d3..f7e877056 100644
--- a/libc/bionic/jemalloc.h
+++ b/libc/bionic/jemalloc.h
@@ -26,6 +26,7 @@
__BEGIN_DECLS
struct mallinfo je_mallinfo();
+int je_mallopt(int, int);
int je_iterate(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*);
void je_malloc_disable();
void je_malloc_enable();
diff --git a/libc/bionic/jemalloc_wrapper.cpp b/libc/bionic/jemalloc_wrapper.cpp
index e33d560a4..266b9660c 100644
--- a/libc/bionic/jemalloc_wrapper.cpp
+++ b/libc/bionic/jemalloc_wrapper.cpp
@@ -14,6 +14,7 @@
* limitations under the License.
*/
+#include <malloc.h>
#include <sys/param.h>
#include <unistd.h>
@@ -46,3 +47,38 @@ void* je_memalign_round_up_boundary(size_t boundary, size_t size) {
}
return je_memalign(boundary, size);
}
+
+int je_mallopt(int param, int value) {
+ // The only parameter we currently understand is M_DECAY_TIME.
+ if (param == M_DECAY_TIME) {
+ // Only support setting the value to 1 or 0.
+ ssize_t decay_time;
+ if (value) {
+ decay_time = 1;
+ } else {
+ decay_time = 0;
+ }
+ // First get the total number of arenas.
+ unsigned narenas;
+ size_t sz = sizeof(unsigned);
+ if (je_mallctl("arenas.narenas", &narenas, &sz, nullptr, 0) != 0) {
+ return 0;
+ }
+
+ // Set the decay time for any arenas that will be created in the future.
+ if (je_mallctl("arenas.decay_time", nullptr, nullptr, &decay_time, sizeof(decay_time)) != 0) {
+ return 0;
+ }
+
+ // Change the decay on the already existing arenas.
+ char buffer[100];
+ for (unsigned i = 0; i < narenas; i++) {
+ snprintf(buffer, sizeof(buffer), "arena.%d.decay_time", i);
+ if (je_mallctl(buffer, nullptr, nullptr, &decay_time, sizeof(decay_time)) != 0) {
+ break;
+ }
+ }
+ return 1;
+ }
+ return 0;
+}
diff --git a/libc/bionic/malloc_common.cpp b/libc/bionic/malloc_common.cpp
index e05061917..8053535d9 100644
--- a/libc/bionic/malloc_common.cpp
+++ b/libc/bionic/malloc_common.cpp
@@ -68,6 +68,7 @@ static constexpr MallocDispatch __libc_malloc_default_dispatch
Malloc(iterate),
Malloc(malloc_disable),
Malloc(malloc_enable),
+ Malloc(mallopt),
};
// In a VM process, this is set to 1 after fork()ing out of zygote.
@@ -101,6 +102,14 @@ extern "C" struct mallinfo mallinfo() {
return Malloc(mallinfo)();
}
+extern "C" int mallopt(int param, int value) {
+ auto _mallopt = __libc_globals->malloc_dispatch.mallopt;
+ if (__predict_false(_mallopt != nullptr)) {
+ return _mallopt(param, value);
+ }
+ return Malloc(mallopt)(param, value);
+}
+
extern "C" void* malloc(size_t bytes) {
auto _malloc = __libc_globals->malloc_dispatch.malloc;
if (__predict_false(_malloc != nullptr)) {
@@ -248,6 +257,10 @@ static bool InitMalloc(void* malloc_impl_handler, MallocDispatch* table, const c
prefix, "mallinfo")) {
return false;
}
+ if (!InitMallocFunction<MallocMallopt>(malloc_impl_handler, &table->mallopt,
+ prefix, "mallopt")) {
+ return false;
+ }
if (!InitMallocFunction<MallocMalloc>(malloc_impl_handler, &table->malloc,
prefix, "malloc")) {
return false;
diff --git a/libc/include/malloc.h b/libc/include/malloc.h
index 87555a96b..f0cdf82f3 100644
--- a/libc/include/malloc.h
+++ b/libc/include/malloc.h
@@ -70,6 +70,11 @@ extern struct mallinfo mallinfo(void);
*/
extern int malloc_info(int, FILE *);
+/* mallopt options */
+#define M_DECAY_TIME -100
+
+int mallopt(int, int) __INTRODUCED_IN(26);
+
__END_DECLS
#endif /* LIBC_INCLUDE_MALLOC_H_ */
diff --git a/libc/libc.arm.map b/libc/libc.arm.map
index 38f8437f4..52698b6f0 100644
--- a/libc/libc.arm.map
+++ b/libc/libc.arm.map
@@ -1494,4 +1494,5 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
+ mallopt;
} LIBC_N;
diff --git a/libc/libc.arm64.map b/libc/libc.arm64.map
index afbd0ee4b..db7368ded 100644
--- a/libc/libc.arm64.map
+++ b/libc/libc.arm64.map
@@ -1209,4 +1209,5 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
+ mallopt;
} LIBC_N;
diff --git a/libc/libc.mips.map b/libc/libc.mips.map
index 46c835b0b..2e272f5ca 100644
--- a/libc/libc.mips.map
+++ b/libc/libc.mips.map
@@ -1335,4 +1335,5 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
+ mallopt;
} LIBC_N;
diff --git a/libc/libc.mips64.map b/libc/libc.mips64.map
index afbd0ee4b..db7368ded 100644
--- a/libc/libc.mips64.map
+++ b/libc/libc.mips64.map
@@ -1209,4 +1209,5 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
+ mallopt;
} LIBC_N;
diff --git a/libc/libc.x86.map b/libc/libc.x86.map
index 9417d5620..6598e3d4b 100644
--- a/libc/libc.x86.map
+++ b/libc/libc.x86.map
@@ -1334,4 +1334,5 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
+ mallopt;
} LIBC_N;
diff --git a/libc/libc.x86_64.map b/libc/libc.x86_64.map
index afbd0ee4b..db7368ded 100644
--- a/libc/libc.x86_64.map
+++ b/libc/libc.x86_64.map
@@ -1209,4 +1209,5 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
+ mallopt;
} LIBC_N;
diff --git a/libc/malloc_debug/malloc_debug.cpp b/libc/malloc_debug/malloc_debug.cpp
index 1ee76897d..329e72505 100644
--- a/libc/malloc_debug/malloc_debug.cpp
+++ b/libc/malloc_debug/malloc_debug.cpp
@@ -76,6 +76,7 @@ void* debug_memalign(size_t alignment, size_t bytes);
void* debug_realloc(void* pointer, size_t bytes);
void* debug_calloc(size_t nmemb, size_t bytes);
struct mallinfo debug_mallinfo();
+int debug_mallopt(int param, int value);
int debug_posix_memalign(void** memptr, size_t alignment, size_t size);
int debug_iterate(uintptr_t base, size_t size,
void (*callback)(uintptr_t base, size_t size, void* arg), void* arg);
@@ -584,6 +585,10 @@ struct mallinfo debug_mallinfo() {
return g_dispatch->mallinfo();
}
+int debug_mallopt(int param, int value) {
+ return g_dispatch->mallopt(param, value);
+}
+
int debug_posix_memalign(void** memptr, size_t alignment, size_t size) {
if (DebugCallsDisabled()) {
return g_dispatch->posix_memalign(memptr, alignment, size);
diff --git a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
index 014b91352..8014f0652 100644
--- a/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_unit_tests.cpp
@@ -58,6 +58,7 @@ void debug_get_malloc_leak_info(uint8_t**, size_t*, size_t*, size_t*, size_t*);
void debug_free_malloc_leak_info(uint8_t*);
struct mallinfo debug_mallinfo();
+int debug_mallopt(int, int);
#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
void* debug_pvalloc(size_t);
@@ -125,6 +126,7 @@ MallocDispatch MallocDebugTest::dispatch = {
nullptr,
nullptr,
nullptr,
+ mallopt,
};
void VerifyAllocCalls() {
@@ -1471,6 +1473,20 @@ TEST_F(MallocDebugTest, debug_mallinfo) {
ASSERT_STREQ("", getFakeLogPrint().c_str());
}
+TEST_F(MallocDebugTest, debug_mallopt) {
+ Init("guard");
+
+ void* pointer = debug_malloc(150);
+ ASSERT_TRUE(pointer != nullptr);
+
+ EXPECT_EQ(0, debug_mallopt(-1000, 1));
+
+ debug_free(pointer);
+
+ ASSERT_STREQ("", getFakeLogBuf().c_str());
+ ASSERT_STREQ("", getFakeLogPrint().c_str());
+}
+
TEST_F(MallocDebugTest, debug_posix_memalign) {
Init("guard");
diff --git a/libc/private/bionic_malloc_dispatch.h b/libc/private/bionic_malloc_dispatch.h
index 02a092f40..cdae466c9 100644
--- a/libc/private/bionic_malloc_dispatch.h
+++ b/libc/private/bionic_malloc_dispatch.h
@@ -45,6 +45,7 @@ typedef void* (*MallocRealloc)(void*, size_t);
typedef int (*MallocIterate)(uintptr_t, size_t, void (*)(uintptr_t, size_t, void*), void*);
typedef void (*MallocMallocDisable)();
typedef void (*MallocMallocEnable)();
+typedef int (*MallocMallopt)(int, int);
#if defined(HAVE_DEPRECATED_MALLOC_FUNCS)
typedef void* (*MallocPvalloc)(size_t);
@@ -69,6 +70,7 @@ struct MallocDispatch {
MallocIterate iterate;
MallocMallocDisable malloc_disable;
MallocMallocEnable malloc_enable;
+ MallocMallopt mallopt;
} __attribute__((aligned(32)));
#endif
diff --git a/linker/Android.mk b/linker/Android.mk
index 4a4ca5c5a..0d592c97f 100644
--- a/linker/Android.mk
+++ b/linker/Android.mk
@@ -54,6 +54,10 @@ ifeq ($(TARGET_IS_64_BIT),true)
LOCAL_CPPFLAGS += -DTARGET_IS_64_BIT
endif
+ifeq ($(TARGET_NEEDS_PLATFORM_TEXT_RELOCATIONS),true)
+LOCAL_CPPFLAGS += -DTARGET_NEEDS_PLATFORM_TEXT_RELOCATIONS
+endif
+
# We need to access Bionic private headers in the linker.
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../libc/
diff --git a/linker/linker.cpp b/linker/linker.cpp
index a043b859a..cd1874fe7 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -560,7 +560,7 @@ static bool realpath_fd(int fd, std::string* realpath) {
std::vector<char> buf(PATH_MAX), proc_self_fd(PATH_MAX);
__libc_format_buffer(&proc_self_fd[0], proc_self_fd.size(), "/proc/self/fd/%d", fd);
if (readlink(&proc_self_fd[0], &buf[0], buf.size()) == -1) {
- PRINT("readlink(\"%s\") failed: %s [fd=%d]", &proc_self_fd[0], strerror(errno), fd);
+// PRINT("readlink(\"%s\") failed: %s [fd=%d]", &proc_self_fd[0], strerror(errno), fd);
return false;
}
@@ -1545,8 +1545,8 @@ static int open_library_in_zipfile(ZipArchiveCache* zip_archive_cache,
if (realpath_fd(fd, realpath)) {
*realpath += separator;
} else {
- PRINT("warning: unable to get realpath for the library \"%s\". Will use given path.",
- normalized_path.c_str());
+// PRINT("warning: unable to get realpath for the library \"%s\". Will use given path.",
+// normalized_path.c_str());
*realpath = normalized_path;
}
@@ -3953,11 +3953,18 @@ bool soinfo::link_image(const soinfo_list_t& global_group, const soinfo_list_t&
#if !defined(__LP64__)
if (has_text_relocations) {
// Fail if app is targeting sdk version > 22
- if (get_application_target_sdk_version() > 22) {
+#if !defined(__i386__) // ffmpeg says that they require text relocations on x86
+#if defined(TARGET_NEEDS_PLATFORM_TEXT_RELOCATIONS)
+ if (get_application_target_sdk_version() != __ANDROID_API__
+ && get_application_target_sdk_version() > 22) {
+#else
+ if (get_application_target_sdk_version() > 22) {
+#endif
PRINT("%s: has text relocations", get_realpath());
DL_ERR("%s: has text relocations", get_realpath());
return false;
}
+#endif
// Make segments writable to allow text relocations to work properly. We will later call
// phdr_table_protect_segments() after all of them are applied.
DL_WARN("%s has text relocations. This is wasting memory and prevents "
diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp
index 8fba1c449..a7b9d52e5 100644
--- a/tests/malloc_test.cpp
+++ b/tests/malloc_test.cpp
@@ -500,3 +500,10 @@ TEST(malloc, verify_alignment) {
delete[] values_64;
delete[] values_ldouble;
}
+
+TEST(malloc, mallopt_smoke) {
+ errno = 0;
+ ASSERT_EQ(0, mallopt(-1000, 1));
+ // mallopt doesn't set errno.
+ ASSERT_EQ(0, errno);
+}