Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-zero RELA section contents #12

Open
ghost opened this issue Apr 17, 2022 · 4 comments
Open

Non-zero RELA section contents #12

ghost opened this issue Apr 17, 2022 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 17, 2022

@Hello71 reported that jwasm-family assemblers (jwasm, asmc, uasm) generate wrong relocation.

See also:
https://sourceforge.net/p/sevenzip/bugs/2338/
https://sourceware.org/pipermail/binutils/2022-April/120428.html

@Baron-von-Riedesel
Copy link
Owner

They're using rather outdated versions of jwasm - current release is v2.15.
Relocation generation was slightly updated in jwasm in recent versions, so jwasm may differ from uasm/asmc now...

@nidud
Copy link

nidud commented Apr 20, 2022

GCC seems to add offset to the relocation and subtract it from the code.

https://github.com/nidud/asmc/issues/22

Added a hack for this by adding the offset and simply clearing the output.

Test case for v2.15:

.data
 a db 3
 d db 1,2
.code
    mov al,a
    mov al,d
    mov al,d[1]
    end
...
mov al, byte ptr [a]    ; 0000 _ 8A. 05, 00000000(rel)
mov al, byte ptr [d]    ; 0006 _ 8A. 05, 00000000(rel)
mov al, byte ptr [d+1H] ; 000C _ 8A. 05, 00000001(rel)
...
0000000000000002 R_X86_64_PC32     a-0x0000000000000004
0000000000000008 R_X86_64_PC32     d-0x0000000000000004
000000000000000e R_X86_64_PC32     d-0x0000000000000004

Asmc:

mov al, byte ptr [a]    ; 0000 _ 8A. 05, 00000000(rel)
mov al, byte ptr [d]    ; 0006 _ 8A. 05, 00000000(rel)
mov al, byte ptr [d+1H] ; 000C _ 8A. 05, 00000000(rel)
...
0000000000000002 R_X86_64_PC32     a-0x0000000000000004
0000000000000008 R_X86_64_PC32     d-0x0000000000000004
000000000000000e R_X86_64_PC32     d-0x0000000000000003

@Hello71
Copy link

Hello71 commented Apr 20, 2022

the difference between rel and rela is that in rela, the addend is stored in the relocation table. the instruction stream contents are "unspecified" but i think everyone agrees that they should be set to zero. it's not gcc, it's x86_64 elf platforms (actually binutils, not gcc).

@nidud
Copy link

nidud commented Apr 20, 2022

I guess it's more of a "correction" as the numbers actually adds up but there's an additional variable that fails:

lea rax,$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants