Instead of cloning full bionic source repo (~70MB)  everytime we need to
build tests image, this patch simply adds seven small source files
to the OSv repo. The files are copies from the directory tests/libs 
of https://android.googlesource.com/platform/bionic at the commit
47ddeb1ae45dcd62c30c232c9b5490877da6185b.

Please note the bionic test source code is licenced
under permissive BSD-like license Apache 2.0.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
---
 .gitignore                                    |  1 -
 licenses/bionic.txt                           | 15 ++++++
 modules/dl_tests/Makefile                     |  9 ----
 .../libs/check_rtld_next_from_library.cpp     | 37 +++++++++++++
 .../bionic/tests/libs/dlext_test_library.cpp  | 43 +++++++++++++++
 .../tests/libs/dlopen_testlib_simple.cpp      | 24 +++++++++
 .../tests/libs/dlsym_from_this_functions.cpp  | 52 +++++++++++++++++++
 .../tests/libs/dlsym_from_this_symbol.cpp     | 17 ++++++
 .../tests/libs/dlsym_from_this_symbol2.cpp    | 18 +++++++
 modules/dl_tests/bionic/tests/libs/empty.cpp  |  0
 10 files changed, 206 insertions(+), 10 deletions(-)
 create mode 100644 licenses/bionic.txt
 create mode 100644 
modules/dl_tests/bionic/tests/libs/check_rtld_next_from_library.cpp
 create mode 100644 modules/dl_tests/bionic/tests/libs/dlext_test_library.cpp
 create mode 100644 modules/dl_tests/bionic/tests/libs/dlopen_testlib_simple.cpp
 create mode 100644 
modules/dl_tests/bionic/tests/libs/dlsym_from_this_functions.cpp
 create mode 100644 
modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol.cpp
 create mode 100644 
modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol2.cpp
 create mode 100644 modules/dl_tests/bionic/tests/libs/empty.cpp

diff --git a/.gitignore b/.gitignore
index da64d10e..16e192db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,7 +46,6 @@ modules/httpserver-jvm-plugin/obj/
 modules/libtools/*.so
 modules/libtools/*.o
 modules/libyaml/usr.manifest
-modules/dl_tests/bionic/
 modules/dl_tests/usr.manifest
 .idea
 compile_commands.json
diff --git a/licenses/bionic.txt b/licenses/bionic.txt
new file mode 100644
index 00000000..37766bde
--- /dev/null
+++ b/licenses/bionic.txt
@@ -0,0 +1,15 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
diff --git a/modules/dl_tests/Makefile b/modules/dl_tests/Makefile
index 8f3bd0da..97546205 100644
--- a/modules/dl_tests/Makefile
+++ b/modules/dl_tests/Makefile
@@ -31,18 +31,9 @@ tests := libtest_simple.so libtest_empty.so 
libtest_dlsym_from_this_grandchild.s
        libtest_dlsym_from_this_child.so libtest_dlsym_from_this.so 
libdlext_test.so \
        libtest_with_dependency.so libtest_check_rtld_next_from_library.so
 
-.PHONY: get_file
-get_file:
-       if cd $(src)/modules/dl_tests/bionic; then \
-               git pull; \
-       else \
-               git clone --depth=1 
https://android.googlesource.com/platform/bionic 
$(src)/modules/dl_tests/bionic; \
-       fi
-
 all_tests := $(tests:%=dl_tests/%)
 
 build_all:
-       $(MAKE) get_file
        $(MAKE) $(all_tests:%=$(out)/%)
 .PHONY: build_all
 
diff --git 
a/modules/dl_tests/bionic/tests/libs/check_rtld_next_from_library.cpp 
b/modules/dl_tests/bionic/tests/libs/check_rtld_next_from_library.cpp
new file mode 100644
index 00000000..fb15e2ab
--- /dev/null
+++ b/modules/dl_tests/bionic/tests/libs/check_rtld_next_from_library.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <dlfcn.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+static void* g_libc_fclose_ptr;
+
+static void __attribute__((constructor)) __libc_fclose_lookup() {
+  g_libc_fclose_ptr = dlsym(RTLD_NEXT, "fclose");
+}
+
+// A libc function used for RTLD_NEXT.
+// This function in not supposed to be called.
+extern "C" int __attribute__((weak)) fclose(FILE*) {
+  abort();
+}
+
+extern "C" void* get_libc_fclose_ptr() {
+  return g_libc_fclose_ptr;
+}
+
+
diff --git a/modules/dl_tests/bionic/tests/libs/dlext_test_library.cpp 
b/modules/dl_tests/bionic/tests/libs/dlext_test_library.cpp
new file mode 100644
index 00000000..5c04329e
--- /dev/null
+++ b/modules/dl_tests/bionic/tests/libs/dlext_test_library.cpp
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+class A {
+public:
+  virtual int getRandomNumber() {
+    return 4;  // chosen by fair dice roll.
+               // guaranteed to be random.
+  }
+
+  virtual ~A() {}
+};
+
+A a;
+
+// nested macros to make it easy to define a large amount of read-only data
+// which will require relocation.
+#define A_16 &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a, &a,
+#define A_128 A_16 A_16 A_16 A_16 A_16 A_16 A_16 A_16
+#define A_1024 A_128 A_128 A_128 A_128 A_128 A_128 A_128 A_128
+
+extern "C" A* const lots_of_relro[] = {
+  A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 A_1024 A_1024
+};
+
+extern "C" int getRandomNumber() {
+  // access the relro section (twice, in fact, once for the pointer, and once
+  // for the vtable of A) to check it's actually there.
+  return lots_of_relro[0]->getRandomNumber();
+}
diff --git a/modules/dl_tests/bionic/tests/libs/dlopen_testlib_simple.cpp 
b/modules/dl_tests/bionic/tests/libs/dlopen_testlib_simple.cpp
new file mode 100644
index 00000000..32269557
--- /dev/null
+++ b/modules/dl_tests/bionic/tests/libs/dlopen_testlib_simple.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+
+uint32_t dlopen_testlib_taxicab_number = 1729;
+
+extern "C" bool dlopen_testlib_simple_func() {
+  return true;
+}
diff --git a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_functions.cpp 
b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_functions.cpp
new file mode 100644
index 00000000..1f357e01
--- /dev/null
+++ b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_functions.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <dlfcn.h>
+#include <stdio.h>
+
+extern int test_dlsym_symbol;
+
+int test_dlsym_symbol = -1;
+
+extern "C" int* lookup_dlsym_symbol_using_RTLD_DEFAULT() {
+  dlerror();
+  int* result = static_cast<int*>(dlsym(RTLD_DEFAULT, "test_dlsym_symbol"));
+  // TODO: remove this once b/20049306 is fixed
+  if (result == nullptr) {
+    printf("Cannot find the answer\n");
+  }
+  return result;
+}
+
+extern "C" int* lookup_dlsym_symbol2_using_RTLD_DEFAULT() {
+  dlerror();
+  int* result = static_cast<int*>(dlsym(RTLD_DEFAULT, "test_dlsym_symbol2"));
+  // TODO: remove this once b/20049306 is fixed
+  if (result == nullptr) {
+    printf("Cannot find the answer\n");
+  }
+  return result;
+}
+
+extern "C" int* lookup_dlsym_symbol_using_RTLD_NEXT() {
+  dlerror();
+  int* result = static_cast<int*>(dlsym(RTLD_NEXT, "test_dlsym_symbol"));
+  // TODO: remove this once b/20049306 is fixed
+  if (result == nullptr) {
+    printf("Cannot find the answer\n");
+  }
+  return result;
+}
+
diff --git a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol.cpp 
b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol.cpp
new file mode 100644
index 00000000..c3ec255c
--- /dev/null
+++ b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol.cpp
@@ -0,0 +1,17 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+int test_dlsym_symbol = 42;
diff --git a/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol2.cpp 
b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol2.cpp
new file mode 100644
index 00000000..20da1d57
--- /dev/null
+++ b/modules/dl_tests/bionic/tests/libs/dlsym_from_this_symbol2.cpp
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+int test_dlsym_symbol = 43;
+int test_dlsym_symbol2 = 44;
diff --git a/modules/dl_tests/bionic/tests/libs/empty.cpp 
b/modules/dl_tests/bionic/tests/libs/empty.cpp
new file mode 100644
index 00000000..e69de29b
-- 
2.20.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20200218041658.29888-1-jwkozaczuk%40gmail.com.

Reply via email to