Skip to content

Commit

Permalink
[XCOFF] Write source language ID and CPU version ID into C_FILE symbol.
Browse files Browse the repository at this point in the history
Summary: The source language ID and CPU version ID are required by debuggers on AIX. AIX's system assembler determines the source language ID based on the source file's name suffix, and the behavior in this patch is consistent with it.

Reviewed By: shchenz

Differential Revision: https://reviews.llvm.org/D155684
  • Loading branch information
EsmeYi committed Jul 24, 2023
1 parent f573bc2 commit 7761958
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 25 deletions.
1 change: 1 addition & 0 deletions llvm/include/llvm/BinaryFormat/XCOFF.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ enum CFileStringType : uint8_t {

enum CFileLangId : uint8_t {
TB_C = 0, ///< C language.
TB_Fortran = 1, ///< Fortran language.
TB_CPLUSPLUS = 9 ///< C++ language.
};

Expand Down
33 changes: 29 additions & 4 deletions llvm/lib/MC/XCOFFObjectWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,11 +1104,36 @@ void XCOFFObjectWriter::writeRelocations() {

void XCOFFObjectWriter::writeSymbolTable(const MCAsmLayout &Layout) {
// Write C_FILE symbols.
// The n_name of a C_FILE symbol is the source file's name when no auxiliary
// 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,
// The n_name of a C_FILE symbol is the source file's name when no auxiliary
// entries are present.
StringRef FileName = F.first;

// For C_FILE symbols, the Source Language ID overlays the high-order byte
// of the SymbolType field, and the CPU Version ID is defined as the
// low-order byte.
// AIX's system assembler determines the source language ID based on the
// source file's name suffix, and the behavior here is consistent with it.
uint8_t LangID;
if (FileName.ends_with(".c"))
LangID = XCOFF::TB_C;
else if (FileName.ends_with_insensitive(".f") ||
FileName.ends_with_insensitive(".f77") ||
FileName.ends_with_insensitive(".f90") ||
FileName.ends_with_insensitive(".f95") ||
FileName.ends_with_insensitive(".f03") ||
FileName.ends_with_insensitive(".f08"))
LangID = XCOFF::TB_Fortran;
else
LangID = XCOFF::TB_CPLUSPLUS;
uint8_t CpuID;
if (is64Bit())
CpuID = XCOFF::TCPU_PPC64;
else
CpuID = XCOFF::TCPU_COM;

writeSymbolEntry(FileName, /*Value=*/0, XCOFF::ReservedSectionNum::N_DEBUG,
/*SymbolType=*/(LangID << 8) | CpuID, XCOFF::C_FILE,
/*NumberOfAuxEntries=*/0);
}

Expand Down
5 changes: 3 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-extern-weak.ll
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ declare extern_weak void @foo_ext_weak(ptr)
; CHECKSYM-NEXT: Name: <stdin>
; CHECKSYM-NEXT: Value (SymbolTableIndex): 0x0
; CHECKSYM-NEXT: Section: N_DEBUG
; CHECKSYM-NEXT: Source Language ID: TB_C (0x0)
; CHECKSYM-NEXT: CPU Version ID: 0x0
; CHECKSYM-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; CHECKSYM32-NEXT: CPU Version ID: TCPU_COM (0x3)
; CHECKSYM64-NEXT: CPU Version ID: TCPU_PPC64 (0x2)
; CHECKSYM-NEXT: StorageClass: C_FILE (0x67)
; CHECKSYM-NEXT: NumberOfAuxEntries: 0
; CHECKSYM-NEXT: }
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-extern.ll
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ declare i32 @bar_extern(ptr)
; CHECKSYM-NEXT: Name: <stdin>
; CHECKSYM-NEXT: Value (SymbolTableIndex): 0x0
; CHECKSYM-NEXT: Section: N_DEBUG
; CHECKSYM-NEXT: Source Language ID: TB_C (0x0)
; CHECKSYM-NEXT: CPU Version ID: 0x0
; CHECKSYM-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; CHECKSYM32-NEXT: CPU Version ID: TCPU_COM (0x3)
; CHECKSYM64-NEXT: CPU Version ID: TCPU_PPC64 (0x2)
; CHECKSYM-NEXT: StorageClass: C_FILE (0x67)
; CHECKSYM-NEXT: NumberOfAuxEntries: 0
; CHECKSYM-NEXT: }
Expand Down
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/PowerPC/aix-filename-c.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %s
; RUN: llvm-readobj --symbols %t.o | FileCheck --check-prefixes=OBJ,OBJ32 %s
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -filetype=obj -o %t64.o < %s
; RUN: llvm-readobj --symbols %t64.o | FileCheck --check-prefixes=OBJ,OBJ64 %s

source_filename = "1.c"

; OBJ: Name: 1.c
; OBJ: Source Language ID: TB_C (0x0)
; OBJ32: CPU Version ID: TCPU_COM (0x3)
; OBJ64: CPU Version ID: TCPU_PPC64 (0x2)
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/PowerPC/aix-filename-cpp.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %s
; RUN: llvm-readobj --symbols %t.o | FileCheck --check-prefixes=OBJ,OBJ32 %s
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -filetype=obj -o %t64.o < %s
; RUN: llvm-readobj --symbols %t64.o | FileCheck --check-prefixes=OBJ,OBJ64 %s

source_filename = "1.cpp"

; OBJ: Name: 1.cpp
; OBJ: Source Language ID: TB_CPLUSPLUS (0x9)
; OBJ32: CPU Version ID: TCPU_COM (0x3)
; OBJ64: CPU Version ID: TCPU_PPC64 (0x2)
11 changes: 11 additions & 0 deletions llvm/test/CodeGen/PowerPC/aix-filename-f.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -filetype=obj -o %t.o < %s
; RUN: llvm-readobj --symbols %t.o | FileCheck --check-prefixes=OBJ,OBJ32 %s
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -filetype=obj -o %t64.o < %s
; RUN: llvm-readobj --symbols %t64.o | FileCheck --check-prefixes=OBJ,OBJ64 %s

source_filename = "1.f95"

; OBJ: Name: 1.f95
; OBJ: Source Language ID: TB_Fortran (0x1)
; OBJ32: CPU Version ID: TCPU_COM (0x3)
; OBJ64: CPU Version ID: TCPU_PPC64 (0x2)
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-func-dsc-gen.ll
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ entry:
; CHECK-NEXT: Name: <stdin>
; CHECK-NEXT: Value (SymbolTableIndex): 0x0
; CHECK-NEXT: Section: N_DEBUG
; CHECK-NEXT: Source Language ID: TB_C (0x0)
; CHECK-NEXT: CPU Version ID: 0x0
; CHECK-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; CHECK-NEXT: CPU Version ID: TCPU_COM (0x3)
; CHECK-NEXT: StorageClass: C_FILE (0x67)
; CHECK-NEXT: NumberOfAuxEntries: 0
; CHECK-NEXT: }
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-llvm-intrinsic.ll
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ declare void @llvm.memset.p0.i32(ptr nocapture writeonly, i8, i32, i1 immarg)
; CHECKSYM-NEXT: Name: <stdin>
; CHECKSYM-NEXT: Value (SymbolTableIndex): 0x0
; CHECKSYM-NEXT: Section: N_DEBUG
; CHECKSYM-NEXT: Source Language ID: TB_C (0x0)
; CHECKSYM-NEXT: CPU Version ID: 0x0
; CHECKSYM-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; CHECKSYM32-NEXT: CPU Version ID: TCPU_COM (0x3)
; CHECKSYM64-NEXT: CPU Version ID: TCPU_PPC64 (0x2)
; CHECKSYM-NEXT: StorageClass: C_FILE (0x67)
; CHECKSYM-NEXT: NumberOfAuxEntries: 0
; CHECKSYM-NEXT: }
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc-large.ll
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ entry:
; SYM-NEXT: Name: <stdin>
; SYM-NEXT: Value (SymbolTableIndex): 0x0
; SYM-NEXT: Section: N_DEBUG
; SYM-NEXT: Source Language ID: TB_C (0x0)
; SYM-NEXT: CPU Version ID: 0x0
; SYM-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; SYM-NEXT: CPU Version ID: TCPU_COM (0x3)
; SYM-NEXT: StorageClass: C_FILE (0x67)
; SYM-NEXT: NumberOfAuxEntries: 0
; SYM-NEXT: }
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-tls-xcoff-reloc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ entry:
; SYM-NEXT: Name: <stdin>
; SYM-NEXT: Value (SymbolTableIndex): 0x0
; SYM-NEXT: Section: N_DEBUG
; SYM-NEXT: Source Language ID: TB_C (0x0)
; SYM-NEXT: CPU Version ID: 0x0
; SYM-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; SYM-NEXT: CPU Version ID: TCPU_COM (0x3)
; SYM-NEXT: StorageClass: C_FILE (0x67)
; SYM-NEXT: NumberOfAuxEntries: 0
; SYM-NEXT: }
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-tls-xcoff-variables.ll
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
; SYMS-NEXT: Name: <stdin>
; SYMS-NEXT: Value (SymbolTableIndex): 0x0
; SYMS-NEXT: Section: N_DEBUG
; SYMS-NEXT: Source Language ID: TB_C (0x0)
; SYMS-NEXT: CPU Version ID: 0x0
; SYMS-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; SYMS-NEXT: CPU Version ID: TCPU_COM (0x3)
; SYMS-NEXT: StorageClass: C_FILE (0x67)
; SYMS-NEXT: NumberOfAuxEntries: 0
; SYMS-NEXT: }
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-weak.ll
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ entry:
; CHECKSYM-NEXT: Name: <stdin>
; CHECKSYM-NEXT: Value (SymbolTableIndex): 0x0
; CHECKSYM-NEXT: Section: N_DEBUG
; CHECKSYM-NEXT: Source Language ID: TB_C (0x0)
; CHECKSYM-NEXT: CPU Version ID: 0x0
; CHECKSYM-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; CHECKSYM32-NEXT: CPU Version ID: TCPU_COM (0x3)
; CHECKSYM64-NEXT: CPU Version ID: TCPU_PPC64 (0x2)
; CHECKSYM-NEXT: StorageClass: C_FILE (0x67)
; CHECKSYM-NEXT: NumberOfAuxEntries: 0
; CHECKSYM-NEXT: }
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-data.ll
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,9 @@
; SYMS-NEXT: Name: <stdin>
; SYMS-NEXT: Value (SymbolTableIndex): 0x0
; SYMS-NEXT: Section: N_DEBUG
; SYMS-NEXT: Source Language ID: TB_C (0x0)
; SYMS-NEXT: CPU Version ID: 0x0
; SYMS-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; SYMS32-NEXT: CPU Version ID: TCPU_COM (0x3)
; SYMS64-NEXT: CPU Version ID: TCPU_PPC64 (0x2)
; SYMS-NEXT: StorageClass: C_FILE (0x67)
; SYMS-NEXT: NumberOfAuxEntries: 0
; SYMS-NEXT: }
Expand Down
5 changes: 3 additions & 2 deletions llvm/test/CodeGen/PowerPC/aix-xcoff-reloc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,9 @@ declare i32 @bar(i32)
; SYM-NEXT: Name: <stdin>
; SYM-NEXT: Value (SymbolTableIndex): 0x0
; SYM-NEXT: Section: N_DEBUG
; SYM-NEXT: Source Language ID: TB_C (0x0)
; SYM-NEXT: CPU Version ID: 0x0
; SYM-NEXT: Source Language ID: TB_CPLUSPLUS (0x9)
; SYM32-NEXT: CPU Version ID: TCPU_COM (0x3)
; SYM64-NEXT: CPU Version ID: TCPU_PPC64 (0x2)
; SYM-NEXT: StorageClass: C_FILE (0x67)
; SYM-NEXT: NumberOfAuxEntries: 0
; SYM-NEXT: }
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-readobj/XCOFFDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ static StringRef GetSymbolValueName(XCOFF::StorageClass SC) {
const EnumEntry<XCOFF::CFileLangId> CFileLangIdClass[] = {
#define ECase(X) \
{ #X, XCOFF::X }
ECase(TB_C), ECase(TB_CPLUSPLUS)
ECase(TB_C), ECase(TB_Fortran), ECase(TB_CPLUSPLUS)
#undef ECase
};

Expand Down

0 comments on commit 7761958

Please sign in to comment.