bebbo / gcc

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

DOpus5 fails to link with internal compiler error #153

Closed mheyer32 closed 3 years ago

mheyer32 commented 3 years ago

Compiling the master branch at https://github.com/mheyer32/dopus5allamigas via make os3 release debug=no fails with:

m68k-amigaos-gcc data.o string_data.o function_data.o menu_data.o palette_routines.o pattern.o key_press.o key_finder_data.o main.o commands.o menus.o popup.o popup_build.o iconpos.o cx.o wb.o text.o help.o eliza.o event_loop.o main_reset.o backdrop.o backdrop_render.o backdrop_idcmp.o backdrop_buttons.o backdrop_utils.o backdrop_arrange.o backdrop_position.o backdrop_open.o backdrop_drag.o backdrop_groups.o backdrop_notify.o backdrop_appicon.o backdrop_devices.o backdrop_snapshot.o backdrop_popup.o backdrop_format.o backdrop_select.o backdrop_info.o backdrop_leftout.o backdrop_replace.o desktop.o desktop_delete.o desktop_drop.o desktop_rename.o desktop_folder.o groups_new.o toolbar.o requesters.o notify.o graphics.o misc.o misc_proc.o dates.o links.o path_routines.o status_text.o scripts.o buffers.o buffers_util.o buffers_sort.o buffers_reselect.o filetypes.o filetypes_proc.o search_data.o lister.o lister_data.o lister_proc.o lister_idcmp.o lister_function.o lister_window.o lister_diskinfo.o lister_display.o lister_busy.o lister_title.o lister_activate.o lister_buffers.o lister_dir.o lister_show.o lister_toolbar.o lister_drop.o lister_icons.o lister_progress.o lister_clip.o lister_menus.o lister_hotname.o lister_edit.o lister_ftp.o buttons.o buttons_data.o buttons_proc.o buttons_draw.o buttons_window.o buttons_display.o buttons_idcmp.o buttons_function.o buttons_run.o buttons_io.o buttons_edit.o buttons_popup.o start_menu.o dirlist_read.o dirlist_scroll.o dirlist_util.o function_launch.o function_paths.o function_readdir.o function_run.o function_parse.o function_internal.o function_external.o function_script.o function_support.o function_filechange.o function_filetype.o function_files.o function_all.o function_none.o function_toggle.o function_copy.o function_delete.o function_makedir.o function_rename.o function_stopsniff.o function_select.o function_select_data.o function_devicelist.o function_change.o function_change_data.o function_scandir.o function_clearbuffers.o function_show.o function_disk.o function_loadbuttons.o function_loadenvironment.o function_loadfonts.o function_leaveout.o function_runprog.o function_addicon.o function_search.o function_getsizes.o function_hunt.o function_parent.o function_user.o function_verify.o function_cli.o function_printdir.o function_set.o function_closebuttons.o function_special.o function_reselect.o function_assign.o function_configure.o function_setbackground.o function_runcommand.o function_reset.o clock_task.o environment.o app_msg.o icons.o icon_function.o file_select.o file_openwith.o window_activate.o cleanup.o tile.o display.o display_pattern.o rexx_proc.o rexx_lister.o rexx_files.o rexx_util.o rexx_data.o rexx_traps.o rexx_apps.o rexx_handler.o rexx_cmd.o rexx_dopus.o dos_notify.o replace.o position.o callback_main.o callback_dir.o callback_help.o callback_lister.o about.o amiga.o 68k_asm_a4_a5.o -m68020-60 -flto -fshort-enums -D__amigaos3__ -D__USE_SYSBASE -D__NO_NET_API -DUSE_64BIT -DCOMPDATE=30.03.2021 -g -ggdb -noixemul -Os -fomit-frame-pointer -specs _gcc.spec -stackswap -lamiga -o ../bin.os3/DirectoryOpus
(insn 1084 1203 1202 73 (set (mem:QI (post_inc:SI (reg:SI 8 a0)) [0 MEM[base: _521, offset: 0B]+0 S1 A8])
        (plus:QI (mem:QI (reg:SI 9 a1) [0  S1 A8])
            (reg:QI 0 d0 [ _RandomDopus_re+1 ]))) function_copy.c:1566 141 {addqi3}
     (expr_list:REG_INC (reg:SI 8 a0)
        (nil)))
function_copy.c: In function 'function_copy_file':
function_copy.c:1737:1: error: insn does not satisfy its constraints:
 }
 ^
(insn 1084 1203 1202 73 (set (mem:QI (post_inc:SI (reg:SI 8 a0)) [0 MEM[base: _521, offset: 0B]+0 S1 A8])
        (plus:QI (mem:QI (reg:SI 9 a1) [0  S1 A8])
            (reg:QI 0 d0 [ _RandomDopus_re+1 ]))) function_copy.c:1566 141 {addqi3}
     (expr_list:REG_INC (reg:SI 8 a0)
        (nil)))
function_copy.c:1737:1: internal compiler error: in extract_constrain_insn, at recog.c:2199
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: fatal error: m68k-amigaos-gcc returned 1 exit status
compilation terminated.
collect2: fatal error: lto-wrapper returned 1 exit status
compilation terminated.
makefile.os3:21: recipe for target '../bin.os3/DirectoryOpus' failed
make[1]: *** [../bin.os3/DirectoryOpus] Error 1
make[1]: Leaving directory '/home/matze/dopus5allamigas/source/Program'
makefile:126: recipe for target 'program' failed
make: *** [program] Error 2
mheyer32 commented 3 years ago

It builds again, but doesn't run - even with -flto disabled. It'll just crash :-( The '-flto' compiler switch can be found in dopus5allamigas/source/makefile.comon

I'll let you know once I dug a bit deeper.

mheyer32 commented 3 years ago

I think this might be a regression related to https://github.com/bebbo/gcc/issues/137#issue-776812265

When looking at ADoom, I can see that the a5 parameter passed into c2p_6_020 (this will be used when choosing an EHB screen modes) gets screwed up again.

DOpus also makes use of A5 in a few places.

bebbo commented 3 years ago

the inline macros are using d7 instead of a5 plus an exg d7,a5 before and after the function call. I guess you have to establish something similar to be safe.

mheyer32 commented 3 years ago

The A5 thingy was a red herring - that's not it. Also, even with -fbbb=- I experience crashes. Continueing the investigation.

bebbo commented 3 years ago

what's the last working version?

mheyer32 commented 3 years ago

IDK - I hadn't recompiled DOpus in a while. Do you have a suggestion for a known good version of GCC I could start a bisection with?

bebbo commented 3 years ago

try this one please: e0013462782186e62d08d7426da2127d24d00e7d

mheyer32 commented 3 years ago

This one crashes the compiler:

>>>>>Compiling window_activate.c
(insn 1082 1206 1205 73 (set (mem:QI (post_inc:SI (reg:SI 8 a0)) [0 MEM[base: _60, offset: 0B]+0 S1 A8])
        (plus:QI (mem:QI (reg:SI 9 a1) [0  S1 A8])
            (reg:QI 0 d0 [ _RandomDopus_re+1 ]))) function_copy.c:1566 141 {addqi3}
     (expr_list:REG_INC (reg:SI 8 a0)
        (nil)))
function_copy.c: In function 'function_copy_file':
function_copy.c:1737:1: error: insn does not satisfy its constraints:
 }
 ^
(insn 1082 1206 1205 73 (set (mem:QI (post_inc:SI (reg:SI 8 a0)) [0 MEM[base: _60, offset: 0B]+0 S1 A8])
        (plus:QI (mem:QI (reg:SI 9 a1) [0  S1 A8])
            (reg:QI 0 d0 [ _RandomDopus_re+1 ]))) function_copy.c:1566 141 {addqi3}
     (expr_list:REG_INC (reg:SI 8 a0)
        (nil)))
function_copy.c:1737:1: internal compiler error: in extract_constrain_insn, at recog.c:2199
Please submit a full bug report,
with preprocessed source if appropriate.
bebbo commented 3 years ago

hm - maybe: c0d957cf8ba93e529a1f3ca04d4c741ea267f254

mheyer32 commented 3 years ago

I got a lead. The issue was that when DOpus opens xadopus.module, it'll try to find and read a string from its built-in catalog. That would never return and eventually the machine would crash.

// Locale marker
struct DOpusLocale
{
    APTR        li_LocaleBase;
    APTR        li_Catalog;
    char        *li_BuiltIn;       <<<<<<<<<<<< pointing to the list of strings in its own catalog defined by  'XADopus_Block'
    struct Locale   *li_Locale;
};

I later found that somewhere along the way the li_BuiltIn pointer got corrupted and thus sending L_GetString() into the weeds.

This happens in source/Modules/xadopus/init/libinit.c at this place:

    // Allocate and open locale data
    if(!(locale=AllocVec(sizeof(struct DOpusLocale),MEMF_CLEAR)))
        return 1;
    init_locale_data(locale);

    bug("locale: 0x%lx locale->li_BuiltIn %lx : %s", locale, locale->li_BuiltIn, locale->li_BuiltIn);

    // Open locale library
    if((LocaleBase=(APTR)OpenLibrary("locale.library",38)))
    {
        // Initialise catalog
        locale->li_LocaleBase=LocaleBase;
        if(module_info.locale_name) locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,0);
        locale->li_Locale=OpenLocale(0);
    }

    bug("locale: 0x%lx locale->li_BuiltIn %lx : %s", locale, locale->li_BuiltIn, locale->li_BuiltIn);

The last bug() output already shows that the locale->li_BuiltIn had been modified somewhere inside the if() clause.

Looking at the asm, I believe there's some issue either with symbol reloading or wrong accounting for auto-increment happening:

    if((LocaleBase=(APTR)OpenLibrary("locale.library",38)))
 796:   movea.l 0 0 __start,a6
 79c:   moveq #38,d0
 79e:   lea 5a2 5a2 _freeBase+0x238(pc),a1
 7a2:   jsr -552(a6)
 7a6:   move.l d0,10 10 _exit+0xc
 7ac:   addq.l #4,sp
 7ae:   beq.s 758 758 _UserLibInit+0x1e
        locale->li_LocaleBase=LocaleBase;
 7b0:   movea.l 0 0 __start,a3           >>>>>>>>> points to li_LocalBase
 7b6:   move.l d0,(a3)+                     >>>>>>>>>> now points to li_Catalog
        if(module_info.locale_name) locale->li_Catalog=OpenCatalogA(NULL,module_info.locale_name,0);
 7b8:   movea.l 8 8 _exit+0x4,a1
 7be:   move.l a1,d1
 7c0:   beq.s 7d6 7d6 _UserLibInit+0x9c
 7c2:   lea 0 0 __start,a2
 7c6:   movea.l a2,a0
 7c8:   movea.l d0,a6
 7ca:   jsr -150(a6)
 7ce:   move.l d0,(a3)             //  update li_Catalog
 7d0:   movea.l 0 0 __start,a3                           // RELOAD  locale, again pointing back to li_LocalBase
        locale->li_Locale=OpenLocale(0);
 7d6:   lea 0 0 __start,a0
 7da:   movea.l 10 10 _exit+0xc,a6
 7e0:   jsr -156(a6)
 7e4:   move.l d0,8(a3)                                    // HERE's the bug: 8(a3) is pointing to li_BuiltIn, not li_Locale; li_BuiltIn gets corrupted
    return 0;   
 7e8:   clr.l d0
 7ea:   bra.w 758 758 _UserLibInit+0x1e
bebbo commented 3 years ago

so this here: https://franke.ms/cex/z/T1TMdx

mheyer32 commented 3 years ago

Yep, I'm glad its reproducing in the explorer! Its doing the same thing

        move.l _locale,a2
.L5:
        clr.l -(sp)
        jsr _OpenLocale
        move.l d0,(8,a2)  << should be 12 or above reload of _locale could be avoided
bebbo commented 3 years ago

but -fbbb=- avoids it - and yes, it's a bug. The path after the assignment must not intersect the modified path

mheyer32 commented 3 years ago

but -fbbb=- avoids it - and yes, it's a bug. The path after the assignment must not intersect the modified path

Yes, sorry, that probably was some mistake on my side. At the same time I also have an issue with ADoom's EHB mode. That is something I still need to figure out...

bebbo commented 3 years ago

please test

mheyer32 commented 3 years ago

That didn't do it. The code remained unchanged. I did a complete clean & rebuild of the toolchain. Compiler Explorer also still shows the old code.

bebbo commented 3 years ago

... I forgot one change - there are so many pending changes^^

mheyer32 commented 3 years ago

Sind wir nicht alle ein bisschen bluna? :-D

mheyer32 commented 3 years ago

That still wasn't enough. This one is stubborn.

bebbo commented 3 years ago

on cex it's ok now (you have to wait for the nightly cex (or manual by me) update and force recompiling)

mheyer32 commented 3 years ago

You can see for yourself: take -flto out of makefile.common then compile with make os3 release debug=no -j8

then m68k-amigaos-objdump -m68020-60 --no-show-raw-insn -d -S Modules/xadopus/init/libinit.o > libinit.asm

and search for

if((LocaleBase=(APTR)OpenLibrary("locale.library",38)))

bebbo commented 3 years ago

all good things come in threes...

mheyer32 commented 3 years ago

Third time works a charm!

mheyer32 commented 3 years ago

Closing!