From ffc89b17f2a432389ef15485fa887231a0d2b6c3 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 8 Jun 2016 12:41:50 -0700 Subject: i386: Test external function reference without PLT MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To call an external function, the direct branch to the PLT entry can be replaced by an indirect branch via the GOT slot, which is similar to the first instruction in the PLT slot. Instead using the PLT slot as function address, the function address is retrieved from the GOT slot. The R_386_GOT32X relocation can be used to compute the address of the symbol’s GOT entry without base register when PIC is disabled. In non-PIC executable, call/jmp *func@GOT should be used for indirect branch via the GOT slot and movl func@GOT, %eax should be used to load function address. Unlike PIC case, no register is needed to access GOT. If linker determines the function is defined locally, it converts indirect branch via the GOT slot to direct branch with a nop prefix and converts load via the GOT slot to load immediate or lea. * testsuite/ld-i386/libno-plt-1b.dd: New file. * testsuite/ld-i386/libno-plt-1b.rd: Likewise. * testsuite/ld-i386/no-plt-1a.dd: Likewise. * testsuite/ld-i386/no-plt-1a.rd: Likewise. * testsuite/ld-i386/no-plt-1b.dd: Likewise. * testsuite/ld-i386/no-plt-1b.rd: Likewise. * testsuite/ld-i386/no-plt-1c.dd: Likewise. * testsuite/ld-i386/no-plt-1c.rd: Likewise. * testsuite/ld-i386/no-plt-1d.dd: Likewise. * testsuite/ld-i386/no-plt-1d.rd: Likewise. * testsuite/ld-i386/no-plt-1e.dd: Likewise. * testsuite/ld-i386/no-plt-1e.rd: Likewise. * testsuite/ld-i386/no-plt-1f.dd: Likewise. * testsuite/ld-i386/no-plt-1f.rd: Likewise. * testsuite/ld-i386/no-plt-1g.dd: Likewise. * testsuite/ld-i386/no-plt-1g.rd: Likewise. * testsuite/ld-i386/no-plt-1h.dd: Likewise. * testsuite/ld-i386/no-plt-1h.rd: Likewise. * testsuite/ld-i386/no-plt-1i.dd: Likewise. * testsuite/ld-i386/no-plt-1i.rd: Likewise. * testsuite/ld-i386/no-plt-1j.dd: Likewise. * testsuite/ld-i386/no-plt-1j.rd: Likewise. * testsuite/ld-i386/no-plt-check1a.S: Likewise. * testsuite/ld-i386/no-plt-check1b.S: Likewise. * testsuite/ld-i386/no-plt-extern1a.S: Likewise. * testsuite/ld-i386/no-plt-extern1b.S: Likewise. * testsuite/ld-i386/no-plt-func1.c: Likewise. * testsuite/ld-i386/no-plt-main1.c: Likewise. * testsuite/ld-i386/no-plt.exp: Likewise. --- ld/testsuite/ld-i386/no-plt-1d.dd | 43 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 ld/testsuite/ld-i386/no-plt-1d.dd (limited to 'ld/testsuite/ld-i386/no-plt-1d.dd') diff --git a/ld/testsuite/ld-i386/no-plt-1d.dd b/ld/testsuite/ld-i386/no-plt-1d.dd new file mode 100644 index 0000000..246b252 --- /dev/null +++ b/ld/testsuite/ld-i386/no-plt-1d.dd @@ -0,0 +1,43 @@ +#objdump: -dwrj.text +#target: i?86-*-* + +.*: +file format elf32-i386.* + +Disassembly of section .text: + +#... +[0-9a-f]+ : + +[a-f0-9]+: 53 push %ebx + +[a-f0-9]+: e8 ([0-9a-f]{2} ){4}[ ]+call [a-f0-9]+ <__x86.get_pc_thunk.bx> + +[a-f0-9]+: 81 c3 ([0-9a-f]{2} ){4}[ ]+add +\$0x[a-f0-9]+,%ebx + +[a-f0-9]+: 83 ec 08 sub \$0x8,%esp + +[a-f0-9]+: 67 e8 ([0-9a-f]{2} ){4}[ ]+addr16 call [0-9a-f]+ + +[a-f0-9]+: 81 f8 ([0-9a-f]{2} ){4}[ ]+cmp +\$0x[0-9a-f]+,%eax + +[a-f0-9]+: 75 2f jne [0-9a-f]+ + +[a-f0-9]+: 67 e8 ([0-9a-f]{2} ){4}[ ]+addr16 call [0-9a-f]+ + +[a-f0-9]+: 3d 78 56 34 12 cmp \$0x12345678,%eax + +[a-f0-9]+: 75 22 jne +[0-9a-f]+ + +[a-f0-9]+: 67 e8 ([0-9a-f]{2} ){4}[ ]+addr16 call [0-9a-f]+ + +[a-f0-9]+: 3d 78 56 34 12 cmp \$0x12345678,%eax + +[a-f0-9]+: 75 15 jne +[0-9a-f]+ + +[a-f0-9]+: 8d 83 ([0-9a-f]{2} ){4}[ ]+lea +-0x[a-f0-9]+\(%ebx\),%eax + +[a-f0-9]+: 83 ec 0c sub \$0xc,%esp + +[a-f0-9]+: 50 push %eax + +[a-f0-9]+: 67 e8 ([0-9a-f]{2} ){4}[ ]+addr16 call [0-9a-f]+ <.*puts.*> + +[a-f0-9]+: 83 c4 18 add \$0x18,%esp + +[a-f0-9]+: 5b pop %ebx + +[a-f0-9]+: c3 ret + +[a-f0-9]+: 67 e8 ([0-9a-f]{2} ){4}[ ]+addr16 call [0-9a-f]+ +#... +[0-9a-f]+ : + +[a-f0-9]+: e8 ([0-9a-f]{2} ){4}[ ]+call +[a-f0-9]+ <__x86.get_pc_thunk.ax> + +[a-f0-9]+: 05 ([0-9a-f]{2} ){4}[ ]+add +\$0x[a-f0-9]+,%eax + +[a-f0-9]+: c7 c0 ([0-9a-f]{2} ){4}[ ]+mov +\$0x[a-f0-9]+,%eax + +[a-f0-9]+: c3 ret +#... +[0-9a-f]+ : + +[a-f0-9]+: e8 ([0-9a-f]{2} ){4}[ ]+call +[a-f0-9]+ <__x86.get_pc_thunk.ax> + +[a-f0-9]+: 05 ([0-9a-f]{2} ){4}[ ]+add +\$0x[a-f0-9]+,%eax + +[a-f0-9]+: e9 ([0-9a-f]{2} ){4}[ ]+jmp +[0-9a-f]+ + +[a-f0-9]+: 90 nop +#pass -- cgit v1.1