casaroli commented on code in PR #19940:
URL: https://github.com/apache/nuttx/pull/19940#discussion_r3879807190


##########
tools/fdpic/crt0.c:
##########
@@ -0,0 +1,126 @@
+/****************************************************************************
+ * tools/fdpic/crt0.c
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/* The start-up file of an FDPIC module, the counterpart of
+ * arch/<arch>/src/common/crt0.c for a module that the in-tree build
+ * produces.  A module that exec() runs is entered here rather than at main,
+ * so that its constructors run on the task that runs the module, in that
+ * task's group and with that task's data base, rather than on whichever
+ * task happened to call the loader.
+ *
+ * Destructors are not registered here.  -fno-use-cxa-atexit puts them in
+ * .fini_array, which the loader walks in libelf_uninit() when the module is
+ * unloaded, and registering them again would run each one twice.
+ *
+ * A shared library is not entered at all, so it does not link this file.
+ * Its constructors run from libelf_insert() when dlopen() maps it.
+ */
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+int main(int argc, char *argv[]);
+void exit(int status);
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* init-array.ld defines these around .init_array.  The linker's built-in
+ * script does not, when it links a shared object.
+ *
+ * They are declared hidden so that the compiler reaches them through the
+ * GOT of this object rather than through a dynamic symbol, which is what
+ * lets the loader resolve them with an ordinary R_ARM_RELATIVE.
+ *
+ * Each entry is a code address rather than a function descriptor: the
+ * linker resolves .init_array with R_ARM_RELATIVE too, not with
+ * R_ARM_FUNCDESC_VALUE.
+ */
+
+extern uintptr_t __init_array_start[] __attribute__((visibility("hidden")));
+extern uintptr_t __init_array_end[] __attribute__((visibility("hidden")));
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: call_initializer
+ *
+ * Description:
+ *   Enter one .init_array entry.  A plain call through a function pointer
+ *   cannot be used: under -mfdpic the compiler would take the entry for a
+ *   function descriptor and load a data base out of the code address.  The
+ *   data base is right already, because this runs inside the module.
+ *
+ ****************************************************************************/
+
+static void call_initializer(uintptr_t entry)
+{
+  __asm__ __volatile__
+  (
+    "blx %[entry]\n"
+    :
+    : [entry] "r" (entry)
+    : "r0", "r1", "r2", "r3", "r12", "lr", "cc", "memory"
+  );
+}
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: _start
+ *
+ * Description:
+ *   The entry point of a module.  Runs the constructors, calls main and
+ *   passes its return value to exit().
+ *
+ * Input Parameters:
+ *   argc - The number of parameters being passed.
+ *   argv - The parameters being passed.
+ *
+ * Returned Value:
+ *   Does not return.
+ *
+ ****************************************************************************/
+
+void _start(int argc, char *argv[])

Review Comment:
   when I figure out how to integrate the build, I think we can drop this crt0.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to