pkg mistakenly tries to use both -ffreestanding and <inttypes.h> for the same source files for its libecc

From: Mark Millard <marklmi_at_yahoo.com>
Date: Sun, 20 Jul 2025 01:22:51 UTC
koobs on discord reported on build failures for attempting to
build pkg 2.2.1 using devel/llvm20 . He got errors like:

--- pkg_libecc_rand.pico ---
In file included from pkg_libecc_rand.c:5:
In file included from /wrkdirs/usr/ports/ports-mgmt/pkg-devel/work/pkg-3f6b36f19/external/libecc/include/libecc/external_deps/rand.h:18:
In file included from /wrkdirs/usr/ports/ports-mgmt/pkg-devel/work/pkg-3f6b36f19/external/libecc/include/libecc/words/words.h:60:
In file included from /wrkdirs/usr/ports/ports-mgmt/pkg-devel/work/pkg-3f6b36f19/external/libecc/include/libecc/words/words_64.h:23:
In file included from /wrkdirs/usr/ports/ports-mgmt/pkg-devel/work/pkg-3f6b36f19/external/libecc/include/libecc/words/types.h:64:
In file included from /usr/local/llvm20/lib/clang/20/include/inttypes.h:24:
In file included from /usr/include/inttypes.h:33:
/usr/include/sys/stdint.h:48:24: error: typedef redefinition with different types ('__int_fast8_t' (aka 'int') vs 'int8_t' (aka 'signed char'))
   48 | typedef __int_fast8_t           int_fast8_t;
      |                                 ^
/usr/local/llvm20/lib/clang/20/include/stdint.h:280:24: note: previous definition is here
  280 | typedef __int_least8_t int_fast8_t;
      |                        ^
. . .

(Various *.c files for libecc for various integer types,
the above being just one example.)

The compile command used -ffreestanding and -DWITH_STDLIB
and the source code uses <inttypes.h> when WITH_STDLIB
is defined:

. . ./work/pkg-*/external/libecc/include/libecc/words/types.h :
. . .
/*** Handling the types ****/
#ifdef WITH_STDLIB

/*
 * User explicitly needs to build w/ stdlib. Let's include the headers
 * we need to get basic types: (uint*_t), NULL, etc. You can see below
 * (i.e. under #else) what is precisely needed.
 */
#include <stdint.h>
#include <inttypes.h>
#include <stddef.h>
#else /* WITH_STDLIB */
. . .

My testing the specific file's failure via removing the
-ffreestanding from the compile command lead to it
compiling without any complaints.

NOTE from the C standards with <inttypes.h> :

"The header <inttypes.h> includes the header <stdint.h>
and extends it with additional facilities provided by
hosted implementations."

It makes no guarantees about <inttypes.h> usability for
freestanding contexts. Freestanding and hosted do not
even need to agree about various points generally and
mixing the two is --at best-- implementation defined
for C --and likely has points of Undefined Behavior.

In other words, the above combination is incoherent
relative to the C standards that include <inttypes.h> .

Only the libecc code seemed to have use of -ffreestanding .

Other places outside libecc had use of <inttypes.h> .


For reference for the libecc -ffreestanding use:

# pwd
/wrkdirs/usr/ports/ports-mgmt/pkg-devel/work/pkg-3f6b36f19

# grep -r -e -ffreestanding ./
./external/libecc/common.mk:LIB_CFLAGS  ?= $(CFLAGS) $(FPIC_CFLAG) -MMD -MP -ffreestanding
./external/libecc/Makefile:             -ffreestanding \
./external/libecc/meson.build:  '-ffreestanding'
./external/libecc/Makefile.autosetup:           -ffreestanding \
./external/libecc/README.md:    -ffreestanding -fno-builtin -nostdlib -DWORDSIZE=64" \
./external/libecc/README.md:    -ffreestanding -fno-builtin -nostdlib -DWORDSIZE=64" \

===
Mark Millard
marklmi at yahoo.com