bebbo / gcc

Bebbo's gcc-6-branch for m68k-amigaos
GNU General Public License v2.0
33 stars 11 forks source link

-fno-leading-underscore LTO bug #195

Closed RetroRevivalGames closed 1 year ago

RetroRevivalGames commented 1 year ago

Just a quick bug report.

Using -flto doesn't work when using -fno-leading-underscore. I tested this on 64-bit Cygwin running on a 64-bit Windows 10 system. It compiles fine using LTO without -fno-leading-underscore. But using the flag causes no .out file to be produced. Note I've only tested this on Cygwin. I can't confirm if this happens on Linux.

Example Command (Doesn't produce .out): m68k-amigaos-gcc -flto -fno-leading-underscore -O3 -nostdlib main.c

Example Command (Produces .out): m68k-amigaos-gcc -flto -O3 -nostdlib main.c

bebbo commented 1 year ago

lto needs to find the entry point. if there is none, there is no output.

RetroRevivalGames commented 1 year ago

I'll have to look into this further. Unfortunately adding an entry symbol to my linker script doesn't solve the problem. Still not outputting a .out.

bebbo commented 1 year ago

this creates a file:

m68k-amigaos-gcc -flto  -O3 -nostdlib main.c -Wl,-init,_main -o main
RetroRevivalGames commented 1 year ago

I gave that a try. There's no -fno-leading-underscore in your example though which is what's causing the problem for me.

bebbo commented 1 year ago

please update and test

RetroRevivalGames commented 1 year ago

I've updated and tested. Looks like it's now producing a .out file with the contents I expect. But the symbols still have underscores even when using the -fno-leading-underscore option ONLY FOR LTO. When compiling without LTO the option works fine.

bebbo commented 1 year ago

Guess it's now a pebcak.

main.c:

int foo();

int main() {
  return foo() - 1;
}

foo.c:

int foo() {
  return 1;
}

m68k-amigaos-gcc -flto -fno-leading-underscore -O3 -nostdlib main.c foo.c -o test m68k-amigaos-objdump -x test


test:     file format amiga
test
architecture: m68k:68000, flags 0x00000010:
HAS_SYMS
start address 0x00000000

Sections:
Idx Name          Size      VMA       LMA       File off  Algn
  0 .text         00000008  00000000  00000000  00000020  2**2
                  CONTENTS, ALLOC, LOAD, CODE
SYMBOL TABLE:
00000008 g       .text      0000 00 __etext
00008006 g       .text      0000 00 ___a4_init
00000008 g       .text      0000 00 ___datadata_relocs
00000008 g       .text      0000 00 __end
00000008 g       .text      0000 00 __edata
00000008 g       .text      0000 00 __bss_start
00000000 g       .text      0000 00 main
00000000 g       .text      0000 00 __stext
00000008 g       .text      0000 00 __sdata
00000004 g       .text      0000 00 foo

no underscores

and using m68k-amigaos-gcc -flto -fwhole-program -fno-leading-underscore -O3 -nostdlib main.c foo.c -o test gets rid of foo too

RetroRevivalGames commented 1 year ago

I tested it again. Yes it works. Tested in Cygwin and WSL.