flat assembler
Message board for the users of flat assembler.
Index
> Main > [SOLVED] Avoiding redundant program headers |
Author |
|
Roman 21 Jul 2024, 13:48
Show your elf code.
Why elf code must be big when using couple files ? Yes. Many programmers using several files. Its include "some code or data" This normally practices. |
|||
21 Jul 2024, 13:48 |
|
anbyte 21 Jul 2024, 15:28
Roman wrote: Show your elf code. To give an example, I may have a main.s and a print_buffer.s source files. In print_buffer.s I may have some reserved data. Code: PRINT_BUFFER_SIZE equ 4096 segment readable writeable print_buffer.idx rq 1 print_buffer rb PRINT_BUFFER_SIZE segment executable print_buffer: ; .... ret print_buffer_flush: ; .... ret Then, in my main.s I may have something along the lines of this: Code: format ELF64 executable include "print_buffer.s" segment readable msg_str db "hi there", 0x0a msg_len = $-msg_str segment executable entry start start: mov rdi, msg_str mov rsi, msg_len call print_buffer call print_buffer_flush mov rax, 60 ; SYS_exit xor rdi, rdi syscall Well, the exact code doesn't matter that much (maybe I made an error but ignore it). I now have 2 segments for code, 1 for initialized data and 1 for reserved memory. If I needed some initialized data in print_buffer.s (perhaps a stride, doesn't really matter) I'd now have 2 data segments, so this is not even the best example. Point being, it's redundant to have 2 executable segments and 2 data segments if the routines could all be in the same segment, as well as the initialized data be in the same segment. I could split up my print_buffer.s file, but that means I'm either going to have to make some questionable assumptions (e.g. this source file HAS to be included in an executable segment), or the reader of the source code will lose important information, like how the data for the print buffer is defined when they are reading the print_buffer routine. I think the best solution would be if you could defer executable code, initialized data and reserved memory to 3 single segments and avoid redundancy in it's entirety, perhaps with some preprocessor directive. But maybe I'm doing something wrong in the structuring of this program? Last edited by anbyte on 21 Jul 2024, 18:29; edited 1 time in total |
|||
21 Jul 2024, 15:28 |
|
revolution 21 Jul 2024, 15:58
Options:
- You can use a normal (non executable) elf format in fasm, and use an external linker to combine each segment. - There are also some small projects people have posted here that use macros to collect up code/data for each logical section and then use a final ".end", or similarly named macro, to make the final exe. Here is a link to one example: https://board.flatassembler.net/topic.php?t=12012 Last edited by revolution on 21 Jul 2024, 19:01; edited 1 time in total |
|||
21 Jul 2024, 15:58 |
|
anbyte 21 Jul 2024, 18:58
revolution wrote: Options: I gave the linker a shot for producing regular ELF objects and linking them into an executable. I used a linker script to merge sections and reduce the binary file size as much as possible, but using the linker only seemed to introduce more unnecessary overhead. It's good to know if I decide to link against external libraries, but I'm not planning on with my current program. I guess I'll have to use macros to aggregate my code into single segments. The project that you referenced seems to be just what I'm looking for. Thank you for the help! |
|||
21 Jul 2024, 18:58 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.