[PATCH] D30699: [ELF] - Stop producing broken output for R_386_GOT32X relocation.

H.J. Lu via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 23 11:26:47 PDT 2017

On Thu, Mar 23, 2017 at 10:37 AM, Rui Ueyama via Phabricator via
llvm-commits <llvm-commits at lists.llvm.org> wrote:
> ruiu added a comment.
> I spent a few hours to understand the situation. Here are my conclusions:
> 1. The expression to compute R_386_GOT32 value in the i386 psABI draft version 1.1 doesn't indeed make sense. It says that you need to use G+A (as opposed to G+A-GOT) when the relocation is "[a]pplied on memory operand without base register when position-independent code is disabled". However, it is not doable because you are allowed to use R_386_GOT32 anywhere and we cannot make an assumption that an R_386_GOT32 follows some certain limited set of instructions. I think this is a bug in the draft spec.
> 2. That being said, I believe what we are doing now for R_386_GOT32X is correct, and this patch will break it. When you compute G+A instead of G+A-GOT for an R_386_GOT32X, you always need to rewrite instructions as well. If you don't rewrite instructions, you should always compute G+A-GOT (which is what we are currently doing.)
> https://reviews.llvm.org/D30699

"name at GOT" is a memory operand.  It is usually computed as "G + A" to
get the GOT address.   If it is computed as G + A - GOT,

op name at GOT, %reg

will lead to random result since G + A - GOT is the GOT index, not address.
LEA is an exception, relocation in

lea name at GOT, %reg

should be computed as  G + A - GOT for the GOT index.   The motivation is
to allow GOT access without base register when PIC is disabled.


More information about the llvm-commits mailing list