Skip to content

llvm-objdump disassemly does not correctly decode data references in PIC code? #145757

Open
@MatzeB

Description

@MatzeB

Reproducer:

test.c:

int foo = 0;
int get_foo() { return foo; }
void set_foo(int val) { foo = val; }

compile and dump:

$ clang -fPIC -shared -o libtest.so test.c
$ llvm-objdump -d  libtest.so
...
0000000000001100 <get_foo>:
    1100: 55                            pushq   %rbp
    1101: 48 89 e5                      movq    %rsp, %rbp
    1104: 48 8b 05 dd 2e 00 00          movq    0x2edd(%rip), %rax      # 0x3fe8 <__gmon_start__+0x3fe8>
    110b: 8b 00                         movl    (%rax), %eax
    110d: 5d                            popq    %rbp
    110e: c3                            retq
    110f: 90                            nop

0000000000001110 <set_foo>:
    1110: 55                            pushq   %rbp
    1111: 48 89 e5                      movq    %rsp, %rbp
    1114: 89 7d fc                      movl    %edi, -0x4(%rbp)
    1117: 8b 4d fc                      movl    -0x4(%rbp), %ecx
    111a: 48 8b 05 c7 2e 00 00          movq    0x2ec7(%rip), %rax      # 0x3fe8 <__gmon_start__+0x3fe8>
    1121: 89 08                         movl    %ecx, (%rax)
    1123: 5d                            popq    %rbp
    1124: c3                            retq

Note that this says __gmon_start__+0x3fe8 at the place where it references the foo variable (or rather references the entry for foo in the PLT table I think).

GNU objdump produces a more reasonable result:

...
   1104:       48 8b 05 dd 2e 00 00    mov    0x2edd(%rip),%rax        # 3fe8 <foo@@Base-0x3c>
...
   111a:       48 8b 05 c7 2e 00 00    mov    0x2ec7(%rip),%rax        # 3fe8 <foo@@Base-0x3c>
...

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