[PATCH][x86_64] Convert indirect call via GOT to direct when possible

Cary Coutant ccoutant@gmail.com
Mon Jun 20 19:04:00 GMT 2016


> I am attaching the patch after making all the changes mentioned.
> Please take a look.

+       // If relocation type is R_X86_64_GOTPCRELX it is automatically a
+       // candidate for conversion.
+       if (r_type ==  elfcpp::R_X86_64_GOTPCRELX)
+         break;

If you're not calling can_convert_callq_to_direct() here, then you
shouldn't be calling it here:

+      // Convert
+      // callq *foo@GOTPCRELX(%rip) to
+      // addr32 callq foo
+      // and jmpq *foo@GOTPCRELX(%rip) to
+      // jmpq foo
+      // nop
+      else if (gsym != NULL
+              && rela.get_r_offset() >= 2
+              && Target_x86_64<size>::can_convert_callq_to_direct(gsym,
+                                                                  r_type,
+                                                                  0, &view))

What will happen if it returns false in relocate()? You'll get no
conversion, but also no GOT entry. Since you're only doing this for
the GOTPCRELX relocation, you don't need can_convert_callq_to_direct()
at all, but you will need an error case for when this is false:

+    return ((*view)[r_offset - 2] == 0xff
+            && ((*view)[r_offset - 1] == 0x15
+                || (*view)[r_offset - 1] == 0x25));

If you see a GOTPCRELX relocation, and the opcode isn't either 0xff
0x15 or 0xff 0x25, that's a bad input that should be diagnosed.

-cary



More information about the Binutils mailing list