Bug 271131 - net/asterisk18: utils.c:99:12: error: static declaration of 'gethostbyname_r' follows non-static declaration
Summary: net/asterisk18: utils.c:99:12: error: static declaration of 'gethostbyname_r'...
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-ports-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-29 12:32 UTC by O. Hartmann
Modified: 2023-06-02 16:49 UTC (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description O. Hartmann 2023-04-29 12:32:21 UTC
CURRENT host running poudriere for 13-STABLE jails.
CURRENT: 14.0-CURRENT #30 main-n262556-82bc33d5ad2: Tue Apr 25 22:53:05 CEST 2023

Building of net/asterisk18 fails due to the error shown below.

SAME ERROR STRUCK DOWN net/asterisk16!

=>> Building net/asterisk18
build started at Sat Apr 29 11:18:12 UTC 2023
port directory: /usr/ports/net/asterisk18
package name: asterisk18-18.17.1_1
building for: FreeBSD host.der 13.2-STABLE FreeBSD 13.2-STABLE 1302505 amd64
maintained by: ports@FreeBSD.org
Makefile datestamp: -rw-r--r--  1 root  wheel  10576 Apr 25 15:38 /usr/ports/net/asterisk18/Makefile
Ports top last git commit: 5493ec9d4041
Ports top unclean checkout: no
Port dir last git commit: feb1fa34f58e
Port dir unclean checkout: no
Poudriere version: poudriere-git-3.3.99.20220831
Host OSVERSION: 1400088
Jail OSVERSION: 1302505
Job Id: 01

---Begin Environment---
SHELL=/bin/csh
OSVERSION=1302505
UNAME_v=FreeBSD 13.2-STABLE 1302505
UNAME_r=13.2-STABLE
BLOCKSIZE=K
MAIL=/var/mail/root
MM_CHARSET=UTF-8
LANG=C.UTF-8
STATUS=1
HOME=/root
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/root/bin
LOCALBASE=/usr/local
USER=root
POUDRIERE_NAME=poudriere-git
LIBEXECPREFIX=/usr/local/libexec/poudriere
POUDRIERE_VERSION=3.3.99.20220831
MAKEOBJDIRPREFIX=/pool/sources/13-STABLE/obj/
MASTERMNT=/pool/poudriere/data/.m/13-amd64-head-default/ref
LC_COLLATE=C
POUDRIERE_BUILD_TYPE=bulk
PACKAGE_BUILDING=yes
SAVED_TERM=screen
OUTPUT_REDIRECTED_STDERR=4
OUTPUT_REDIRECTED=1
PWD=/pool/poudriere/data/.m/13-amd64-head-default/01/.p
OUTPUT_REDIRECTED_STDOUT=3
P_PORTS_FEATURES=FLAVORS SELECTED_OPTIONS
MASTERNAME=13-amd64-head-default
SCRIPTPREFIX=/usr/local/share/poudriere
SCRIPTNAME=bulk.sh
OLDPWD=/pool/poudriere/data/.m/13-amd64-head-default/ref/.p/pool
POUDRIERE_PKGNAME=poudriere-git-3.3.99.20220831
SCRIPTPATH=/usr/local/share/poudriere/bulk.sh
POUDRIEREPATH=/usr/local/bin/poudriere
---End Environment---

---Begin Poudriere Port Flags/Env---
PORT_FLAGS=
PKGENV=
FLAVOR=
DEPENDS_ARGS=
MAKE_ARGS=
---End Poudriere Port Flags/Env---

---Begin OPTIONS List---
===> The following configuration options are available for asterisk18-18.17.1_1:
     ASTVERSION=off: Install astversion (requires bash)
     BACKTRACE=off: Stack backtrace support via (lib)execinfo
     CURL=on: Data transfer support via cURL
     DAHDI=on: DAHDI support
     EXCHANGE=off: Exchange calendar support
     FREETDS=on: FreeTDS library support
     G729=on: Install G.729 format sounds for Music-on-Hold (MoH)
     GEOLOCATION=off: Enable SIP Geolocation support
     LDAP=on: LDAP protocol support
     LUA=on: Lua scripting language support
     MACRO=on: Enable app_macro (deprecated)
     MP3PLAYER=on: Install MP3 Player for Music-On-Hold (mpg123)
     OOH323=off: ooh323 support
     OPTIMIZED_CFLAGS=on: Use extra compiler optimizations
     PJSIP=on: Build the PJSIP based SIP channel
     PORTAUDIO=on: PortAudio library support
     RADIUS=on: RADIUS protocol support
     SNMP=on: SNMP network protocol support
     SPANDSP=on: SpanDSP faxing support
     SRTP=on: SecureRTP support
     SYSINFO=off: Use devel/libsysinfo to get system information
     URIPARSER=on: Use RFC 3986 compliant uriparser library
     XMLDOC=on: Build and install XML documentation
     XMPP=on: XMPP/GTALK support
====> Menuselect Interface Backend: you have to choose at least one of them
     NCURSES=off: Console (text) interface support
     NEWT=on: Newt User Interface
====> Encoder/Decoder (Codec) Support
     GSM=on: GSM codec support
     NEWG711=off: New G711 Codec
     OPUS=on: Opus Codec
     SPEEX=on: Speex audio format support
     VORBIS=on: Ogg Vorbis audio codec support
====> Database Support
     MYSQL=on: MySQL database support
     ODBC=on: ODBC database backend
     PGSQL=on: PostgreSQL database support
===> Use 'make config' to modify these settings
---End OPTIONS List---

[...]
cc -o version.o -c version.c -MD -MT version.o -MF .version.o.d -MP -pthread -I/wrkdirs/usr/ports/net/asterisk18/work/asterisk-18.17.1/include -O2 -pipe  -I/usr/local/include/lua54 -DLIBICONV_PLUG -DLDAP_DEPRECATED -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing   -I/usr/local/include/libxml2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations  -fblocks  -isystem /usr/local/include -O3 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -march=native -DAST_MODULE=\"core\" -DAST_IN_CORE -O2 -pipe  -I/usr/local/include/lua54 -DLIBICONV_PLUG -DLDAP_DEPRECATED -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -Wno-unused-value -Wno-parentheses-equality 
cc -o xml.o -c xml.c -MD -MT xml.o -MF .xml.o.d -MP -pthread -I/wrkdirs/usr/ports/net/asterisk18/work/asterisk-18.17.1/include -O2 -pipe  -I/usr/local/include/lua54 -DLIBICONV_PLUG -DLDAP_DEPRECATED -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing   -I/usr/local/include/libxml2 -Wall -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations  -fblocks  -isystem /usr/local/include -O3 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -march=native -DAST_MODULE=\"core\" -DAST_IN_CORE -O2 -pipe  -I/usr/local/include/lua54 -DLIBICONV_PLUG -DLDAP_DEPRECATED -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing  -Wno-unused-value -Wno-parentheses-equality 
utils.c:99:12: error: static declaration of 'gethostbyname_r' follows non-static declaration
static int gethostbyname_r (const char *name, struct hostent *ret, char *buf,
Comment 1 Mina Galić freebsd_triage 2023-04-29 12:52:25 UTC
please check upstream https://issues.asterisk.org/jira/secure/Dashboard.jspa / https://github.com/asterisk/asterisk/issues
for existing issues and submit it, if it's missing
Comment 2 O. Hartmann 2023-04-29 13:19:36 UTC
What? Is this a joke?
Comment 3 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-04-29 18:54:18 UTC
(In reply to O. Hartmann from comment #2)
What is the joking part here?
Comment 4 Vladimir Druzenko freebsd_committer freebsd_triage 2023-04-29 19:32:31 UTC
18.17.1_1 build fine for me on 13.2 amd64 with options:
        ASTVERSION     : on
        BACKTRACE      : off
        CURL           : on
        DAHDI          : on
        EXCHANGE       : off
        FREETDS        : off
        G729           : on
        GEOLOCATION    : on
        GSM            : on
        LDAP           : on
        LUA            : on
        MACRO          : off
        MP3PLAYER      : on
        MYSQL          : off
        NCURSES        : on
        NEWG711        : on
        NEWT           : on
        ODBC           : off
        OOH323         : on
        OPTIMIZED_CFLAGS: on
        OPUS           : on
        PGSQL          : off
        PJSIP          : on
        PORTAUDIO      : off
        RADIUS         : off
        SNMP           : on
        SPANDSP        : on
        SPEEX          : on
        SRTP           : on
        SYSINFO        : on
        URIPARSER      : on
        VORBIS         : on
        XMLDOC         : off
        XMPP           : on
Comment 5 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-04-29 19:34:30 UTC
(In reply to Vladimir Druzenko from comment #4)
It's not about 13.2 or HEAD it's about llvm15. I am doing the final build test which I will commit today or tomorrow.
Comment 6 O. Hartmann 2023-05-09 19:15:57 UTC
Hello,

I'm running into the very same issue here on CURRENT builder host, running 13-STABLE jail:

=>> Building net/asterisk18
build started at Mon May  8 08:36:14 UTC 2023
port directory: /usr/ports/net/asterisk18
package name: asterisk18-18.17.1_1
[...]
13.2-STABLE 1302505 amd64
[...]
/net/asterisk18/Makefile
Ports top last git commit: ec23a17e0f51
Ports top unclean checkout: no
Port dir last git commit: 6ee7f9f1ae2e
Port dir unclean checkout: no
Poudriere version: poudriere-git-3.3.99.20220831
Host OSVERSION: 1400088
Jail OSVERSION: 1302505
Job Id: 02

poudriere shows the very same error as reported before.

My understanding of the techniques of the C code is limited, but looking at 

main/utils.c

reveals that there is a static declaration of gethostbyname_r() (as reported in the error) for which the comment says it is a replacement for BSD-versions, see below.

Checking the manpages for gethostbyname_r(), found in libc, obviously prototyped in /usr/include/netdb.h definitely states, that the routine is threadsafe AND reentrant!
I have not checked with upstream so far, but I found it logic to eliminate the extranous gehthostbyname_r() routine in main/utils.c with the (clumsy) #ifdef clause show below - and the code is compiling. Haven't tested it.

I have no idea since when the code starts to bread to determine __FreeBSD_version, but this might be a first approach to a workaround?

Otherwise, sorry for the noise, if the suggestion is illogical and ill-adviced.

[... main/utisl.c ...]
/*! \brief Reentrant replacement for gethostbyname for BSD-based systems.
\note This
routine is derived from code originally written and placed in the public
domain by Enzo Michelangeli <em@em.no-ip.com> */

#if !defined(__FreeBSD__)
static int gethostbyname_r (const char *name, struct hostent *ret, char *buf,
                size_t buflen, struct hostent **result,
                int *h_errnop)
[...]
}
#endif
Comment 7 O. Hartmann 2023-05-13 15:05:02 UTC
Hello.

The reason why net/asterisk16 and net/asterisk18 are broken on CURRENT and 13-STABLE seems not to be LLVM15 (LLVM14 doesn't work either, at least for me here on 13-STABLE and CURRENT). As one can easily confirm, on the same CURRENT using LLVM14 doesn't work either as on 13-STABLE as I reported using LLVM15.

Somehow a GNUautotool check doesn't work properly (in my opinion):

main/utils.c checks for a 5- or 6-argument gethostbyname_r(). The enveloping clause is (see line 87):

#if !defined(HAVE_GETHOSTBYNAME_R_5) && !defined(HAVE_GETHOSTBYNAME_R_6)
...
#endif

So, the check would define HAVE_GETHOSTBYNAME_R_5=1, HAVE_GETHOSTBYNAME_R_6=1 on FreeBSD and the static declaration would never be touched.

Is this correct?
Comment 8 Mina Galić freebsd_triage 2023-05-13 16:06:55 UTC
they can't both be correct.
if my count isn't off, it's 6
Comment 9 O. Hartmann 2023-05-13 17:47:21 UTC
(In reply to Mina Galić from comment #8)

I understand the logic o the check that six arguments includes five arguments, see foryourself. And both checks set to logical 1  "qualifies" for the existence of a reentrant gethostbyname_r(). Well ...

I try to focus on a practical solution. My attempt to compile the original port (asterisk18) with the latest patch for LLVM14 also failed. Either the base framework (Mk) has made changes, or LLVM prior to 15/14 did not check for the  bailing-out ambigous declaration of gethostbyname_r() and I'm curious whether the compiler has always on FreeBSD picked up the "wrong" function (libc has the more recent one, according to the head comment of the file main/utils.c in asterisk18, it has been edited last time 2006). In the latter case, the whole #if statement should be enveloped into 

#if !defined(__FreeBSD__)

#endif

This is the way I do the workaround. net/asterisk18 compiles and as for now, I didn't realise any problems while operating the binary - for now.

I can provide the patch here - but I fear I have made myself a fool by discussing "my naive" impressions (I do not active develop ...).
Comment 10 Samuel Chow 2023-06-02 16:49:39 UTC
There is an upstream patch for this issue:

https://github.com/asterisk/asterisk/commit/0e6295128c605f1cf41d897c53e6e23e893a6ffa

I applied the patch to my port tree (still at asterisk18-18.15.1 though), and I can confirm that it builds fine.

I did check the latest release asterisk18-18.18.0, and it does not have this patch. I am not sure if we need to provide our port patch files, or continue to wait for newer releases.