Skip to content

problems when building for ppc64 #157515

@paleozogt

Description

@paleozogt

In #156704 I misunderstood where the problem was. Clang seems to be ok when cross-compiling for ppc64(be), but ld.lld and llvm-objdump have problems with debug symbols.

Given a simple c file:

// test.c
int foobar(int v) {
   return v+1;
}

Build and link with gnu, but objdump with llvm, which doesn't seem to know where the symbols are:

$ powerpc64-linux-gnu-gcc -ffreestanding -O0 -c test.c -o test.ppc64.o
$ powerpc64-linux-gnu-ld -nostdlib test.ppc64.o -o test.ppc64.elf
$ llvm-objdump-14 -d test.ppc64.elf

test.ppc64.elf: file format elf64-powerpc

Disassembly of section .text:

00000000100000e8 <.text>:
100000e8: fb e1 ff f8   std 31, -8(1)
100000ec: f8 21 ff c1   stdu 1, -64(1)
100000f0: 7c 3f 0b 78   mr      31, 1
100000f4: 7c 69 1b 78   mr      9, 3
100000f8: 91 3f 00 70   stw 9, 112(31)
100000fc: 81 3f 00 70   lwz 9, 112(31)
10000100: 39 29 00 01   addi 9, 9, 1
10000104: 7d 29 07 b4   extsw 9, 9
10000108: 7d 23 4b 78   mr      3, 9
1000010c: 38 3f 00 40   addi 1, 31, 64
10000110: eb e1 ff f8   ld 31, -8(1)
10000114: 4e 80 00 20   blr
                ...
10000120: 80 01 00 01   lwz 0, 1(1)

Contrast that with gnu's objdump behavior:

$ powerpc64-linux-gnu-objdump -d test.ppc64.elf

test.ppc64.elf:     file format elf64-powerpc

Disassembly of section .text:

00000000100000e8 <.foobar>:
    100000e8:   fb e1 ff f8     std     r31,-8(r1)
    100000ec:   f8 21 ff c1     stdu    r1,-64(r1)
    100000f0:   7c 3f 0b 78     mr      r31,r1
    100000f4:   7c 69 1b 78     mr      r9,r3
    100000f8:   91 3f 00 70     stw     r9,112(r31)
    100000fc:   81 3f 00 70     lwz     r9,112(r31)
    10000100:   39 29 00 01     addi    r9,r9,1
    10000104:   7d 29 07 b4     extsw   r9,r9
    10000108:   7d 23 4b 78     mr      r3,r9
    1000010c:   38 3f 00 40     addi    r1,r31,64
    10000110:   eb e1 ff f8     ld      r31,-8(r1)
    10000114:   4e 80 00 20     blr
        ...
    10000120:   80 01 00 01     lwz     r0,1(r1)

If we build and objdump with gnu, but link with llvm, it doesn't seem to bring over the debug symbols:

$ powerpc64-linux-gnu-gcc -ffreestanding -O0 -c test.c -o test.ppc64.o
$ ld.lld --oformat=elf_ppc64 -nostdlib test.ppc64.o -o test.ppc64.elf
$ powerpc64-linux-gnu-objdump -d test.ppc64.elf

test.ppc64.elf:     file format elf64-powerpc

Disassembly of section .text:

0000000010010204 <.text>:
    10010204:   fb e1 ff f8     std     r31,-8(r1)
    10010208:   f8 21 ff c1     stdu    r1,-64(r1)
    1001020c:   7c 3f 0b 78     mr      r31,r1
    10010210:   7c 69 1b 78     mr      r9,r3
    10010214:   91 3f 00 70     stw     r9,112(r31)
    10010218:   81 3f 00 70     lwz     r9,112(r31)
    1001021c:   39 29 00 01     addi    r9,r9,1
    10010220:   7d 29 07 b4     extsw   r9,r9
    10010224:   7d 23 4b 78     mr      r3,r9
    10010228:   38 3f 00 40     addi    r1,r31,64
    1001022c:   eb e1 ff f8     ld      r31,-8(r1)
    10010230:   4e 80 00 20     blr
        ...
    1001023c:   80 01 00 01     lwz     r0,1(r1)

The same behavior happens if I build with clang targeting ppc64. Also, this all seems to work fine on ppc64le.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions