[llvm] [llvm-readobj] enable demangle option for the xcoff object file (PR #78455)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 11:05:50 PST 2024
https://github.com/diggerlin updated https://github.com/llvm/llvm-project/pull/78455
>From 95bd9a2af50ea3a011d7d2c0b5c4dd66b3b867cd Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Wed, 17 Jan 2024 10:02:35 -0500
Subject: [PATCH 1/3] enable demanlge option for the llvm-readobj
---
.../tools/llvm-readobj/XCOFF/loader-section-symbol.test | 9 +++++++--
llvm/test/tools/llvm-readobj/XCOFF/symbols.test | 8 +++++---
llvm/tools/llvm-readobj/XCOFFDumper.cpp | 6 ++++--
3 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/llvm/test/tools/llvm-readobj/XCOFF/loader-section-symbol.test b/llvm/test/tools/llvm-readobj/XCOFF/loader-section-symbol.test
index 8f2b20ca814963..f899865e601cac 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/loader-section-symbol.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/loader-section-symbol.test
@@ -6,10 +6,14 @@
# RUN: llvm-readobj --loader-section-symbols %t_xcoff32.o |\
# RUN: FileCheck %s --check-prefixes=CHECK32
+# RUN: llvm-readobj --loader-section-symbols --demangle %t_xcoff32.o |\
+# RUN: FileCheck %s --check-prefixes=CHECK32
# RUN: llvm-readobj --loader-section-symbols %t_xcoff32_invalid.o 2>&1 |\
# RUN: FileCheck -DFILE=%t_xcoff32_invalid.o %s --check-prefixes=CHECK32,WARN
# RUN: llvm-readobj --loader-section-symbols %t_xcoff64.o |\
-# RUN: FileCheck %s --check-prefixes=CHECK64
+# RUN: FileCheck %s --check-prefixes=CHECK64,NODEMAN64
+# RUN: llvm-readobj --loader-section-symbols --demangle %t_xcoff64.o |\
+# RUN: FileCheck %s --check-prefixes=CHECK64,DEMAN64
--- !XCOFF
FileHeader:
@@ -112,7 +116,8 @@ Sections:
# CHECK64-NEXT: ParameterTypeCheck: 0
# CHECK64-NEXT: }
# CHECK64-NEXT: Symbol {
-# CHECK64-NEXT: Name: _Z5func0v
+# NODEMAN64-NEXT: Name: _Z5func0v
+# DEMAN64-NEXT: Name: func0()
# CHECK64-NEXT: Virtual Address: 0x110000308
# CHECK64-NEXT: SectionNum: 2
# CHECK64-NEXT: SymbolType: 0x11
diff --git a/llvm/test/tools/llvm-readobj/XCOFF/symbols.test b/llvm/test/tools/llvm-readobj/XCOFF/symbols.test
index 72ec8967cc9576..6ba2fbab0ba837 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/symbols.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/symbols.test
@@ -2,7 +2,8 @@
## 32-bit XCOFF object file.
# RUN: yaml2obj %s -o %t
-# RUN: llvm-readobj --symbols %t | FileCheck --check-prefix=SYMBOL32 %s
+# RUN: llvm-readobj --symbols %t | FileCheck --check-prefixes=SYMBOL32,NODEMANGLE %s
+# RUN: llvm-readobj --symbols --demangle %t | FileCheck --check-prefixes=SYMBOL32,DEMANGLE %s
--- !XCOFF
FileHeader:
@@ -56,7 +57,7 @@ Symbols:
StabInfoIndex: 5
StabSectNum: 6
## The C_EXT symbol with a CSECT auxiliary entry.
- - Name: .fun1
+ - Name: ._Z5func1i
Value: 0x0
Section: .text
Type: 0x20
@@ -224,7 +225,8 @@ Symbols:
# SYMBOL32-NEXT: }
# SYMBOL32-NEXT: Symbol {
# SYMBOL32-NEXT: Index: 8
-# SYMBOL32-NEXT: Name: .fun1
+# NODEMANGLE-NEXT: Name: ._Z5func1i
+# DEMANGLE-NEXT: Name: .func1(int)
# SYMBOL32-NEXT: Value (RelocatableAddress): 0x0
# SYMBOL32-NEXT: Section: .text
# SYMBOL32-NEXT: Type: 0x20
diff --git a/llvm/tools/llvm-readobj/XCOFFDumper.cpp b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
index 8ebd670d5d56af..5816ac5856ee9e 100644
--- a/llvm/tools/llvm-readobj/XCOFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
@@ -13,6 +13,7 @@
#include "ObjDumper.h"
#include "llvm-readobj.h"
#include "llvm/Object/XCOFFObjectFile.h"
+#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/ScopedPrinter.h"
@@ -250,7 +251,8 @@ void XCOFFDumper::printLoaderSectionSymbolsHelper(uintptr_t LoaderSectionAddr) {
}
DictScope DS(W, "Symbol");
- W.printString("Name", SymbolNameOrErr.get());
+ StringRef SymbolName = SymbolNameOrErr.get();
+ W.printString("Name", opts::Demangle ? demangle(SymbolName) : SymbolName);
W.printHex("Virtual Address", LoadSecSymEntPtr->Value);
W.printNumber("SectionNum", LoadSecSymEntPtr->SectionNumber);
W.printHex("SymbolType", LoadSecSymEntPtr->SymbolType);
@@ -752,7 +754,7 @@ void XCOFFDumper::printSymbol(const SymbolRef &S) {
XCOFF::StorageClass SymbolClass = SymbolEntRef.getStorageClass();
W.printNumber("Index", SymbolIdx);
- W.printString("Name", SymbolName);
+ W.printString("Name", opts::Demangle ? demangle(SymbolName) : SymbolName);
W.printHex(GetSymbolValueName(SymbolClass), SymbolEntRef.getValue());
StringRef SectionName =
>From 38126d53fdb24df45a6c60f05d29eae62702f2cd Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Wed, 17 Jan 2024 10:20:51 -0500
Subject: [PATCH 2/3] run git clang format
---
llvm/tools/llvm-readobj/XCOFFDumper.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/tools/llvm-readobj/XCOFFDumper.cpp b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
index 5816ac5856ee9e..453d231e44d211 100644
--- a/llvm/tools/llvm-readobj/XCOFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
@@ -12,8 +12,8 @@
#include "ObjDumper.h"
#include "llvm-readobj.h"
-#include "llvm/Object/XCOFFObjectFile.h"
#include "llvm/Demangle/Demangle.h"
+#include "llvm/Object/XCOFFObjectFile.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/ScopedPrinter.h"
>From fd0f6eac6cf6e4dc632f6b625346aa466b0fa9b5 Mon Sep 17 00:00:00 2001
From: zhijian <zhijian at ca.ibm.com>
Date: Wed, 17 Jan 2024 14:05:36 -0500
Subject: [PATCH 3/3] enable --demangle for symbol name in relocation for xcoff
---
.../XCOFF/loader-section-relocation.test | 27 ++++++++++++-------
.../tools/llvm-readobj/XCOFF/relocations.test | 17 ++++++++----
llvm/tools/llvm-readobj/XCOFFDumper.cpp | 16 ++++++-----
3 files changed, 39 insertions(+), 21 deletions(-)
diff --git a/llvm/test/tools/llvm-readobj/XCOFF/loader-section-relocation.test b/llvm/test/tools/llvm-readobj/XCOFF/loader-section-relocation.test
index 42eb897d073939..f0423914d184ce 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/loader-section-relocation.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/loader-section-relocation.test
@@ -2,18 +2,22 @@
# RUN: yaml2obj --docnum=1 %s -o %t_xcoff32.o
# RUN: yaml2obj --docnum=2 %s -o %t_xcoff64.o
-# RUN: llvm-readobj --loader-section-relocations --expand-relocs %t_xcoff32.o | FileCheck --check-prefixes=COMMON,EXPAND %s
-# RUN: llvm-readobj --loader-section-relocations --expand-relocs %t_xcoff64.o | FileCheck --check-prefixes=COMMON,EXPAND %s
-# RUN: llvm-readobj --loader-section-relocations %t_xcoff32.o | FileCheck --check-prefixes=COMMON,NOEXPAND32 %s
-# RUN: llvm-readobj --loader-section-relocations %t_xcoff64.o | FileCheck --check-prefixes=COMMON,NOEXPAND64 %s
+# RUN: llvm-readobj --loader-section-relocations --expand-relocs %t_xcoff32.o | FileCheck --check-prefixes=COMMON,EXPAND,NODEMANEXP %s
+# RUN: llvm-readobj --loader-section-relocations --expand-relocs %t_xcoff64.o | FileCheck --check-prefixes=COMMON,EXPAND,NODEMANEXP %s
+# RUN: llvm-readobj --loader-section-relocations %t_xcoff32.o | FileCheck --check-prefixes=COMMON,NOEXPAND32,NODEMAN32 %s
+# RUN: llvm-readobj --loader-section-relocations %t_xcoff64.o | FileCheck --check-prefixes=COMMON,NOEXPAND64,NODEMAN64 %s
+# RUN: llvm-readobj --loader-section-relocations --expand-relocs --demangle %t_xcoff32.o | FileCheck --check-prefixes=COMMON,EXPAND,DEMANEXP %s
+# RUN: llvm-readobj --loader-section-relocations --expand-relocs --demangle %t_xcoff64.o | FileCheck --check-prefixes=COMMON,EXPAND,DEMANEXP %s
+# RUN: llvm-readobj --loader-section-relocations --demangle %t_xcoff32.o | FileCheck --check-prefixes=COMMON,NOEXPAND32,DEMAN32 %s
+# RUN: llvm-readobj --loader-section-relocations --demangle %t_xcoff64.o | FileCheck --check-prefixes=COMMON,NOEXPAND64,DEMAN64 %s
--- !XCOFF
FileHeader:
MagicNumber: 0x1DF
Sections:
- Name: .loader
Flags: [ STYP_LOADER ]
- SectionData: "0000000100000001000000020000016D00000001000000A400000000000000506d79696e747661722000028000021105000000000000000020000294000000011f0000022000029c000000031f000002"
+ SectionData: "0000000100000001000000020000016D00000001000000A400000000000000505f5a3466756e63762000028000021105000000000000000020000294000000011f0000022000029c000000031f000002"
## ^------- -Version=1
## ^------- -NumberOfSymbolEntries=1
## ^------- -NumberOfRelocationEntries=2
@@ -22,7 +26,7 @@ Sections:
## ^------- -OffsetToImportFileIDs=0xA4
## ^------- -LengthOfStringTable=0
## ^------- -OffsetToStringTable=0
-## ^--------------- SymbolName=myintvar
+## ^--------------- SymbolName=_Z4funcv
## ^------- Value=0x20000280
## ^--- sectionNumber = 2
## ^- SymbolType=0x11
@@ -44,7 +48,7 @@ FileHeader:
Sections:
- Name: .loader
Flags: [ STYP_LOADER ]
- SectionData: "0000000200000001000000020000016D000000010000001200000000000000D000000000000000700000000000000038000000000000005000000001100003000000000200021105000000000000000000000000200002941f00000200000001000000002000029C1f0000020000000300096d79696e747661720000"
+ SectionData: "0000000200000001000000020000016D000000010000001200000000000000D000000000000000700000000000000038000000000000005000000001100003000000000200021105000000000000000000000000200002941f00000200000001000000002000029C1f0000020000000300095f5a3466756e63760000"
## ^------- -Version=2
## ^------- -NumberOfSymbolEntries=1
## ^------- -NumberOfRelocationEntries=2
@@ -76,10 +80,12 @@ Sections:
# COMMON-NEXT: Loader Section Relocations {
# NOEXPAND64-NEXT: Vaddr Type SecNum SymbolName (Index)
# NOEXPAND64-NEXT: 0x0000000020000294 0x1f00 (R_POS) 2 .data (1)
-# NOEXPAND64-NEXT: 0x000000002000029c 0x1f00 (R_POS) 2 myintvar (3)
+# NODEMAN64-NEXT: 0x000000002000029c 0x1f00 (R_POS) 2 _Z4funcv (3)
+# DEMAN64-NEXT: 0x000000002000029c 0x1f00 (R_POS) 2 func() (3)
# NOEXPAND32-NEXT: Vaddr Type SecNum SymbolName (Index)
# NOEXPAND32-NEXT: 0x20000294 0x1f00 (R_POS) 2 .data (1)
-# NOEXPAND32-NEXT: 0x2000029c 0x1f00 (R_POS) 2 myintvar (3)
+# NODEMAN32-NEXT: 0x2000029c 0x1f00 (R_POS) 2 _Z4funcv (3)
+# DEMAN32-NEXT: 0x2000029c 0x1f00 (R_POS) 2 func() (3)
# EXPAND-NEXT: Relocation {
# EXPAND-NEXT: Virtual Address: 0x20000294
# EXPAND-NEXT: Symbol: .data (1)
@@ -91,7 +97,8 @@ Sections:
# EXPAND-NEXT: }
# EXPAND-NEXT: Relocation {
# EXPAND-NEXT: Virtual Address: 0x2000029C
-# EXPAND-NEXT: Symbol: myintvar (3)
+# NODEMANEXP-NEXT: Symbol: _Z4funcv (3)
+# DEMANEXP-NEXT: Symbol: func() (3)
# EXPAND-NEXT: IsSigned: No
# EXPAND-NEXT: FixupBitValue: 0
# EXPAND-NEXT: Length: 32
diff --git a/llvm/test/tools/llvm-readobj/XCOFF/relocations.test b/llvm/test/tools/llvm-readobj/XCOFF/relocations.test
index 9e327c4fbbdccd..e80a9abc34861a 100644
--- a/llvm/test/tools/llvm-readobj/XCOFF/relocations.test
+++ b/llvm/test/tools/llvm-readobj/XCOFF/relocations.test
@@ -2,9 +2,14 @@
# RUN: yaml2obj %s -o %t
# RUN: llvm-readobj --relocs --expand-relocs %t | \
-# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefix=RELOCSEXP
+# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefixes=RELOCSEXP,NODEMANEXP
# RUN: llvm-readobj --relocs %t | \
-# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefix=RELOCS
+# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefixes=RELOCS,NODEMAN
+
+# RUN: llvm-readobj --relocs --expand-relocs --demangle %t | \
+# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefixes=RELOCSEXP,DEMANEXP
+# RUN: llvm-readobj --relocs --demangle %t | \
+# RUN: FileCheck %s --strict-whitespace --match-full-lines --check-prefixes=RELOCS,DEMAN
# RELOCSEXP:Relocations [
# RELOCSEXP-NEXT: Section (index: 1) .text {
@@ -28,7 +33,8 @@
# RELOCSEXP-NEXT: Section (index: 2) .data {
# RELOCSEXP-NEXT: Relocation {
# RELOCSEXP-NEXT: Virtual Address: 0x200
-# RELOCSEXP-NEXT: Symbol: bar (1)
+# NODEMANEXP-NEXT: Symbol: _Z3fwpv (1)
+# DEMANEXP-NEXT: Symbol: fwp() (1)
# RELOCSEXP-NEXT: IsSigned: No
# RELOCSEXP-NEXT: FixupBitValue: 0
# RELOCSEXP-NEXT: Length: 20
@@ -43,7 +49,8 @@
# RELOCS-NEXT: 0x100 R_REL foo(0) 0x14
# RELOCS-NEXT: }
# RELOCS-NEXT: Section (index: 2) .data {
-# RELOCS-NEXT: 0x200 R_TOC bar(1) 0x13
+# NODEMAN-NEXT: 0x200 R_TOC _Z3fwpv(1) 0x13
+# DEMAN-NEXT: 0x200 R_TOC fwp()(1) 0x13
# RELOCS-NEXT: }
# RELOCS-NEXT:]
@@ -73,6 +80,6 @@ Symbols:
- Name: foo
Value: 0x0
Section: .text
- - Name: bar
+ - Name: _Z3fwpv
Value: 0x80
Section: .data
diff --git a/llvm/tools/llvm-readobj/XCOFFDumper.cpp b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
index 453d231e44d211..ef9af8f3169fd0 100644
--- a/llvm/tools/llvm-readobj/XCOFFDumper.cpp
+++ b/llvm/tools/llvm-readobj/XCOFFDumper.cpp
@@ -328,7 +328,8 @@ void XCOFFDumper::printLoaderSectionRelocationEntry(
uint8_t Info = Type >> 8;
W.printHex("Virtual Address", LoaderSecRelEntPtr->VirtualAddr);
- W.printNumber("Symbol", SymbolName, LoaderSecRelEntPtr->SymbolIndex);
+ W.printNumber("Symbol", opts::Demangle ? demangle(SymbolName) : SymbolName,
+ LoaderSecRelEntPtr->SymbolIndex);
W.printString("IsSigned", IsRelocationSigned(Info) ? "Yes" : "No");
W.printNumber("FixupBitValue", IsFixupIndicated(Info) ? 1 : 0);
W.printNumber("Length", GetRelocatedLength(Info));
@@ -342,8 +343,9 @@ void XCOFFDumper::printLoaderSectionRelocationEntry(
<< XCOFF::getRelocationTypeString(
static_cast<XCOFF::RelocationType>(Type))
<< ")" << format_decimal(LoaderSecRelEntPtr->SectionNum, 8)
- << " " << SymbolName << " ("
- << LoaderSecRelEntPtr->SymbolIndex << ")\n";
+ << " "
+ << (opts::Demangle ? demangle(SymbolName) : SymbolName)
+ << " (" << LoaderSecRelEntPtr->SymbolIndex << ")\n";
}
}
@@ -468,15 +470,17 @@ template <typename RelTy> void XCOFFDumper::printRelocation(RelTy Reloc) {
if (opts::ExpandRelocs) {
DictScope Group(W, "Relocation");
W.printHex("Virtual Address", Reloc.VirtualAddress);
- W.printNumber("Symbol", SymbolName, Reloc.SymbolIndex);
+ W.printNumber("Symbol", opts::Demangle ? demangle(SymbolName) : SymbolName,
+ Reloc.SymbolIndex);
W.printString("IsSigned", Reloc.isRelocationSigned() ? "Yes" : "No");
W.printNumber("FixupBitValue", Reloc.isFixupIndicated() ? 1 : 0);
W.printNumber("Length", Reloc.getRelocatedLength());
W.printEnum("Type", (uint8_t)Reloc.Type, ArrayRef(RelocationTypeNameclass));
} else {
raw_ostream &OS = W.startLine();
- OS << W.hex(Reloc.VirtualAddress) << " " << RelocName << " " << SymbolName
- << "(" << Reloc.SymbolIndex << ") " << W.hex(Reloc.Info) << "\n";
+ OS << W.hex(Reloc.VirtualAddress) << " " << RelocName << " "
+ << (opts::Demangle ? demangle(SymbolName) : SymbolName) << "("
+ << Reloc.SymbolIndex << ") " << W.hex(Reloc.Info) << "\n";
}
}
More information about the llvm-commits
mailing list