Retro68 icon indicating copy to clipboard operation
Retro68 copied to clipboard

Optimisation fails in PIC modes

Open elliotnunn opened this issue 1 year ago • 1 comments

Wolfgang, thank you for fixing my previous issue with -msep-data. My ROM driver is working well. Working with the A5 data model I also noticed that compilation fails on any non-0 optimisation level.

Currently I work around this by giving a long list of individual "-fsomething" arguments that does NOT include "-fcombine-stack-adjustments".

I poked around expr.cc, where I got the vague idea that "note" structures track how much scratch data needs to be popped from the stack, but my understanding is limited. From the history of expr.cc it seems that this is bug came from upstream GCC.

COMPILING THIS TEST CODE:
        void func1(char *string);
        void func2(void) {
            func1("string");
        }

COMPILED WITH "m68k-apple-macos-gcc -c -O1 "
           0:	4879 0000 0000 	pea 0 <func2>
           6:	4eb9 0000 0000 	jsr 0 <func2>
           c:	588f           	addql #4,%sp
           e:	4e75           	rts
          10:	8566           	orw %d2,%fp@-
          12:	756e           	.short 0x756e
          14:	6332           	blss 48 <func2+0x48>

COMPILED WITH "m68k-apple-macos-gcc -c -O1 -mpcrel"
           0:	487a 0000      	pea %pc@(2 <func2+0x2>)
           4:	6100 0000      	bsrw 6 <func2+0x6>
           8:	588f           	addql #4,%sp
           a:	4e75           	rts
           c:	8566           	orw %d2,%fp@-
           e:	756e           	.short 0x756e
          10:	6332           	blss 44 <func2+0x44>

COMPILED WITH "m68k-apple-macos-gcc -c -O1 -fpic"
        during RTL pass: combine
        /tmp/ctest.c: In function ‘func2’:
        /tmp/ctest.c:4:1: internal compiler error: in fixup_args_size_notes, at expr.cc:4469
            4 | }
              | ^
        Please submit a full bug report, with preprocessed source (by using -freport-bug).
        See <https://gcc.gnu.org/bugs/> for instructions.

COMPILED WITH "m68k-apple-macos-gcc -c -O1 -fPIC"
        during RTL pass: combine
        /tmp/ctest.c: In function ‘func2’:
        /tmp/ctest.c:4:1: internal compiler error: in fixup_args_size_notes, at expr.cc:4469
            4 | }
              | ^
        Please submit a full bug report, with preprocessed source (by using -freport-bug).
        See <https://gcc.gnu.org/bugs/> for instructions.

COMPILED WITH "m68k-apple-macos-gcc -c -O1 -msep-data"
        during RTL pass: combine
        /tmp/ctest.c: In function ‘func2’:
        /tmp/ctest.c:4:1: internal compiler error: in fixup_args_size_notes, at expr.cc:4469
            4 | }
              | ^
        Please submit a full bug report, with preprocessed source (by using -freport-bug).
        See <https://gcc.gnu.org/bugs/> for instructions.

COMPILED WITH "m68k-apple-macos-gcc -c -O1 -mid-shared-library"
        during RTL pass: combine
        /tmp/ctest.c: In function ‘func2’:
        /tmp/ctest.c:4:1: internal compiler error: in fixup_args_size_notes, at expr.cc:4469
            4 | }
              | ^
        Please submit a full bug report, with preprocessed source (by using -freport-bug).
        See <https://gcc.gnu.org/bugs/> for instructions.

elliotnunn avatar May 07 '24 00:05 elliotnunn

I'm rapidly growing to dislike fixup_args_size_notes. Never figured out what's going on there.

I also assume that it's related to #232...

The assertion failure is close to a 'HALF-UNDERSTOOD HACK' that I added to prevent a different internal compiler error. So the first thing to try will be to disable that hack...

autc04 avatar May 07 '24 17:05 autc04