dubugger
dubugger

Reputation: 109

Question about relocation entries in assembly code

I write 2 C programs : main.c and sum.c.

Here is main.c :

int array[2] = {1, 2};
int main() {
    int val = sum(array, 2);
    return val;
}

Here is sum.c :

int sum(int* a, int n) {
    int i, s = 0;
    for (i = 0; i < n; i++) {
        s += a[i];
    }
    return s;
}

I use command gcc -c -o main.o main.c and objdump -d -r main.o>main.d and I get :

main.o:     file format elf64-x86-64


Disassembly of section .text:

0000000000000000 <main>:
   0:   f3 0f 1e fa             endbr64 
   4:   48 83 ec 08             sub    $0x8,%rsp
   8:   be 02 00 00 00          mov    $0x2,%esi
   d:   48 8d 3d 00 00 00 00    lea    0x0(%rip),%rdi        # 14 <main+0x14>
            10: R_X86_64_PC32   array-0x4
  14:   b8 00 00 00 00          mov    $0x0,%eax
  19:   e8 00 00 00 00          callq  1e <main+0x1e>
            1a: R_X86_64_PLT32  sum-0x4
  1e:   48 83 c4 08             add    $0x8,%rsp
  22:   c3                      retq   

What does 1e: R_X86_64_PLT32 sum-0x4 mean? Shouldn't it be sum-0x22 because at that time the RIP is 0x22?

And also what does 0x4 in 10: R_X86_64_PC32 array-0x4 stand for?

And one more question : My computer is 64-bit but why the address is 32-bit in the assembly code?

Upvotes: 0

Views: 202

Answers (0)

Related Questions