[compiler-rt] c520863 - [crt][test] Make ctor_dtor.c robust if DT_INIT/DT_FINI is disabled
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 12 09:31:35 PDT 2021
Author: Fangrui Song
Date: 2021-08-12T09:31:31-07:00
New Revision: c520863abb901912799a1178a6caa9079f6214bf
URL: https://github.com/llvm/llvm-project/commit/c520863abb901912799a1178a6caa9079f6214bf
DIFF: https://github.com/llvm/llvm-project/commit/c520863abb901912799a1178a6caa9079f6214bf.diff
LOG: [crt][test] Make ctor_dtor.c robust if DT_INIT/DT_FINI is disabled
New ports in glibc typically don't define ELF_INITFINI, so
DT_INIT/DT_FINI support is disabled.
(rhel ppc64le likely patches their glibc this way as well.)
musl can disable DT_INIT/DT_FINI via -DNO_LEGACY_INITFINI.
So we cannot guarantee ctor()/dtor() will be printed.
Added:
Modified:
compiler-rt/test/crt/ctor_dtor.c
Removed:
################################################################################
diff --git a/compiler-rt/test/crt/ctor_dtor.c b/compiler-rt/test/crt/ctor_dtor.c
index 69848a01c7ca..90be0b452eed 100644
--- a/compiler-rt/test/crt/ctor_dtor.c
+++ b/compiler-rt/test/crt/ctor_dtor.c
@@ -3,16 +3,18 @@
// RUN: %run %t 2>&1 | FileCheck %s
#include <stdio.h>
+#include <stdlib.h>
// Ensure the various startup functions are called in the proper order.
// CHECK: __register_frame_info()
-// CHECK-NEXT: ctor()
-// CHECK-NEXT: main()
-// CHECK-NEXT: dtor()
-// CHECK-NEXT: __deregister_frame_info()
+/// ctor() is here if ld.so/libc supports DT_INIT/DT_FINI
+// CHECK: main()
+/// dtor() is here if ld.so/libc supports DT_INIT/DT_FINI
+// CHECK: __deregister_frame_info()
struct object;
+static int counter;
void __register_frame_info(const void *fi, struct object *obj) {
printf("__register_frame_info()\n");
@@ -24,10 +26,13 @@ void __deregister_frame_info(const void *fi) {
void __attribute__((constructor)) ctor() {
printf("ctor()\n");
+ ++counter;
}
void __attribute__((destructor)) dtor() {
printf("dtor()\n");
+ if (--counter != 0)
+ abort();
}
int main() {
More information about the llvm-commits
mailing list