Index: ELF/Driver.cpp =================================================================== --- ELF/Driver.cpp +++ ELF/Driver.cpp @@ -681,7 +681,10 @@ template static void readCallGraphsFromObjectFiles() { auto FindSection = [&](const Symbol *Sym) -> const InputSectionBase * { - warnUnorderableSymbol(Sym); + // When linking a shared object, we may not link all object files and some + // symbols are left undefined. Don't warn on undefined symbols by relying on + // --shared implying UnresolvedPolicy::Ignore. + warnUnorderableSymbol(Sym); if (const auto *SymD = dyn_cast(Sym)) return dyn_cast_or_null(SymD->Section); return nullptr; Index: ELF/Symbols.cpp =================================================================== --- ELF/Symbols.cpp +++ ELF/Symbols.cpp @@ -268,16 +268,26 @@ auto Warn = [&](StringRef S) { warn(toString(File) + S + Sym->getName()); }; - if (Sym->isUndefined()) - Warn(": unable to order undefined symbol: "); - else if (Sym->isShared()) + if (Sym->isUndefined()) { + // For .llvm.call-graph-profile, when linking a shared object, we may not + // link all object files and some symbols are left undefined. Don't warn on + // undefined symbols by relying on --shared implying + // UnresolvedPolicy::Ignore. + // + // Note, ld.bfd --symbol-ordering-file= does not warn on undefined symbols, + // but we don't have to be compatible here. + if (Config->UnresolvedSymbols != UnresolvedPolicy::Ignore) + Warn(": unable to order undefined symbol: "); + } else if (Sym->isShared()) { Warn(": unable to order shared symbol: "); - else if (D && !D->Section) - Warn(": unable to order absolute symbol: "); - else if (D && isa(D->Section)) - Warn(": unable to order synthetic symbol: "); - else if (D && !D->Section->Repl->Live) - Warn(": unable to order discarded symbol: "); + } else if (D) { + if (!D->Section) + Warn(": unable to order absolute symbol: "); + else if (isa(D->Section)) + Warn(": unable to order synthetic symbol: "); + else if (!D->Section->Repl->Live) + Warn(": unable to order discarded symbol: "); + } } // Returns a symbol for an error message. Index: test/ELF/cgprofile-shared-warn.s =================================================================== --- /dev/null +++ test/ELF/cgprofile-shared-warn.s @@ -0,0 +1,11 @@ +# REQUIRES: x86 + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld --shared %t.o -o /dev/null 2>&1 | count 0 +# RUN: ld.lld -e A --unresolved-symbols=ignore-all %t.o -o /dev/null 2>&1 | count 0 + .section .text.A,"ax",@progbits + .globl A +A: + callq B + + .cg_profile A, B, 10 Index: test/ELF/symbol-ordering-file-warnings.s =================================================================== --- test/ELF/symbol-ordering-file-warnings.s +++ test/ELF/symbol-ordering-file-warnings.s @@ -19,11 +19,6 @@ # RUN: --unresolved-symbols=ignore-all --no-warn-symbol-ordering --warn-symbol-ordering 2>&1 | \ # RUN: FileCheck %s --check-prefixes=WARN,MISSING -# Check that a warning is emitted for undefined symbols. -# RUN: echo "undefined" > %t-order-undef.txt -# RUN: ld.lld %t1.o %t3.o -o %t --symbol-ordering-file %t-order-undef.txt \ -# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,UNDEFINED - # Check that a warning is emitted for imported shared symbols. # RUN: echo "shared" > %t-order-shared.txt # RUN: ld.lld %t1.o %t.so -o %t --symbol-ordering-file %t-order-shared.txt \ @@ -97,29 +92,20 @@ # RUN: echo "_GLOBAL_OFFSET_TABLE_" >> %t-order-multi.txt # RUN: echo "_start" >> %t-order-multi.txt # RUN: ld.lld %t1.o %t3.o %t.so -o %t --symbol-ordering-file %t-order-multi.txt --gc-sections -T %t.script \ -# RUN: --unresolved-symbols=ignore-all 2>&1 | FileCheck %s --check-prefixes=WARN,SAMESYM,ABSOLUTE,SHARED,UNDEFINED,GC,DISCARD,MISSING2,SYNTHETIC +# RUN: 2>&1 | FileCheck %s --check-prefixes=WARN,SAMESYM,ABSOLUTE,SHARED,UNDEFINED,GC,DISCARD,MISSING2,SYNTHETIC # WARN-NOT: warning: # SAMESYM: warning: {{.*}}.txt: duplicate ordered symbol: _start -# WARN-NOT: warning: # SYNTHETIC: warning: : unable to order synthetic symbol: _GLOBAL_OFFSET_TABLE_ -# WARN-NOT: warning: # DISCARD: warning: {{.*}}1.o: unable to order discarded symbol: discard -# WARN-NOT: warning: # GC: warning: {{.*}}1.o: unable to order discarded symbol: gc -# WARN-NOT: warning: # SHARED: warning: {{.*}}.so: unable to order shared symbol: shared -# WARN-NOT: warning: # UNDEFINED: warning: {{.*}}3.o: unable to order undefined symbol: undefined -# WARN-NOT: warning: # ABSOLUTE: warning: {{.*}}1.o: unable to order absolute symbol: absolute -# WARN-NOT: warning: # MISSING: warning: symbol ordering file: no such symbol: missing # MISSING2: warning: symbol ordering file: no such symbol: missing_sym # COMDAT: warning: {{.*}}1.o: unable to order discarded symbol: comdat -# MULTI: warning: {{.*}}3.o: unable to order undefined symbol: multi -# MULTI-NEXT: warning: {{.*}}2.o: unable to order absolute symbol: multi -# WARN-NOT: warning: +# MULTI: warning: {{.*}}2.o: unable to order absolute symbol: multi absolute = 0x1234