[2/2] RISC-V: Add _LITE_EXIT in crt0.S.

Message ID a60d2bd52d80df4aebac5ddb2ec5969b@optimitech.com
State New
Headers show
Series
  • [1/2] RISC-V: Add memcpy, memmove, memset and strcmp implementations optimized for size.
Related show

Commit Message

Ilia Diachkov May 17, 2019, 11:53 p.m.
This patch adds _LITE_EXIT in crt0.S to enable "lite exit" technique in 
RISC-V. The changes have been tested in riscv/riscv-gnu-toolchain by 
riscv-dejagnu with riscv-sim.exp/riscv-sim-nano.exp.

 From d51d7c69a2c60041ef583686f24ccae74b675edc Mon Sep 17 00:00:00 2001
 From: Ilia Diachkov <ilia.diachkov@optimitech.com>

Date: Sat, 18 May 2019 02:08:36 +0300
Subject: [PATCH 2/2] RISC-V: Add _LITE_EXIT in crt0.S.

---
  libgloss/riscv/crt0.S | 11 +++++++++++
  1 file changed, 11 insertions(+)

  
#=========================================================================
@@ -30,9 +32,18 @@ _start:
    sub     a2, a2, a0
    li      a1, 0
    call    memset
+#ifdef _LITE_EXIT
+  # Make reference to atexit weak to avoid unconditionally pulling in
+  # support code.  Refer to comments in __atexit.c for more details.
+  .weak   atexit
+  la      a0, atexit
+  beqz    a0, .Lweak_atexit
+  .weak   __libc_fini_array
+#endif

    la      a0, __libc_fini_array   # Register global termination 
functions
    call    atexit                  #  to be called upon exit
+.Lweak_atexit:
    call    __libc_init_array       # Run global initialization functions

    lw      a0, 0(sp)                  # a0 = argc
-- 
1.8.3.1

Comments

Jim Wilson May 20, 2019, 9:11 p.m. | #1
On Fri, May 17, 2019 at 4:53 PM <ilia.diachkov@optimitech.com> wrote:
> This patch adds _LITE_EXIT in crt0.S to enable "lite exit" technique in

> RISC-V. The changes have been tested in riscv/riscv-gnu-toolchain by

> riscv-dejagnu with riscv-sim.exp/riscv-sim-nano.exp.


Same comments as first part of the patch set.

Personally, I'd put the .Lweak_atexit label inside _LITE_EXT ifdefs,
but this matches the way that the ARM port does it, so should be OK
also.

To be fully effective, this requires build script changes to the
github riscv/riscv-gnu-toolchain project, which will be handled as a
separate patch.

Jim
Kito Cheng May 21, 2019, 3:23 a.m. | #2
Hi Illa:

This patch LGTM :)

Hi Jim:

Seems like it's time to bump newlib in riscv/riscv-gnu-toolchain, I'll
do that after this 2 patches apply :)

On Tue, May 21, 2019 at 5:12 AM Jim Wilson <jimw@sifive.com> wrote:
>

> On Fri, May 17, 2019 at 4:53 PM <ilia.diachkov@optimitech.com> wrote:

> > This patch adds _LITE_EXIT in crt0.S to enable "lite exit" technique in

> > RISC-V. The changes have been tested in riscv/riscv-gnu-toolchain by

> > riscv-dejagnu with riscv-sim.exp/riscv-sim-nano.exp.

>

> Same comments as first part of the patch set.

>

> Personally, I'd put the .Lweak_atexit label inside _LITE_EXT ifdefs,

> but this matches the way that the ARM port does it, so should be OK

> also.

>

> To be fully effective, this requires build script changes to the

> github riscv/riscv-gnu-toolchain project, which will be handled as a

> separate patch.

>

> Jim
Jim Wilson May 21, 2019, 8:25 p.m. | #3
On Mon, May 20, 2019 at 8:23 PM Kito Cheng <kito.cheng@gmail.com> wrote:
> Hi Illa:

> This patch LGTM :)


This has similar mailer corruption to the first part, but I have an
uncorrupted copy I got in private email earlier that I can apply.
I'll wait for both parts to be approved then I can commit them.

> Seems like it's time to bump newlib in riscv/riscv-gnu-toolchain, I'll

> do that after this 2 patches apply :)


Sounds good.  I'd like to see the patches in riscv-gnu-toolchain also.
I'll submit Ilia's riscv-gnu-toolchain makefile patch as a pull
request just to keep things moving.

Jim
Ilia Diachkov May 21, 2019, 8:41 p.m. | #4
Jim,

Yesterday I have send both patches as attachments to "[PATCH 1/2]..." 
letter so they both should be ok (not corrupted). In the second patch 
.Lweak_atexit label was put inside _LITE_EXIT as you suggested.

Jim Wilson писал 2019-05-21 15:25:
> On Mon, May 20, 2019 at 8:23 PM Kito Cheng <kito.cheng@gmail.com> 

> wrote:

>> Hi Illa:

>> This patch LGTM :)

> 

> This has similar mailer corruption to the first part, but I have an

> uncorrupted copy I got in private email earlier that I can apply.

> I'll wait for both parts to be approved then I can commit them.

> 

>> Seems like it's time to bump newlib in riscv/riscv-gnu-toolchain, I'll

>> do that after this 2 patches apply :)

> 

> Sounds good.  I'd like to see the patches in riscv-gnu-toolchain also.

> I'll submit Ilia's riscv-gnu-toolchain makefile patch as a pull

> request just to keep things moving.

> 

> Jim

Patch

diff --git a/libgloss/riscv/crt0.S b/libgloss/riscv/crt0.S
index 3d2a12d..7e1c025 100644
--- a/libgloss/riscv/crt0.S
+++ b/libgloss/riscv/crt0.S
@@ -9,6 +9,8 @@ 
     http://www.opensource.org/licenses.
  */

+#include "newlib.h"
+
  
#=========================================================================
  # crt0.S : Entry point for RISC-V user programs