[PATCH] D20622: [ELF] - Added support for jmp/call relaxations when R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX are used.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Wed May 25 08:37:44 PDT 2016


> --- ELF/Target.cpp
> +++ ELF/Target.cpp
> @@ -740,14 +740,39 @@
>                                     uint64_t Offset) const {
>    if (Type != R_X86_64_GOTPCRELX && Type != R_X86_64_REX_GOTPCRELX)
>      return false;
> -
> -  // Converting mov foo at GOTPCREL(%rip), %reg to lea foo(%rip), %reg
> -  // is the only supported relaxation for now.
> -  return (Offset >= 2 && Data[Offset - 2] == 0x8b);

This deletes the "Offset >= 2" check. Do you know if it will be needed
once all optimizations are implemented? If it is there just to guard
against corrupted inputs, for now just remove the Offset argument and
pass Data+Offset to this function. That can be another patch.


> +  if (Op == 0x8b) {
> +    // Convert mov foo at GOTPCREL(%rip), %reg to lea foo(%rip), %reg.
> +    *(Loc - 2) = 0x8d;

Use an early return here.

> +  } else if (Op == 0xff) {
> +    if (ModRm == 0x15) {
> +      // ABI says we can convert call *foo at GOTPCREL(%rip) to nop call foo.
> +      // Instead we convert to addr32 call foo, where addr32 is instruction
> +      // prefix. That makes result expression to be a single instruction.

Interesting idea. For tls data16 and rex64 are used. Any idea which
one is better when? Would you mind sending hjl.tools at gmail.com this
suggestion for addition in the psabi?


> +      *(Loc - 2) = 0x67; // addr32 prefix
> +      *(Loc - 1) = 0xe8; // call
early return.

> +    } else {
> +      // ModRm == 0x25.
> +      // Convert jmp *foo at GOTPCREL(%rip) to jmp foo nop.

Can't you use a prefix in here?

> +      *(Loc - 2) = 0xe9; // jmp
> +      *(Loc + 3) = 0x90; // nop
> +      Loc -= 1;
> +      Val += 1;
> +    }
> +  }
> +
>    relocateOne(Loc, R_X86_64_PC32, Val);
>  }

Cheers,
Rafael


More information about the llvm-commits mailing list