Skip to content

Revert "libc: Remove extern "C" from main declarations" #102827

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 1 commit into from
Aug 11, 2024

Conversation

SchrodingerZhu
Copy link
Contributor

Reverts #102825

@SchrodingerZhu SchrodingerZhu merged commit b7c7dbd into main Aug 11, 2024
5 of 6 checks passed
@SchrodingerZhu SchrodingerZhu deleted the revert-102825-libc_extern_C_main branch August 11, 2024 20:40
@llvmbot
Copy link
Member

llvmbot commented Aug 11, 2024

@llvm/pr-subscribers-libc

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

Changes

Reverts llvm/llvm-project#102825


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

7 Files Affected:

  • (modified) libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp (+1-1)
  • (modified) libc/startup/gpu/amdgpu/start.cpp (+1-1)
  • (modified) libc/startup/gpu/nvptx/start.cpp (+1-1)
  • (modified) libc/startup/linux/do_start.cpp (+1-1)
  • (modified) libc/test/IntegrationTest/test.h (+1-1)
  • (modified) libc/test/UnitTest/LibcTestMain.cpp (+1-1)
  • (modified) libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp (+1-1)
diff --git a/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp b/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
index c4cc1a1731ce34..97366e55194a90 100644
--- a/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
+++ b/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
@@ -1,6 +1,6 @@
 #include "LibcGpuBenchmark.h"
 
-int main(int argc, char **argv, char **envp) {
+extern "C" 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 e10e4cd9c2cd74..5aaa7e938d2792 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"
 
-int main(int argc, char **argv, char **envp);
+extern "C" 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 561301638c3ca8..ef1e63e5161a61 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"
 
-int main(int argc, char **argv, char **envp);
+extern "C" 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 7009895f0036c2..72060b4adb2148 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>
 
-int main(int argc, char **argv, char **envp);
+extern "C" 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 f7068ed628a3d5..5be66d9edff02a 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 int main
+#define TEST_MAIN extern "C" 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 eb1125b5dcaf1f..94536e97164686 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
 
-int main(int argc, char **argv, char **envp) {
+extern "C" 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 4cac072104ca9a..551b97caf81fd6 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 << "int main() {\n";
+  OS << "extern \"C\" int main() {\n";
   for (const auto &entrypoint : EntrypointNamesOption) {
     if (entrypoint == "errno")
       continue;

@llvmbot
Copy link
Member

llvmbot commented Aug 11, 2024

@llvm/pr-subscribers-backend-amdgpu

Author: Schrodinger ZHU Yifan (SchrodingerZhu)

Changes

Reverts llvm/llvm-project#102825


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

7 Files Affected:

  • (modified) libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp (+1-1)
  • (modified) libc/startup/gpu/amdgpu/start.cpp (+1-1)
  • (modified) libc/startup/gpu/nvptx/start.cpp (+1-1)
  • (modified) libc/startup/linux/do_start.cpp (+1-1)
  • (modified) libc/test/IntegrationTest/test.h (+1-1)
  • (modified) libc/test/UnitTest/LibcTestMain.cpp (+1-1)
  • (modified) libc/utils/HdrGen/PrototypeTestGen/PrototypeTestGen.cpp (+1-1)
diff --git a/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp b/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
index c4cc1a1731ce34..97366e55194a90 100644
--- a/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
+++ b/libc/benchmarks/gpu/LibcGpuBenchmarkMain.cpp
@@ -1,6 +1,6 @@
 #include "LibcGpuBenchmark.h"
 
-int main(int argc, char **argv, char **envp) {
+extern "C" 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 e10e4cd9c2cd74..5aaa7e938d2792 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"
 
-int main(int argc, char **argv, char **envp);
+extern "C" 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 561301638c3ca8..ef1e63e5161a61 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"
 
-int main(int argc, char **argv, char **envp);
+extern "C" 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 7009895f0036c2..72060b4adb2148 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>
 
-int main(int argc, char **argv, char **envp);
+extern "C" 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 f7068ed628a3d5..5be66d9edff02a 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 int main
+#define TEST_MAIN extern "C" 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 eb1125b5dcaf1f..94536e97164686 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
 
-int main(int argc, char **argv, char **envp) {
+extern "C" 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 4cac072104ca9a..551b97caf81fd6 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 << "int main() {\n";
+  OS << "extern \"C\" int main() {\n";
   for (const auto &entrypoint : EntrypointNamesOption) {
     if (entrypoint == "errno")
       continue;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants