[compiler-rt] 83a0ac1 - [ORC-RT] Invert the layout of the trivial-jit-re-dlopen testcase.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 15 19:21:01 PDT 2022
Author: Lang Hames
Date: 2022-09-15T19:11:51-07:00
New Revision: 83a0ac12f5f074fbaf773793de0e95572e073fa7
URL: https://github.com/llvm/llvm-project/commit/83a0ac12f5f074fbaf773793de0e95572e073fa7
DIFF: https://github.com/llvm/llvm-project/commit/83a0ac12f5f074fbaf773793de0e95572e073fa7.diff
LOG: [ORC-RT] Invert the layout of the trivial-jit-re-dlopen testcase.
Compiles and moves the original C code for main to Inputs/dlopen-dlclose-x2.S,
where it can be shared with other testcases that want a
dlopen-dlclose-dlopen-dlclose sequence. The assembly containging the
initializers to be tested is moved into the test file.
Added:
compiler-rt/test/orc/TestCases/Darwin/x86-64/Inputs/dlopen-dlclose-x2.s
compiler-rt/test/orc/TestCases/Darwin/x86-64/jit-re-dlopen-trivial.S
Modified:
Removed:
compiler-rt/test/orc/TestCases/Darwin/x86-64/trivial-jit-re-dlopen.c
################################################################################
diff --git a/compiler-rt/test/orc/TestCases/Darwin/x86-64/Inputs/dlopen-dlclose-x2.s b/compiler-rt/test/orc/TestCases/Darwin/x86-64/Inputs/dlopen-dlclose-x2.s
new file mode 100644
index 000000000000..3fbd1778878d
--- /dev/null
+++ b/compiler-rt/test/orc/TestCases/Darwin/x86-64/Inputs/dlopen-dlclose-x2.s
@@ -0,0 +1,90 @@
+// Runs a sequence of dlopen, dlclose, dlopen, dlclose on a library "inits".
+// This is intended as a standard harness for testing constructor / destructor
+// behavior in the context of a full dlclose and then re-dlopen'ing of the
+// inits library.
+//
+// Compiled from:
+//
+// int main(int argc, char *argv[]) {
+// printf("entering main\n");
+// void *H = dlopen("inits", 0);
+// if (!H) {
+// printf("failed\n");
+// return -1;
+// }
+// if (dlclose(H) == -1) {
+// printf("failed\n");
+// return -1;
+// }
+// H = dlopen("inits", 0);
+// if (!H) {
+// printf("failed\n");
+// return -1;
+// }
+// if (dlclose(H) == -1) {
+// printf("failed\n");
+// return -1;
+// }
+// printf("leaving main\n");
+// return 0;
+//}
+
+ .section __TEXT,__text,regular,pure_instructions
+ .build_version macos, 13, 0 sdk_version 13, 0
+ .globl _main
+ .p2align 4, 0x90
+_main:
+
+ pushq %r14
+ pushq %rbx
+ pushq %rax
+ leaq L_str(%rip), %rdi
+ callq _puts
+ leaq L_.str.1(%rip), %rdi
+ xorl %esi, %esi
+ callq _dlopen
+ movl $-1, %ebx
+ leaq L_str.8(%rip), %r14
+ testq %rax, %rax
+ je LBB0_4
+
+ movq %rax, %rdi
+ callq _dlclose
+ cmpl $-1, %eax
+ je LBB0_4
+
+ leaq L_.str.1(%rip), %rdi
+ xorl %esi, %esi
+ callq _dlopen
+ testq %rax, %rax
+ je LBB0_4
+
+ movq %rax, %rdi
+ callq _dlclose
+ xorl %ebx, %ebx
+ cmpl $-1, %eax
+ sete %bl
+ leaq L_str.8(%rip), %rax
+ leaq L_str.6(%rip), %r14
+ cmoveq %rax, %r14
+ negl %ebx
+LBB0_4:
+ movq %r14, %rdi
+ callq _puts
+ movl %ebx, %eax
+ addq $8, %rsp
+ popq %rbx
+ popq %r14
+ retq
+
+ .section __TEXT,__cstring,cstring_literals
+L_.str.1:
+ .asciz "inits"
+L_str:
+ .asciz "entering main"
+L_str.6:
+ .asciz "leaving main"
+L_str.8:
+ .asciz "failed"
+
+.subsections_via_symbols
diff --git a/compiler-rt/test/orc/TestCases/Darwin/x86-64/jit-re-dlopen-trivial.S b/compiler-rt/test/orc/TestCases/Darwin/x86-64/jit-re-dlopen-trivial.S
new file mode 100644
index 000000000000..e8f48cac9c97
--- /dev/null
+++ b/compiler-rt/test/orc/TestCases/Darwin/x86-64/jit-re-dlopen-trivial.S
@@ -0,0 +1,57 @@
+// Test that __orc_rt_macho_jit_dlopen and __orc_rt_macho_jit_dlclose work as
+// expected when dlopen and dlclose are run twice in sequence (i.e. dlopen,
+// dlclose, dlopen, dlclose) on a testcase containing simple stateless
+// constructors and destructors (in this case they just print "constructor" and
+// "destructor" respectively).
+//
+// RUN: %clang -c -o %t.main.o %p/Inputs/dlopen-dlclose-x2.S
+// RUN: %clang -c -o %t.inits.o %s
+// RUN: %llvm_jitlink \
+// RUN: -alias _dlopen=___orc_rt_macho_jit_dlopen \
+// RUN: -alias _dlclose=___orc_rt_macho_jit_dlclose \
+// RUN: %t.main.o -jd inits %t.inits.o -lmain | FileCheck %s
+
+// CHECK: entering main
+// CHECK-NEXT: constructor
+// CHECK-NEXT: destructor
+// CHECK-NEXT: constructor
+// CHECK-NEXT: destructor
+// CHECK-NEXT: leaving main
+
+ .section __TEXT,__text,regular,pure_instructions
+ .build_version macos, 12, 0 sdk_version 12, 0, 1
+ .globl _deinitializer
+ .p2align 4, 0x90
+_deinitializer:
+ pushq %rbp
+ movq %rsp, %rbp
+ leaq L_str.2(%rip), %rdi
+ popq %rbp
+ jmp _puts
+
+ .section __TEXT,__StaticInit,regular,pure_instructions
+ .p2align 4, 0x90
+_initializer:
+ pushq %rbp
+ movq %rsp, %rbp
+ leaq L_str(%rip), %rdi
+ callq _puts
+ movq _deinitializer at GOTPCREL(%rip), %rdi
+ leaq _I(%rip), %rsi
+ leaq ___dso_handle(%rip), %rdx
+ popq %rbp
+ jmp ___cxa_atexit
+
+ .globl _I
+.zerofill __DATA,__common,_I,1,0
+ .section __DATA,__mod_init_func,mod_init_funcs
+ .p2align 3
+ .quad _initializer
+ .section __TEXT,__cstring,cstring_literals
+L_str:
+ .asciz "constructor"
+
+L_str.2:
+ .asciz "destructor"
+
+.subsections_via_symbols
diff --git a/compiler-rt/test/orc/TestCases/Darwin/x86-64/trivial-jit-re-dlopen.c b/compiler-rt/test/orc/TestCases/Darwin/x86-64/trivial-jit-re-dlopen.c
deleted file mode 100644
index 1f3c88bf9b43..000000000000
--- a/compiler-rt/test/orc/TestCases/Darwin/x86-64/trivial-jit-re-dlopen.c
+++ /dev/null
@@ -1,45 +0,0 @@
-// Test that __orc_rt_macho_jit_dlopen and __orc_rt_macho_jit_dlclose work as
-// expected for a dlopen; dlclose; dlopen; dlclose; sequence: the first dlclose
-// should run destructors, and the second dlopen should re-run initializers.
-//
-// RUN: %clang -c -o %t.inits.o %p/Inputs/standalone-ctor-and-cxa-atexit-dtor.S
-// RUN: %clang -c -o %t.test.o %s
-// RUN: %llvm_jitlink \
-// RUN: -alias _dlopen=___orc_rt_macho_jit_dlopen \
-// RUN: -alias _dlclose=___orc_rt_macho_jit_dlclose \
-// RUN: %t.test.o -jd inits %t.inits.o -lmain | FileCheck %s
-
-// CHECK: entering main
-// CHECK-NEXT: constructor
-// CHECK-NEXT: destructor
-// CHECK-NEXT: constructor
-// CHECK-NEXT: destructor
-// CHECK-NEXT: leaving main
-
-int printf(const char * restrict format, ...);
-void *dlopen(const char* path, int mode);
-int dlclose(void *handle);
-
-int main(int argc, char *argv[]) {
- printf("entering main\n");
- void *H = dlopen("inits", 0);
- if (!H) {
- printf("failed\n");
- return -1;
- }
- if (dlclose(H) == -1) {
- printf("failed\n");
- return -1;
- }
- H = dlopen("inits", 0);
- if (!H) {
- printf("failed\n");
- return -1;
- }
- if (dlclose(H) == -1) {
- printf("failed\n");
- return -1;
- }
- printf("leaving main\n");
- return 0;
-}
More information about the llvm-commits
mailing list