-
Notifications
You must be signed in to change notification settings - Fork 13.6k
libc: Remove extern "C"
from main declarations
#102825
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
Conversation
This is invalid in C++, and clang recently started warning on it as of 37ec6e5
@llvm/pr-subscribers-libc @llvm/pr-subscribers-backend-amdgpu Author: David Blaikie (dwblaikie) ChangesThis is invalid in C++, and clang recently started warning on it as of 37ec6e5 Full diff: https://github.com/llvm/llvm-project/pull/102825.diff 7 Files Affected:
diff --git a/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp b/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
index 97366e55194a90..c4cc1a1731ce34 100644
--- a/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
+++ b/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
@@ -1,6 +1,6 @@
#include "LibcGpuBenchmark.h"
-extern "C" int main(int argc, char **argv, char **envp) {
+int main(int argc, char **argv, char **envp) {
LIBC_NAMESPACE::benchmarks::Benchmark::run_benchmarks();
return 0;
}
diff --git a/libc/startup/gpu/amdgpu/start.cpp b/libc/startup/gpu/amdgpu/start.cpp
index 5aaa7e938d2792..e10e4cd9c2cd74 100644
--- a/libc/startup/gpu/amdgpu/start.cpp
+++ b/libc/startup/gpu/amdgpu/start.cpp
@@ -13,7 +13,7 @@
#include "src/stdlib/atexit.h"
#include "src/stdlib/exit.h"
-extern "C" int main(int argc, char **argv, char **envp);
+int main(int argc, char **argv, char **envp);
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/startup/gpu/nvptx/start.cpp b/libc/startup/gpu/nvptx/start.cpp
index ef1e63e5161a61..561301638c3ca8 100644
--- a/libc/startup/gpu/nvptx/start.cpp
+++ b/libc/startup/gpu/nvptx/start.cpp
@@ -13,7 +13,7 @@
#include "src/stdlib/atexit.h"
#include "src/stdlib/exit.h"
-extern "C" int main(int argc, char **argv, char **envp);
+int main(int argc, char **argv, char **envp);
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/startup/linux/do_start.cpp b/libc/startup/linux/do_start.cpp
index 72060b4adb2148..7009895f0036c2 100644
--- a/libc/startup/linux/do_start.cpp
+++ b/libc/startup/linux/do_start.cpp
@@ -20,7 +20,7 @@
#include <sys/mman.h>
#include <sys/syscall.h>
-extern "C" int main(int argc, char **argv, char **envp);
+int main(int argc, char **argv, char **envp);
extern "C" {
// These arrays are present in the .init_array and .fini_array sections.
diff --git a/libc/test/IntegrationTest/test.h b/libc/test/IntegrationTest/test.h
index 5be66d9edff02a..f7068ed628a3d5 100644
--- a/libc/test/IntegrationTest/test.h
+++ b/libc/test/IntegrationTest/test.h
@@ -83,6 +83,6 @@
// tests, then we should not need to explicitly declare/define the main
// function in individual integration tests. We will not need this macro
// then.
-#define TEST_MAIN extern "C" int main
+#define TEST_MAIN int main
#endif // LLVM_LIBC_UTILS_INTEGRATION_TEST_TEST_H
diff --git a/libc/test/UnitTest/LibcTestMain.cpp b/libc/test/UnitTest/LibcTestMain.cpp
index 94536e97164686..eb1125b5dcaf1f 100644
--- a/libc/test/UnitTest/LibcTestMain.cpp
+++ b/libc/test/UnitTest/LibcTestMain.cpp
@@ -43,7 +43,7 @@ TestOptions parseOptions(int argc, char **argv) {
} // anonymous namespace
-extern "C" int main(int argc, char **argv, char **envp) {
+int main(int argc, char **argv, char **envp) {
LIBC_NAMESPACE::testing::argc = argc;
LIBC_NAMESPACE::testing::argv = argv;
LIBC_NAMESPACE::testing::envp = envp;
diff --git a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
index 551b97caf81fd6..4cac072104ca9a 100644
--- a/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
+++ b/libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp
@@ -47,7 +47,7 @@ bool TestGeneratorMain(llvm::raw_ostream &OS, llvm::RecordKeeper &records) {
OS << '\n';
- OS << "extern \"C\" int main() {\n";
+ OS << "int main() {\n";
for (const auto &entrypoint : EntrypointNamesOption) {
if (entrypoint == "errno")
continue;
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/71/builds/4073 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/179/builds/3987 Here is the relevant piece of the build log for the reference:
|
I have to revert this. Seems that extern C has its effect. Please take a look. |
This reverts commit 1b71c47.
Yeah - beats me. Hopefulyl someone on libc can look into this, turn off the warning, or whatnot. Maybe one of these files puts "main" in a namespace by accident and the |
It's because we compile everything with |
Ah, so maybe all the |
I think it's because we build the tests in two configurations. One is with |
Summary: According to the C++ standard, The main function shall not be declared with a linkage-specification. after some changes in llvm#101853 this started emitting warnings when building / testing the C library. This source file is shared with the overlay tests as well as the full build tests. The full build tests are compiled with `-ffreestanding`, as are all the startup / integration files. The standard says freestanding environment are all implementation defined, so this is valid in those cases. This patch simply prevents adding the linkage when we are compiling unit tests, which are hosted. This is a continuation on llvm#102825.
oooh :/ yeah, that'll be annoying then. Would need to use macros to enable/disable this sort of thing when building freestanding V not. Or disable the warning (-Wno-main) |
I made #102973 for this |
Summary: According to the C++ standard, The main function shall not be declared with a linkage-specification. after some changes in llvm#101853 this started emitting warnings when building / testing the C library. This source file is shared with the overlay tests as well as the full build tests. The full build tests are compiled with `-ffreestanding`, as are all the startup / integration files. The standard says freestanding environment are all implementation defined, so this is valid in those cases. This patch simply prevents adding the linkage when we are compiling unit tests, which are hosted. This is a continuation on llvm#102825.
Summary: According to the C++ standard, The main function shall not be declared with a linkage-specification. after some changes in #101853 this started emitting warnings when building / testing the C library. This source file is shared with the overlay tests as well as the full build tests. The full build tests are compiled with `-ffreestanding`, as are all the startup / integration files. The standard says freestanding environment are all implementation defined, so this is valid in those cases. This patch simply prevents adding the linkage when we are compiling unit tests, which are hosted. This is a continuation on #102825.
This is invalid in C++, and clang recently started warning on it as of #101853