[Bug] 4.4.4 fails to build with clang: incomplete definition of the 'struct next' type
Describe the bug Version 4.4.4 fails to build with clang (previous version 4.4.3 builds fine):
Compiler version:
$ clang --version
FreeBSD clang version 14.0.5 (https://github.com/llvm/llvm-project.git llvmorg-14.0.5-0-gc12386ae247c)
Target: x86_64-unknown-freebsd13.2
Thread model: posix
InstalledDir: /usr/bin
In 'mod.c', a fatal error occurs due to an incomplete definition of the 'struct next' type, resulting in a build failure.
cc -DHAVE_CONFIG_H -I. -I../../src -I./.. -I./../.. -I/usr/local/include -D_U_="__attribute__((unused))" -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -Wno-variadic-macros -Wfatal-errors -I/usr/lib -I/usr/include -MT libfragroute_a-fragroute.o -MD -MP -MF .deps/libfragroute_a-fragroute.Tpo -c -o libfragroute_a-fragroute.o `test -f 'fragroute.c' || echo './'`fragroute.c
mv -f .deps/libfragroute_a-fragroute.Tpo .deps/libfragroute_a-fragroute.Po
cc -DHAVE_CONFIG_H -I. -I../../src -I./.. -I./../.. -I/usr/local/include -D_U_="__attribute__((unused))" -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -Wno-variadic-macros -Wfatal-errors -I/usr/lib -I/usr/include -MT libfragroute_a-bget.o -MD -MP -MF .deps/libfragroute_a-bget.Tpo -c -o libfragroute_a-bget.o `test -f 'bget.c' || echo './'`bget.c
mv -f .deps/libfragroute_a-bget.Tpo .deps/libfragroute_a-bget.Po
cc -DHAVE_CONFIG_H -I. -I../../src -I./.. -I./../.. -I/usr/local/include -D_U_="__attribute__((unused))" -O2 -pipe -fstack-protector-strong -fno-strict-aliasing -Wno-variadic-macros -Wfatal-errors -I/usr/lib -I/usr/include -MT libfragroute_a-mod.o -MD -MP -MF .deps/libfragroute_a-mod.Tpo -c -o libfragroute_a-mod.o `test -f 'mod.c' || echo './'`mod.c
mod.c:180:5: fatal error: incomplete definition of type 'struct next'
TAILQ_FOREACH_REVERSE(rule, &rules, next, head)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/sys/queue.h:750:15: note: expanded from macro 'TAILQ_FOREACH_REVERSE'
for ((var) = TAILQ_LAST((head), headname); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/sys/queue.h:824:44: note: expanded from macro 'TAILQ_LAST'
(*(((struct headname *)((head)->tqh_last))->tqh_last))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
mod.c:180:41: note: forward declaration of 'struct next'
TAILQ_FOREACH_REVERSE(rule, &rules, next, head)
^
Full build log: tcpreplay-4.4.4.log
To Reproduce
- Download a FreeBSD vagrant image
- Try to compile 4.4.4
System (please complete the following information):
- OS: FreeBSD
- OS version: 13.1-RELEASE-p7
- Tcpreplay Version: 4.4.4
I tried with clang-13 and clang-17 on Debian Linux. No failure. Do you see this fail on 4.4.3?
4.4.3 builds fine.
OK, I'll build up a FreeBSD VM to test on.
OK, I'll build up a FreeBSD VM to test on.
Quick setup to have all deps:
Vagrant.configure("2") do |config|
config.vm.box = "freebsd/FreeBSD-13.2-RELEASE"
config.vm.box_version = "2023.04.07"
config.vm.provision "shell", inline: <<-SHELL
sed -i'' -e 's|quarterly|latest|' /etc/pkg/FreeBSD.conf
pkg install -y bash git
portsnap --interactive fetch extract
sh -c '(cd /usr/ports/net-mgmt/tcpreplay; make missing | xargs pkg install -y)'
SHELL
end
Just to verify, I attempted compiling with a different compiler (gcc 12.2.0), but it failed as well.
See tcpreplay-4.4.4_gcc_freebsd_13_1.log
The title of the issue should probably be changed to:
[Bug] 4.4.4 fails to build on FreeBSD: incomplete definition of the 'struct next' type
According to repology, no other *BSD has updated to 4.4.4 so this bug likely exists on those platforms as well.
Maybe this is the patch:
--- src/fragroute/mod.c.orig 2024-05-02 00:04:53 UTC
+++ src/fragroute/mod.c
@@ -8,11 +8,11 @@
*/
#include "mod.h"
+#include "lib/queue.h"
#include "defines.h"
#include "config.h"
#include "common.h"
#include "argv.h"
-#include "lib/queue.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
--- src/fragroute/pkt.h.orig 2024-05-02 00:04:56 UTC
+++ src/fragroute/pkt.h
@@ -8,9 +8,9 @@
#pragma once
+#include "lib/queue.h"
#include "defines.h"
#include "config.h"
-#include "lib/queue.h"
#include <sys/time.h>
#ifdef HAVE_LIBDNET
I want to say it work for me: without patch I have same error, but with patch build without errors.
Somehow this got missed for 4.5.1. I'll target for next minor release.
On FreeBSD, this issue is mitigated by applying the following patch:
--- lib/queue.h.orig 2024-03-24 16:55:28 UTC
+++ lib/queue.h
@@ -36,8 +36,8 @@
* @(#)queue.h 8.5 (Berkeley) 8/20/94
*/
-#ifndef _SYS_QUEUE_H_
-#define _SYS_QUEUE_H_
+#ifndef _QUEUE_H_
+#define _QUEUE_H_
/*
* This file defines five types of data structures: singly-linked lists,
@@ -508,4 +508,4 @@ struct { \
(elm2)->field.cqe_prev->field.cqe_next = (elm2); \
} while (0)
-#endif /* !_SYS_QUEUE_H_ */
+#endif /* !_QUEUE_H_ */
@ehaupt, check this PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280260
@ehaupt, check this PR: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=280260
I'll respond in bugzilla.