nasm/output
knut st. osmundsen 8e6feefb3b outobj.c: Fix for RIP relative addressing relocation.
For 16-bit and 32-bit x86 code, the size and realsize() always
matches as only jumps, calls and loops uses PC relative
addressing and the address isn't followed by any other opcode
bytes.  In 64-bit mode there is RIP relative addressing which
means the fixup location can be followed by an immediate value,
meaning that size > realsize().

When the CPU is calculating the effective address, it takes the
RIP at the end of the instruction and adds the fixed up relative
address value to it.

The linker's point of reference is the end of the fixup location
(which is the end of the instruction for Jcc, CALL, LOOP[cc]).
It is calculating distance between the target symbol and the end
of the fixup location, and add this to the displacement value we
are calculating here and storing at the fixup location.

To get the right effect, we need to _reduce_ the displacement
value by the number of bytes following the fixup.

Example:
 data at address 0x100; REL4ADR at 0x050, 4 byte immediate,
 end of fixup at 0x054, end of instruction at 0x058.
 => size = 8.
 => realsize() -> 4
 => CPU needs a value of:   0x100 - 0x058 = 0x0a8
 => linker/loader will add: 0x100 - 0x054 = 0x0ac
 => We must add an addend of -4.
 => realsize() - size = -4.

The code used to do size - realsize() at least since v0.90,
probably because it wasn't needed...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-06-03 23:54:12 -07:00
..
codeview.c codeview: use nasm_realpath() to find the canonical name of the outfile 2016-05-24 23:35:57 -07:00
dwarf.h output/dwarf.h: update dwarf constants 2009-08-10 16:00:43 -07:00
elf.h Elf: Use SHA_ANY constant instead of open coded number 2010-04-11 12:58:05 +04:00
nulldbg.c Add missing header file in output/nulldbg.c 2014-11-25 12:14:52 -08:00
nullout.c Rename SEGALIGN to SECTALIGN 2010-04-21 18:09:54 +04:00
outaout.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outaout.mac NASM: relicense under the 2-clause BSD license 2009-07-06 11:09:11 -07:00
outas86.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outas86.mac NASM: relicense under the 2-clause BSD license 2009-07-06 11:09:11 -07:00
outbin.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outbin.mac NASM: relicense under the 2-clause BSD license 2009-07-06 11:09:11 -07:00
outcoff.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outcoff.mac NASM: relicense under the 2-clause BSD license 2009-07-06 11:09:11 -07:00
outdbg.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outelf32.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outelf64.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outelf.c output: elf -- Move elf_directive into single instance 2014-08-29 20:30:57 +04:00
outelf.h output: elf -- Move common structures into outelf.h header 2014-09-21 13:03:26 +04:00
outelf.mac NASM: relicense under the 2-clause BSD license 2009-07-06 11:09:11 -07:00
outelfx32.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outform.c Defer debug format search until after command line parsing 2016-03-07 23:20:00 -08:00
outform.h Defer debug format search until after command line parsing 2016-03-07 23:20:00 -08:00
outieee.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outlib.c Add support for one-byte relocations 2010-05-06 15:33:24 -07:00
outlib.h Rename SEGALIGN to SECTALIGN 2010-04-21 18:09:54 +04:00
outmacho.c outmacho: Fix missing brace 2016-05-09 11:36:55 -07:00
outmacho.mac macho64: Manually merge macho64 branch with master branch. 2009-07-08 23:04:52 -05:00
outobj.c outobj.c: Fix for RIP relative addressing relocation. 2016-06-03 23:54:12 -07:00
outobj.mac NASM: relicense under the 2-clause BSD license 2009-07-06 11:09:11 -07:00
outrdf2.c ofmt: get rid of the debuginfo parameter to ofmt->cleanup() 2016-03-07 22:55:43 -08:00
outrdf2.mac NASM: relicense under the 2-clause BSD license 2009-07-06 11:09:11 -07:00
outrdf.mac NASM: relicense under the 2-clause BSD license 2009-07-06 11:09:11 -07:00
pecoff.h coff: Add support for the Codeview 8 debug format 2016-01-24 14:14:39 +03:00
stabs.h Remove unnecessary C99-isms 2016-03-02 10:48:53 -08:00