bebbo / amiga-gcc

The GNU C-Compiler with Binutils and other useful tools for cross development for Amiga
GNU General Public License v2.0
312 stars 66 forks source link

LTO Plugin Support? #297

Closed RetroRevivalGames closed 2 years ago

RetroRevivalGames commented 2 years ago

Hello,

Since my last post I have gotten LTO to work! However, I am trying to build a static library of LTO object files and I can't seem to get it to work. In order to build static libraries with LTO objects you need lto plugins enabled. So, seeing the makefile has the --disable-plugins flag for configuring binutils, I removed the flag to enable them. I build an object file to include in the library. Example:

m68k-amigaos-gcc -c -O3 -mregparm=3 -flto add.c

Then, I use m68k-amigaos-ar with the lto plugin to create the lib file. Example:

m68k-amigaos-ar rcs --plugin=/home/${USER}/m68k-amigaos-toolchain/libexec/gcc/m68k-amigaos/6.5.0b/liblto_plugin.so lib/libadd.a add.o

And finally I link the library:

m68k-amigaos-gcc -O3 -nostdlib -flto -fuse-linker-plugin main.c -L lib -ladd

But I get undefined reference:

/home/matthew/m68k-amigaos-toolchain/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: /tmp/ccLaoR5d.ltrans0.ltrans.o: in function main': /tmp/ccLaoR5d.ltrans0.ltrans.o:(.text+0xe): undefined reference toadd' collect2: fatal error: ld returned 1 exit status compilation terminated.

When I check the contents of libadd.a I also don't see the _add symbol.

m68k-amigaos-nm --plugin=/home/matthew/m68k-amigaos-toolchain/libexec/gcc/m68k-amigaos/6.5.0b/liblto_plugin.so.0 lib/libadd.a

Output: add.o: 00000000 T nacc' '-mregparm=3' <---- _add should be here!!

Does your gcc toolchain support plugins?

Thank you!

RetroRevivalGames commented 2 years ago

The _add symbol refers to a basic function that adds two input integers and returns the result.

bebbo commented 2 years ago

sorry - but the plugin is disabled, since there is some implementation missing.

RetroRevivalGames commented 2 years ago

OK. No problem. Just wanted to confirm the status of lto plugins.

RetroRevivalGames commented 2 years ago

As an important note, it looks like you can compile with -ffat-lto-objects if you want to place the objects in a static library using ar without an lto plugin. Or you could just keep each of the object files individually and use those.

bebbo commented 2 years ago

As an important note, it looks like you can compile with -ffat-lto-objects if you want to place the objects in a static library using ar without an lto plugin. Or you could just keep each of the object files individually and use those.

The -ffat-lto-objects .o files do not participate in LTO. Single .o files will work.