platform_bionic/tests/libs/segment_gap_outer.cpp
Stephen Hines 15027e048f Specify sections to merge in segment_gap_outer.lds more precisely
https://reviews.llvm.org/D75225 changed the way that orphan sections are
retained, breaking this test. The test relied on these sections being
merged in an implementation-defined order that no longer holds true. We
can use custom sections to place the symbols we want more precisely.

Bug: http://b/161943302
Test: adb shell /data/nativetest64/bionic-unit-tests/bionic-unit-tests --gtest_filter=dlfcn.segment_gap --no_isolate
Change-Id: I65656080e39be16833191cb92d3d4c41e409b216
2020-07-24 10:57:48 -07:00

24 lines
714 B
C++

#include <android/dlext.h>
#include <dlfcn.h>
#include <stdlib.h>
extern "C" void __attribute__((section(".custom_text"))) text_before_start_of_gap() {}
char __attribute__((section(".custom_bss"))) end_of_gap[0x1000];
extern "C" void* get_inner() {
android_dlextinfo info = {};
info.flags = ANDROID_DLEXT_RESERVED_ADDRESS;
char* start_of_gap =
reinterpret_cast<char*>(reinterpret_cast<uintptr_t>(text_before_start_of_gap) & ~0xfffull) +
0x1000;
info.reserved_addr = start_of_gap;
info.reserved_size = end_of_gap - start_of_gap;
void *handle = android_dlopen_ext("libsegment_gap_inner.so", RTLD_NOW, &info);
if (!handle) {
__builtin_trap();
}
return dlsym(handle, "inner");
}