Bug 3298 - -mrelax broken for sh-elf
Summary: -mrelax broken for sh-elf
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-03 13:35 UTC by Joern Rennecke
Modified: 2015-01-23 17:27 UTC (History)
5 users (show)

See Also:
Host:
Target: sh-elf
Build:
Last reconfirmed:


Attachments
patch to enable relaxation when optimizing (489 bytes, patch)
2006-10-03 13:38 UTC, Joern Rennecke
Details | Diff
GCC patch to enable -mrelax by default (571 bytes, patch)
2015-01-23 17:27 UTC, Oleg Endo
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Joern Rennecke 2006-10-03 13:35:31 UTC
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.
Comment 1 Joern Rennecke 2006-10-03 13:38:33 UTC
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.
Comment 2 Joern Rennecke 2006-10-05 12:56:05 UTC
(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.
Comment 3 Joern Rennecke 2014-11-10 19:04:27 UTC
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.
Comment 4 Oleg Endo 2015-01-23 17:27:47 UTC
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.