flat assembler
Message board for the users of flat assembler.
Index
> Windows > [Solved] Linker issues while embedding FASM in C++ library |
Author |
|
l_inc 02 May 2017, 20:48
A$M
As long as you compile that to an obj file, the labels are relocatable and hence do not have absolute values (e.g., you cannot divide such a label by a constant). Therefore relativeto is your friend here. First make sure the argument is of an expression type via eqtype, then make sure that expression has a non-absolute value by comparing it with relativeto 0. This will not catch expressions with registers though, so you also may choose to compare relativeto some_label_with_same_base_as_needed, but this wouldn't be necessary for mov. Things may get different with push, if the code you compile employs its dirty features. _________________ Faith is a superposition of knowledge and fallacy |
|||
02 May 2017, 20:48 |
|
A$M 02 May 2017, 23:32
l_inc wrote: A$M So this is what I did. First, a "purge mov" because "modes.inc" already defines it. Then this: Code: macro mov dest, src { if src eq esp mov dest, ESP ; This is from modes.inc. I'm not sure what it does but I'm keeping it else if src eqtype 0 & ~src relativeto 0 lea r8d, [src] mov dest, r8d else mov dest, src end if } Code: macro loop dest { dec ecx jnz dest } Thank you again, l_inc. |
|||
02 May 2017, 23:32 |
|
A$M 03 May 2017, 03:12
Ok, so I managed to make all the macros and it linked properly. However, I didn't know that everything was loaded in 32-bit inaccessible memory (RIP for main is 0x00007FF6985589C0) so everything crashes and explodes. For example, "lea eax, variable / mov dword[eax], 123" fails for obvious reasons.
How could I fix this? Maybe if I use more macros to make everything 64-bit. But I think I'm either giving up or at least shelving this project for now. Good thing I've been doing this only since Saturday because it's a simple port so there's not much harm. But still, thanks again for your help. :-D |
|||
03 May 2017, 03:12 |
|
l_inc 03 May 2017, 20:33
A$M
My ability to think is very limited at the afterwork hours, but it seems you are pointing out a bug in fasm: Code: use64 org $100000000 mov eax,$$ lea eax,[$$] None of the above two instructions should compile, but the overflow is caught for mov only. _________________ Faith is a superposition of knowledge and fallacy |
|||
03 May 2017, 20:33 |
|
l_inc 03 May 2017, 21:30
OK. I thought a few more times about that, and this is probably not a bug, as fasm has never been conservative enough to expect an explicit "cast" with things like lea ax,[eax]. In fact, such a cast already has a different effect assigned to it, which is forcing a longer immediate encoding.
The problem with the above code is that rip in the address expression became implicit similarly to how ip has always been implicit in control transfer instructions with ip-relative addressing. So I see a bit of an inconsistency in that the overflow check is performed in the following code, but not in the code above. Code: org $10000
jmp $ _________________ Faith is a superposition of knowledge and fallacy |
|||
03 May 2017, 21:30 |
|
A$M 03 May 2017, 21:36
l_inc wrote: A$M I said I would be shelving this or giving up, but I changed my mind. I have a new hope. I'm now doing something like this: Code: use64 org 0x10000 dq asm_test ; This is how I get the public symbols from C++ dq val1 dq val2 asm_test: add rsp, 8*5 mov rax, val1 mov qword[rax], 25 lea eax, [val2] mov qword[eax], 50 sub rsp, 8*5 ret val1 dq 0 val2 dq 0 Thanks again for your help. I'll update shortly. |
|||
03 May 2017, 21:36 |
|
A$M 04 May 2017, 13:47
l_inc wrote: OK. I thought a few more times about that, and this is probably not a bug, as fasm has never been conservative enough to expect an explicit "cast" with things like lea ax,[eax]. In fact, such a cast already has a different effect assigned to it, which is forcing a longer immediate encoding. |
|||
04 May 2017, 13:47 |
|
A$M 10 May 2017, 01:03
IDK if this is against any rules, but I'm using this post to say I've published this library on GitHub. I've called it fasmcpp.
|
|||
10 May 2017, 01:03 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.