Bug 215600 - devel/powerpc64-gcc based buildkernel: sys/powerpc/powerpc/db_trace.c rejected for: '__builtin_frame_address' with a nonzero argument is unsafe
Summary: devel/powerpc64-gcc based buildkernel: sys/powerpc/powerpc/db_trace.c rejecte...
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: powerpc Any
: --- Affects Only Me
Assignee: Justin Hibbits
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-27 08:28 UTC by Mark Millard
Modified: 2017-06-19 02:02 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Millard 2016-12-27 08:28:13 UTC
[This was for head -r310556 via devel/powerpc64-gcc (6.2.0 based gcc), found
while testing an unrelated patch that let the buildkernel get this far under
6.2.0's vintage.]

sys/powerpc/powerpc/db_trace.c 's:

void
db_trace_self(void)
{
        db_addr_t addr;

        addr = (db_addr_t)__builtin_frame_address(1);
        db_backtrace(curthread, addr, -1);
}

ended up with:

--- db_trace.o ---
/usr/src/sys/powerpc/powerpc/db_trace.c: In function 'db_trace_self':
/usr/src/sys/powerpc/powerpc/db_trace.c:299:20: error: calling '__builtin_frame_address' with a nonzero argument is unsafe [-Werror=frame-address]
  addr = (db_addr_t)__builtin_frame_address(1);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
. . .
--- db_trace.o ---
cc1: all warnings being treated as errors
*** [db_trace.o] Error code 1

make[2]: stopped in /usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/sys/GENERIC64vtsc-NODBG
.ERROR_TARGET='db_trace.o'
.ERROR_META_FILE='/usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/sys/GENERIC64vtsc-NODBG/db_trace.o.meta'



Note:

sys/powerpc/powerpc/db_trace.c -r132070 2004-Jul-12 is when this
__builtin_frame_address use was introduced.



# Meta data file /usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/sys/GENERIC64vtsc-NODBG/db_trace.o.meta
CMD /usr/local/bin/powerpc64-unknown-freebsd12.0-gcc -isystem /usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/tmp/usr/include -L/usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/tmp/usr/lib -B/usr/obj/powerpc64vtsc_xtoolchain_kernel/powe
rpc.powerpc64/usr/src/tmp/usr/lib --sysroot=/usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/tmp -B/usr/local/powerpc64-freebsd/bin/ -c -O -pipe  -g -nostdinc  -I. -I/usr/src/sys -I/usr/src/sys/contrib/libfdt -D_KERNEL -DHAVE_KERNEL_OPTION_HEADERS -includ
e opt_global.h  -msoft-float -Wa,-many -fPIC -fno-omit-frame-pointer -mno-altivec -ffreestanding -fwrapv -fstack-protector -gdwarf-2 -Wall -Wredundant-decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-
sign -fformat-extensions -Wmissing-include-dirs -fdiagnostics-show-option -Wno-unknown-pragmas -Wno-error=address -Wno-error=aggressive-loop-optimizations -Wno-error=array-bounds -Wno-error=attributes -Wno-error=cast-qual -Wno-error=enum-compare -Wno-error=inline -Wno-erro
r=maybe-uninitialized -Wno-error=overflow -Wno-error=sequence-point -Wno-error=strict-overflow -Wno-error=unused-but-set-variable -Wno-error=misleading-indentation -Wno-error=nonnull-compare -Wno-error=shift-overflow -Wno-error=tautological-compare  -v -fno-common -fms-ext
ensions -finline-limit=15000 --param inline-unit-growth=100 --param large-function-growth=1000 -msoft-float -mcall-aixdesc  -std=iso9899:1999 -Werror  /usr/src/sys/powerpc/powerpc/db_trace.c
CMD ctfconvert -L VERSION -g db_trace.o
CWD /usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/sys/GENERIC64vtsc-NODBG
TARGET db_trace.o
-- command output --
Using built-in specs.
COLLECT_GCC=/usr/local/bin/powerpc64-unknown-freebsd12.0-gcc
Target: powerpc64-unknown-freebsd12.0
Configured with: /usr/obj/portswork/usr/ports/devel/powerpc64-gcc/work/gcc-6.2.0/configure --target=powerpc64-unknown-freebsd12.0 --disable-nls --enable-languages=c,c++ --without-headers --with-gmp=/usr/local --with-pkgversion='FreeBSD Ports Collection for powerpc64' --wit
h-system-zlib --with-gcc-include-dir=/usr/include/c++/v1/ --with-as=/usr/local/bin/powerpc64-freebsd-as --with-ld=/usr/local/bin/powerpc64-freebsd-ld --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/info/ --build=x86_64-unknown-freebsd1
2.0
Thread model: posix
gcc version 6.2.0 (FreeBSD Ports Collection for powerpc64)
COLLECT_GCC_OPTIONS='-isystem' '/usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/tmp/usr/include' '-L/usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/tmp/usr/lib' '-B' '/usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/t
mp/usr/lib' '-B' '/usr/local/powerpc64-freebsd/bin/' '-c' '-O' '-pipe' '-g' '-nostdinc' '-I' '.' '-I' '/usr/src/sys' '-I' '/usr/src/sys/contrib/libfdt' '-D' '_KERNEL' '-D' 'HAVE_KERNEL_OPTION_HEADERS' '-include' 'opt_global.h' '-msoft-float' '-fPIC' '-fno-omit-frame-pointe
r' '-mno-altivec' '-ffreestanding' '-fwrapv' '-fstack-protector' '-gdwarf-2' '-Wall' '-Wredundant-decls' '-Wnested-externs' '-Wstrict-prototypes' '-Wmissing-prototypes' '-Wpointer-arith' '-Winline' '-Wcast-qual' '-Wundef' '-Wno-pointer-sign' '-fformat-extensions' '-Wmissin
g-include-dirs' '-fdiagnostics-show-option' '-Wno-unknown-pragmas' '-Wno-error=address' '-Wno-error=aggressive-loop-optimizations' '-Wno-error=array-bounds' '-Wno-error=attributes' '-Wno-error=cast-qual' '-Wno-error=enum-compare' '-Wno-error=inline' '-Wno-error=maybe-unini
tialized' '-Wno-error=overflow' '-Wno-error=sequence-point' '-Wno-error=strict-overflow' '-Wno-error=unused-but-set-variable' '-Wno-error=misleading-indentation' '-Wno-error=nonnull-compare' '-Wno-error=shift-overflow' '-Wno-error=tautological-compare' '-v' '-fno-common' '
-fms-extensions' '-finline-limit=15000' '--param' 'inline-unit-growth=100' '--param' 'large-function-growth=1000' '-msoft-float' '-mcall-aixdesc' '-std=c99' '-Werror'
 /usr/local/libexec/gcc/powerpc64-unknown-freebsd12.0/6.2.0/cc1 -quiet -nostdinc -v -I . -I /usr/src/sys -I /usr/src/sys/contrib/libfdt -isysroot /usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/tmp -D _KERNEL -D HAVE_KERNEL_OPTION_HEADERS -isystem /usr/o
bj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/tmp/usr/include -include opt_global.h /usr/src/sys/powerpc/powerpc/db_trace.c -quiet -dumpbase db_trace.c -msoft-float -mno-altivec -msoft-float -mcall-aixdesc -auxbase db_trace -g -gdwarf-2 -O -Wall -Wredundant-
decls -Wnested-externs -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith -Winline -Wcast-qual -Wundef -Wno-pointer-sign -Wmissing-include-dirs -Wno-unknown-pragmas -Wno-error=address -Wno-error=aggressive-loop-optimizations -Wno-error=array-bounds -Wno-error=attribu
tes -Wno-error=cast-qual -Wno-error=enum-compare -Wno-error=inline -Wno-error=maybe-uninitialized -Wno-error=overflow -Wno-error=sequence-point -Wno-error=strict-overflow -Wno-error=unused-but-set-variable -Wno-error=misleading-indentation -Wno-error=nonnull-compare -Wno-e
rror=shift-overflow -Wno-error=tautological-compare -Werror -std=c99 -version -fPIC -fno-omit-frame-pointer -ffreestanding -fwrapv -fstack-protector -fformat-extensions -fdiagnostics-show-option -fno-common -fms-extensions -finline-limit=15000 --param inline-unit-growth=10
0 --param large-function-growth=1000 -o - |
 /usr/local/bin/powerpc64-freebsd-as -v -I . -I /usr/src/sys -I /usr/src/sys/contrib/libfdt --traditional-format -a64 -mppc64 -many -many -o db_trace.o
GNU assembler version 2.27 (powerpc64-freebsd) using BFD version (GNU Binutils) 2.27
GNU C99 (FreeBSD Ports Collection for powerpc64) version 6.2.0 (powerpc64-unknown-freebsd12.0)
        compiled by GNU C version 4.2.1 Compatible FreeBSD Clang 3.9.1 (tags/RELEASE_391/final 289601), GMP version 5.1.3, MPFR version 3.1.5, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
#include "..." search starts here:
#include <...> search starts here:
 .
 /usr/src/sys
 /usr/src/sys/contrib/libfdt
 /usr/obj/powerpc64vtsc_xtoolchain_kernel/powerpc.powerpc64/usr/src/tmp/usr/include
End of search list.
GNU C99 (FreeBSD Ports Collection for powerpc64) version 6.2.0 (powerpc64-unknown-freebsd12.0)
        compiled by GNU C version 4.2.1 Compatible FreeBSD Clang 3.9.1 (tags/RELEASE_391/final 289601), GMP version 5.1.3, MPFR version 3.1.5, MPC version 1.0.3, isl version none
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: b395363e48891085cf87f23546ed513a
/usr/src/sys/powerpc/powerpc/db_trace.c: In function 'db_trace_self':
/usr/src/sys/powerpc/powerpc/db_trace.c:299:20: error: calling '__builtin_frame_address' with a nonzero argument is unsafe [-Werror=frame-address]
  addr = (db_addr_t)__builtin_frame_address(1);
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~
Comment 1 Mark Millard 2016-12-27 10:27:09 UTC
(In reply to Mark Millard from comment #0)

Use of WERROR= does sidestep buildkernel stopping for this:
buildkernel then completes.
Comment 2 Mark Millard 2017-01-02 20:25:13 UTC
[Just recording John Baldwin's note about the issue in bugzilla.]

In:

https://lists.freebsd.org/pipermail/freebsd-toolchain/2017-January/002542.html

John Baldwin wrote the following:


From: John Baldwin . . .
. . .
Date: January 2, 2017 at 8:07:57 AM PST
. . .
Try using '0' instead of '1'.  You might get an extra frame in the backtrace
compared to before.  A simple way to test is to add 'options KDB_TRACE' and
then trigger a panic (e.g. sysctl debug.kdb.panic=1)


Side note by Mark Millard:

I've no clue if this is the direction that the powerpc64 (and powerpc)
FreeBSD folks want to go/investigate for the compiler's report or not.

As stands I'm using WERROR= to allow the buildkernel to complete.
Comment 3 commit-hook freebsd_committer freebsd_triage 2017-01-23 04:03:25 UTC
A commit references this bug:

Author: jhibbits
Date: Mon Jan 23 04:03:12 UTC 2017
New revision: 312659
URL: https://svnweb.freebsd.org/changeset/base/312659

Log:
  Avoid using non-zero argument for __builtin_frame_address().

  Building kernel with devel/powerpc64-gcc (6.2.0) yields the following error:
  /usr/src/sys/powerpc/powerpc/db_trace.c:299:20: error: calling
  '__builtin_frame_address' with a nonzero argument is unsafe
  [-Werror=frame-address]

  Work around this by dereferencing the frame address manually instead.

  PR:		215600
  Reported by:	Mark Millard <markmi AT dsl-only DOT net>
  MFC after:	2 weeks

Changes:
  head/sys/powerpc/powerpc/db_trace.c
Comment 4 Justin Hibbits freebsd_committer freebsd_triage 2017-04-01 19:34:02 UTC
MFC'd to stable/11 r316369
Comment 5 Mark Millard 2017-06-19 02:02:54 UTC
(In reply to Justin Hibbits from comment #4)

Turns out that there are more examples:

--- stack_machdep.o ---
/usr/src/sys/powerpc/powerpc/stack_machdep.c: In function 'stack_save':
/usr/src/sys/powerpc/powerpc/stack_machdep.c:113:22: error: calling '__builtin_frame_address' with a nonzero argument is unsafe [-Werror=frame-address]
  frame = (register_t)__builtin_frame_address(1);
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~
Building /usr/obj/powerpc64vtscdbg_xtoolchain-gcc_kernel/powerpc.powerpc64/usr/src/sys/GENERIC64vtsc-DBG/mmu_phyp.o

I'll submit another report for this distinct place.