Skip to content

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));

yamt added a commit to yamt/wasi-libc that referenced this pull request Aug 19, 2024
yamt added a commit to yamt/garbage that referenced this pull request Feb 10, 2025
yamt added a commit to yamt/garbage that referenced this pull request Feb 10, 2025
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