A.D.A. Amiga Demoscene Archive

        Welcome guest!

  

  

  

log in with SceneID

  

Demos Amiga Demoscene Archive Forum / Coding / Linking with vlink works, while linking with m68k-amiga-elf-ld or gcc doesn't

 

Author Message
rloaderror
Member
#1 - Posted: 18 Sep 2024 20:55
Reply Quote
I'm using Bartman's toolchain and I'd like to use gcc/ld to compile and link in order to get some benefits from its link time optimizations (-flto) or other.whole program optimizations.

The demo has a mix of c and asm object files. Both vasm and gcc outputs elf object files:

When linking with vlink everything works fine. vlink invocation:

vlink -bamigahunk -S -s -sd -sc -o $(PRG) $(OBJ)


But when linking with gcc or ld the demo crashes when entering certain asm files. If I rewrite those asm files to be pc relative it seems to fix the issue. However, I'd like to know whether I'm just missing some option for ld/gcc that could fix this rather than having to make all my old cranky asm pc relative? (vlink doesn't require this for sure)

Here is my linker invocation:

m68k-amiga-elf-ld -r -nostdlib --emit-relocs --verbose $(OBJ) -o demo.elf
elf2hunk demo.elf demo.hunk


Any idea? What parameters are you using?
rloaderror
Member
#2 - Posted: 19 Sep 2024 16:25
Reply Quote
Found a solution by using vlink to convert the final linked (and presumably link time optimized) elf file output from gcc to hunk format


m68k-amiga-elf-ld -r -nostdlib --emit-relocs --verbose $(OBJ) -o demo.elf
vlink -bamigahunk -S -s -sd -sc -o demo.hunk demo.elf


Elf2hunk may have a limitation or bug
rloaderror
Member
#3 - Posted: 19 Sep 2024 19:01
Reply Quote
After enabling -flto -fwhole-program the demo exe size reduced from 171K to 156K crunched. There were some complications in that the __start function (that calls main) got eliminated and when forcing it to be present by telling the compiler it is used it still got moved away from address 0 in the exe file.

I solved this by omitting the __start from the main compilation and linking and adding it back in the final vlink conversion step :) A bit ugly.

I tried using the --entry=__start option in gcc and the -e option in vlink to set another start address than 0 for the exe, but it didn't seem to have any effect.
Jamie2021
Member
#4 - Posted: 22 Sep 2024 17:29 - Edited
Reply Quote
Currently I use version 13.2 of GCC, I compile a single C/C++/ASM file to make the executable. If I only use one cpp file, this cpp file includes all the .h and other .cpp files, it's a big blob which allows me to do rebuilds in less than 2 seconds.

I also use -flto but it shouldn't optimize much given my blob architecture. I'm not sure this will help you since I don't use Vasm but I give you my link command

m68k-amiga-elf-ld --gc-sections -s -nostdlib --emit-relocs -Ttext=0 -o ^
C:/Dev/number8/source/gcc13/obj/number8.elf ^
C:/Dev/number8/source/gcc13/obj/mainAsm.o ^
C:/Dev/number8/source/gcc13/obj/mainC.o ^
C:/Dev/number8/source/gcc13/obj/mainCpp.o
rloaderror
Member
#5 - Posted: 23 Sep 2024 16:21
Reply Quote
Thanks! I think a single file with all cpp/h put into one could be a good solution.

While the stuff I wrote above works when using -std=c99 it actually causes some weird errors when I set std=c++11 or later. The linker errors report "stray [unicode] character in file", but the files in question are .o files. *shrug* Not sure what is going on.
noname
Member
#6 - Posted: 25 Sep 2024 13:31
Reply Quote
We also used Bartman's toolchain for The Loop and incorporated vasm into the mix, but without neither calling vlink, nor m68k-amiga-elf-ld explicitly.

We also we forced vasm to produce elf-output from our sources as well and threw it all at gcc. Here is our makefile: makefile m68k-amiga-elf-gcc w. vasm -Felf
rloaderror
Member
#7 - Posted: 29 Sep 2024 04:28
Reply Quote
Thanks a lot! If it worked for you it should work for me as well. I also output elf from vasm in the current build. Maybe I need to upgrade some of the tools. I haven't looked at a new vasm for ages.

 

  Please log in to comment

  

  

  

 

A.D.A. Amiga Demoscene Archive, Version 3.0