[clang-repl] Fix dynamic library test to avoid cstdio and linker
authorAnubhab Ghosh <anubhabghosh.me@gmail.com>
Sat, 22 Apr 2023 13:44:29 +0000 (19:14 +0530)
committerAnubhab Ghosh <anubhabghosh.me@gmail.com>
Wed, 26 Apr 2023 03:41:09 +0000 (09:11 +0530)
Some platforms do not have a working linker present. The goal is to
only test the loading of a shared library in clang-repl. A precompiled
library is used instead.

The cstdio header may also not be present. We only need printf.

Related discussion in D141824

Differential Revision: https://reviews.llvm.org/D148992

clang/test/Interpreter/Inputs/dynamic-library-test.cpp [deleted file]
clang/test/Interpreter/Inputs/libdynamic-library-test.so [new file with mode: 0755]
clang/test/Interpreter/dynamic-library.cpp

diff --git a/clang/test/Interpreter/Inputs/dynamic-library-test.cpp b/clang/test/Interpreter/Inputs/dynamic-library-test.cpp
deleted file mode 100644 (file)
index 1f143ba..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-int ultimate_answer = 0;
-
-int calculate_answer() {
-  ultimate_answer = 42;
-  return 5;
-}
diff --git a/clang/test/Interpreter/Inputs/libdynamic-library-test.so b/clang/test/Interpreter/Inputs/libdynamic-library-test.so
new file mode 100755 (executable)
index 0000000..bb7c7b5
Binary files /dev/null and b/clang/test/Interpreter/Inputs/libdynamic-library-test.so differ
index 145c58b..e2bfc81 100644 (file)
@@ -1,13 +1,25 @@
 // REQUIRES: host-supports-jit, system-linux
-// UNSUPPORTED: target={{.*-(ps4|ps5)}}
 
-// RUN: %clang -xc++ -o %T/libdynamic-library-test.so -fPIC -shared -DLIBRARY %S/Inputs/dynamic-library-test.cpp
-// RUN: cat %s | env LD_LIBRARY_PATH=%T:$LD_LIBRARY_PATH clang-repl | FileCheck %s
+// To generate libdynamic-library-test.so :
+// clang -xc++ -o libdynamic-library-test.so -fPIC -shared
+//
+// extern "C" {
+//
+// int ultimate_answer = 0;
+// 
+// int calculate_answer() {
+//   ultimate_answer = 42;
+//   return 5;
+// }
+//
+// }
 
-#include <cstdio>
+// RUN: cat %s | env LD_LIBRARY_PATH=%S/Inputs:$LD_LIBRARY_PATH clang-repl | FileCheck %s
 
-extern int ultimate_answer;
-int calculate_answer();
+extern "C" int printf(const char* format, ...);
+
+extern "C" int ultimate_answer;
+extern "C" int calculate_answer();
 
 %lib libdynamic-library-test.so