From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26294 invoked by alias); 19 Jun 2015 21:11:11 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 26277 invoked by uid 48); 19 Jun 2015 21:11:07 -0000 From: "bugdal at aerifal dot cx" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/66609] New: [sh] Relative address expressions bind at as-time, even if symbol is weak Date: Fri, 19 Jun 2015 21:11:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bugdal at aerifal dot cx X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-06/txt/msg01803.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66609 Bug ID: 66609 Summary: [sh] Relative address expressions bind at as-time, even if symbol is weak Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: bugdal at aerifal dot cx Target Milestone: --- Minimal test case (compile with -fPIC and -Os or higher, for sh2 or later): __attribute__((__weak__,__visibility__("hidden"))) void foo() { } void bar() { foo(); } For the call from bar to foo, gcc generates: mov.l .L3,r1 braf r1 .LPCS0: nop .align 2 .L3: .long foo-(.LPCS0+2) Gas in turn ignores the fact that foo is weak and assembles the literal to a constant with no relocation. This is the following bug I just reported in binutils: https://sourceware.org/bugzilla/show_bug.cgi?id=18561 However, GCC can and probably should work around it, by instead generating the equivalent form that gas assembles correctly: .long foo@PCREL-(.LPCS0+2-.) This is easily changed at the following location: https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/config/sh/sh.c;h=e5fcd7683ef7e06d56a10427d792ba018d1af884;hb=HEAD#l1662 and changing it seems to have solved the problem for me, but I did not yet test extensively. I'm not sure if the subsequent case for UNSPEC_PCREL_SYMOFF also needs changes.