From 1d891a32cf433e205b5d30697beb265dc0e1f248 Mon Sep 17 00:00:00 2001 From: Sterling Augustine Date: Fri, 27 Dec 2019 11:52:12 -0800 Subject: [PATCH] Support powerpc and sparc when building without init_array. Summary: Support powerpc and sparc when building without init_array. Reviewers: rdhindsa, gribozavr Subscribers: jyknight, nemanjai, fedor.sergeev, jsji, shchenz, steven.zhang, #sanitizers, llvm-commits Tags: #sanitizers, #llvm Differential Revision: https://reviews.llvm.org/D71944 --- compiler-rt/lib/crt/crtbegin.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/crt/crtbegin.c b/compiler-rt/lib/crt/crtbegin.c index 5b56ea3..b2b6279 100644 --- a/compiler-rt/lib/crt/crtbegin.c +++ b/compiler-rt/lib/crt/crtbegin.c @@ -48,8 +48,7 @@ static void __attribute__((used)) __do_init() { #ifdef CRT_HAS_INITFINI_ARRAY __attribute__((section(".init_array"), used)) static void (*__init)(void) = __do_init; -#else // CRT_HAS_INITFINI_ARRAY -#if defined(__i386__) || defined(__x86_64__) +#elif defined(__i386__) || defined(__x86_64__) __asm__(".pushsection .init,\"ax\",@progbits\n\t" "call " __USER_LABEL_PREFIX__ "__do_init\n\t" ".popsection"); @@ -57,8 +56,18 @@ __asm__(".pushsection .init,\"ax\",@progbits\n\t" __asm__(".pushsection .init,\"ax\",%progbits\n\t" "bl " __USER_LABEL_PREFIX__ "__do_init\n\t" ".popsection"); -#endif // CRT_HAS_INITFINI_ARRAY -#endif +#elif defined(__powerpc__) || defined(__powerpc64__) +__asm__(".pushsection .init,\"ax\",@progbits\n\t" + "bl " __USER_LABEL_PREFIX__ "__do_init\n\t" + "nop\n\t" + ".popsection"); +#elif defined(__sparc__) +__asm__(".pushsection .init,\"ax\",@progbits\n\t" + "call " __USER_LABEL_PREFIX__ "__do_init\n\t" + ".popsection"); +#else +#error "crtbegin without .init_fini array unimplemented for this architecture" +#endif // CRT_HAS_INITFINI_ARRAY #ifndef CRT_HAS_INITFINI_ARRAY static fp __DTOR_LIST__[] @@ -88,8 +97,7 @@ static void __attribute__((used)) __do_fini() { #ifdef CRT_HAS_INITFINI_ARRAY __attribute__((section(".fini_array"), used)) static void (*__fini)(void) = __do_fini; -#else // CRT_HAS_INITFINI_ARRAY -#if defined(__i386__) || defined(__x86_64__) +#elif defined(__i386__) || defined(__x86_64__) __asm__(".pushsection .fini,\"ax\",@progbits\n\t" "call " __USER_LABEL_PREFIX__ "__do_fini\n\t" ".popsection"); @@ -97,5 +105,15 @@ __asm__(".pushsection .fini,\"ax\",@progbits\n\t" __asm__(".pushsection .fini,\"ax\",%progbits\n\t" "bl " __USER_LABEL_PREFIX__ "__do_fini\n\t" ".popsection"); -#endif +#elif defined(__powerpc__) || defined(__powerpc64__) +__asm__(".pushsection .fini,\"ax\",@progbits\n\t" + "bl " __USER_LABEL_PREFIX__ "__do_fini\n\t" + "nop\n\t" + ".popsection"); +#elif defined(__sparc__) +__asm__(".pushsection .fini,\"ax\",@progbits\n\t" + "call " __USER_LABEL_PREFIX__ "__do_fini\n\t" + ".popsection"); +#else +#error "crtbegin without .init_fini array unimplemented for this architecture" #endif // CRT_HAS_INIT_FINI_ARRAY -- 2.7.4