From patchwork Wed Jul 4 15:55:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christophe Lyon X-Patchwork-Id: 939447 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=uclibc-ng.org (client-ip=89.238.66.15; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=st.com Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41LQfX2QJ9z9s3q for ; Thu, 5 Jul 2018 01:59:32 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 87AAF10002; Wed, 4 Jul 2018 17:59:29 +0200 (CEST) X-Original-To: devel@uclibc-ng.org Delivered-To: devel@helium.openadk.org Received: from mx07-00178001.pphosted.com (mx07-00178001.pphosted.com [62.209.51.94]) by helium.openadk.org (Postfix) with ESMTPS id CA24010002 for ; Wed, 4 Jul 2018 17:59:27 +0200 (CEST) Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id w64FsTY1023944; Wed, 4 Jul 2018 17:59:27 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 2k0dr4csq5-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 04 Jul 2018 17:59:27 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D080631; Wed, 4 Jul 2018 15:59:25 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node1.st.com [10.75.127.13]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A174616B54; Wed, 4 Jul 2018 15:59:25 +0000 (GMT) Received: from gnb.st.com (10.75.127.44) by SFHDAG5NODE1.st.com (10.75.127.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 4 Jul 2018 17:59:24 +0200 From: Christophe Lyon To: , Date: Wed, 4 Jul 2018 17:55:21 +0200 Message-ID: <20180704155605.1892-9-christophe.lyon@st.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180704155605.1892-1-christophe.lyon@st.com> References: <20180704155605.1892-1-christophe.lyon@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG6NODE2.st.com (10.75.127.17) To SFHDAG5NODE1.st.com (10.75.127.13) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-07-04_05:, , signatures=0 Subject: [uclibc-ng-devel] [PATCH 08/32] [ARM][FDPIC] Add application startup code for FDPIC X-BeenThere: devel@uclibc-ng.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: uClibc-ng Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: devel-bounces@uclibc-ng.org Sender: "devel" * libc/sysdeps/linux/arm/crt1.S: Define _start for __FDPIC__. Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon Signed-off-by: Mickaël Guêné Signed-off-by: Christophe Lyon diff --git a/libc/sysdeps/linux/arm/crt1.S b/libc/sysdeps/linux/arm/crt1.S index ab3b0d2..f74cf3b 100644 --- a/libc/sysdeps/linux/arm/crt1.S +++ b/libc/sysdeps/linux/arm/crt1.S @@ -92,6 +92,71 @@ ARM register quick reference: pc r15 program counter */ +#if defined(__FDPIC__) +#include +#include + +.text + .arm + .globl _start + +_start: + /* Start by self relocation. */ + sub r4, pc, #8 + ldr r1, .L__ROFIXUP_LIST__ + add r1, r1, r4 + ldr r2, .L__ROFIXUP_END__ + add r2, r2, r4 + mov r0, r7 + push {r9, r10} + bl __self_reloc + pop {r9, r10} + mov r9, r0 + + /* Clear the frame pointer since this is the outermost frame. */ + mov r3, #0 + mov fp, r3 + + /* Now fill __uClibc_main arguments. */ + sub sp, sp, #16 /* Reserve space for 3 args (keep aligment) */ + ldr r0, .L_main_got_funcdesc /* r0 GOT FUNCDESC of main */ + ldr r0, [r9, r0] + ldr r1, [sp, #16] /* argc */ + add r2, sp, #20 /* argv */ + ldr r3, .L_init_got_funcdesc /* r3 GOT init */ + ldr r3, [r9, r3] + ldr r4, .L_fini_got_funcdesc + ldr r4, [r9, r4] + str r4, [sp, #0] /* sp + 0 GOT fini */ + movs r4, r8 /* Test if static binary (r8 is 0 as there is no interpreter). */ + movne r4, r10 + moveq r4, #0 + str r4, [sp, #4] /* sp + 4 got rtld_fini */ + mov r4, r2 /* stack_end is unused.... */ + str r4, [sp, #8] /* sp + 8 got stack_end */ + bl __uClibc_main + /* We should never get here.... */ + bl abort +.L__ROFIXUP_LIST__: + .word __ROFIXUP_LIST__ - _start +.L__ROFIXUP_END__: + .word __ROFIXUP_END__ - _start +.L_main_got_funcdesc: + .word main(GOTFUNCDESC) +.L_init_got_funcdesc: + .word _init(GOTFUNCDESC) +.L_fini_got_funcdesc: + .word _fini(GOTFUNCDESC) + +/* Define a symbol for the first piece of initialized data. */ + .data + .globl __data_start +__data_start: + .long 0 + .weak data_start + data_start = __data_start + +#else /* defined(__FDPIC__) */ #include #include @@ -250,3 +315,4 @@ __data_start: .long 0 .weak data_start data_start = __data_start +#endif /* defined(__FDPIC__) */