Skip to content

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

Merged
merged 1 commit into from
Aug 11, 2024

Conversation

dwblaikie
Copy link
Collaborator

@dwblaikie dwblaikie commented Aug 11, 2024

This is invalid in C++, and clang recently started warning on it as of #101853

This is invalid in C++, and clang recently started warning on it as of 37ec6e5
@llvmbot
Copy link
Member

llvmbot commented Aug 11, 2024

@llvm/pr-subscribers-libc

@llvm/pr-subscribers-backend-amdgpu

Author: David Blaikie (dwblaikie)

Changes

This 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:

  • (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 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;

@dwblaikie dwblaikie requested review from SchrodingerZhu and jhuber6 and removed request for SchrodingerZhu August 11, 2024 18:52
Copy link
Contributor

@SchrodingerZhu SchrodingerZhu left a comment

Choose a reason for hiding this comment

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

LGTM.

@SchrodingerZhu SchrodingerZhu merged commit 1b71c47 into llvm:main Aug 11, 2024
8 of 10 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 11, 2024

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-fullbuild-dbg running on libc-aarch64-ubuntu while building libc at step 4 "annotate".

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:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[8/99] Building CXX object projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_name_test.__build__.dir/pthread_name_test.cpp.o
[9/99] Building CXX object projects/libc/test/integration/startup/linux/CMakeFiles/libc.test.integration.startup.linux.startup_no_args_test.__build__.dir/main_without_args.cpp.o
[10/99] Building CXX object projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_mutex_test.__build__.dir/pthread_mutex_test.cpp.o
[11/99] Building CXX object projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_equal_test.__build__.dir/pthread_equal_test.cpp.o
[12/99] Building CXX object projects/libc/test/integration/startup/linux/CMakeFiles/libc.test.integration.startup.linux.startup_no_envp_test.__build__.dir/main_without_envp.cpp.o
[13/99] Building CXX object projects/libc/test/integration/startup/linux/CMakeFiles/libc.test.integration.startup.linux.init_fini_array_test.__build__.dir/init_fini_array_test.cpp.o
[14/99] Building CXX object projects/libc/test/integration/src/__support/threads/CMakeFiles/libc.test.integration.src.__support.threads.thread_tls_test.__build__.dir/thread_tls_test.cpp.o
[15/99] Linking CXX executable projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_args_test.__build__
/usr/bin/ld: warning: cannot create .note.gnu.build-id section, --build-id ignored
[16/99] Linking CXX executable projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_join_test.__build__
FAILED: projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_join_test.__build__ 
: && /usr/bin/clang++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_join_test.__build__.dir/pthread_join_test.cpp.o -o projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_join_test.__build__  projects/libc/test/integration/src/pthread/liblibc.test.integration.src.pthread.pthread_join_test.libc.a && :
/usr/bin/ld: warning: cannot create .note.gnu.build-id section, --build-id ignored
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[17/99] Linking CXX executable projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_tls_test.__build__
/usr/bin/ld: warning: cannot create .note.gnu.build-id section, --build-id ignored
[18/99] Building CXX object projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_once_test.__build__.dir/pthread_once_test.cpp.o
[19/99] Linking CXX executable projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_test.__build__
FAILED: projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_test.__build__ 
: && /usr/bin/clang++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_test.__build__.dir/pthread_test.cpp.o -o projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_test.__build__  projects/libc/test/integration/src/pthread/liblibc.test.integration.src.pthread.pthread_test.libc.a && :
/usr/bin/ld: warning: cannot create .note.gnu.build-id section, --build-id ignored
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[20/99] Linking CXX executable projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_spinlock_test.__build__
FAILED: projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_spinlock_test.__build__ 
: && /usr/bin/clang++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_spinlock_test.__build__.dir/pthread_spinlock_test.cpp.o -o projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_spinlock_test.__build__  projects/libc/test/integration/src/pthread/liblibc.test.integration.src.pthread.pthread_spinlock_test.libc.a && :
/usr/bin/ld: warning: cannot create .note.gnu.build-id section, --build-id ignored
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[21/99] Running integration test libc.test.integration.startup.linux.startup_args_test
[22/99] Linking CXX executable projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_exit_test.__build__
FAILED: projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_exit_test.__build__ 
: && /usr/bin/clang++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_exit_test.__build__.dir/pthread_exit_test.cpp.o -o projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_exit_test.__build__  projects/libc/test/integration/src/pthread/liblibc.test.integration.src.pthread.pthread_exit_test.libc.a && :
/usr/bin/ld: warning: cannot create .note.gnu.build-id section, --build-id ignored
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[23/99] Linking CXX executable projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_tss_test.__build__
FAILED: projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_tss_test.__build__ 
: && /usr/bin/clang++ -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_tss_test.__build__.dir/pthread_tss_test.cpp.o -o projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_tss_test.__build__  projects/libc/test/integration/src/pthread/liblibc.test.integration.src.pthread.pthread_tss_test.libc.a && :
/usr/bin/ld: warning: cannot create .note.gnu.build-id section, --build-id ignored
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[24/99] Linking CXX executable projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_no_args_test.__build__

@llvm-ci
Copy link
Collaborator

llvm-ci commented Aug 11, 2024

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-fullbuild-dbg running on libc-x86_64-debian-fullbuild while building libc at step 4 "annotate".

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:

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[21/99] Building CXX object projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_once_test.__build__.dir/pthread_once_test.cpp.o
[22/99] Building CXX object projects/libc/test/integration/src/threads/CMakeFiles/libc.test.integration.src.threads.call_once_test.__build__.dir/call_once_test.cpp.o
[23/99] Building CXX object projects/libc/test/integration/src/threads/CMakeFiles/libc.test.integration.src.threads.cnd_test.__build__.dir/cnd_test.cpp.o
[24/99] Building CXX object projects/libc/test/integration/src/unistd/CMakeFiles/libc.test.integration.src.unistd.getcwd_test.__build__.dir/getcwd_test.cpp.o
[25/99] Building CXX object projects/libc/test/integration/src/unistd/CMakeFiles/libc.test.integration.src.unistd.execv_test.__build__.dir/execv_test.cpp.o
[26/99] Building CXX object projects/libc/test/integration/src/unistd/CMakeFiles/libc.test.integration.src.unistd.execve_test.__build__.dir/execve_test.cpp.o
[27/99] Building CXX object projects/libc/test/integration/src/unistd/CMakeFiles/libc.test.integration.src.unistd.fork_test.__build__.dir/fork_test.cpp.o
[28/99] Building CXX object projects/libc/test/integration/src/spawn/CMakeFiles/libc.test.integration.src.spawn.posix_spawn_test.__build__.dir/posix_spawn_test.cpp.o
[29/99] Building CXX object projects/libc/test/integration/src/__support/threads/CMakeFiles/libc.test.integration.src.__support.threads.thread_tls_test.__build__.dir/thread_tls_test.cpp.o
[30/99] Linking CXX executable projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_no_envp_test.__build__
FAILED: projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_no_envp_test.__build__ 
: && /usr/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/startup/linux/CMakeFiles/libc.test.integration.startup.linux.startup_no_envp_test.__build__.dir/main_without_envp.cpp.o -o projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_no_envp_test.__build__  projects/libc/test/integration/startup/linux/liblibc.test.integration.startup.linux.startup_no_envp_test.libc.a && :
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[31/99] Linking CXX executable projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_no_args_test.__build__
FAILED: projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_no_args_test.__build__ 
: && /usr/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/startup/linux/CMakeFiles/libc.test.integration.startup.linux.startup_no_args_test.__build__.dir/main_without_args.cpp.o -o projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_no_args_test.__build__  projects/libc/test/integration/startup/linux/liblibc.test.integration.startup.linux.startup_no_args_test.libc.a && :
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[32/99] Linking CXX executable projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_tls_test.__build__
[33/99] Linking CXX executable projects/libc/test/integration/src/stdlib/libc.test.integration.src.stdlib.getenv_test.__build__
[34/99] Linking CXX executable projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.startup_args_test.__build__
[35/99] Linking CXX executable projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.init_fini_array_test.__build__
FAILED: projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.init_fini_array_test.__build__ 
: && /usr/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/startup/linux/CMakeFiles/libc.test.integration.startup.linux.init_fini_array_test.__build__.dir/init_fini_array_test.cpp.o -o projects/libc/test/integration/startup/linux/libc.test.integration.startup.linux.init_fini_array_test.__build__  projects/libc/test/integration/startup/linux/liblibc.test.integration.startup.linux.init_fini_array_test.libc.a && :
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[36/99] Linking CXX executable projects/libc/test/integration/src/stdio/libc.test.integration.src.stdio.sprintf_size_test_no_sprintf.__build__
[37/99] Linking CXX executable projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_equal_test.__build__
FAILED: projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_equal_test.__build__ 
: && /usr/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/src/pthread/CMakeFiles/libc.test.integration.src.pthread.pthread_equal_test.__build__.dir/pthread_equal_test.cpp.o -o projects/libc/test/integration/src/pthread/libc.test.integration.src.pthread.pthread_equal_test.__build__  projects/libc/test/integration/src/pthread/liblibc.test.integration.src.pthread.pthread_equal_test.libc.a && :
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[38/99] Linking CXX executable projects/libc/test/integration/src/threads/libc.test.integration.src.threads.thrd_test.__build__
FAILED: projects/libc/test/integration/src/threads/libc.test.integration.src.threads.thrd_test.__build__ 
: && /usr/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/src/threads/CMakeFiles/libc.test.integration.src.threads.thrd_test.__build__.dir/thrd_test.cpp.o -o projects/libc/test/integration/src/threads/libc.test.integration.src.threads.thrd_test.__build__  projects/libc/test/integration/src/threads/liblibc.test.integration.src.threads.thrd_test.libc.a && :
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
[39/99] Linking CXX executable projects/libc/test/integration/src/threads/libc.test.integration.src.threads.thrd_exit_test.__build__
FAILED: projects/libc/test/integration/src/threads/libc.test.integration.src.threads.thrd_exit_test.__build__ 
: && /usr/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -nolibc -nostartfiles -nostdlib++ -static projects/libc/startup/linux/crt1.o projects/libc/test/IntegrationTest/CMakeFiles/libc.test.IntegrationTest.test.dir/test.cpp.o projects/libc/test/integration/src/threads/CMakeFiles/libc.test.integration.src.threads.thrd_exit_test.__build__.dir/thrd_exit_test.cpp.o -o projects/libc/test/integration/src/threads/libc.test.integration.src.threads.thrd_exit_test.__build__  projects/libc/test/integration/src/threads/liblibc.test.integration.src.threads.thrd_exit_test.libc.a && :
/usr/bin/ld: projects/libc/startup/linux/crt1.o: in function `__llvm_libc_19_0_0_git::do_start()':
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-fullbuild-dbg/llvm-project/libc/startup/linux/do_start.cpp:147: undefined reference to `main(int, char**, char**)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

@SchrodingerZhu
Copy link
Contributor

I have to revert this. Seems that extern C has its effect. Please take a look.

@dwblaikie
Copy link
Collaborator Author

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 extern "C" works around this?

@jhuber6
Copy link
Contributor

jhuber6 commented Aug 12, 2024

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 extern "C" works around this?

It's because we compile everything with -ffreestanding.

@dwblaikie
Copy link
Collaborator Author

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 extern "C" works around this?

It's because we compile everything with -ffreestanding.

Ah, so maybe all the main rules shouldn't apply when building with that mode? it looks like at least -Wreturn-type does this (it warns on main-without-return-statement when compiling with -ffreestanding but doesn't warn without that flag, so all makes sense)

@jhuber6
Copy link
Contributor

jhuber6 commented Aug 12, 2024

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 extern "C" works around this?

It's because we compile everything with -ffreestanding.

Ah, so maybe all the main rules shouldn't apply when building with that mode? it looks like at least -Wreturn-type does this (it warns on main-without-return-statement when compiling with -ffreestanding but doesn't warn without that flag, so all makes sense)

I think it's because we build the tests in two configurations. One is with -ffreestanding during the "full build" mode, the other is a standard hosted C++ compilation for the "overlay" mode. The warning is likely only printed for the latter.

jhuber6 added a commit to jhuber6/llvm-project that referenced this pull request Aug 12, 2024
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.
@dwblaikie
Copy link
Collaborator Author

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 extern "C" works around this?

It's because we compile everything with -ffreestanding.

Ah, so maybe all the main rules shouldn't apply when building with that mode? it looks like at least -Wreturn-type does this (it warns on main-without-return-statement when compiling with -ffreestanding but doesn't warn without that flag, so all makes sense)

I think it's because we build the tests in two configurations. One is with -ffreestanding during the "full build" mode, the other is a standard hosted C++ compilation for the "overlay" mode. The warning is likely only printed for the latter.

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)

@jhuber6
Copy link
Contributor

jhuber6 commented Aug 12, 2024

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

jhuber6 added a commit to jhuber6/llvm-project that referenced this pull request Aug 12, 2024
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.
jhuber6 added a commit that referenced this pull request Aug 12, 2024
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.
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.

6 participants