[PATCH] D140279: Adds support for GOT relocations to i386/ELF backend

Lang Hames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 23 19:58:35 PST 2022


lhames accepted this revision.
lhames added a comment.
This revision is now accepted and ready to land.

This looks great, and it's a big step forward for the i386 backend. (Side note: I had no idea how steep the learning curve on this one would be -- nice work getting through it!)

LGTM. :)



================
Comment at: llvm/test/ExecutionEngine/JITLink/i386/ELF_external_to_absolute_conversion.s:27-31
+        addl    $_GLOBAL_OFFSET_TABLE_+(.Ltmp0-.L0$pb), %eax
+        movl    $0, -4(%ebp)
+        movl    a at GOTOFF(%eax), %eax
+        addl    $4, %esp
+        popl    %ebp
----------------
This sequence is trying to access the non-existent GOT-entry, which is why it crashes at runtime.

I think the assembly can be reduced to the i386 equivalent of the x86-64 sequence:
```
        .text
        .globl  main                            
        .p2align        4, 0x90
        .type   main, at function
main:                    
.L0$pb:
        movl    $_GLOBAL_OFFSET_TABLE_-.L0$pb, %eax
        movl    $foo at GOTOFF, %eax
        xorl    %eax, %eax
        retl
        .size   main, .-main
```
The '$' symbol at the start of the expression means that we're treating the result of the expression as an immediate, not an address to be loaded from. The immediate values that we move into `%eax` will be zeros, but since `%eax` isn't used anyway we can disregard that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140279/new/

https://reviews.llvm.org/D140279



More information about the llvm-commits mailing list