Skip to content

[libc] Include empty remove in baremetal stdio.h #85336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2024

Conversation

petrhosek
Copy link
Member

This is required to avoid compilation error in libc++.

See #85335 for more details.

This is required to avoid compilation error in libc++.

See llvm#85335 for more details.
@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2024

@llvm/pr-subscribers-libc

Author: Petr Hosek (petrhosek)

Changes

This is required to avoid compilation error in libc++.

See #85335 for more details.


Full diff: https://github.com/llvm/llvm-project/pull/85336.diff

4 Files Affected:

  • (modified) libc/config/baremetal/arm/entrypoints.txt (+1)
  • (modified) libc/config/baremetal/riscv/entrypoints.txt (+1)
  • (added) libc/src/stdio/baremetal/CMakeLists.txt (+7)
  • (added) libc/src/stdio/baremetal/remove.cpp (+22)
diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt
index 589ec5237e98da..d97c8d75fe309a 100644
--- a/libc/config/baremetal/arm/entrypoints.txt
+++ b/libc/config/baremetal/arm/entrypoints.txt
@@ -79,6 +79,7 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.inttypes.strtoumax
 
     # stdio.h entrypoints
+    libc.src.stdio.remove
     libc.src.stdio.sprintf
     libc.src.stdio.snprintf
     libc.src.stdio.vsprintf
diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt
index 09de1b416e0e94..19c9ac7fbe8515 100644
--- a/libc/config/baremetal/riscv/entrypoints.txt
+++ b/libc/config/baremetal/riscv/entrypoints.txt
@@ -79,6 +79,7 @@ set(TARGET_LIBC_ENTRYPOINTS
     libc.src.inttypes.strtoumax
 
     # stdio.h entrypoints
+    libc.src.stdio.remove
     libc.src.stdio.sprintf
     libc.src.stdio.snprintf
     libc.src.stdio.vsprintf
diff --git a/libc/src/stdio/baremetal/CMakeLists.txt b/libc/src/stdio/baremetal/CMakeLists.txt
new file mode 100644
index 00000000000000..734a66f72ecf6f
--- /dev/null
+++ b/libc/src/stdio/baremetal/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_entrypoint_object(
+  remove
+  SRCS
+    remove.cpp
+  HDRS
+    ../remove.h
+)
diff --git a/libc/src/stdio/baremetal/remove.cpp b/libc/src/stdio/baremetal/remove.cpp
new file mode 100644
index 00000000000000..c1c834d13952bf
--- /dev/null
+++ b/libc/src/stdio/baremetal/remove.cpp
@@ -0,0 +1,22 @@
+//===-- Linux implementation of remove ------------------------------------===//
+//
+// 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 "src/stdio/remove.h"
+
+#include "src/__support/common.h"
+
+namespace LIBC_NAMESPACE {
+
+// TODO: See https://github.com/llvm/llvm-project/issues/85335 for more details
+// on why this is needed.
+
+LLVM_LIBC_FUNCTION(int, remove, (const char *)) {
+  return -1;
+}
+
+} // namespace LIBC_NAMESPACE

Copy link

github-actions bot commented Mar 14, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@michaelrj-google michaelrj-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -0,0 +1,22 @@
//===-- Linux implementation of remove ------------------------------------===//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Update comment and formatting.

@nickdesaulniers
Copy link
Member

I'm curious, does this become a problem for other cases of _LIBCPP_USING_IF_EXISTS in libcxx/include/cstdio such as fopen, freopen, rename, tmpfile, or tmpnam? If so, is baremetal going to need stubs for all of the above?

Or is this specifically because man 3 remove from stdio.h is conflicting with std::remove from <algorithm> (and the functions listed above do not)?

@petrhosek
Copy link
Member Author

I'm curious, does this become a problem for other cases of _LIBCPP_USING_IF_EXISTS in libcxx/include/cstdio such as fopen, freopen, rename, tmpfile, or tmpnam? If so, is baremetal going to need stubs for all of the above?

I expect this to be only a temporary workaround until we address #85335.

Or is this specifically because man 3 remove from stdio.h is conflicting with std::remove from <algorithm> (and the functions listed above do not)?

This is only an issue for remove because of the declaration with the same name provided by <algorithm>.

@petrhosek petrhosek merged commit 5a75242 into llvm:main Mar 17, 2024
@petrhosek petrhosek deleted the libc-baremetal-stdio-remove branch July 12, 2024 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants