Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DragonFly and cpuset.h:62:16: error: unknown type name 'cpuid_t' #75

Closed
noloader opened this issue Mar 19, 2020 · 3 comments
Closed

DragonFly and cpuset.h:62:16: error: unknown type name 'cpuid_t' #75

noloader opened this issue Mar 19, 2020 · 3 comments

Comments

@noloader
Copy link
Contributor

noloader commented Mar 19, 2020

Hi Everyone,

I'm testing nsd master on DragonFly 5.6 x86_64, fully patched. DragonFly is a BSD variant.

Bootstrap and configure go well. Below is the output of make. Several files show the same issue.

 int cpuset_set(cpuid_t cpu, cpuset_t *set);
                ^~~~~~~
                uid_t
./compat/cpuset.h:66:16: error: unknown type name 'cpuid_t'; did you mean 'uid_t'?
 int cpuset_clr(cpuid_t cpu, cpuset_t *set);
                ^~~~~~~
                uid_t
./compat/cpuset.h:70:18: error: unknown type name 'cpuid_t'; did you mean 'uid_t'?
 int cpuset_isset(cpuid_t cpu, const cpuset_t *set);
                  ^~~~~~~
                  uid_t
*** Error code 1

It looks like DragonFly has <sched.h>.

% grep -IR cpu_set_t /usr/include
/usr/include/sched.h:typedef	cpumask_t		cpu_set_t;
...

And cpumask_t is declared in /usr/include/cpu/types.h:

/*
 * cpumask_t - a mask representing a set of cpus and supporting routines.
 *
 * WARNING! It is recommended that this mask NOT be made variably-sized
 *	    because it affects a huge number of system structures.  However,
 *	    kernel code (non-module) can be optimized to not operate on the
 *	    whole mask.
 */

#define _CPUMASK_ELEMENTS	4	/* tested by assembly for #error */

typedef struct {
	__uint64_t      ary[4];
} cpumask_t;

This may help.

% gcc -dM -E - < /dev/null | sort | grep -i -E 'linux|bsd|gnu|linux|dragon|i*86|amd'
#define __DragonFly__ 1
#define __GNUC_MINOR__ 3
#define __GNUC_PATCHLEVEL__ 0
#define __GNUC_STDC_INLINE__ 1
#define __GNUC__ 8
#define __VERSION__ "8.3 [DragonFly] Release/2019-02-22"
#define __amd64 1
#define __amd64__ 1
#define __x86_64 1
#define __x86_64__ 1
@noloader
Copy link
Contributor Author

noloader commented Mar 19, 2020

% cat /usr/include/sched.h
...

typedef	cpumask_t		cpu_set_t;
typedef	cpumask_t		cpuset_t;	/* FreeBSD compat */

#define	CPU_SETSIZE		((int)(sizeof(cpumask_t) * 8))

The first try compiles OK, but it results in link errors.

% git diff
diff --git a/compat/cpuset.h b/compat/cpuset.h
index c7cd2dc1..d52ab852 100644
--- a/compat/cpuset.h
+++ b/compat/cpuset.h
@@ -44,6 +44,9 @@ typedef int cpuid_t;
 #ifdef __FreeBSD__
 typedef size_t cpuid_t;
 #endif
+#ifdef __DragonFly__
+typedef size_t cpuid_t;
+#endif
 #endif
 
 #ifndef HAVE_CPUSET_CREATE

But then:

% make
gcc -g -O2 -flto -L/usr/local/lib -L/usr/local/lib -o nsd answer.o axfr.o buffer
.o configlexer.o configparser.o dname.o dns.o edns.o iterated_hash.o lookup3.o n
amedb.o nsec3.o options.o packet.o query.o rbtree.o radtree.o rdata.o region-all
ocator.o rrl.o tsig.o tsig-openssl.o udb.o udbradtree.o udbzone.o util.o bitset.
o popen3.o xfrd-disk.o xfrd-notify.o xfrd-tcp.o xfrd.o remote.o  difffile.o ipc.
o mini_event.o netio.o nsd.o server.o dbaccess.o dbcreate.o zlexer.o zonec.o zpa
rser.o cpuset.o b64_pton.o b64_ntop.o -lssl -lcrypto -lutil -levent
./server.c:2819: error: undefined reference to 'set_cpu_affinity'
./server.c:2205: error: undefined reference to 'set_cpu_affinity'
./nsd.c:546: error: undefined reference to 'cpuset_destroy'
./nsd.c:1190: error: undefined reference to 'cpuset_create'
./nsd.c:1198: error: undefined reference to 'cpuset_isset'
./nsd.c:1204: error: undefined reference to 'cpuset_set'
./nsd.c:1195: error: undefined reference to 'cpuset_or'
./nsd.c:1117: error: undefined reference to 'number_of_cpus'
./nsd.c:1121: error: undefined reference to 'cpuset_create'
./nsd.c:1129: error: undefined reference to 'cpuset_set'
./nsd.c:1144: error: undefined reference to 'cpuset_create'
./nsd.c:1150: error: undefined reference to 'cpuset_isset'
./nsd.c:1154: error: undefined reference to 'cpuset_set'
./nsd.c:1147: error: undefined reference to 'cpuset_or'
./nsd.c:1321: error: undefined reference to 'set_cpu_affinity'
./server.c:1575: error: undefined reference to 'set_cpu_affinity'
collect2: error: ld returned 1 exit status

One other comment about this in compat/cpuset.h... Are those datatypes correct for i386/i686 builds? That is, should size_t be used, or should uint64_t be used?

#ifndef HAVE_CPUID_T
#ifdef __linux__
typedef int cpuid_t;
#endif
#ifdef __FreeBSD__
typedef size_t cpuid_t;
#endif
#endif

@wcawijngaards
Copy link
Member

See the fix in #76, that should also fix this one, for the cpuid_t issue. Thanks for the detailed information, by the way, that helps dig through the issue. Then about the issues you get after the cpuid_t is fixed.

@wcawijngaards
Copy link
Member

Committed a fix that uses configure to test for the features, instead of just having linux and freebsd specific code. That may not work, if the system has cpuset_t but nothing else, but may work for more systems, by the detection in configure. Perhaps this works for the compile on your target system too, DragonFlyBSD and GNU Hurd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants