Skip to content
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

[clang][WebAssembly] Link crt2-command.o if available #104755

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yamt
Copy link
Contributor

@yamt yamt commented Aug 19, 2024

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Aug 19, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 19, 2024

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-clang

Author: YAMAMOTO Takashi (yamt)

Changes

cf. WebAssembly/wasi-libc#528


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

1 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/WebAssembly.cpp (+10-1)
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 9aacda5fd5702..7b95b95e3eee8 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -103,6 +103,7 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
 
   bool IsCommand = true;
   const char *Crt1;
+  const char *Crt2 = nullptr;
   const char *Entry = nullptr;
 
   // When -shared is specified, use the reactor exec model unless
@@ -132,13 +133,21 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
     Crt1 = "crt1.o";
     if (ToolChain.GetFilePath("crt1-command.o") != "crt1-command.o")
       Crt1 = "crt1-command.o";
+    // Link another object as well if it's provided. It's planned to
+    // be used to fix https://github.com/WebAssembly/wasi-libc/issues/485
+    if (ToolChain.GetFilePath("crt2-command.o") != "crt2-command.o") {
+      Crt2 = "crt2-command.o";
+    }
   } else {
     Crt1 = "crt1-reactor.o";
     Entry = "_initialize";
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles))
+  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles)) {
     CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt1)));
+    if (Crt2)
+      CmdArgs.push_back(Args.MakeArgString(ToolChain.GetFilePath(Crt2)));
+  }
   if (Entry) {
     CmdArgs.push_back(Args.MakeArgString("--entry"));
     CmdArgs.push_back(Args.MakeArgString(Entry));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants