From 0354491bea04beb6d1db44f8ca522bfc597ab0d3 Mon Sep 17 00:00:00 2001 From: dyung Date: Tue, 27 May 2025 17:43:59 -0400 Subject: Avoid emitting a linker options section in the compiler if it is empty. (#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. --- clang/lib/CodeGen/CodeGenModule.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index 039507b..6d2c705 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3275,9 +3275,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() { -- cgit v1.1