NetBSD Problem Report #52253

From www@NetBSD.org  Tue May 23 01:21:04 2017
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 15BF17A167
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 23 May 2017 01:21:04 +0000 (UTC)
Message-Id: <20170523012102.977927A2AC@mollari.NetBSD.org>
Date: Tue, 23 May 2017 01:21:02 +0000 (UTC)
From: coypu@sdf.org
Reply-To: coypu@sdf.org
To: gnats-bugs@NetBSD.org
Subject: clang seems to unconditionally emits frame pointer code
X-Send-Pr-Version: www-1.0

>Number:         52253
>Category:       toolchain
>Synopsis:       clang seems to unconditionally emits frame pointer code
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    toolchain-manager
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue May 23 01:25:00 +0000 2017
>Closed-Date:    Sat Feb 08 19:19:03 +0000 2020
>Last-Modified:  Sat Feb 08 19:19:03 +0000 2020
>Originator:     coypu
>Release:        NetBSD 7.99.71
>Organization:
>Environment:
NetBSD loggy 7.99.71 NetBSD 7.99.71 (SAFE) #0: Sat May 13 15:28:53 IDT 2017  fly@loggy:/usr/src/sys/arch/amd64/compile/SAFE amd64

>Description:
While experimenting with compiling to mips, I noticed frame pointer code is always emitted, even if -On is used. I believe this is the case for all architectures (I see a difference in x86

with clang 4.0.0 from pkgsrc, compare:

$ clang --target=mipsel--netbsd7.99 -nostdlib -o test test.c -O3
/usr/bin/ld: warning: cannot find entry symbol __start; defaulting to 0x20000
$ llvm-objdump -d test

test:	file format ELF32-mips

Disassembly of section .text:
main:
   20000:	f8 ff bd 27 	addiu	$sp, $sp, -8
   20004:	04 00 be af 	sw	$fp, 4($sp)
   20008:	25 f0 a0 03 	move	 $fp, $sp
   2000c:	00 00 02 24 	addiu	$2, $zero, 0
   20010:	25 e8 c0 03 	move	 $sp, $fp
   20014:	04 00 be 8f 	lw	$fp, 4($sp)
   20018:	08 00 e0 03 	jr	$ra
   2001c:	08 00 bd 27 	addiu	$sp, $sp, 8

$ clang --target=mipsel--netbsd7.99 -nostdlib -o test test.c -O3 -fomit-frame-pointer
/usr/bin/ld: warning: cannot find entry symbol __start; defaulting to 0x20000
$ llvm-objdump -d test

test:	file format ELF32-mips

Disassembly of section .text:
main:
   20000:	08 00 e0 03 	jr	$ra
   20004:	00 00 02 24 	addiu	$2, $zero, 0

>How-To-Repeat:

>Fix:
Presumably the following untested patch, but it needs to undergo some level of testing / architecture specific limitations.

This file has moved in clang upstream, and the code is now located in:
https://github.com/llvm-mirror/clang/blob/master/lib/Driver/ToolChains/Clang.cpp#L520-L570

Index: Tools.cpp
===================================================================
RCS file: /cvsroot/src/external/bsd/llvm/dist/clang/lib/Driver/Tools.cpp,v
retrieving revision 1.1.1.14
diff -u -p -r1.1.1.14 Tools.cpp
--- Tools.cpp	9 Feb 2017 17:38:05 -0000	1.1.1.14
+++ Tools.cpp	23 May 2017 01:05:09 -0000
@@ -3467,6 +3467,10 @@ static bool useFramePointerForTargetByDe
     }
   }

+  if (Triple.isOSNetBSD()) {
+    return !areOptimizationsEnabled(Args);
+  }
+
   return true;
 }


>Release-Note:

>Audit-Trail:

State-Changed-From-To: open->closed
State-Changed-By: maya@NetBSD.org
State-Changed-When: Sat, 08 Feb 2020 19:19:03 +0000
State-Changed-Why:
fixed by joerg in upstream clang.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.