[clang] [lld] [llvm] [LLVM][WebAssembly] Implement branch hinting proposal (PR #146230)

Lukas Döllerer via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 1 07:14:24 PDT 2025


================
@@ -165,14 +165,17 @@ void Writer::createCustomSections() {
   for (auto &pair : customSectionMapping) {
     StringRef name = pair.first;
     LLVM_DEBUG(dbgs() << "createCustomSection: " << name << "\n");
-
-    OutputSection *sec = make<CustomSection>(std::string(name), pair.second);
+    OutputSection *Sec;
+    if (name == "metadata.code.branch_hint")
+      Sec = make<CodeMetaDataSection>(std::string(name), pair.second);
----------------
Lukasdoe wrote:

You are entirely correct, the [Overview.md](https://github.com/WebAssembly/branch-hinting/blob/main/proposals/branch-hinting/Overview.md) file of the branch-hinting proposal mentions "The branch hints section should appear only once in a module, and only before the code section." However (what I based the implementation on), the [final code metadata specification](https://webassembly.github.io/branch-hinting/metadata/code/_download/WebAssembly-Metadata-Code.pdf) does not mention this require any longer. 

It does not specify any other placement requirement though and I see the appeal of having the branch hints before the code section for fast baseline compilation in a streaming setup.

So, following your suggestion, I'll amend lld to insert the combined branch-hint section at the appropriate place. Thanks for spotting this!

https://github.com/llvm/llvm-project/pull/146230


More information about the llvm-commits mailing list