[libc-commits] [libc] [libc] Mark baremetal write_to_stderr as inline (PR #86890)
Petr Hosek via libc-commits
libc-commits at lists.llvm.org
Wed Mar 27 16:35:45 PDT 2024
https://github.com/petrhosek updated https://github.com/llvm/llvm-project/pull/86890
>From 0b277d645abd03ff8fbcf81c95947183bf83fb9f Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 27 Mar 2024 16:24:37 -0700
Subject: [PATCH 1/3] [libc] Mark baremetal write_to_stderr as inline
This is required to avoid multiple definitions error.
---
libc/src/__support/OSUtil/baremetal/io.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/OSUtil/baremetal/io.h b/libc/src/__support/OSUtil/baremetal/io.h
index a50c11d4aea123..baf4d49cabbc0e 100644
--- a/libc/src/__support/OSUtil/baremetal/io.h
+++ b/libc/src/__support/OSUtil/baremetal/io.h
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE {
// This is intended to be provided by the vendor.
extern "C" void __llvm_libc_log_write(const char *msg, size_t len);
-void write_to_stderr(cpp::string_view msg) {
+inline void write_to_stderr(cpp::string_view msg) {
__llvm_libc_log_write(msg.data(), msg.size());
}
>From ea7bd3557de68f16e50cdc6572600c1a122e7420 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 27 Mar 2024 16:31:28 -0700
Subject: [PATCH 2/3] Use LIBC_INLINE
---
libc/src/__support/OSUtil/baremetal/io.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/src/__support/OSUtil/baremetal/io.h b/libc/src/__support/OSUtil/baremetal/io.h
index baf4d49cabbc0e..959b31bb3adb4f 100644
--- a/libc/src/__support/OSUtil/baremetal/io.h
+++ b/libc/src/__support/OSUtil/baremetal/io.h
@@ -16,7 +16,7 @@ namespace LIBC_NAMESPACE {
// This is intended to be provided by the vendor.
extern "C" void __llvm_libc_log_write(const char *msg, size_t len);
-inline void write_to_stderr(cpp::string_view msg) {
+LIBC_INLINE void write_to_stderr(cpp::string_view msg) {
__llvm_libc_log_write(msg.data(), msg.size());
}
>From f24dbde0f65d4750a4b2473c1d08a5f48a1891e9 Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Wed, 27 Mar 2024 16:35:23 -0700
Subject: [PATCH 3/3] Move the implementation to io.cpp
---
.../__support/OSUtil/baremetal/CMakeLists.txt | 1 +
libc/src/__support/OSUtil/baremetal/io.cpp | 22 +++++++++++++++++++
libc/src/__support/OSUtil/baremetal/io.h | 7 +-----
3 files changed, 24 insertions(+), 6 deletions(-)
create mode 100644 libc/src/__support/OSUtil/baremetal/io.cpp
diff --git a/libc/src/__support/OSUtil/baremetal/CMakeLists.txt b/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
index 23da40326bbb72..e78301d104c1f3 100644
--- a/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
+++ b/libc/src/__support/OSUtil/baremetal/CMakeLists.txt
@@ -1,6 +1,7 @@
add_object_library(
baremetal_util
SRCS
+ io.cpp
quick_exit.cpp
HDRS
io.h
diff --git a/libc/src/__support/OSUtil/baremetal/io.cpp b/libc/src/__support/OSUtil/baremetal/io.cpp
new file mode 100644
index 00000000000000..347c7d405b0a9f
--- /dev/null
+++ b/libc/src/__support/OSUtil/baremetal/io.cpp
@@ -0,0 +1,22 @@
+//===---------- Baremetal implementation of IO utils ------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "io.h"
+
+#include "src/__support/CPP/string_view.h"
+
+// This is intended to be provided by the vendor.
+extern "C" void __llvm_libc_log_write(const char *msg, size_t len);
+
+namespace LIBC_NAMESPACE {
+
+void write_to_stderr(cpp::string_view msg) {
+ __llvm_libc_log_write(msg.data(), msg.size());
+}
+
+} // namespace LIBC_NAMESPACE
diff --git a/libc/src/__support/OSUtil/baremetal/io.h b/libc/src/__support/OSUtil/baremetal/io.h
index 959b31bb3adb4f..87534641b1fa4d 100644
--- a/libc/src/__support/OSUtil/baremetal/io.h
+++ b/libc/src/__support/OSUtil/baremetal/io.h
@@ -13,12 +13,7 @@
namespace LIBC_NAMESPACE {
-// This is intended to be provided by the vendor.
-extern "C" void __llvm_libc_log_write(const char *msg, size_t len);
-
-LIBC_INLINE void write_to_stderr(cpp::string_view msg) {
- __llvm_libc_log_write(msg.data(), msg.size());
-}
+void write_to_stderr(cpp::string_view msg);
} // namespace LIBC_NAMESPACE
More information about the libc-commits
mailing list