From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D722F3858D32; Sun, 8 Jan 2023 18:56:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D722F3858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1673204168; bh=NWEaWorTPRajGuTqPjKqXcDQEk0uo4H6xovU2wmW5Xc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TJyhBNPIAWPilLF+ObkP5iCoi+M283hMjDRQh1q8cKj3TBr9MWpptdhb0idtu8TON Bd6GMQa+iBIAxPBxfaIJvWYUHHukwVQQe1A9elSonNHE9HZtc5AeDiKUMB18An1X7e OIGNHieGCbiKpv3ukW1Wx5udp6Dkl8MRBpLfHKOE= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/108337] Misaligned memory access issues when inline assembly is used with optimization on x86_64 Date: Sun, 08 Jan 2023 18:56:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.2.1 X-Bugzilla-Keywords: inline-asm X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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_status resolution Message-ID: In-Reply-To: References: 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=3D108337 Andrew Pinski changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution|--- |INVALID --- Comment #2 from Andrew Pinski --- int main(int argc, char *argv[]) { int i =3D 0; char msg[65] =3D "Hello World 0!\n"; auto result =3D write(1, msg, sizeof(msg) - 1); i =3D 0; uintptr_t t; asm("mov %%rsp, %0":"=3Dr"(t)); while (i < 64) { uintptr_t tt =3D (t >> i) & 0xf; msg[(64-i-1)] =3D (tt > 9) ? (tt - 10 + 'a') : (tt + '0'); i++; } result =3D write(1, msg, sizeof(msg) - 1); exit(result >=3D 0 ? 0 : 1); } Gives: 00000000000000000137fffffffffffeda5b6db6da5a49248124925b7eda5a48 For -static -nostartfiles -nostdlib -Wl,-emain without gives: 00000000000000000137ffffffffffedb6c92480001248137ec8125b6da5a480 You need -mstackrealign to correct for the not aligned stack pointer that = the kernel gives.=