Page MenuHomeFreeBSD

Key decleration of union semun on src version

Authored by brooks on Oct 22 2020, 4:11 PM.



FreeBSD is defined by the compiler derived from the triple. When
building FreeBSD 11 on a FreeBSD 12 with a CROSS_TOOLCHAIN=llvm10,
FreeBSD was set to 12 when building lib32 (for some reason no triple
is being passed which seems to mean that we're taking default values
from the build system). This in turn meant we end up with a double
decleration of union semun which is a build error.

Diff Detail

rS FreeBSD src repository
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

brooks created this revision.

This could also be fixed by consistently setting the -target flag when building sources. For instance, on stable/12 the default (x86_64-unknown-freebsd12.2 in my case) gives:

% clang -dM -E -x c /dev/null|grep __FreeBSD__
#define __FreeBSD__ 12

But if you use a lower version in the target, clang uses its (major) version instead:

% clang -target x86_64-unknown-freebsd11.4 -dM -E -x c /dev/null|grep __FreeBSD__
#define __FreeBSD__ 11

The check is also just plain wrong. The question isn't "what version of FreeBSD is the compiler targeting?" It's "what version of FreeBSD is providing the headers?" Obviously they should match, but checking the right thing means I don't have to dig into libcompat build bits on 11.

Yes, I agree. __FreeBSD__ is mostly to be used for "am I on FreeBSD at all" checks, that it has a major version in it is maybe a little misleading. The only disadvantage of __FreeBSD_version is that you have to include <osreldate.h> at least.

This revision is now accepted and ready to land.Oct 22 2020, 8:12 PM

Technically speaking this code is broken on FreeBSD <2 (see the code right above this), but I can't bring myself to do the reshuffling to fix that...

I'll make the change in the upstream vendor version.

I've added the fix upstream using the following diff (slightly different than your diff):

This revision was automatically updated to reflect the committed changes.