anchao commented on code in PR #14838:
URL: https://github.com/apache/nuttx/pull/14838#discussion_r1853286278


##########
libs/libbuiltin/libgcc/gcov.c:
##########
@@ -0,0 +1,271 @@
+/****************************************************************************
+ * libs/libbuiltin/libgcc/gcov.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <gcov.h>
+#include <string.h>
+#include <syslog.h>
+
+#include <nuttx/lib/lib.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define GCOV_DATA_MAGIC       (0x67636461)
+#define GCOV_NOTE_MAGIC       (0x67636e6f)
+#define GCOV_FILENAME_MAGIC   (0x6763666e)
+
+#define GCOV_TAG_FUNCTION     (0x01000000)
+#define GCOV_TAG_COUNTER_BASE (0x01a10000)
+
+#define GCOV_TAG_FOR_COUNTER(count) \
+  (GCOV_TAG_COUNTER_BASE + ((uint32_t)(count) << 17))
+
+#ifdef GCOV_12_FORMAT
+#  define GCOV_TAG_FUNCTION_LENGTH 12
+#else
+#  define GCOV_TAG_FUNCTION_LENGTH 3
+#endif
+
+#ifdef GCOV_12_FORMAT
+#  define GCOV_UNIT_SIZE      4
+#else
+#  define GCOV_UNIT_SIZE      1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+typedef unsigned int gcov_unsigned_t;
+
+/* Information about counters for a single function
+ *
+ * This data is generated by gcc during compilation and doesn't change
+ * at run-time.
+ */
+
+struct gcov_ctr_info
+{
+  unsigned int num;      /* Number of counter values for this type */
+  FAR gcov_type *values; /* Array of counter values for this type */
+};
+
+/* Profiling meta data per function
+ *
+ * This data is generated by gcc during compilation and doesn't change
+ * at run-time.
+ */
+
+struct gcov_fn_info
+{
+  FAR const struct gcov_info *key; /* Comdat key */
+  unsigned int ident;              /* Unique ident of function */
+  unsigned int lineno_checksum;    /* Function lineno checksum */
+  unsigned int cfg_checksum;       /* Function cfg checksum */
+  struct gcov_ctr_info ctrs[1];    /* Instrumented counters */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+FAR struct gcov_info *__gcov_info_start;
+FAR struct gcov_info *__gcov_info_end;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void dump_counter(FAR void *buffer, FAR size_t *off, uint64_t v)
+{
+  if (buffer)
+    {
+      memcpy((FAR uint8_t *)buffer + *off, (FAR uint8_t *)&v, sizeof(v));

Review Comment:
   ```suggestion
         *(FAR uint64_t *)((FAR uint8_t *)buffer + *off) = v;
   ```



##########
libs/libbuiltin/libgcc/gcov.c:
##########
@@ -0,0 +1,271 @@
+/****************************************************************************
+ * libs/libbuiltin/libgcc/gcov.c
+ *
+ * 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.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <gcov.h>
+#include <string.h>
+#include <syslog.h>
+
+#include <nuttx/lib/lib.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define GCOV_DATA_MAGIC       (0x67636461)
+#define GCOV_NOTE_MAGIC       (0x67636e6f)
+#define GCOV_FILENAME_MAGIC   (0x6763666e)
+
+#define GCOV_TAG_FUNCTION     (0x01000000)
+#define GCOV_TAG_COUNTER_BASE (0x01a10000)
+
+#define GCOV_TAG_FOR_COUNTER(count) \
+  (GCOV_TAG_COUNTER_BASE + ((uint32_t)(count) << 17))
+
+#ifdef GCOV_12_FORMAT
+#  define GCOV_TAG_FUNCTION_LENGTH 12
+#else
+#  define GCOV_TAG_FUNCTION_LENGTH 3
+#endif
+
+#ifdef GCOV_12_FORMAT
+#  define GCOV_UNIT_SIZE      4
+#else
+#  define GCOV_UNIT_SIZE      1
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+typedef unsigned int gcov_unsigned_t;
+
+/* Information about counters for a single function
+ *
+ * This data is generated by gcc during compilation and doesn't change
+ * at run-time.
+ */
+
+struct gcov_ctr_info
+{
+  unsigned int num;      /* Number of counter values for this type */
+  FAR gcov_type *values; /* Array of counter values for this type */
+};
+
+/* Profiling meta data per function
+ *
+ * This data is generated by gcc during compilation and doesn't change
+ * at run-time.
+ */
+
+struct gcov_fn_info
+{
+  FAR const struct gcov_info *key; /* Comdat key */
+  unsigned int ident;              /* Unique ident of function */
+  unsigned int lineno_checksum;    /* Function lineno checksum */
+  unsigned int cfg_checksum;       /* Function cfg checksum */
+  struct gcov_ctr_info ctrs[1];    /* Instrumented counters */
+};
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+FAR struct gcov_info *__gcov_info_start;
+FAR struct gcov_info *__gcov_info_end;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static void dump_counter(FAR void *buffer, FAR size_t *off, uint64_t v)
+{
+  if (buffer)
+    {
+      memcpy((FAR uint8_t *)buffer + *off, (FAR uint8_t *)&v, sizeof(v));
+    }
+
+  *off += sizeof(uint64_t);
+}
+
+static void dump_unsigned(FAR void *buffer, FAR size_t *off, uint32_t v)
+{
+  if (buffer)
+    {
+      memcpy((FAR uint8_t *)buffer + *off, (FAR uint8_t *)&v, sizeof(v));

Review Comment:
   ```suggestion
         *(FAR uint32_t *)((FAR uint8_t *)buffer + *off) = v;
   ```



-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to