Page MenuHomeFreeBSD

D46404.diff
No OneTemporary

D46404.diff

diff --git a/lib/csu/riscv/Makefile b/lib/csu/riscv/Makefile
--- a/lib/csu/riscv/Makefile
+++ b/lib/csu/riscv/Makefile
@@ -1,5 +1,3 @@
.PATH: ${.CURDIR:H}/common
-CRT1OBJS+= crt1_s.o
-
.include <bsd.lib.mk>
diff --git a/lib/csu/riscv/crt1_c.c b/lib/csu/riscv/crt1_c.c
--- a/lib/csu/riscv/crt1_c.c
+++ b/lib/csu/riscv/crt1_c.c
@@ -2,6 +2,7 @@
/*-
* Copyright 1996-1998 John D. Polstra.
* Copyright (c) 2015-2017 Ruslan Bukin <br@bsdpad.com>
+ * Copyright (c) 2024 Alex Richardson <arichardson@freebsd.org>
* All rights reserved.
*
* Portions of this software were developed by SRI International and the
@@ -37,15 +38,36 @@
#include "libc_private.h"
#include "csu_common.h"
-void __start(int argc, char **argv, char **env, void (*cleanup)(void)) __dead2;
+struct Obj_Entry;
-void
-__start(int argc, char **argv, char **env, void (*cleanup)(void))
+void _start(void *procargs, const struct Obj_Entry *obj,
+ void (*cleanup)(void)) __dead2 __exported;
+
+static void
+__start(void *procargs, const struct Obj_Entry *obj __unused,
+ void (*cleanup)(void))
{
+ int argc = (int)(*(size_t *)procargs);
+ char **argv = ((char **)procargs) + 1;
+ char **envv = argv + argc + 1;
+
#ifdef GCRT
- __libc_start1_gcrt(argc, argv, env, cleanup, main, &eprol, &etext);
+ __libc_start1_gcrt(argc, argv, envv, cleanup, main, &eprol, &etext);
__asm__("eprol:");
#else
- __libc_start1(argc, argv, env, cleanup, main);
+ __libc_start1(argc, argv, envv, cleanup, main);
#endif
}
+
+void __attribute__((naked))
+_start(void *procargs, const struct Obj_Entry *obj, void (*cleanup)(void))
+{
+ __asm__(
+ ".option push\n"
+ ".option norelax\n"
+ /* Safe before call - lla will not clobber any other registers. */
+ "lla gp, __global_pointer$\n"
+ ".option pop\n"
+ "call %0"
+ :: "i"(__start));
+}
diff --git a/lib/csu/riscv/crt1_s.S b/lib/csu/riscv/crt1_s.S
deleted file mode 100644
--- a/lib/csu/riscv/crt1_s.S
+++ /dev/null
@@ -1,51 +0,0 @@
-/* LINTLIBRARY */
-/*-
- * Copyright 1996-1998 John D. Polstra.
- * Copyright (c) 2015-2017 Ruslan Bukin <br@bsdpad.com>
- * All rights reserved.
- *
- * Portions of this software were developed by SRI International and the
- * University of Cambridge Computer Laboratory under DARPA/AFRL contract
- * FA8750-10-C-0237 ("CTSRD"), as part of the DARPA CRASH research programme.
- *
- * Portions of this software were developed by the University of Cambridge
- * Computer Laboratory as part of the CTSRD Project, with support from the
- * UK Higher Education Innovation Fund (HEIF).
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <machine/asm.h>
-ENTRY(_start)
- mv a3, a2 # cleanup
- addi a1, a0, 8 # get argv
- ld a0, 0(a0) # load argc
- slli t0, a0, 3 # mult by arg size
- add a2, a1, t0 # env is after argv
- addi a2, a2, 8 # argv is null terminated
- .option push
- .option norelax
- lla gp, __global_pointer$
- .option pop
- call __start
-END(_start)
-
- .section .note.GNU-stack,"",%progbits

File Metadata

Mime Type
text/plain
Expires
Thu, Jun 18, 2:19 PM (2 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34052397
Default Alt Text
D46404.diff (4 KB)

Event Timeline