From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DC8013853D65; Thu, 17 Nov 2022 19:21:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DC8013853D65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668712894; bh=BwlZ+HttFFRy4vgHxV0ZxFy7ufT6Ib/Izvu5LsGxdtY=; h=From:To:Subject:Date:From; b=MDladxkfn6ojhLSqbVjmNtXczK0mgjf4PjOSCX/S6Kn8b1E7hINDkdbxUBqSXZxWd mbScqQDFziESCag6CRnt1HoNz9I6OPpSycjSq9ageoSAQsCxhN63mup0bn4JYv42v3 Vy2xZ7YKV8JdZ1RKob0316076QSBnOaIwFK3wLFE= From: "miladfarca at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107736] New: call to a function, generated by inline asm, is off by one byte Date: Thu, 17 Nov 2022 19:21:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: miladfarca at gmail dot com 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: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107736 Bug ID: 107736 Summary: call to a function, generated by inline asm, is off by one byte Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: miladfarca at gmail dot com Target Milestone: --- Tested on Arm64, PPC64 and s390x with gcc 12. ``` const char num =3D 0; void call(); asm( ".globl call \n" ".type call, %function \n" ".hidden call \n" "call: \n" // Just return. "ret \n"); int main(){ call(); return 0; } ``` TL;DR: The instruction generated for `call();` is jumping to the address of `num` = and causing a crash as `num` is not an instruction, seems to be an alignment is= sue? Details: - This doesn't happen on x64 and call is made to the correct address. It al= so does not happen with clang on either platforms (tested with version 6.0). - gcc is putting "call" into .rodata section of memory including on x64. Not sure if this is a separate bug or intentional. clang is putting it under ".text" as expected. - gcc is incorrectly assuming `&num` is the address of `call` and jumping t= o it which is off by 1 byte. - Workarounds include adding either ".text \n" or ".align 8" to the inline = asm, tho call should be made to the correct address even without them?=