Skip to content

Commit 0354491

Browse files
authored
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.
1 parent 04a96c6 commit 0354491

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3275,9 +3275,11 @@ void CodeGenModule::EmitModuleLinkOptions() {
32753275
LinkerOptionsMetadata.append(MetadataArgs.begin(), MetadataArgs.end());
32763276

32773277
// Add the linker options metadata flag.
3278-
auto *NMD = getModule().getOrInsertNamedMetadata("llvm.linker.options");
3279-
for (auto *MD : LinkerOptionsMetadata)
3280-
NMD->addOperand(MD);
3278+
if (!LinkerOptionsMetadata.empty()) {
3279+
auto *NMD = getModule().getOrInsertNamedMetadata("llvm.linker.options");
3280+
for (auto *MD : LinkerOptionsMetadata)
3281+
NMD->addOperand(MD);
3282+
}
32813283
}
32823284

32833285
void CodeGenModule::EmitDeferred() {

clang/test/Modules/module-impl-with-link.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#include "foo.h"
44
// Make sure we don't generate linker option for module Clib since this TU is
55
// an implementation of Clib.
6-
// CHECK: !llvm.linker.options = !{}
6+
// CHECK-NOT: !llvm.linker.options =

0 commit comments

Comments
 (0)