Skip to content

Commit f416e57

Browse files
author
serge-sans-paille
committed
[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 f114f00 with a new test setup that doesn't involves (unsupported) corefiles. Differential Revision: https://reviews.llvm.org/D124760
1 parent 405bf90 commit f416e57

File tree

5 files changed

+84
-7
lines changed

5 files changed

+84
-7
lines changed

lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,19 @@ static uint32_t riscvVariantFromElfFlags(const elf::ELFHeader &header) {
310310
}
311311
}
312312

313+
static uint32_t ppc64VariantFromElfFlags(const elf::ELFHeader &header) {
314+
uint32_t endian = header.e_ident[EI_DATA];
315+
if (endian == ELFDATA2LSB)
316+
return ArchSpec::eCore_ppc64le_generic;
317+
else
318+
return ArchSpec::eCore_ppc64_generic;
319+
}
320+
313321
static uint32_t subTypeFromElfHeader(const elf::ELFHeader &header) {
314322
if (header.e_machine == llvm::ELF::EM_MIPS)
315323
return mipsVariantFromElfFlags(header);
324+
else if (header.e_machine == llvm::ELF::EM_PPC64)
325+
return ppc64VariantFromElfFlags(header);
316326
else if (header.e_machine == llvm::ELF::EM_RISCV)
317327
return riscvVariantFromElfFlags(header);
318328

lldb/source/Utility/ArchSpec.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,10 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = {
358358
0xFFFFFFFFu, 0xFFFFFFFFu}, // Intel MCU // FIXME: is this correct?
359359
{ArchSpec::eCore_ppc_generic, llvm::ELF::EM_PPC, LLDB_INVALID_CPUTYPE,
360360
0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC
361-
{ArchSpec::eCore_ppc64le_generic, llvm::ELF::EM_PPC64, LLDB_INVALID_CPUTYPE,
362-
0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC64le
363-
{ArchSpec::eCore_ppc64_generic, llvm::ELF::EM_PPC64, LLDB_INVALID_CPUTYPE,
364-
0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC64
361+
{ArchSpec::eCore_ppc64le_generic, llvm::ELF::EM_PPC64,
362+
ArchSpec::eCore_ppc64le_generic, 0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC64le
363+
{ArchSpec::eCore_ppc64_generic, llvm::ELF::EM_PPC64,
364+
ArchSpec::eCore_ppc64_generic, 0xFFFFFFFFu, 0xFFFFFFFFu}, // PowerPC64
365365
{ArchSpec::eCore_arm_generic, llvm::ELF::EM_ARM, LLDB_INVALID_CPUTYPE,
366366
0xFFFFFFFFu, 0xFFFFFFFFu}, // ARM
367367
{ArchSpec::eCore_arm_aarch64, llvm::ELF::EM_AARCH64, LLDB_INVALID_CPUTYPE,
@@ -400,8 +400,8 @@ static const ArchDefinitionEntry g_elf_arch_entries[] = {
400400
LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu, 0xFFFFFFFFu}, // HEXAGON
401401
{ArchSpec::eCore_arc, llvm::ELF::EM_ARC_COMPACT2, LLDB_INVALID_CPUTYPE,
402402
0xFFFFFFFFu, 0xFFFFFFFFu}, // ARC
403-
{ArchSpec::eCore_avr, llvm::ELF::EM_AVR, LLDB_INVALID_CPUTYPE,
404-
0xFFFFFFFFu, 0xFFFFFFFFu}, // AVR
403+
{ArchSpec::eCore_avr, llvm::ELF::EM_AVR, LLDB_INVALID_CPUTYPE, 0xFFFFFFFFu,
404+
0xFFFFFFFFu}, // AVR
405405
{ArchSpec::eCore_riscv32, llvm::ELF::EM_RISCV,
406406
ArchSpec::eRISCVSubType_riscv32, 0xFFFFFFFFu, 0xFFFFFFFFu}, // riscv32
407407
{ArchSpec::eCore_riscv64, llvm::ELF::EM_RISCV,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.text
2+
.abiversion 2
3+
4+
.globl lfunc
5+
.p2align 4
6+
.type lfunc,@function
7+
lfunc: # @lfunc
8+
.Lfunc_begin0:
9+
.Lfunc_gep0:
10+
addis 2, 12, .TOC.-.Lfunc_gep0@ha
11+
addi 2, 2, .TOC.-.Lfunc_gep0@l
12+
.Lfunc_lep0:
13+
.localentry lfunc, .Lfunc_lep0-.Lfunc_gep0
14+
# BB#0:
15+
mr 4, 3
16+
addis 3, 2, .LC0@toc@ha
17+
ld 3, .LC0@toc@l(3)
18+
stw 4, -12(1)
19+
lwz 4, 0(3)
20+
lwz 5, -12(1)
21+
mullw 4, 4, 5
22+
extsw 3, 4
23+
blr
24+
.long 0
25+
.quad 0
26+
.Lfunc_end0:
27+
.size lfunc, .Lfunc_end0-.Lfunc_begin0
28+
29+
.globl simple
30+
.p2align 4
31+
.type simple,@function
32+
simple: # @simple
33+
.Lfunc_begin1:
34+
# %bb.0: # %entry
35+
mr 4, 3
36+
stw 4, -12(1)
37+
lwz 4, -12(1)
38+
mulli 4, 4, 10
39+
extsw 3, 4
40+
blr
41+
.long 0
42+
.quad 0
43+
.Lfunc_end1:
44+
.size simple, .Lfunc_end1-.Lfunc_begin1
45+
46+
.section .toc,"aw",@progbits
47+
.LC0:
48+
.tc g_foo[TC],g_foo
49+
.type g_foo,@object # @g_foo
50+
.data
51+
.globl g_foo
52+
.p2align 2
53+
g_foo:
54+
.long 2 # 0x2
55+
.size g_foo, 4

lldb/test/Shell/Breakpoint/ppc64-localentry.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# REQUIRES: powerpc
22
#
3-
# RUN: llvm-mc -triple=powerpc64le -filetype=obj %p/Inputs/ppc64-localentry.s -o %t
3+
# RUN: llvm-mc -triple=powerpc64 -filetype=obj %p/Inputs/ppc64-localentry.s -o %t
44
# RUN: lldb-test breakpoints %t %s | FileCheck %s
55

66
breakpoint set -n lfunc
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# REQUIRES: powerpc
2+
#
3+
# RUN: llvm-mc -triple=powerpc64le -filetype=obj %p/Inputs/ppc64le-localentry.s -o %t
4+
# RUN: lldb-test breakpoints %t %s | FileCheck %s
5+
6+
breakpoint set -n lfunc
7+
# CHECK-LABEL: breakpoint set -n lfunc
8+
# CHECK: Address: {{.*}}`lfunc + 8
9+
10+
breakpoint set -n simple
11+
# CHECK-LABEL: breakpoint set -n simple
12+
# CHECK: Address: {{.*}}`simple

0 commit comments

Comments
 (0)