flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 24 Jul 2025, 02:18
Relocations for ELF format in the current version are not working.
However ... I do have a branch that has working relocations for ARM32 and ARM64 but I can't release it at this time. I am negotiating with all the parties involved to try and get a new version with the new features made public. I haven't been given a timeline for the approval process though. ![]() |
|||
![]() |
|
rrq 24 Jul 2025, 02:48
Thanks. Fair enough. I do appreciate all your effort, and a clear answer is very good!
(I'll set up something for myself using "nm" and "sed" meanwhile) |
|||
![]() |
|
rrq 30 Jul 2025, 14:49
Just in case someone is interested: this is a brief description of my DIY approach for linking fasmarm code with gcc code; more specifically for making a flat binary with fasmarm as main program and some support functions together with gcc-compiled object modules and static libraries with other functions.
The fasmarm code has "extrn" directives for calls to gcc C code and it has "public" directives to support calls into to it. However the "extrn" directives are wrapped into using a "LINK" macro so that the external labels get duly defined for the actual load addresses. Code: macro LINK reladdr, name { name = (0x#reladdr - 0x000100d8 ) ; relative default _start address extrn `name as _#name } The load addresses (reladdr) are picked from the "nm" output of the linked executable and the Makefile is set up to verify this prior to extracting the flat binary from the executable. All in all the Makefile includes the following generic rules (in addition to the specific dependences): Code: .SUFFIXES: # Disable all standard generic rules # Generic rule to compile C into .o (ELF 32-bit LSB relocatable) ## (the same as the standard rule) %.o: %.c (COMPILE.c) $(OUTPUT_OPTION) $< # Generic rule to compile fasmarm into .elf (ELF 32-bit LSB relocatable) ## with the additional dependency on $@-externals.S %.elf: %.S %-externals.S fasmarm $(FASMARGS) $< $@ # Generic rule to link .elf and .o into .bin (ELF 32-bit LSB executable) LINKARGS = -nostartfiles -nolibc -nostdlib -nodefaultlibs \ -pie -static -static-pie -fno-plt -Wl,--no-wchar-size-warning %.bin: %.elf gcc $(CFLAGS) $(LINKARGS) $^ -o $@ $(LIBS) # Generic rule to obtain the flat binary (after confirming %-externals.S) ## with a shell command to report entry points in $@.bin define NMLIST nm -t x $@.bin 2> /dev/null | sed '/ T /!d;s/^//' endef ## and an awk script to confirm $@-externals.S with that nm output define AWKPROG $$1 == "LINK" { LN = LN sprintf( "\nLINK %s, %s", MAP[$$3], $$3 ); \ if ( MAP[$$3] != $$2 ) { ER = 1 } ; next } \ $$2=="T" { MAP[$$3]=$$1 ; next } \ END { if ( ER != 1 ) exit 0; \ print "*** $@-external.S should be:" LN | "LC_ALL=C sort"; exit 1; } endef ## %: %.bin ( $(NMLIST) ; tr , ' ' < $@-externals.S ) | awk '$(AWKPROG)' objcopy -O binary -j .text -j .rodata $^ $@ Note that $(LIBS) may include object module libraries as per normal; the linking resolves all their references and only the references out of the fasmarm module(s) need the special attention via the "$@-externals.S" file. To make it all work the fasmarm main program, myprog.S, has a lead-in for an armv7 elf object module even though the end product is a flat binary. The lead-in is as follows: Code: format elf processor CPU32_ALL use32 postpone { include 'myprog-externals.inc' } section '.text' executable public _start _start: The Makefile will build and extract the flat binary if the LINK directives in $@-externals.S conform with the ELF executable. Otherwise it builds the ELF executable and then it fails before extraction, and prints how the LINK file should look. EDIT: corrected LINK macro to use 0x000100d8 (had it as 0x000100b8 before, which was wrong). |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.