diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2015-10-22 04:53:04 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2015-10-22 04:56:39 -0700 |
commit | caa65211bbbfd53c40c9ce1b79b97ccf2c679a52 (patch) | |
tree | fb1a002a3550e25bdfa5c224a52d4a5fd7fab63b /bfd | |
parent | 56ceb5b5405af23eddd12e12d8ba849010120324 (diff) | |
download | gdb-caa65211bbbfd53c40c9ce1b79b97ccf2c679a52.zip gdb-caa65211bbbfd53c40c9ce1b79b97ccf2c679a52.tar.gz gdb-caa65211bbbfd53c40c9ce1b79b97ccf2c679a52.tar.bz2 |
Add "-z call-nop=PADDING" option to ld
The ld linker can transform indirect call to a locally defined function,
foo, via its GOT slot, to either "NOP call foo" or "call foo NOP" where
NOP is a 1-byte NOP padding. This patch adds a "-z call-nop=PADDING"
option to x86 ld to control 1-byte NOP padding for x86 call instruction.
PADDING is one of prefix-addr, prefix-nop, suffix-nop, prefix-NUMBER or
suffix-NUMBER.
bfd/
* elf32-i386.c (elf_i386_convert_load): Use call_nop_byte and
check call_nop_as_suffix for 1-byte NOP padding to pad call.
* elf64-x86-64.c (elf_x86_64_convert_load): Likewise.
include/
* bfdlink.h (bfd_link_info): Add call_nop_as_suffix and
call_nop_byte.
ld/
* ld/ld.texinfo: Document "-z call-nop=PADDING" option.
* emulparams/call_nop.sh: New file.
* emulparams/elf_i386_be.sh: Source
${srcdir}/emulparams/call_nop.sh.
* emulparams/elf_i386_chaos.sh: Likewise.
* emulparams/elf_i386_ldso.sh: Likewise.
* emulparams/elf_i386_vxworks.sh: Likewise.
* emulparams/elf_iamcu.sh: Likewise.
* emulparams/elf_k1om.sh: Likewise.
* emulparams/elf_l1om.sh: Likewise.
* emulparams/elf_x86_64.sh: Likewise.
* emultempl/elf32.em (gld${EMULATION_NAME}_before_parse): Set
link_info.call_nop_byte if $CALL_NOP_BYTE isn't empty.
ld/testsuite/
* ld-i386/call3.s: New file.
* ld-i386/call3a.d: Likewise.
* ld-i386/call3b.d: Likewise.
* ld-i386/call3c.d: Likewise.
* ld-i386/call3d.d: Likewise.
* ld-i386/call3e.d: Likewise.
* ld-i386/call3f.d: Likewise.
* ld-i386/call3g.d: Likewise.
* ld-i386/call3h.d: Likewise.
* ld-i386/load1-nacl.d: Likewise.
* ld-x86-64/call1.s: Likewise.
* ld-x86-64/call1a.d: Likewise.
* ld-x86-64/call1b.d: Likewise.
* ld-x86-64/call1c.d: Likewise.
* ld-x86-64/call1d.d: Likewise.
* ld-x86-64/call1e.d: Likewise.
* ld-x86-64/call1f.d: Likewise.
* ld-x86-64/call1g.d: Likewise.
* ld-x86-64/call1h.d: Likewise.
* ld-x86-64/call1i.d: Likewise.
* ld-x86-64/load1a-nacl.d: Likewise.
* ld-x86-64/load1b-nacl.d: Likewise.
* ld-x86-64/load1c-nacl.d: Likewise.
* ld-x86-64/load1d-nacl.d: Likewise.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/ChangeLog | 6 | ||||
-rw-r--r-- | bfd/elf32-i386.c | 10 | ||||
-rw-r--r-- | bfd/elf64-x86-64.c | 14 |
3 files changed, 25 insertions, 5 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index afc8029..961a385 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,11 @@ 2015-10-22 H.J. Lu <hongjiu.lu@intel.com> + * elf32-i386.c (elf_i386_convert_load): Use call_nop_byte and + check call_nop_as_suffix for 1-byte NOP padding to pad call. + * elf64-x86-64.c (elf_x86_64_convert_load): Likewise. + +2015-10-22 H.J. Lu <hongjiu.lu@intel.com> + * elf64-x86-64.c: Include opcode/i386.h. (x86_64_elf_howto_table): Add R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX. diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index f56b39e..60cd91a 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -2924,8 +2924,14 @@ convert_branch: /* Convert to "nop call foo". ADDR_PREFIX_OPCODE is a nop prefix. */ modrm = 0xe8; - nop = ADDR_PREFIX_OPCODE; - nop_offset = roff - 2; + nop = link_info->call_nop_byte; + if (link_info->call_nop_as_suffix) + { + nop_offset = roff + 3; + irel->r_offset -= 1; + } + else + nop_offset = roff - 2; } else { diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index f8bb0d5..f864834 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -3217,6 +3217,7 @@ elf_x86_64_convert_load (bfd *abfd, asection *sec, { /* We have "call/jmp *foo@GOTPCREL(%rip)". */ unsigned int nop; + unsigned int disp; bfd_vma nop_offset; /* Convert R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX to @@ -3224,7 +3225,6 @@ elf_x86_64_convert_load (bfd *abfd, asection *sec, modrm = bfd_get_8 (abfd, contents + roff - 1); if (modrm == 0x25) { - unsigned int disp; /* Convert to "jmp foo nop". */ modrm = 0xe9; nop = NOP_OPCODE; @@ -3238,8 +3238,16 @@ elf_x86_64_convert_load (bfd *abfd, asection *sec, /* Convert to "nop call foo". ADDR_PREFIX_OPCODE is a nop prefix. */ modrm = 0xe8; - nop = ADDR_PREFIX_OPCODE; - nop_offset = irel->r_offset - 2; + nop = link_info->call_nop_byte; + if (link_info->call_nop_as_suffix) + { + nop_offset = irel->r_offset + 3; + disp = bfd_get_32 (abfd, contents + irel->r_offset); + irel->r_offset -= 1; + bfd_put_32 (abfd, disp, contents + irel->r_offset); + } + else + nop_offset = irel->r_offset - 2; } bfd_put_8 (abfd, nop, contents + nop_offset); bfd_put_8 (abfd, modrm, contents + irel->r_offset - 1); |