diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp --- a/llvm/lib/MC/XCOFFObjectWriter.cpp +++ b/llvm/lib/MC/XCOFFObjectWriter.cpp @@ -200,7 +200,7 @@ uint64_t SymbolTableOffset = 0; uint16_t SectionCount = 0; uint64_t RelocationEntryOffset = 0; - StringRef SourceFileName = ".file"; + std::vector> FileNames; support::endian::Writer W; std::unique_ptr TargetObjectWriter; @@ -494,9 +494,13 @@ Strings.add(XSym->getSymbolTableName()); } - // The first symbol entry is for the source file's name. - if (nameShouldBeInStringTable(SourceFileName)) - Strings.add(SourceFileName); + FileNames = Asm.getFileNames(); + if (FileNames.empty()) + FileNames.emplace_back(".file", 0); + for (const std::pair &F : FileNames) { + if (nameShouldBeInStringTable(F.first)) + Strings.add(F.first); + } Strings.finalize(); assignAddressesAndIndices(Layout); @@ -853,15 +857,14 @@ } void XCOFFObjectWriter::writeSymbolTable(const MCAsmLayout &Layout) { - // Write symbol 0 as C_FILE. + // Write .file symbols. // The n_name of a C_FILE symbol is the source file's name when no auxiliary - // entries are present. The source file's name is alternatively provided by an - // auxiliary entry, in which case the n_name of the C_FILE symbol is `.file`. - // FIXME: add the real source file's name. - writeSymbolEntry(SourceFileName, /*Value=*/0, - XCOFF::ReservedSectionNum::N_DEBUG, - /*SymbolType=*/0, XCOFF::C_FILE, - /*NumberOfAuxEntries=*/0); + // entries are present. + for (const std::pair &F : FileNames) { + writeSymbolEntry(F.first, /*Value=*/0, XCOFF::ReservedSectionNum::N_DEBUG, + /*SymbolType=*/0, XCOFF::C_FILE, + /*NumberOfAuxEntries=*/0); + } for (const auto &Csect : UndefinedCsects) { writeSymbolEntryForControlSection(Csect, XCOFF::ReservedSectionNum::N_UNDEF, @@ -957,8 +960,8 @@ } void XCOFFObjectWriter::assignAddressesAndIndices(const MCAsmLayout &Layout) { - // The first symbol table entry (at index 0) is for the file name. - uint32_t SymbolTableIndex = 1; + // The symbol table starts with all the .file symbols. + uint32_t SymbolTableIndex = FileNames.size(); // Calculate indices for undefined symbols. for (auto &Csect : UndefinedCsects) { diff --git a/llvm/test/CodeGen/PowerPC/aix-extern-weak.ll b/llvm/test/CodeGen/PowerPC/aix-extern-weak.ll --- a/llvm/test/CodeGen/PowerPC/aix-extern-weak.ll +++ b/llvm/test/CodeGen/PowerPC/aix-extern-weak.ll @@ -66,7 +66,7 @@ ; CHECKSYM: Symbols [ ; CHECKSYM-NEXT: Symbol { ; CHECKSYM-NEXT: Index: 0 -; CHECKSYM-NEXT: Name: .file +; CHECKSYM-NEXT: Name: ; CHECKSYM-NEXT: Value (SymbolTableIndex): 0x0 ; CHECKSYM-NEXT: Section: N_DEBUG ; CHECKSYM-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-extern.ll b/llvm/test/CodeGen/PowerPC/aix-extern.ll --- a/llvm/test/CodeGen/PowerPC/aix-extern.ll +++ b/llvm/test/CodeGen/PowerPC/aix-extern.ll @@ -89,7 +89,7 @@ ; CHECKSYM: Symbols [ ; CHECKSYM-NEXT: Symbol { ; CHECKSYM-NEXT: Index: 0 -; CHECKSYM-NEXT: Name: .file +; CHECKSYM-NEXT: Name: ; CHECKSYM-NEXT: Value (SymbolTableIndex): 0x0 ; CHECKSYM-NEXT: Section: N_DEBUG ; CHECKSYM-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll b/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll --- a/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll +++ b/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll @@ -13,7 +13,7 @@ ; CHECK-NEXT: AddressSize: 32bit ; CHECK: Symbol { ; CHECK-NEXT: Index: 0 -; CHECK-NEXT: Name: .file +; CHECK-NEXT: Name: ; CHECK-NEXT: Value (SymbolTableIndex): 0x0 ; CHECK-NEXT: Section: N_DEBUG ; CHECK-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll b/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll --- a/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll +++ b/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll @@ -39,7 +39,7 @@ ; CHECKSYM: Symbol { ; CHECKSYM-NEXT: Index: 0 -; CHECKSYM-NEXT: Name: .file +; CHECKSYM-NEXT: Name: ; CHECKSYM-NEXT: Value (SymbolTableIndex): 0x0 ; CHECKSYM-NEXT: Section: N_DEBUG ; CHECKSYM-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc-large.ll b/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc-large.ll --- a/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc-large.ll +++ b/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc-large.ll @@ -210,7 +210,7 @@ ; SYM-NEXT: Symbols [ ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: 0 -; SYM-NEXT: Name: .file +; SYM-NEXT: Name: ; SYM-NEXT: Value (SymbolTableIndex): 0x0 ; SYM-NEXT: Section: N_DEBUG ; SYM-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll b/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll --- a/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll +++ b/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll @@ -171,7 +171,7 @@ ; SYM-NEXT: Symbols [ ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: 0 -; SYM-NEXT: Name: .file +; SYM-NEXT: Name: ; SYM-NEXT: Value (SymbolTableIndex): 0x0 ; SYM-NEXT: Section: N_DEBUG ; SYM-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll b/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll --- a/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll +++ b/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll @@ -66,7 +66,7 @@ ; SYMS-NEXT: Symbols [ ; SYMS-NEXT: Symbol { ; SYMS-NEXT: Index: 0 -; SYMS-NEXT: Name: .file +; SYMS-NEXT: Name: ; SYMS-NEXT: Value (SymbolTableIndex): 0x0 ; SYMS-NEXT: Section: N_DEBUG ; SYMS-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-weak.ll b/llvm/test/CodeGen/PowerPC/aix-weak.ll --- a/llvm/test/CodeGen/PowerPC/aix-weak.ll +++ b/llvm/test/CodeGen/PowerPC/aix-weak.ll @@ -101,7 +101,7 @@ ; CHECKSYM: Symbols [ ; CHECKSYM-NEXT: Symbol { ; CHECKSYM-NEXT: Index: 0 -; CHECKSYM-NEXT: Name: .file +; CHECKSYM-NEXT: Name: ; CHECKSYM-NEXT: Value (SymbolTableIndex): 0x0 ; CHECKSYM-NEXT: Section: N_DEBUG ; CHECKSYM-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll --- a/llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll +++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll @@ -208,7 +208,7 @@ ; SYMS: Symbols [ ; SYMS-NEXT: Symbol { ; SYMS-NEXT: Index: 0 -; SYMS-NEXT: Name: .file +; SYMS-NEXT: Name: ; SYMS-NEXT: Value (SymbolTableIndex): 0x0 ; SYMS-NEXT: Section: N_DEBUG ; SYMS-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll b/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll --- a/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll +++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll @@ -159,7 +159,7 @@ ; SYM: Symbols [ ; SYM-NEXT: Symbol { ; SYM-NEXT: Index: 0 -; SYM-NEXT: Name: .file +; SYM-NEXT: Name: ; SYM-NEXT: Value (SymbolTableIndex): 0x0 ; SYM-NEXT: Section: N_DEBUG ; SYM-NEXT: Source Language ID: TB_C (0x0) diff --git a/llvm/test/MC/PowerPC/aix-symtbl-order.s b/llvm/test/MC/PowerPC/aix-symtbl-order.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/PowerPC/aix-symtbl-order.s @@ -0,0 +1,20 @@ +# RUN: llvm-mc -triple powerpc-ibm-aix-xcoff %s -filetype=obj -o - | \ +# RUN: llvm-objdump --syms - | FileCheck %s + +## TODO: Test more types of symbols when support is added to llvm-mc. + + .file "1.c" + .globl var1 +var1: + .file "2.c" + .globl var2 +var2: + .file "3.c" + +# CHECK: SYMBOL TABLE: +# CHECK-NEXT: 00000000 df *DEBUG* 00000000 1.c +# CHECK-NEXT: 00000000 df *DEBUG* 00000000 2.c +# CHECK-NEXT: 00000000 df *DEBUG* 00000000 3.c +# CHECK-NEXT: 00000000 l .text 00000000 .text +# CHECK-NEXT: 00000000 g F .text (csect: .text) 00000000 var1 +# CHECK-NEXT: 00000000 g F .text (csect: .text) 00000000 var2 diff --git a/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test b/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test --- a/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test +++ b/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test @@ -66,7 +66,7 @@ } ; SYM: SYMBOL TABLE: -; SYM-NEXT: 00000000 df *DEBUG* 00000000 .file +; SYM-NEXT: 00000000 df *DEBUG* 00000000 ; SYM-NEXT: 00000000 *UND* 00000000 ei ; SYM-NEXT: 00000000 l .text 00000091 .text ; SYM-NEXT: 00000000 g F .text (csect: .text) 00000000 .bar @@ -88,7 +88,7 @@ ; SYM-NEXT: 000000ec l O *COM* 00000004 si ; SYM-DES: SYMBOL TABLE: -; SYM-DES-NEXT: 00000000 df *DEBUG* 00000000 (idx: 0) .file +; SYM-DES-NEXT: 00000000 df *DEBUG* 00000000 (idx: 0) ; SYM-DES-NEXT: 00000000 *UND* 00000000 (idx: 1) ei[UA] ; SYM-DES-NEXT: 00000000 l .text 00000091 (idx: 3) .text[PR] ; SYM-DES-NEXT: 00000000 g F .text (csect: (idx: 3) .text[PR]) 00000000 (idx: 5) .bar