libbsd issueshttps://gitlab.freedesktop.org/libbsd/libbsd/-/issues2023-06-11T22:53:03Zhttps://gitlab.freedesktop.org/libbsd/libbsd/-/issues/17Fails to build on FreeBSD2023-06-11T22:53:03ZJan BeichFails to build on FreeBSDREADME doesn't mention if libbsd is supposed to build and work on traditional BSDs. For example, libbsd can be packaged or bundled as subproject to avoid extra conditionals.
```c
$ cc --version
FreeBSD clang version 16.0.4 (https://gith...README doesn't mention if libbsd is supposed to build and work on traditional BSDs. For example, libbsd can be packaged or bundled as subproject to avoid extra conditionals.
```c
$ cc --version
FreeBSD clang version 16.0.4 (https://github.com/llvm/llvm-project.git llvmorg-16.0.4-0-gae42196bc493)
Target: x86_64-unknown-freebsd14.0
Thread model: posix
InstalledDir: /usr/bin
$ ./autogen
$ ./configure
[...]
checking for library containing MD5Update... -lmd
checking for library containing SHA512Update... no
configure: error: cannot find required SHA-2 functions in libc or libmd
$ gmake
[...]
progname.c:141:2: error: "Function getprogname() needs to be ported."
#error "Function getprogname() needs to be ported."
^
In file included from md5.c:27:
In file included from ../include/bsd/md5.h:28:
In file included from /usr/include/md5.h:46:
/usr/include/sys/md5.h:39:3: error: unknown type name 'u_int32_t'; did you mean '__int128_t'?
u_int32_t state[4]; /* state (ABCD) */
^
note: '__int128_t' declared here
/usr/include/sys/md5.h:40:3: error: unknown type name 'u_int32_t'; did you mean '__int128_t'?
u_int32_t count[2]; /* number of bits, modulo 2^64 (lsb first) */
^
note: '__int128_t' declared here
/usr/include/sys/md5.h:53:39: error: redefinition of parameter 'off_t'
char * MD5FdChunk(int, char *, off_t, off_t);
^
/usr/include/sys/md5.h:53:32: note: previous declaration is here
char * MD5FdChunk(int, char *, off_t, off_t);
^
/usr/include/sys/md5.h:55:50: error: redefinition of parameter 'off_t'
char * MD5FileChunk(const char *, char *, off_t, off_t);
^
/usr/include/sys/md5.h:55:43: note: previous declaration is here
char * MD5FileChunk(const char *, char *, off_t, off_t);
^
md5.c:43:42: error: unknown type name 'uint8_t'
libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
^
md5.c:43:57: error: unknown type name 'size_t'
libbsd_MD5Update(MD5_CTX *context, const uint8_t *data, size_t len)
^
md5.c:55:2: warning: call to undeclared function '_libmd_MD5Pad'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
MD5Pad(context);
^
/usr/include/md5.h:17:17: note: expanded from macro 'MD5Pad'
#define MD5Pad _libmd_MD5Pad
^
md5.c:60:20: error: conflicting types for '_libmd_MD5Pad'
libbsd_symver_weak(MD5Pad, libbsd_MD5Pad, LIBBSD_0.0);
^
/usr/include/md5.h:17:17: note: expanded from macro 'MD5Pad'
#define MD5Pad _libmd_MD5Pad
^
md5.c:55:2: note: previous implicit declaration is here
MD5Pad(context);
^
/usr/include/md5.h:17:17: note: expanded from macro 'MD5Pad'
#define MD5Pad _libmd_MD5Pad
^
md5.c:63:17: error: unknown type name 'uint8_t'
libbsd_MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context)
^
md5.c:73:21: error: unknown type name 'uint32_t'
libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
^
md5.c:73:46: error: unknown type name 'uint8_t'
libbsd_MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
^
md5.c:75:2: warning: call to undeclared function '_libmd_MD5Transform'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
MD5Transform(state, block);
^
/usr/include/md5.h:23:22: note: expanded from macro 'MD5Transform'
#define MD5Transform _libmd_MD5Transform
^
md5.c:103:54: error: unknown type name 'off_t'
libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
^
md5.c:103:68: error: unknown type name 'off_t'
libbsd_MD5FileChunk(const char *filename, char *buf, off_t offset, off_t length)
^
md5.c:113:22: error: unknown type name 'uint8_t'
libbsd_MD5Data(const uint8_t *data, size_t len, char *buf)
^
md5.c:113:37: error: unknown type name 'size_t'
libbsd_MD5Data(const uint8_t *data, size_t len, char *buf)
^
2 warnings and 14 errors generated.
```https://gitlab.freedesktop.org/libbsd/libbsd/-/issues/11deprecate "libbsd," strongly recommend using "libbsd-overlay"2023-12-25T08:12:06Zguijandeprecate "libbsd," strongly recommend using "libbsd-overlay"Would you consider deprecating libbsd on non-overlay mode? By that, I mean giving a compile-time warning if libbsd is used without the overlay mode, and only documenting using libbsd through _libbsd-overlay.pc_.
I'm willing to do the (li...Would you consider deprecating libbsd on non-overlay mode? By that, I mean giving a compile-time warning if libbsd is used without the overlay mode, and only documenting using libbsd through _libbsd-overlay.pc_.
I'm willing to do the (little) work it would require, I'm just asking before doing it.
The issue with not using the overlay mode is that it creates programs that use BSD functions, but don't actually compile on BSD. It's a simple header inclusion issue: the BSDs don't have headers inside `<bsd/*>`. Fixing it (without the overlay mode) means using an `#ifdef` and/or more build system trickery, when it could be done with less work, less conditional compilation, and without touching the C code by using libbsd-overlay.
I suggest [this scrot _configure.ac_ tidbit](https://github.com/resurrecting-open-source-projects/scrot/blob/ed96aa4ae3d69c186b3dda88543cc541acaf83c2/configure.ac#L35-L43) should be the only official (autotools) way to use libbsd.
This is a real issue, many programmers use libbsd by passing "-lbsd" to the linker manually and don't seem to realize their use case could benefit from the pkg-config and the overlay mode. libbsd isn't used only to port BSD programs, it's also used as "that library with strlcpy() and setproctitle()," so we have a few Linux-centric programs that paradoxically have to be ported to BSD because they use BSD functions. Not using pkg-config creates another issue: OpenBSD, NetBSD, and FreeBSD don't include packages in the default linker path. This isn't currently an issue for libbsd because it only runs on Linux, but the BSDs are not 100% compatible, so this library makes sense even within the BSD ecosystem.
The only downside I'm aware of is that libbsd-overlay breaks compilers without an `#include_next` directive.
A "Hello, world!" program that uses `#include_next` shows the extension is widely supported outside GCC/Clang:
```c
#include_next <stdio.h>
int
main(void)
{
puts("Hello, world!");
}
```
Successfully builds with cparser, tcc, and CompCert.
Doesn't build with MSVC, although it does build with clang-cl (clang with a MSVC command-line interface).
My interest in this is that I'm writing my own libbsd-like library which only provides an overlay mode at https://github.com/guijan/libobsd.
I've already ported it to a large amount of platforms: Windows (including MSVC), MacOS, FreeBSD, dietlibc, Haiku, and more. I provide a _libbsd-overlay.pc_ file for libbsd compatibility and I've already been bitten by the portability issues that not using the overlay mode creates.
I'd like to make it easy on myself and on users to write portable programs and use either libbsd or libobsd to reduce the amount of porting work and fallback code out there, and I believe leaving the non-overlay mode undocumented and deprecated to keep current code working but strongly direct people towards libbsd-overlay would be the way to do it.https://gitlab.freedesktop.org/libbsd/libbsd/-/issues/10error: conflicting types for 'setmode'2023-04-04T22:07:57ZMizuki Nguyenerror: conflicting types for 'setmode'error compiling on windows with msys2/mingw following the procedure from ['https://gitlab.freedesktop.org/libbsd/libbsd/merge_requests/1'](https://gitlab.freedesktop.org/libbsd/libbsd/merge_requests/1)
```
In file included from ../includ...error compiling on windows with msys2/mingw following the procedure from ['https://gitlab.freedesktop.org/libbsd/libbsd/merge_requests/1'](https://gitlab.freedesktop.org/libbsd/libbsd/merge_requests/1)
```
In file included from ../include/bsd/getopt.h:32,
from C:/msys64/mingw64/x86_64-w64-mingw32/include/unistd.h:12,
from ../include/bsd/unistd.h:31,
from arc4random.c:33:
../include/bsd/unistd.h:60:7: error: conflicting types for 'setmode'; have 'void *(const char *)'
60 | void *setmode(const char *mode_str);
| ^~~~~~~
In file included from C:/msys64/mingw64/x86_64-w64-mingw32/include/fcntl.h:8,
from arc4random.c:27:
C:/msys64/mingw64/x86_64-w64-mingw32/include/io.h:342:15: note: previous declaration of 'setmode' with type 'int(int, int)'
342 | int __cdecl setmode(int _FileHandle,int _Mode) __MINGW_ATTRIB_DEPRECATED_MSVC2005;
| ^~~~~~~
```https://gitlab.freedesktop.org/libbsd/libbsd/-/issues/5<sys/queue.h> is broken in overlay mode2023-04-04T22:11:32ZAlejandro Colomaralx@kernel.org<sys/queue.h> is broken in overlay mode``libbsd-overlay`` breaks ``<sys/queue.h>``
Concretely, it hides the header from the system, showing only the BSD version. If I don't compile with ``libbsd`` at all, I have ``CRICLEQ_*`` definitions from my system library, but if I com...``libbsd-overlay`` breaks ``<sys/queue.h>``
Concretely, it hides the header from the system, showing only the BSD version. If I don't compile with ``libbsd`` at all, I have ``CRICLEQ_*`` definitions from my system library, but if I compile with ``libbsd-overlay``, those definitions disappear.
Example code:
.. code-block:: c
#include <sys/queue.h>
struct Node {
int data;
CIRCLEQ_ENTRY(Node) circleq;
};
typedef int foo;
_______________________________________
Compilation command:
- Works: ``gcc test.c -S -o test.s``
- Breaks: ``gcc test.c -S -o test.s `pkg-config --cflags libbsd-overlay` ``
_______________________________________
System:
Debian testing
.. code-block::
$ uname -a
Linux debian-VLC 5.6.0-2-amd64 #1 SMP Debian 5.6.14-1 (2020-05-23) x86_64 GNU/Linux
_______________________________________
Libbsd:
.. code-block::
$ dpkg -l |grep libbsd
ii libbsd-dev:amd64 0.10.0-1 amd64 utility functions from BSD systems - development files
ii libbsd0:amd64 0.10.0-1 amd64 utility functions from BSD systems - shared library