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.
This commit is contained in:
dyung 2025-05-27 17:43:59 -04:00 committed by GitHub
parent 04a96c6900
commit 0354491bea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 4 deletions

View File

@ -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() {

View File

@ -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 =