[llvm] d29e986 - [XCOFF] write the real source file name in C_FILE symbol.

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 22 03:25:13 PDT 2022


Author: esmeyi
Date: 2022-06-22T06:23:36-04:00
New Revision: d29e986ed5c1f74518148171da5a6040ddccbd09

URL: https://github.com/llvm/llvm-project/commit/d29e986ed5c1f74518148171da5a6040ddccbd09
DIFF: https://github.com/llvm/llvm-project/commit/d29e986ed5c1f74518148171da5a6040ddccbd09.diff

LOG: [XCOFF] write the real source file name in C_FILE symbol.

The symbol table starts with all the C_FILE symbols.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D126623

Added: 
    llvm/test/MC/PowerPC/aix-file-symbols-empty.s
    llvm/test/MC/PowerPC/aix-file-symbols.s

Modified: 
    llvm/lib/MC/XCOFFObjectWriter.cpp
    llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
    llvm/test/CodeGen/PowerPC/aix-extern.ll
    llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll
    llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll
    llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc-large.ll
    llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll
    llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
    llvm/test/CodeGen/PowerPC/aix-weak.ll
    llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
    llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
    llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index 9e241345cf7d2..938942b7ef113 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -201,6 +201,7 @@ class XCOFFObjectWriter : public MCObjectWriter {
   uint16_t SectionCount = 0;
   uint64_t RelocationEntryOffset = 0;
   StringRef SourceFileName = ".file";
+  std::vector<std::pair<std::string, size_t>> FileNames;
 
   support::endian::Writer W;
   std::unique_ptr<MCXCOFFObjectTargetWriter> TargetObjectWriter;
@@ -494,9 +495,14 @@ void XCOFFObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
       Strings.add(XSym->getSymbolTableName());
   }
 
-  // The first symbol entry is for the source file's name.
-  if (nameShouldBeInStringTable(SourceFileName))
-    Strings.add(SourceFileName);
+  FileNames = Asm.getFileNames();
+  // Emit ".file" as the source file name when there is no file name.
+  if (FileNames.empty())
+    FileNames.emplace_back(".file", 0);
+  for (const std::pair<std::string, size_t> &F : FileNames) {
+    if (nameShouldBeInStringTable(F.first))
+      Strings.add(F.first);
+  }
 
   Strings.finalize();
   assignAddressesAndIndices(Layout);
@@ -853,15 +859,14 @@ void XCOFFObjectWriter::writeRelocations() {
 }
 
 void XCOFFObjectWriter::writeSymbolTable(const MCAsmLayout &Layout) {
-  // Write symbol 0 as C_FILE.
+  // Write C_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<std::string, size_t> &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 +962,8 @@ void XCOFFObjectWriter::finalizeSectionInfo() {
 }
 
 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 C_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
index e8044f3735a72..4e282d23d730e 100644
--- a/llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
@@ -66,7 +66,7 @@ declare extern_weak void @foo_ext_weak(i32*)
 ; CHECKSYM:      Symbols [
 ; CHECKSYM-NEXT:   Symbol {
 ; CHECKSYM-NEXT:     Index: 0
-; CHECKSYM-NEXT:     Name: .file
+; CHECKSYM-NEXT:     Name: <stdin>
 ; 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
index 1ac6d2270ed1b..6b8573ee6d459 100644
--- a/llvm/test/CodeGen/PowerPC/aix-extern.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-extern.ll
@@ -89,7 +89,7 @@ declare i32 @bar_extern(i32*)
 ; CHECKSYM:       Symbols [
 ; CHECKSYM-NEXT:   Symbol {
 ; CHECKSYM-NEXT:     Index: 0
-; CHECKSYM-NEXT:     Name: .file
+; CHECKSYM-NEXT:     Name: <stdin>
 ; 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
index 7d335198e023b..d3f1712576ce5 100644
--- a/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll
@@ -13,7 +13,7 @@ entry:
 ; CHECK-NEXT: AddressSize: 32bit
 ; CHECK:        Symbol {
 ; CHECK-NEXT:     Index: 0
-; CHECK-NEXT:     Name: .file
+; CHECK-NEXT:     Name: <stdin>
 ; 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
index 1921dfb745f1d..9b9ac30100db3 100644
--- a/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll
@@ -39,7 +39,7 @@ declare void @llvm.memset.p0i8.i32(i8* nocapture writeonly, i8, i32, i1 immarg)
 
 ; CHECKSYM:        Symbol {
 ; CHECKSYM-NEXT:     Index: 0
-; CHECKSYM-NEXT:     Name: .file
+; CHECKSYM-NEXT:     Name: <stdin>
 ; 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
index 4b753ac53cf16..550f2c29cd3a0 100644
--- 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 @@ entry:
 ; SYM-NEXT: Symbols [
 ; SYM-NEXT:   Symbol {
 ; SYM-NEXT:     Index: 0
-; SYM-NEXT:     Name: .file
+; SYM-NEXT:     Name: <stdin>
 ; 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
index 97fed400922cf..8485743ade80c 100644
--- a/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll
@@ -171,7 +171,7 @@ entry:
 ; SYM-NEXT: Symbols [
 ; SYM-NEXT:   Symbol {
 ; SYM-NEXT:     Index: 0
-; SYM-NEXT:     Name: .file
+; SYM-NEXT:     Name: <stdin>
 ; 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
index 7f536e7a96013..dfa8f5513f0e6 100644
--- 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: <stdin>
 ; 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
index bdf8cf799fd7f..57cc5abdce8ee 100644
--- a/llvm/test/CodeGen/PowerPC/aix-weak.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-weak.ll
@@ -101,7 +101,7 @@ entry:
 ; CHECKSYM:      Symbols [
 ; CHECKSYM-NEXT:   Symbol {
 ; CHECKSYM-NEXT:     Index: 0
-; CHECKSYM-NEXT:     Name: .file
+; CHECKSYM-NEXT:     Name: <stdin>
 ; 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
index 588994618d326..d187ff054083c 100644
--- 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: <stdin>
 ; 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
index 8bbf9174ef60a..1423a86330bea 100644
--- a/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
+++ b/llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
@@ -159,7 +159,7 @@ declare i32 @bar(i32)
 ; SYM:      Symbols [
 ; SYM-NEXT:   Symbol {
 ; SYM-NEXT:     Index: 0
-; SYM-NEXT:     Name: .file
+; SYM-NEXT:     Name: <stdin>
 ; 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-file-symbols-empty.s b/llvm/test/MC/PowerPC/aix-file-symbols-empty.s
new file mode 100644
index 0000000000000..77dbbb94bc3e5
--- /dev/null
+++ b/llvm/test/MC/PowerPC/aix-file-symbols-empty.s
@@ -0,0 +1,14 @@
+## Emit ".file" as the source file name when there is no file name.
+# RUN: llvm-mc -triple powerpc-ibm-aix-xcoff %s -filetype=obj -o - | \
+# RUN:    llvm-objdump --syms - | FileCheck %s
+
+      .globl .var1
+.var1:
+      .globl .var2
+.var2:
+
+# CHECK:      SYMBOL TABLE:
+# CHECK-NEXT: 00000000      df *DEBUG*	00000000 .file
+# 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/MC/PowerPC/aix-file-symbols.s b/llvm/test/MC/PowerPC/aix-file-symbols.s
new file mode 100644
index 0000000000000..acdffb23ca2cc
--- /dev/null
+++ b/llvm/test/MC/PowerPC/aix-file-symbols.s
@@ -0,0 +1,19 @@
+## Check mutiple C_FILE symbols are emitted.
+# RUN: llvm-mc -triple powerpc-ibm-aix-xcoff %s -filetype=obj -o - | \
+# RUN:    llvm-objdump --syms - | FileCheck %s
+
+      .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
index 2ce9b4279b206..9d2fca2c5bc40 100644
--- a/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test
+++ b/llvm/test/tools/llvm-objdump/XCOFF/symbol-table.test
@@ -66,7 +66,7 @@ entry:
 }
 
 ; SYM:      SYMBOL TABLE:
-; SYM-NEXT: 00000000      df *DEBUG*    00000000 .file
+; SYM-NEXT: 00000000      df *DEBUG*    00000000 <stdin>
 ; 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 @@ entry:
 ; 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) <stdin>
 ; 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


        


More information about the llvm-commits mailing list