yasm_output_value_func gets the wrong offseet
Reported by Peter Johnson | June 25th, 2011 @ 07:52 PM | in 1.2.0 (closed)
Originally posted on Trac by bird-yasm@anduin.net
Original
Trac Ticket
Description
When yasm_bc_tobytes does more than one iteration in for loop (i in {0...bc->mult_int}) there is no way the offset parameter of output_value calls can be right. This affects fixup generation of elf and possible other targets.
I've hacked up a very unrealistic example of how to reproduce the issue (I've got another one for OMF but that depends on unfinished code):
tst-value-offset-elf64.asm:
section .data
foobar:
dq 42
section .text
foo:
times 4 mov rax, [foobar wrt rip]
Assemble the file as elf64.
Use objdump to disassemble and dump relocations:
tst-value-offset-elf64.o: file format elf64-little
SYMBOL TABLE:
0000000000000000 l df *ABS* 0000000000000000 tst-value-offset-elf64.asm
0000000000000000 l .text 0000000000000000
0000000000000000 l .data 0000000000000000
0000000000000000 l d .data 0000000000000000 .data
0000000000000000 l d .text 0000000000000000 .text
Disassembly of section .text:
0000000000000000 :
0: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 0x7
3: UNKNOWN .data+0xfffffffffffffffc
3: UNKNOWN .data+0xfffffffffffffff5
3: UNKNOWN .data+0xffffffffffffffee
3: UNKNOWN .data+0xffffffffffffffe7
7: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 0xe
e: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 0x15
15: 48 8b 05 00 00 00 00 mov 0x0(%rip),%rax # 0x1c
One would expect each of the 4 mov instructions to get fixed up, instead there are 4 fixups for the first instruction.
I think the fix would be to make the tobytes bytecode callback take an extra parameter that is either buf/mybuf or the current offset into the buffer.
Trac Attachments
http://www.tortall.net/projects/yasm/attachment/ticket/229/yasm-out...
http://www.tortall.net/projects/yasm/raw-attachment/ticket/229/yasm...
http://www.tortall.net/projects/yasm/timeline?from=2010-11-01T12%3A...
Trac Comments
Changed 8 months ago by bird-yasm@anduin.net
fix proposal that passes the pointer to the beginning of the buffer around.
Changed 8 months ago by bird-yasm@anduin.net
attachment
yasm-output_value_offset-1b.diff
added
fix proposal that passes the pointer to the beginning of the buffer around.
attachment
yasm-output_value_offset-1b.diff
added
Comments and changes to this ticket
-

Peter Johnson June 25th, 2011 @ 08:21 PM
- → Milestone set to 1.2.0
- → Assigned user set to Peter Johnson
-

Peter Johnson June 26th, 2011 @ 06:34 AM
- → State changed from new to resolved
(from [de38127f1c626d7ea46aedc45723b9ae7f79d082]) Fix "times" relocation handling.
Previously a line such as "times 4 mov rax, [rel foobar]" would result
in incorrect relocations being generated.Patch by: bird-yasm@anduin.net
[#211 state:resolved] https://github.com/yasm/yasm/commit/de38127f1c626d7ea46aedc45723b9a...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
The Yasm Modular Assembler Project