This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH][x86_64] Convert indirect call via GOT to direct when possible
- From: Cary Coutant <ccoutant at gmail dot com>
- To: Sriraman Tallam <tmsriram at google dot com>
- Cc: "H.J. Lu" <hjl dot tools at gmail dot com>, binutils <binutils at sourceware dot org>, David Li <davidxl at google dot com>
- Date: Mon, 20 Jun 2016 12:04:49 -0700
- Subject: Re: [PATCH][x86_64] Convert indirect call via GOT to direct when possible
- Authentication-results: sourceware.org; auth=none
- References: <CAAs8HmxxdBpS7w8udZgK0QFi5TnenU3wGhpPfhWeKE8Tr=thvA at mail dot gmail dot com> <CAMe9rOpk3aOK5mMkKvYQyzeQxJ-h8o+3KjLRikKSkLmMfqoUtg at mail dot gmail dot com> <CAAs8Hmw2KQ2neDNP5cnQPBVBZMJthvQGTARPiwa-NfAx5R6ugw at mail dot gmail dot com> <CAMe9rOrOyYv0+svcObyaBcoYbAWZTadEPm-mAGQUFFyNjPgctg at mail dot gmail dot com> <CAAs8HmzoxWe2YpvjviV-bs2BRotGa_WFWbCyyLh-_L=s00yxjQ at mail dot gmail dot com> <CAJimCsF4h+e_Ey-fGxPXM0h8ZJ-SmSzyP9XoYaNuEOByJSm=1A at mail dot gmail dot com> <CAAs8HmzH3qjeOSHYe_WEEdx-iuF5oGn5FwkA9vtUBV_5gO3r4w at mail dot gmail dot com>
> 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