Bug 242827 - [Possible patch] net/samba410 with DEBUG options still builds with optimizations
Summary: [Possible patch] net/samba410 with DEBUG options still builds with optimizations
Status: Closed Overcome By Events
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Timur I. Bakeyev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-12-23 10:42 UTC by ml
Modified: 2020-04-08 02:37 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (timur)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ml 2019-12-23 10:42:10 UTC
I'm trying to debug a problem where smbd crashes, so I built the port (in Poudriere) with DEBUG option enabled.
While debugging symbols are now there, the code is still built with -O2, making it difficult to analyze core dumps.

Some extract of the build log (notice CFLAGS="-O2..."):
ZEROCONF=none PERL_USE_UNSAFE_INC=1 OPENSSLBASE=/usr OPENSSLDIR=/etc/ssl OPENSSLINC=/usr/include OPENSSLLIB=/usr/lib NOCOLOR=yes WAF_LOG_FORMAT='%(c1)s%(zone)s%(c2)s %(message)s' RPCGEN_CPP="cpp" XDG_DATA_HOME=/wrkdirs/usr/ports/net/samba410/work  XDG_CONFIG_HOME=/wrkdirs/usr/ports/net/samba410/work  HOME=/wrkdirs/usr/ports/net/samba410/work TMPDIR="/tmp" PATH=/wrkdirs/usr/ports/net/samba410/work/.bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin NO_PIE=yes MK_DEBUG_FILES=no MK_KERNEL_SYMBOLS=no SHELL=/bin/sh NO_LINT=YES PREFIX=/usr/local  LOCALBASE=/usr/local  CC="cc" CFLAGS="-O2 -pipe  -DLIBICONV_PLUG -fno-color-diagnostics -fstack-protector-strong -DLDAP_DEPRECATED -isystem /usr/local/include -fno-strict-aliasing -fno-omit-frame-pointer"  CPP="cpp" CPPFLAGS="-DLIBICONV_PLUG -isystem /usr/local/include"  LDFLAGS="  -fstack-protector-strong -L/usr/local/lib " LIBS=""  CXX="c++" CXXFLAGS="-O2 -pipe -DLIBICONV_PLUG -fno-color-diagnostics -fstack-protector-strong -DLDAP_DEPRECATED -isystem /usr/local/include -fno-strict-aliasing -fno-omit-frame-pointer  -DLIBICONV_PLUG -isystem /usr/local/include "  MANPREFIX="/usr/local" BSD_INSTALL_PROGRAM="install   -m 555"  BSD_INSTALL_LIB="install   -m 0644"  BSD_INSTALL_SCRIPT="install  -m 555"  BSD_INSTALL_DATA="install  -m 0644"  BSD_INSTALL_MAN="install  -m 444"   



There's the following line in the Makefile:
DEBUG_FLAGS=                    -g -ggdb3 -O0
I guess it should be:
DEBUG_CFLAGS=                   -g -ggdb3 -O0   



With the above change, the logs not report:
ZEROCONF=none PERL_USE_UNSAFE_INC=1 OPENSSLBASE=/usr OPENSSLDIR=/etc/ssl OPENSSLINC=/usr/include OPENSSLLIB=/usr/lib NOCOLOR=yes WAF_LOG_FORMAT='%(c1)s%(zone)s%(c2)s %(message)s' RPCGEN_CPP="cpp" XDG_DATA_HOME=/wrkdirs/usr/ports/net/samba410/work  XDG_CONFIG_HOME=/wrkdirs/usr/ports/net/samba410/work  HOME=/wrkdirs/usr/ports/net/samba410/work TMPDIR="/tmp" PATH=/wrkdirs/usr/ports/net/samba410/work/.bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin NO_PIE=yes MK_DEBUG_FILES=no MK_KERNEL_SYMBOLS=no SHELL=/bin/sh NO_LINT=YES PREFIX=/usr/local  LOCALBASE=/usr/local  CC="cc" CFLAGS="-O2 -pipe  -g -ggdb3 -O0 -DLIBICONV_PLUG -fno-color-diagnostics -fstack-protector-strong -DLDAP_DEPRECATED -isystem /usr/local/include -fno-strict-aliasing -fno-omit-frame-pointer"  CPP="cpp" CPPFLAGS="-DLIBICONV_PLUG -isystem /usr/local/include"  LDFLAGS="  -fstack-protector-strong -L/usr/local/lib " LIBS=""  CXX="c++" CXXFLAGS="-O2 -pipe -g -ggdb3 -O0 -DLIBICONV_PLUG -fno-color-diagnostics -fstack-protector-strong -DLDAP_DEPRECATED -isystem /usr/local/include -fno-strict-aliasing -fno-omit-frame-pointer  -DLIBICONV_PLUG -isystem /usr/local/include "  MANPREFIX="/usr/local" BSD_INSTALL_PROGRAM="install  -s -m 555"  BSD_INSTALL_LIB="install  -s -m 0644"  BSD_INSTALL_SCRIPT="install  -m 555"  BSD_INSTALL_DATA="install  -m 0644"  BSD_INSTALL_MAN="install  -m 444"                                           

Notice: "-O2 ... -O0"

I still have to verify if -O0 takes precedence over -O2.
Comment 1 ml 2020-01-13 15:35:09 UTC
I confirm I was able to properly analyze a core with the above Makefile modification.
Comment 2 Timur I. Bakeyev freebsd_committer 2020-01-14 00:51:45 UTC
(In reply to ml from comment #1)

Thanks a lot for the provided information.

This seems to be an interesting case of clashing of the OPTIONS variables and plain normal Makefile variables.

DEBUG_FLAGS(not CFLAGS!) is a documented way of influencing the debugging flags for building the base system and ports:

# Reset value from bsd.own.mk.
.if defined(WITH_DEBUG)
.if !defined(INSTALL_STRIPPED)
STRIP=  #none
MAKE_ENV+=      DONTSTRIP=yes
STRIP_CMD=      ${TRUE}
.endif
DEBUG_FLAGS?=   -g
CFLAGS:=                ${CFLAGS:N-O*:N-fno-strict*} ${DEBUG_FLAGS}
.if defined(INSTALL_TARGET)
INSTALL_TARGET:=        ${INSTALL_TARGET:S/^install-strip$/install/g}
.endif
.endif


I guess the proper combination would be:

DEBUG_CONFIGURE_ON=             --verbose --enable-debug
DEBUG_MAKE_ARGS=                --verbose
DEBUG_FLAGS=                    -g -ggdb3 -O0
DEBUG_VARS=                     WITH_DEBUG=yes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Which gives us:

# make -V CFLAGS
-pipe  -DLIBICONV_PLUG -fno-color-diagnostics -g -ggdb3 -O0 -fstack-protector-strong -DLDAP_DEPRECATED -isystem /usr/local/include -fno-strict-aliasing -fno-omit-frame-pointer


Can you, please, try, if such an fix makes sense for you?
Comment 3 Timur I. Bakeyev freebsd_committer 2020-04-08 02:37:43 UTC
Well, portmgr thinks that users should not have luxury of enabling debugging from the options, see https://reviews.freebsd.org/D23940

So, for debugging you have to enable WITH_DEBUG=yes or WITH_DEBUG_PORTS+=net/samba410 in /etc/make.conf.