Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3028,6 +3028,7 @@ def gno_gnu_pubnames : Flag<["-"], "gno-gnu-pubnames">, Group; def gpubnames : Flag<["-"], "gpubnames">, Group, Flags<[CC1Option]>; def gno_pubnames : Flag<["-"], "gno-pubnames">, Group; +def gapplenames : Flag<["-"], "gapplenames">, Group, Flags<[CC1Option]>; def gdwarf_aranges : Flag<["-"], "gdwarf-aranges">, Group; def gmodules : Flag <["-"], "gmodules">, Group, HelpText<"Generate debug info with external references to clang modules" Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -4246,6 +4246,9 @@ options::OPT_gpubnames) ? "-gpubnames" : "-ggnu-pubnames"); + if (TC.getTriple().isOSBinFormatMachO()) + CmdArgs.push_back("-gapplenames"); + const auto *SimpleTemplateNamesArg = Args.getLastArg(options::OPT_gsimple_template_names, options::OPT_gno_simple_template_names, options::OPT_gsimple_template_names_EQ); Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -1409,6 +1409,10 @@ static_cast( llvm::DICompileUnit::DebugNameTableKind::Default)) GenerateArg(Args, OPT_gpubnames, SA); + else if (Opts.DebugNameTable == + static_cast( + llvm::DICompileUnit::DebugNameTableKind::Apple)) + GenerateArg(Args, OPT_gapplenames, SA); auto TNK = Opts.getDebugSimpleTemplateNames(); if (TNK != codegenoptions::DebugTemplateNamesKind::Full) { @@ -1685,12 +1689,19 @@ Opts.BinutilsVersion = std::string(Args.getLastArgValue(OPT_fbinutils_version_EQ)); - Opts.DebugNameTable = static_cast( - Args.hasArg(OPT_ggnu_pubnames) - ? llvm::DICompileUnit::DebugNameTableKind::GNU - : Args.hasArg(OPT_gpubnames) - ? llvm::DICompileUnit::DebugNameTableKind::Default - : llvm::DICompileUnit::DebugNameTableKind::None); + if (Args.hasArg(OPT_ggnu_pubnames)) + Opts.DebugNameTable = + static_cast(llvm::DICompileUnit::DebugNameTableKind::GNU); + else if (Args.hasArg(OPT_gpubnames)) + Opts.DebugNameTable = + static_cast(llvm::DICompileUnit::DebugNameTableKind::Default); + else if (Args.hasArg(OPT_gapplenames)) + Opts.DebugNameTable = + static_cast(llvm::DICompileUnit::DebugNameTableKind::Apple); + else + Opts.DebugNameTable = + static_cast(llvm::DICompileUnit::DebugNameTableKind::None); + if (const Arg *A = Args.getLastArg(OPT_gsimple_template_names_EQ)) { StringRef Value = A->getValue(); if (Value != "simple" && Value != "mangled") Index: llvm/include/llvm/IR/DebugInfoMetadata.h =================================================================== --- llvm/include/llvm/IR/DebugInfoMetadata.h +++ llvm/include/llvm/IR/DebugInfoMetadata.h @@ -1362,7 +1362,8 @@ enum class DebugNameTableKind : unsigned { Default = 0, GNU = 1, - None = 2, + Apple = 2, + None = 3, LastDebugNameTableKind = None }; Index: llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp +++ llvm/lib/CodeGen/AsmPrinter/AccelTable.cpp @@ -550,9 +550,13 @@ SmallVector CUIndex(CUs.size()); int Count = 0; for (const auto &CU : enumerate(CUs)) { - if (CU.value()->getCUNode()->getNameTableKind() != - DICompileUnit::DebugNameTableKind::Default) + switch (CU.value()->getCUNode()->getNameTableKind()) { + case DICompileUnit::DebugNameTableKind::Default: + case DICompileUnit::DebugNameTableKind::Apple: + break; + default: continue; + } CUIndex[CU.index()] = Count++; assert(CU.index() == CU.value()->getUniqueID()); const DwarfCompileUnit *MainCU = Index: llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -1383,6 +1383,8 @@ // generated for things like Gold's gdb_index generation. case DICompileUnit::DebugNameTableKind::GNU: return true; + case DICompileUnit::DebugNameTableKind::Apple: + return false; case DICompileUnit::DebugNameTableKind::Default: return DD->tuneForGDB() && !includeMinimalInlineScopes() && !CUNode->isDebugDirectivesOnly() && Index: llvm/lib/IR/DebugInfoMetadata.cpp =================================================================== --- llvm/lib/IR/DebugInfoMetadata.cpp +++ llvm/lib/IR/DebugInfoMetadata.cpp @@ -798,6 +798,7 @@ return StringSwitch>(Str) .Case("Default", DebugNameTableKind::Default) .Case("GNU", DebugNameTableKind::GNU) + .Case("Apple", DebugNameTableKind::Apple) .Case("None", DebugNameTableKind::None) .Default(None); } @@ -822,6 +823,8 @@ return nullptr; case DebugNameTableKind::GNU: return "GNU"; + case DebugNameTableKind::Apple: + return "Apple"; case DebugNameTableKind::None: return "None"; }