[Lldb-commits] [lldb] f416e57 - [lldb] Fix ppc64 detection in lldb

via lldb-commits lldb-commits at lists.llvm.org
Thu May 5 00:22:21 PDT 2022


Author: serge-sans-paille
Date: 2022-05-05T09:22:02+02:00
New Revision: f416e57339bd3315834e6c14d6476e63ccb363ff

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

LOG: [lldb] Fix ppc64 detection in lldb

Currently, ppc64le and ppc64 (defaulting to big endian) have the same
descriptor, thus the linear scan always return ppc64le. Handle that through
subtype.

This is a recommit of f114f009486816ed4b3bf984f0fbbb8fc80914f6 with a new test
setup that doesn't involves (unsupported) corefiles.

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

Added: 
    lldb/test/Shell/Breakpoint/Inputs/ppc64le-localentry.s
    lldb/test/Shell/Breakpoint/ppc64le-localentry.test

Modified: 
    lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
    lldb/source/Utility/ArchSpec.cpp
    lldb/test/Shell/Breakpoint/ppc64-localentry.test

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index 684d070c54d26..28ccfbe3d6e64 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -310,9 +310,19 @@ static uint32_t riscvVariantFromElfFlags(const elf::ELFHeader &header) {
   }
 }
 
+static uint32_t ppc64VariantFromElfFlags(const elf::ELFHeader &header) {
+  uint32_t endian = header.e_ident[EI_DATA];
+  if (endian == ELFDATA2LSB)
+    return ArchSpec::eCore_ppc64le_generic;
+  else
+    return ArchSpec::eCore_ppc64_generic;
+}
+
 static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) {
   if (header.e_machine == llvm::ELF::EM_MIPS)
     return mipsVariantFromElfFlags(header);
+  else if (header.e_machine == llvm::ELF::EM_PPC64)
+    return ppc64VariantFromElfFlags(header);
   else if (header.e_machine == llvm::ELF::EM_RISCV)
     return riscvVariantFromElfFlags(header);
 

diff  --git a/lldb/source/Utility/ArchSpec.cpp b/lldb/source/Utility/ArchSpec.cpp
index 963005b5cdfa7..c6feacfc7c1e6 100644
--- a/lldb/source/Utility/ArchSpec.cpp
+++ b/lldb/source/Utility/ArchSpec.cpp
@@ -358,10 +358,10 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = {
      0xFFFFFFFFu, 0xFFFFFFFFu}, // Intel MCU // FIXME: is this correct?
     {ArchSpec::eCore_ppc_generic, llvm::ELF::EM_PPC, LLDB_INVALID_CPUTYPE,
      0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC
-    {ArchSpec::eCore_ppc64le_generic, llvm::ELF::EM_PPC64, LLDB_INVALID_CPUTYPE,
-     0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC64le
-    {ArchSpec::eCore_ppc64_generic, llvm::ELF::EM_PPC64, LLDB_INVALID_CPUTYPE,
-     0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC64
+    {ArchSpec::eCore_ppc64le_generic, llvm::ELF::EM_PPC64,
+     ArchSpec::eCore_ppc64le_generic, 0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC64le
+    {ArchSpec::eCore_ppc64_generic, llvm::ELF::EM_PPC64,
+     ArchSpec::eCore_ppc64_generic, 0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC64
     {ArchSpec::eCore_arm_generic, llvm::ELF::EM_ARM, LLDB_INVALID_CPUTYPE,
      0xFFFFFFFFu, 0xFFFFFFFFu}, // ARM
     {ArchSpec::eCore_arm_aarch64, llvm::ELF::EM_AARCH64, LLDB_INVALID_CPUTYPE,
@@ -400,8 +400,8 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = {
      LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu}, // HEXAGON
     {ArchSpec::eCore_arc, llvm::ELF::EM_ARC_COMPACT2, LLDB_INVALID_CPUTYPE,
      0xFFFFFFFFu, 0xFFFFFFFFu}, // ARC
-    {ArchSpec::eCore_avr, llvm::ELF::EM_AVR, LLDB_INVALID_CPUTYPE,
-     0xFFFFFFFFu, 0xFFFFFFFFu}, // AVR
+    {ArchSpec::eCore_avr, llvm::ELF::EM_AVR, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu,
+     0xFFFFFFFFu}, // AVR
     {ArchSpec::eCore_riscv32, llvm::ELF::EM_RISCV,
      ArchSpec::eRISCVSubType_riscv32, 0xFFFFFFFFu, 0xFFFFFFFFu}, // riscv32
     {ArchSpec::eCore_riscv64, llvm::ELF::EM_RISCV,

diff  --git a/lldb/test/Shell/Breakpoint/Inputs/ppc64le-localentry.s b/lldb/test/Shell/Breakpoint/Inputs/ppc64le-localentry.s
new file mode 100644
index 0000000000000..5fe0a97d06d38
--- /dev/null
+++ b/lldb/test/Shell/Breakpoint/Inputs/ppc64le-localentry.s
@@ -0,0 +1,55 @@
+	.text
+	.abiversion 2
+
+	.globl	lfunc
+	.p2align	4
+	.type	lfunc, at function
+lfunc:                                  # @lfunc
+.Lfunc_begin0:
+.Lfunc_gep0:
+	addis 2, 12, .TOC.-.Lfunc_gep0 at ha
+	addi 2, 2, .TOC.-.Lfunc_gep0 at l
+.Lfunc_lep0:
+	.localentry	lfunc, .Lfunc_lep0-.Lfunc_gep0
+# BB#0:
+	mr 4, 3
+	addis 3, 2, .LC0 at toc@ha
+	ld 3, .LC0 at toc@l(3)
+	stw 4, -12(1)
+	lwz 4, 0(3)
+	lwz 5, -12(1)
+	mullw 4, 4, 5
+	extsw 3, 4
+	blr
+	.long	0
+	.quad	0
+.Lfunc_end0:
+	.size	lfunc, .Lfunc_end0-.Lfunc_begin0
+
+	.globl	simple
+	.p2align	4
+	.type	simple, at function
+simple:                                 # @simple
+.Lfunc_begin1:
+# %bb.0:                                # %entry
+	mr 4, 3
+	stw 4, -12(1)
+	lwz 4, -12(1)
+	mulli 4, 4, 10
+	extsw 3, 4
+	blr
+	.long	0
+	.quad	0
+.Lfunc_end1:
+	.size	simple, .Lfunc_end1-.Lfunc_begin1
+
+	.section	.toc,"aw", at progbits
+.LC0:
+	.tc g_foo[TC],g_foo
+	.type	g_foo, at object           # @g_foo
+	.data
+	.globl	g_foo
+	.p2align	2
+g_foo:
+	.long	2                       # 0x2
+	.size	g_foo, 4

diff  --git a/lldb/test/Shell/Breakpoint/ppc64-localentry.test b/lldb/test/Shell/Breakpoint/ppc64-localentry.test
index 16cce703045c6..ed4e64dfb45ab 100644
--- a/lldb/test/Shell/Breakpoint/ppc64-localentry.test
+++ b/lldb/test/Shell/Breakpoint/ppc64-localentry.test
@@ -1,6 +1,6 @@
 # REQUIRES: powerpc
 #
-# RUN: llvm-mc -triple=powerpc64le -filetype=obj %p/Inputs/ppc64-localentry.s -o %t
+# RUN: llvm-mc -triple=powerpc64 -filetype=obj %p/Inputs/ppc64-localentry.s -o %t
 # RUN: lldb-test breakpoints %t %s | FileCheck %s
 
 breakpoint set -n lfunc

diff  --git a/lldb/test/Shell/Breakpoint/ppc64le-localentry.test b/lldb/test/Shell/Breakpoint/ppc64le-localentry.test
new file mode 100644
index 0000000000000..e5a7a6b3baf1b
--- /dev/null
+++ b/lldb/test/Shell/Breakpoint/ppc64le-localentry.test
@@ -0,0 +1,12 @@
+# REQUIRES: powerpc
+#
+# RUN: llvm-mc -triple=powerpc64le -filetype=obj %p/Inputs/ppc64le-localentry.s -o %t
+# RUN: lldb-test breakpoints %t %s | FileCheck %s
+
+breakpoint set -n lfunc
+# CHECK-LABEL: breakpoint set -n lfunc
+# CHECK: Address: {{.*}}`lfunc + 8
+
+breakpoint set -n simple
+# CHECK-LABEL: breakpoint set -n simple
+# CHECK: Address: {{.*}}`simple


        


More information about the lldb-commits mailing list