Commit Graph

90 Commits

Author SHA1 Message Date
Sam James
b62f36f305 test: nlist: make resilient against -Wl,--gc-sections
With linker sections GC enabled, we get a test failure in `nlist.c`:
```
nlist: nlist.c:72: main: Assertion `rc == 0' failed.
```

This turns out to be because several sections used by the test can be discarded:
```
ld: removing unused section '.text.func_pub' in file 'nlist.o'
ld: removing unused section '.bss.data_pub_uninit' in file 'nlist.o'
ld: removing unused section '.data.data_pub_init' in file 'nlist.o'
```

Reproduced with `CFLAGS="-Og -fdata-sections -ffunction-sections"` and
`LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--gc-sections -Wl,-z,start-stop-gc"`.

Additionally, `LDFLAGS="... -Wl,--print-gc-sections"` can help with diagnosing
which sections get removed.

We already mark these symbols as `used`, but we need `retain` [0] for them
to survive linker GC too.

[0] https://releases.llvm.org/18.1.0/tools/lld/docs/ELF/start-stop-gc.html#annotate-c-identifier-name-sections

Closes: !29
Signed-off-by: Sam James <sam@gentoo.org>
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2024-03-14 09:33:34 +01:00
Guillem Jover
32d18dcf47 Add explicit time32 and time64 support
Handle the three potential system scenarios:

 - system time_t is time64
 - system time_t is time32 and supports time64
 - system time_t is time32 and does not support time64

Add the explicit time32 and time64 functions when necessary and map
them accordingly for each of these cases.
2024-02-27 05:47:50 +01:00
Guillem Jover
be4aced4c5 build: Make almost all exposed interfaces use the new ABI selection
Explicitly select what to include as part of the target ABI, instead of
letting autoconfiguration potentially break ABI if the system grows
functionality provided by the library.

Make almost all the library selectable per target. Do not install manual
pages for interfaces not included in the library. Control inclusion of
symbols in map file via pre-processor macros, and move the comments
describing the ABI selection to configure.ac.

For now the header files are included as is and filtered through
pre-processor conditionals. Eventually they might get switched to be
autogenerated at build time.
2024-02-25 03:50:40 +01:00
Guillem Jover
99739877be build: Rename ABI selection variables from need_ to abi_
This should make the purpose of these variables more clear.
2024-02-25 03:47:54 +01:00
Guillem Jover
a81d0b7113 build: Sort variables and their contents in automake files
This should make it easier to add new entries, and find them afterwards.
2024-02-21 02:09:48 +01:00
Guillem Jover
dd0bdb58e0 test: Close all descriptors before initializing them for closefrom()
On macOS, closefrom() only sets the close-on-exec flag, so we cannot
check whether all file descriptors were closed, which means that if
on entry our file descriptor table was filled after the 4th file
descriptor, then we might fail the assertions for the flags for odd
file descriptors which we expect to be closed.

This can easily happen when running the test suite in parallel mode
with «make -j8 check» for example.

Closes: #23
2024-01-08 01:58:54 +01:00
Guillem Jover
a44f885cd4 test: Fix short-lived memory leak
Warned-by: cppcheck
2024-01-07 16:45:39 +01:00
Guillem Jover
dc1bd1a2cb build: Conditionalize only id-from-name functions not the entire pwcache
On macOS the name-from-id functions are present, but not the
id-from-name ones, so we want to provide those instead of suppressing
the entire file.
2023-04-29 03:52:42 +02:00
Guillem Jover
edc746ea7b build: Conditionalize getprogname()/setprogname on macOS
These functions are provided by the system libc, so there is no need for
us to provide them.
2023-04-22 22:47:33 +02:00
Guillem Jover
90b7f3aeba test: Do not use /dev/null as compiler output file
Some ld(1) implementations, such as the one on AIX, do not support using
/dev/null as the output filename for the compiled object.

Use an actual filename that we will then clean up.
2023-04-18 01:09:05 +02:00
Guillem Jover
21d12b0211 build: On macOS do not build functions provided by the system
We have never built before on macOS, so we can exclude all the functions
that are currently provided in the system.

Closes: #1
Closes: !3
2023-04-17 04:12:42 +02:00
Guillem Jover
bc65806ce2 build: Select whether to include funopen() in the build system
This makes sure we include it when expected, alongside the man pages,
and the test cases, and do not accidentally break the ABI if the system
starts providing such interface.
2023-04-17 04:12:42 +02:00
Guillem Jover
fe16f3863e test: Use open_memstream() only if available
On Solaris this function is not yet available.
2023-04-17 04:12:42 +02:00
Guillem Jover
7c652a94ea test: Do not hardcode root:root user and group names
On some systems the root group is named wheel, and there is no root
group.
2023-04-17 04:12:42 +02:00
Guillem Jover
ed2eb31da9 test: Fix closefrom() test on macOS
On macOS we do not close the file descriptors, and instead mark them all
as close-on-exec. So checking whether they are not valid does not work.
2023-04-17 04:12:42 +02:00
Guillem Jover
0f8bcdfd92 test: Fix closefrom() test to handle open file descriptor limits
If the system has configured a lower limit (either soft or hard) on the
number of open file descriptors, the test will fail. Make sure to check
whether we have exceeded that limit and adapt the max number of file
descriptors appropriately.
2023-04-17 04:12:42 +02:00
Guillem Jover
07192b31e3 test: Disable blank_stack_side_effects() on non-Hurd systems
This code was added to cope with Hurd specific behavior, but it is
causing flakiness on containers on some Linux systems. Only enable
it where it is currently needed to try to get stability back on CI
systems.

Closes: #14
2023-04-17 04:12:32 +02:00
Guillem Jover
536a7d42fd test: Exempt blank_stack_side_effects() from sanitizer checks
This will mean we cannot use sanitizer support on the Hurd, for which
this function was added to fix the test. But the sanitizer suppression
function attribute is not having any effect, so this is better than
nothing.
2023-03-29 02:47:18 +02:00
Guillem Jover
7ed5de0158 test: Import explicit_bzero() sanitizer support changes from OpenBSD 2023-03-29 02:38:26 +02:00
Guillem Jover
05a802a2c1 test: Fix memory leaks in fpurge test
Warned-by: gcc -fsanitize=leak
2023-03-21 04:13:32 +01:00
Guillem Jover
e50896286c build: Do not require funopen() to be ported
This function cannot be easily and (more importantly) correctly ported
without cooperation from the libc stdio layer. We already document that
users should be prepared to have the function not available on some
platforms and that they should ideally switch their code to other
more portable and better interfaces.

Instead of making the build fail, and requiring porters to add
exceptions for something that most probably cannot be ported correctly
anyway, simply print a warning and let it build. This will not be a
regression because on those systems libbsd would have never been built
before.

Prompted-by: Jens Finkhaeuser <jens@finkhaeuser.de>
2022-11-24 23:23:33 +01:00
Guillem Jover
00b538ffa3 build: Terminate lists in variables with «# EOL»
This means we can add a trailing «\» to every element, so that they
can be removed without requiring modification of other lines, and can
be easily sorted.

Replace the old usage of $(nil) which could possibly end up with junk
added if such variable is ever defined, in the environment.
2022-11-23 23:44:09 +01:00
Guillem Jover
d5865759f8 test: Fix explicit_bzero() test on the Hurd
On the Hurd a small read(3) might end up (indirectly) copying the data
on the stack, which we will end up finding even when we have cleared
the buffer.

To avoid these side effects, we add a new function, that we force not
to be inlined, so that we can reuse the same stack space, that will
blank any possible stack side effects. This should be portable
regardless of stack growing up or down.

Diagnosis-by: Samuel Thibault <sthibault@debian.org>
2022-10-04 04:29:37 +02:00
Guillem Jover
c9ff83687c test: Import explicit_bzero and strtonum test cases from OpenBSD
- Remove trailing spaces.
- Declare file-scope functions and variables static.
- Declare functions with a proper prototype.
- Do not mix declarations and code for C90 conformance.
- Do not compare size_t and ssize_t variables.
2022-01-29 14:54:24 +01:00
Guillem Jover
62e67bb49e build: Sort test programs in .gitignore 2022-01-29 14:52:39 +01:00
Duncan Overbruck
87b1307040 test: Add fpurge() test case using open_memstream(3) FILE
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2022-01-29 14:10:55 +01:00
Duncan Overbruck
091097e062 test: Remove static FILE declaration from fpurge test
This does not work with libcs that do not declare the structure
in a header file, like musl. And gets in the way of supporting
non-fd based streams.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2022-01-26 04:39:42 +01:00
Guillem Jover
eef07993c9 Revert "build: Add missing proctitle unit test program"
This reverts commit beafad2657.

This test was already handled later on as part of the BUILD_LIBBSD_CTOR
conditional. Adding it to the unconditional set made the build fail when
the system does not have GNU .init_array section support.

Closes: #9
Analysis-by: Duncan Overbruck <mail@duncano.de>
2022-01-25 01:41:14 +01:00
Guillem Jover
e7cf8c5785 Switch md5 compatibility logic back to direct linking
When using the recent dlsym() based wrapper, we are not requiring any
symbol from libmd, as we resolve those dynamically at run-time. We were
ending up linking against libmd because in another part of the code we
require (depending on the architecture) the SHA512 functions for the
getentropy() local implementation. But that function might be provided
by the system libc on some systems, which means we end up not linking
against libmd at all.

To solve this we go back to the previous simpler solution of linking
directly, which had the main drawback of then making programs fail to
link when not specifying -lmd (on platforms that need it). And then
switch the .so link point from a symlink to a linker script, so that we
can inject the -lmd library as-needed. This is similar to what glibc is
doing.

Fixes: commit 31f034e386
2021-12-01 04:14:35 +01:00
Guillem Jover
1eba406021 test: Check that strdup() does not fail
Warned-by: gcc
2021-11-27 23:42:37 +01:00
Victor Westerhuis
2716dfd0b7 test: Explicitly mark symbols as used
Because some of the symbols are not otherwise referenced, GCC would like
to remove them.

Closes: !14
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2021-11-27 06:52:17 +01:00
Guillem Jover
1808d64b77 test: Fix pipe_feed() to allow checking fprintf format strings
Warned-by: gcc -W
2021-11-27 05:06:14 +01:00
Guillem Jover
beafad2657 build: Add missing proctitle unit test program 2021-11-27 05:06:14 +01:00
Guillem Jover
6145b56178 test: Do not pass NULL as the first funopen() argument
Warned-by: gcc -W
2021-11-27 05:06:14 +01:00
Guillem Jover
25e88f6479 test: Cast literal strings to (char *) on n_name assignment
The member is declared as n_name so we cannot directly assign a literal
string constant.

Warned-by: gcc
2021-11-27 05:06:14 +01:00
Guillem Jover
3c305f2873 test: Add proper prototypes for main() function
Warned-by: gcc
2021-02-28 05:30:31 +01:00
Guillem Jover
25278891d8 Mark local functions as static
Warned-by: gcc
2021-02-28 05:30:25 +01:00
Guillem Jover
31f034e386 Switch libmd wrapper to use dlsym()
Switch from the previous versioned symbol implementation which required
users to also link against the message digest provider explicitly, or
they would fail to find the symbols, to an implementation that loads
the symbols from the linked library providing the functions using
dlsym(), thus preserving backwards compatibility.
2021-02-09 06:23:38 +01:00
Guillem Jover
25f9b30678 test: Improve code coverage for strnstr(3) unit tests 2021-02-07 23:24:51 +01:00
Guillem Jover
233cab9d64 Add support for new LIBBSD_VIS_OPENBSD selection macro
This will make it possible to explicitly select the OpenBSD vis
implementation (the current default) for code of OpenBSD origins.
2021-02-07 02:03:22 +01:00
Guillem Jover
d54ceb37ce Update copyright claims 2021-02-07 01:28:27 +01:00
Guillem Jover
847e682f8d Use libmd hashing function implementations instead of embedding our own
This splits the implementation responsibilities, and reduces embedded
code copies, which was one of the driving points with this project to
start with, so it's nice to give a good example.
2021-02-07 01:28:27 +01:00
Guillem Jover
37a9b56c05 Import pwcache module from OpenBSD 2021-02-07 01:28:27 +01:00
Guillem Jover
d5b04ab19c test: Fix short lived memory leaks
These are non-issues, but having a clean ASAN test suite makes it
possible to detect actual problems in the tested code.

Warned-by: gcc ASAN
2020-12-21 17:44:26 +01:00
James Clarke
61d378f5e9 Re-allow direct use of nlist.n_name in <nlist.h>
Commit e8d340de ("Remove a.out support from nlist()") introduced a copy
of the definition of nlist from a.out.h. However, as well as having
n_name inside n_un, on the various BSDs n_name could also be accessed
as a direct member of nlist, and this is made use of by FreeBSD's
usr.bin/netstat/main.c. Thus we should also add the same enclosing
anonymous union.

[guillem@hadrons.org:
 - Add a minimal unit test. ]

Closes: !4
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2019-08-08 03:47:04 +02:00
Aaron Dierking
0500a1bd08 Don't require <grp.h>
This is only used in the overlay test and Windows does not provide it.

Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-06-18 04:31:00 +02:00
Guillem Jover
e4e15ed286 Fix strnvis() and strnunvis() NetBSD ABI break
The NetBSD implementations have different prototypes to the ones coming
from OpenBSD, which will break builds, and have caused segfaults at
run-time. We provide now both interfaces with different prototypes as
different version nodes allow selecting them at compile-time, defaulting
for now to the OpenBSD one to avoid build-time breakage, while emitting
a compile-time warning. Later on, in 0.10.0, we will be switching the
compile-time default to the NetBSD version.

Ref: http://gnats.netbsd.org/44977
Fixes: https://bugs.debian.org/899282
2018-05-22 16:07:42 +02:00
Jason Duerstock
9ceac74e91 test: Fix nlist(3) unit test on IA64
On IA64 this is only the case in the ELF binary, but it gets normalized
when loaded at run-time.

Fixes: https://bugs.debian.org/881611
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2018-01-13 16:17:28 +01:00
Guillem Jover
3b2b7938f7 test: Fix nlist() unit test on IA64 and PowerPC 64-bit ELFv1
At least on IA64 and PowerPC 64-bit ELFv1, the functions are stored in
the .text sections but they are accessed through a function descriptor
stored in a data section, for example for PowerPC 64-bit ELFv1 that
section is called .opd.

We should take this into account when checking the n_type for the
functions we have requested information from nlist().

Rationale-by: James Clarke <jrtc27@jrtc27.com>
2017-06-25 02:10:26 +02:00
Guillem Jover
c4e58c0950 test: Remove unused variable in nlist() unit test 2017-06-24 16:06:15 +02:00