diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -796,16 +796,19 @@ void FunctionStartsSection::finalizeContents() { raw_svector_ostream os{contents}; std::vector addrs; - for (const Symbol *sym : symtab->getSymbols()) { - if (const auto *defined = dyn_cast(sym)) { - if (!defined->isec || !isCodeSection(defined->isec) || !defined->isLive()) - continue; - if (const auto *concatIsec = dyn_cast(defined->isec)) - if (concatIsec->shouldOmitFromOutput()) - continue; - // TODO: Add support for thumbs, in that case - // the lowest bit of nextAddr needs to be set to 1. - addrs.push_back(defined->getVA()); + + for (const InputFile *file : inputFiles) { + if (auto *objFile = dyn_cast(file)) { + for (const Symbol *sym : objFile->symbols) { + if (const auto *defined = dyn_cast_or_null(sym)) { + if (!defined->isec || !isCodeSection(defined->isec) || + !defined->isLive()) + continue; + // TODO: Add support for thumbs, in that case + // the lowest bit of nextAddr needs to be set to 1. + addrs.push_back(defined->getVA()); + } + } } } llvm::sort(addrs); diff --git a/lld/test/MachO/function-starts.s b/lld/test/MachO/function-starts.s --- a/lld/test/MachO/function-starts.s +++ b/lld/test/MachO/function-starts.s @@ -41,6 +41,21 @@ # RUN: llvm-objdump --macho --function-starts %t/basic >> %t/objdump # RUN: FileCheck %s --check-prefix=BASIC < %t/objdump +# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/local.s -o %t/local.o +# RUN: %lld -lSystem %t/local.o -o %t/local +# RUN: llvm-objdump --syms %t/local > %t/objdump +# RUN: llvm-objdump --macho --function-starts %t/local >> %t/objdump +# RUN: FileCheck %s --check-prefix=LOCAL < %t/objdump + +# LOCAL-LABEL: SYMBOL TABLE: +# LOCAL-NEXT: [[#%x,F1:]] l F __TEXT,__text +[Foo bar] +# LOCAL-NEXT: [[#%x,F2:]] l F __TEXT,__text _foo +# LOCAL: [[#%x,F3:]] g F __TEXT,__text _main +# LOCAL-LABEL: local: +# LOCAL: [[#F1]] +# LOCAL: [[#F2]] +# LOCAL: [[#F3]] + #--- basic.s .section __TEXT,__text,regular,pure_instructions .globl _f1 @@ -62,3 +77,15 @@ retq _main: retq + +#--- local.s +.section __TEXT,__text +"+[Foo bar]": + retq + +_foo: + retq + +.globl _main +_main: + retq