[llvm] c06a314 - [CSKY] Make mapping symbols SF_FormatSpecific
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 27 20:37:47 PDT 2023
Author: Fangrui Song
Date: 2023-07-27T20:37:43-07:00
New Revision: c06a314150cc8fa43d70282e7609e0248fa3da05
URL: https://github.com/llvm/llvm-project/commit/c06a314150cc8fa43d70282e7609e0248fa3da05
DIFF: https://github.com/llvm/llvm-project/commit/c06a314150cc8fa43d70282e7609e0248fa3da05.diff
LOG: [CSKY] Make mapping symbols SF_FormatSpecific
and omit them from llvm-nm output unless --special-syms is specified,
similar to ARM and AArch64.
This is a prerequisite of D156190 as llvm-objdump will only perform
mapping symbol recognition for SF_FormatSpecific symbols.
Added:
llvm/test/DebugInfo/Symbolize/ELF/csky-mapping-symbol.s
llvm/test/tools/llvm-nm/CSKY/lit.local.cfg
llvm/test/tools/llvm-nm/CSKY/special-syms.test
Modified:
llvm/include/llvm/Object/ELFObjectFile.h
llvm/tools/llvm-nm/llvm-nm.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h
index f3016cc141b0ed..e57ece5443e846 100644
--- a/llvm/include/llvm/Object/ELFObjectFile.h
+++ b/llvm/include/llvm/Object/ELFObjectFile.h
@@ -761,6 +761,15 @@ Expected<uint32_t> ELFObjectFile<ELFT>::getSymbolFlags(DataRefImpl Sym) const {
}
if (ESym->getType() == ELF::STT_FUNC && (ESym->st_value & 1) == 1)
Result |= SymbolRef::SF_Thumb;
+ } else if (EF.getHeader().e_machine == ELF::EM_CSKY) {
+ if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
+ StringRef Name = *NameOrErr;
+ if (Name.startswith("$d") || Name.startswith("$t"))
+ Result |= SymbolRef::SF_FormatSpecific;
+ } else {
+ // TODO: Actually report errors helpfully.
+ consumeError(NameOrErr.takeError());
+ }
} else if (EF.getHeader().e_machine == ELF::EM_RISCV) {
if (Expected<StringRef> NameOrErr = getSymbolName(Sym)) {
// Mark empty name symbols used for label
diff erences.
diff --git a/llvm/test/DebugInfo/Symbolize/ELF/csky-mapping-symbol.s b/llvm/test/DebugInfo/Symbolize/ELF/csky-mapping-symbol.s
new file mode 100644
index 00000000000000..d1cab1250636d8
--- /dev/null
+++ b/llvm/test/DebugInfo/Symbolize/ELF/csky-mapping-symbol.s
@@ -0,0 +1,31 @@
+# REQUIRES: csky-registered-target
+## Ignore CSKY mapping symbols (with a prefix of $d or $t).
+
+# RUN: llvm-mc -filetype=obj -triple=csky %s -o %t
+
+## Verify that mapping symbols are actually present in the object at expected
+## addresses.
+# RUN: llvm-nm --special-syms %t | FileCheck %s -check-prefix MAPPING_SYM
+
+# MAPPING_SYM: 00000000 t $d.0
+# MAPPING_SYM-NEXT: 00000008 t $d.2
+# MAPPING_SYM-NEXT: 00000004 t $t.1
+# MAPPING_SYM-NEXT: 00000000 T foo
+
+# RUN: llvm-symbolizer --obj=%t 0 4 0xc | FileCheck %s -check-prefix SYMBOL
+
+# SYMBOL: foo
+# SYMBOL-NEXT: ??:0:0
+# SYMBOL-EMPTY:
+# SYMBOL: foo
+# SYMBOL-NEXT: ??:0:0
+# SYMBOL-EMPTY:
+# SYMBOL: foo
+# SYMBOL-NEXT: ??:0:0
+
+.globl foo
+foo:
+ .long 32
+ nop
+ nop
+ .long 42
diff --git a/llvm/test/tools/llvm-nm/CSKY/lit.local.cfg b/llvm/test/tools/llvm-nm/CSKY/lit.local.cfg
new file mode 100644
index 00000000000000..f87c9bbe30352c
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/CSKY/lit.local.cfg
@@ -0,0 +1,2 @@
+if "CSKY" not in config.root.targets:
+ config.unsupported = True
diff --git a/llvm/test/tools/llvm-nm/CSKY/special-syms.test b/llvm/test/tools/llvm-nm/CSKY/special-syms.test
new file mode 100644
index 00000000000000..b557ff0ac1a7bf
--- /dev/null
+++ b/llvm/test/tools/llvm-nm/CSKY/special-syms.test
@@ -0,0 +1,23 @@
+# RUN: yaml2obj %s -o %t
+# RUN: llvm-nm %t | count 0
+# RUN: llvm-nm --special-syms %t | FileCheck %s
+
+!ELF
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_CSKY
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+Symbols:
+ - Name: $d.1
+ Section: .text
+ - Name: $t.1
+ Section: .text
+
+# CHECK: 00000000 t $d.1
+# CHECK: 00000000 t $t.1
diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp
index 1f6a5d1ab806eb..809641c8de34d9 100644
--- a/llvm/tools/llvm-nm/llvm-nm.cpp
+++ b/llvm/tools/llvm-nm/llvm-nm.cpp
@@ -1802,9 +1802,12 @@ static bool getSymbolNamesFromObject(SymbolicFile &Obj,
// are used to repesent mapping symbols and needed to honor the
// --special-syms option.
auto *ELFObj = dyn_cast<ELFObjectFileBase>(&Obj);
- if ((!ELFObj || (ELFObj->getEMachine() != ELF::EM_ARM &&
- ELFObj->getEMachine() != ELF::EM_AARCH64)) &&
- !DebugSyms && (*SymFlagsOrErr & SymbolRef::SF_FormatSpecific))
+ bool HasMappingSymbol =
+ ELFObj &&
+ llvm::is_contained({ELF::EM_ARM, ELF::EM_AARCH64, ELF::EM_CSKY},
+ ELFObj->getEMachine());
+ if (!HasMappingSymbol && !DebugSyms &&
+ (*SymFlagsOrErr & SymbolRef::SF_FormatSpecific))
continue;
if (WithoutAliases && (*SymFlagsOrErr & SymbolRef::SF_Indirect))
continue;
More information about the llvm-commits
mailing list