flat assembler
Message board for the users of flat assembler.
Index
> Main > ELF Object Portability |
Author |
|
vid 11 Dec 2008, 19:41
GCC can handle ELF, and i think it compiles for all three (but never tried it with Mac OS X). But implementation of libc can differ a bit, you might still need some tiny libc wrapper in some cases.
|
|||
11 Dec 2008, 19:41 |
|
asmcoder 11 Dec 2008, 20:11
[content deleted]
Last edited by asmcoder on 14 Aug 2009, 14:54; edited 1 time in total |
|||
11 Dec 2008, 20:11 |
|
vid 11 Dec 2008, 22:43
Quote: what is linking? Main advantage of this approach is that it allows you to break your source into several modules (object files), so you don't have to always recompile everything, only the module you changed. You'd see this advantage if you would made some bigger project. Of course, there are other advantages. Quote: why u want use gcc to recompile fasm files? gcc != fasm I suggested using GCC just for linking, not compiling. You compile code to ELF object in FASM, and then link it to different executables for various OSes, using GCC. |
|||
11 Dec 2008, 22:43 |
|
mattst88 11 Dec 2008, 22:54
Imagist wrote: IDoes this mean that you can compile an FASM program to an object file (traditionally tagged filename.o) which can be linked by (for example) GCC? Yes, absolutely. Code: fasm code.asm # creates code.o gcc code.o -o code _________________ My x86 Instruction Reference -- includes SSE, SSE2, SSE3, SSSE3, SSE4 instructions. Assembly Programmer's Journal |
|||
11 Dec 2008, 22:54 |
|
asmcoder 11 Dec 2008, 23:12
[content deleted]
Last edited by asmcoder on 14 Aug 2009, 14:54; edited 1 time in total |
|||
11 Dec 2008, 23:12 |
|
vid 12 Dec 2008, 00:35
When you want to write portable ELF file, you must use interface that is present on all OSes. Of course 0x80 isn't. Such interface is libc - Standard C Library. That is present everywhere, with quite minor differences (but still there are some).
Anyway, using same ELF file to build for different OSes is *not* what it was intended for, and it only works to some extent, because existing implementations of C library are pretty similar at binary level. (C library is only defined on C source code level, and can be implemented in any way on binary level) So - you don't use int 0x80. You use libc. For example you declare "printf" as external symbol, and then "call printf". Linker will relocate the address to actual address of actual printf function. For practical example of using libc, get libc version of FASM and study system.inc, for example. Quote: whats diffrent between object file and executable file? object file references all stuff through names, not addresses. For example if you have "mov [var123], 100", object file doesn't generate any address. In object file you only have information that this instruction refers to symbol named "var123". This symbol can lie in same object file, or in another object file. During linking, all objects are pasted together, and address in this instruction is overwritten by actual address (RVA actually) of symbol "var123". Also every object can have various sections, usually data and code. When linking, all data sections are merged into one big data section, and all code sections are merged into one big code sections. This is still one of problems of FASMers who use direct compilation to .EXE, but want to divide source into modules: they have to wrap data definitions in macros like "idata", to have them all collected in one place. |
|||
12 Dec 2008, 00:35 |
|
asmcoder 12 Dec 2008, 11:17
[content deleted]
Last edited by asmcoder on 14 Aug 2009, 14:54; edited 1 time in total |
|||
12 Dec 2008, 11:17 |
|
dosin 12 Dec 2008, 12:36
Quote: why bother with it? I would think this would answer it: Quote: Everyone could then edit it to fit system library This can run into problems... end up with multible versions - run into compatibility problems ... ect.. Quote: Edit imports, header, and perhaps minor code The user can still do this? but create there own funtions.. Then the OS Devel.. has the options to add to the lib or leave it out.. if not the os devel has no control over what is added or removed... even in C you can create your own printf if you dont want to use the one provided.. |
|||
12 Dec 2008, 12:36 |
|
vid 12 Dec 2008, 13:53
Quote: i understand the idea, but... why bother with it? 1. You don't need to always recompile every entire code for executable, just the changed part. This saves considerable amount of time on useless recompilation. 2. You can distribute static libraries (eg. not dynamic, in separate file, like DLLs) without giving away their code, and/or without need for people to study and always recompile their code. 3. It offers good and time-tested platform for breaking code into multiple more/less independent modules, unlike using FASM to compile directly to executable. 4. It allows you to mix code from various languages into same executable. Priceless if you want to use library written in other language than the one you are using. Quote: wouldnt be simplier to just write source code in fasm with proper headers (format pe/format elf)? Everyone could then edit it to fit system library. Edit imports, header, and perhaps minor code. In that case, "editing" would be a stupid way to do it, more sane would be way used by FASM for example. But anyway, that only solves one point - OS portability (original topic of this thread), which object files aren't even supposed to solve. Main reason for using object files is what i have written up. |
|||
12 Dec 2008, 13:53 |
|
Imagist 16 Dec 2008, 21:28
Vid, what would you suggest as the best way to write cross-platform FASM?
_________________ Many things are possible. Few things are likely. |
|||
16 Dec 2008, 21:28 |
|
baldr 16 Dec 2008, 22:48
Imagist,
Define "platform". Common ground for every x86-32/64 linker in existence? |
|||
16 Dec 2008, 22:48 |
|
vid 17 Dec 2008, 02:16
Quote: Vid, what would you suggest as the best way to write cross-platform FASM? Depens... but generaly speaking, it would be: - Platform-specific "bottom" layer to wrap system functions to interface common for all platforms - Platform-specific top-level file (the one you compile, with "format" definitions etc) - Rest can be portable, included from all top-level files. This code can only call OS through the wrapper functions. This is a way that FASM itself uses too, btw |
|||
17 Dec 2008, 02:16 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.