The -mrelax support is broken for sh-elf since PIC code support was added. Most of the work to fix this will likely be in bfd, ld and gas, although some gcc changes may also be necessary. IIRC I've fixed the switch tables once, but ordinary branches are still broken. gcc R117374 with binutils/newlib D2006.10.02.18.00.00 shows 681 failures for check-gcc check-target-libstdc++-v3 testing the variations sh-hms-sim sh-hms-sim/-m4/-ml with a small patch to enable -mrelax when optimizing, the tests are not finished after 17.5 hours, but 2098 failures have been detected so far.
Created attachment 1346 [details] patch to enable relaxation when optimizing This patch to gcc/gcc/config/sh/sh.h enables -mrelax by default when optimizing, thus exposing the brokenness of this feature for an ordinary build / test cycle.
(In reply to comment #0) > with a small patch to enable -mrelax when optimizing, the tests are not finished > after 17.5 hours, but 2098 failures have been detected so far. Still not finished after 64.9 hours, 4074 failures so far.
One thing that I just noticed while browsing through sh_elf_relax_delete_bytes is that we don't process R_SH_ALIGN properly; i.e. when we stop at a larger alignment, we should should check if we should now remove bytes of the full size of the alignment.
Created attachment 8080 [details] GCC patch to enable -mrelax by default This is another patch to turn the -mrelax option in GCC by default. Since PR 10378 and PR 10373 have been fixed, I've tried building GCC with -mrelaxed enabled by default. The build would stop in libgcc/config/sh/lib1funcs.S, where GAS would complain that a mova insn is referring to an unaligned offset. After applying the following: Index: libgcc/config/sh/lib1funcs.S =================================================================== --- libgcc/config/sh/lib1funcs.S (revision 220017) +++ libgcc/config/sh/lib1funcs.S (working copy) @@ -116,7 +116,7 @@ HIDDEN_FUNC(GLOBAL(ashiftrt_r4_31)) HIDDEN_FUNC(GLOBAL(ashiftrt_r4_32)) - .align 1 + .align 4 GLOBAL(ashiftrt_r4_32): GLOBAL(ashiftrt_r4_31): rotcl r4 @@ -765,6 +765,7 @@ bt GLOBAL(movmemSI52) ! done all the large groups, do the remainder ! jump to movmem+ + .balign 4 mova GLOBAL(movmemSI4)+4,r0 add r6,r0 jmp @r0 GCC (sh-elf C,C++, newlib 2.2.0) can be built successfully. When compiling a simple C++ program with the resulting toolchain: #include <iostream> int main (void) { std::cout << "hello world" << std::endl; return 0; } There are a lot of warnings from LD like: /usr/local/lib/gcc/sh-elf/5.0.0/../../../../sh-elf/bin/ld: /usr/local/lib/gcc/sh-elf/5.0.0/../../../../sh-elf/lib/ml/m4/libstdc++.a(locale_init.o): 0x18: warning: symbol in unexpected section /usr/local/lib/gcc/sh-elf/5.0.0/../../../../sh-elf/bin/ld: /usr/local/lib/gcc/sh-elf/5.0.0/../../../../sh-elf/lib/ml/m4/libstdc++.a(locale_init.o): 0x6c: warning: symbol in unexpected section /usr/local/lib/gcc/sh-elf/5.0.0/../../../../sh-elf/bin/ld: /usr/local/lib/gcc/sh-elf/5.0.0/../../../../sh-elf/lib/ml/m4/libstdc++.a(locale_init.o): 0x70: warning: symbol in unexpected section /usr/local/lib/gcc/sh-elf/5.0.0/../../../../sh-elf/bin/ld: /usr/local/lib/gcc/sh-elf/5.0.0/../../../../sh-elf/lib/ml/m4/libstdc++.a(locale_init.o): 0x3c: warning: symbol in unexpected section But linking somehow succeeds. However, the resulting program does not work.