Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Avoid emitting a linker options section in the compiler if it is empty. #139821

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
May 27, 2025

Conversation

dyung
Copy link
Collaborator

@dyung dyung commented May 14, 2025

Recently in some of our internal testing, we noticed that the compiler was sometimes generating an empty linker.options section which seems unnecessary. This proposed change causes the compiler to simply omit emitting the linker.options section if it is empty.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:modules C++20 modules and Clang Header Modules clang:codegen IR generation bugs: mangling, exceptions, etc. labels May 14, 2025
@llvmbot
Copy link
Member

llvmbot commented May 14, 2025

@llvm/pr-subscribers-clang
@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang-codegen

Author: None (dyung)

Changes

Recently in some of our internal testing, we noticed that the compiler was sometimes generating an empty linker.options section which seems unnecessary. This proposed change causes the compiler to simply omit emitting the linker.options section if it is empty.


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

2 Files Affected:

  • (modified) clang/lib/CodeGen/CodeGenModule.cpp (+5-3)
  • (modified) clang/test/Modules/module-impl-with-link.c (+1-1)
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 50041f883cfe5..3bf52428130f7 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3274,9 +3274,11 @@ void CodeGenModule::EmitModuleLinkOptions() {
   LinkerOptionsMetadata.append(MetadataArgs.begin(), MetadataArgs.end());
 
   // Add the linker options metadata flag.
-  auto *NMD = getModule().getOrInsertNamedMetadata("llvm.linker.options");
-  for (auto *MD : LinkerOptionsMetadata)
-    NMD->addOperand(MD);
+  if (!LinkerOptionsMetadata.empty()) {
+    auto *NMD = getModule().getOrInsertNamedMetadata("llvm.linker.options");
+    for (auto *MD : LinkerOptionsMetadata)
+      NMD->addOperand(MD);
+  }
 }
 
 void CodeGenModule::EmitDeferred() {
diff --git a/clang/test/Modules/module-impl-with-link.c b/clang/test/Modules/module-impl-with-link.c
index ffd388c56b90a..be2f1359b5e94 100644
--- a/clang/test/Modules/module-impl-with-link.c
+++ b/clang/test/Modules/module-impl-with-link.c
@@ -3,4 +3,4 @@
 #include "foo.h"
 // Make sure we don't generate linker option for module Clib since this TU is
 // an implementation of Clib.
-// CHECK: !llvm.linker.options = !{}
+// CHECK-NOT: !llvm.linker.options =

@nga888 nga888 requested a review from pcc May 14, 2025 12:01
@dyung
Copy link
Collaborator Author

dyung commented May 16, 2025

Hi @pcc, I believe you originally wrote the code that is being modified, would you mind taking a quick look?

@dyung
Copy link
Collaborator Author

dyung commented May 27, 2025

ping!

@dyung
Copy link
Collaborator Author

dyung commented May 27, 2025

Thank you!

@dyung dyung merged commit 0354491 into llvm:main May 27, 2025
15 checks passed
@dyung dyung deleted the suppress-empty-linker-option branch May 27, 2025 21:44
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…y. (llvm#139821)

Recently in some of our internal testing, we noticed that the compiler
was sometimes generating an empty linker.options section which seems
unnecessary. This proposed change causes the compiler to simply omit
emitting the linker.options section if it is empty.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen IR generation bugs: mangling, exceptions, etc. clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.