Merge "[sw, lib] Move logger format fields to .rodata for CHERIoT"
diff --git a/sw/device/lib/runtime/log.h b/sw/device/lib/runtime/log.h
index e5b98df..c9cd78b 100644
--- a/sw/device/lib/runtime/log.h
+++ b/sw/device/lib/runtime/log.h
@@ -108,7 +108,15 @@
  *               string literal.
  * @param ... format parameters matching the format string.
  */
-#define LOG(severity, format, ...)                               \
+#if __has_feature(capabilities)
+#define LOG(severity, format, ...) \
+  LOG_TO_SECTION(".rodata.fields", severity, format, ##__VA_ARGS__)
+#else
+#define LOG(severity, format, ...) \
+  LOG_TO_SECTION(".logs.fields", severity, format, ##__VA_ARGS__)
+#endif
+
+#define LOG_TO_SECTION(elf_section, severity, format, ...)       \
   do {                                                           \
     if (kDeviceLogBypassUartAddress != 0) {                      \
       /* clang-format off */                                     \
@@ -116,7 +124,7 @@
        * the linker will dutifully discard.
        * Unfortunately, clang-format really mangles these
        * declarations, so we format them manually. */            \
-      __attribute__((section(".logs.fields")))                   \
+      __attribute__((section(elf_section)))                      \
       static const log_fields_t kLogFields =                     \
           LOG_MAKE_FIELDS_(severity, format, ##__VA_ARGS__);     \
       base_log_internal_dv(&kLogFields,                          \