Commit Graph

198 Commits

Author SHA1 Message Date
Chung-Lin Tang
e6fd79f379 elf: Testing infrastructure for ld.so DSO sorting (BZ #17645)
This is the first of a 2-part patch set that fixes slow DSO sorting behavior in
the dynamic loader, as reported in BZ #17645. In order to facilitate such a
large modification to the dynamic loader, this first patch implements a testing
framework for validating shared object sorting behavior, to enable comparison
between old/new sorting algorithms, and any later enhancements.

This testing infrastructure consists of a Python script
scripts/dso-ordering-test.py' which takes in a description language, consisting
of strings that describe a set of link dependency relations between DSOs, and
generates testcase programs and Makefile fragments to automatically test the
described situation, for example:

  a->b->c->d          # four objects linked one after another

  a->[bc]->d;b->c     # a depends on b and c, which both depend on d,
                      # b depends on c (b,c linked to object a in fixed order)

  a->b->c;{+a;%a;-a}  # a, b, c serially dependent, main program uses
                      # dlopen/dlsym/dlclose on object a

  a->b->c;{}!->[abc]  # a, b, c serially dependent; multiple tests generated
                      # to test all permutations of a, b, c ordering linked
                      # to main program

 (Above is just a short description of what the script can do, more
  documentation is in the script comments.)

Two files containing several new tests, elf/dso-sort-tests-[12].def are added,
including test scenarios for BZ #15311 and Redhat issue #1162810 [1].

Due to the nature of dynamic loader tests, where the sorting behavior and test
output occurs before/after main(), generating testcases to use
support/test-driver.c does not suffice to control meaningful timeout for ld.so.
Therefore a new utility program 'support/test-run-command', based on
test-driver.c/support_test_main.c has been added. This does the same testcase
control, but for a program specified through a command-line rather than at the
source code level. This utility is used to run the dynamic loader testcases
generated by dso-ordering-test.py.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1162810

Signed-off-by: Chung-Lin Tang  <cltang@codesourcery.com>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-10-21 11:23:53 -03:00
Jonathan Wakely
8a9a593115 Add alloc_align attribute to memalign et al
GCC 4.9.0 added the alloc_align attribute to say that a function
argument specifies the alignment of the returned pointer. Clang supports
the attribute too. Using the attribute can allow a compiler to generate
better code if it knows the returned pointer has a minimum alignment.
See https://gcc.gnu.org/PR60092 for more details.

GCC implicitly knows the semantics of aligned_alloc and posix_memalign,
but not the obsolete memalign. As a result, GCC generates worse code
when memalign is used, compared to aligned_alloc.  Clang knows about
aligned_alloc and memalign, but not posix_memalign.

This change adds a new __attribute_alloc_align__ macro to <sys/cdefs.h>
and then uses it on memalign (where it helps GCC) and aligned_alloc
(where GCC and Clang already know the semantics, but it doesn't hurt)
and xposix_memalign. It can't be used on posix_memalign because that
doesn't return a pointer (the allocated pointer is returned via a void**
parameter instead).

Unlike the alloc_size attribute, alloc_align only allows a single
argument. That means the new __attribute_alloc_align__ macro doesn't
really need to be used with double parentheses to protect a comma
between its arguments. For consistency with __attribute_alloc_size__
this patch defines it the same way, so that double parentheses are
required.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-10-21 00:19:20 +01:00
Joseph Myers
de82cb0da4 Add TEST_COMPARE_STRING_WIDE to support/check.h
I'd like to be able to test narrow and wide string interfaces, with
the narrow string tests using TEST_COMPARE_STRING and the wide string
tests using something analogous (possibly generated using macros from
a common test template for both the narrow and wide string tests where
appropriate).

Add such a TEST_COMPARE_STRING_WIDE, along with functions
support_quote_blob_wide and support_test_compare_string_wide that it
builds on.  Those functions are built using macros from common
templates shared by the narrow and wide string implementations, though
I didn't do that for the tests of test functions.  In
support_quote_blob_wide, I chose to use the \x{} delimited escape
sequence syntax proposed for C2X in N2785, rather than e.g. trying to
generate the end of a string and the start of a new string when
ambiguity would result from undelimited \x (when the next character
after such an escape sequence is valid hex) or forcing an escape
sequence to be used for the next character in the case of such
ambiguity.

Tested for x86_64.
2021-10-12 13:48:39 +00:00
Siddhesh Poyarekar
27b6edbb09 support: Also return fd when it is 0
The fd validity check in open_dev_null checks if fd > 0, which would
lead to a leaked fd if it is == 0.

Signed-off-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-10-06 22:18:24 +05:30
Florian Weimer
176c88f521 support: Add check for TID zero in support_wait_for_thread_exit
Some kernel versions (observed with kernel 5.14 and earlier) can list
"0" entries in /proc/self/task.  This happens when a thread exits
while the task list is being constructed.  Treat this entry as not
present, like the proposed kernel patch does:

[PATCH] procfs: Do not list TID 0 in /proc/<pid>/task
<https://lore.kernel.org/all/8735pn5dx7.fsf@oldenburg.str.redhat.com/>

Fixes commit 032d74eaf6 ("support: Add
support_wait_for_thread_exit").

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-10-01 18:16:41 +02:00
Adhemerval Zanella
9cba3fa34b support: Add support_mutex_pi_monotonic
Returns true if Priority Inheritance support CLOCK_MONOTONIC.
2021-10-01 10:11:08 -03:00
Stafford Horne
2efca218b5 xsysconf: Only fail on error results and errno set
When testing nptl/tst-pthread-attr-affinity-fail fails with:

    error: xsysconf.c:33: sysconf (83): Cannot allocate memory
    error: 1 test failures

This happens as xsysconf checks the errno after running sysconf.
Internally the sysconf request for _SC_NPROCESSORS_CONF on linux
allocates memory.  But there is a problem, even though malloc succeeds
errno is getting set to ENOMEM.

POSIX allows successful calls to clobber errno.  So xsysconf just
checking errno is wrong.  Fix xsysconf by only failing if we have an
error result and errno is set.
2021-09-24 17:30:03 +09:00
Stafford Horne
5604830dea time: Fix compile error in itimer test affecting hurd
The recent change to use __KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 to avoid
doing 64-bit checks on some platforms broke the test for hurd where
__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64 is not defined.  With error:

    tst-itimer.c: In function 'do_test':
    tst-itimer.c:103:11: error: '__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64' undeclared (first use in this function)
      103 |       if (__KERNEL_OLD_TIMEVAL_MATCHES_TIMEVAL64)
	  |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    tst-itimer.c:103:11: note: each undeclared identifier is reported only once for each function it appears in

Define a support helper to detect when setitimer and getitimer support
64-bit time_t.

Fixes commit 6e8a0aac2f ("time: Fix overflow itimer tests on 32-bit
systems").

Cc: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: Joseph Myers <joseph@codesourcery.com>
2021-09-16 05:21:08 +09:00
Florian Weimer
032d74eaf6 support: Add support_wait_for_thread_exit 2021-08-30 13:43:56 +02:00
Adhemerval Zanella
e814f4b04e support: Add support_open_dev_null_range
It returns a range of file descriptor referring to the '/dev/null'
pathname.  The function takes care of restarting the open range
if a file descriptor is found within the specified range and
also increases RLIMIT_NOFILE if required.

Checked on x86_64-linux-gnu.
2021-08-26 17:13:45 -03:00
Siddhesh Poyarekar
45caed9d67 copy_and_spawn_sgid: Avoid double calls to close()
If close() on infd and outfd succeeded, reset the fd numbers so that
we don't attempt to close them again.

Reviewed-by: Arjun Shankar <arjun@redhat.com>
2021-08-03 21:10:53 +05:30
Siddhesh Poyarekar
70d08ba204 tests: use xmalloc to allocate implementation array
The benchmark and tests must fail in case of allocation failure in the
implementation array.  Also annotate the x* allocators in support.h so
that the compiler has more information about them.

Reviewed-by: Florian Weimer <fweimer@redhat.com>
2021-07-28 17:45:19 +05:30
H.J. Lu
17cef890c9 support: Replace _SC_MINSIGSTKSZ with _SC_SIGSTKSZ
Replace _SC_MINSIGSTKSZ with _SC_SIGSTKSZ since sysconf (_SC_MINSIGSTKSZ)
returns the minimum number of bytes of free stack space required in order
to guarantee successful, non-nested handling of a single signal whose
handler is an empty function while sysconf (_SC_SIGSTKSZ) returns the
suggested minimum number of bytes of stack space required for a signal
stack.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-07-11 07:57:31 -07:00
H.J. Lu
28d07380c2 support: Replace MINSIGSTKSZ with sysconf (_SC_MINSIGSTKSZ)
Replace MINSIGSTKSZ with sysconf (_SC_MINSIGSTKSZ) since the constant
MINSIGSTKSZ used in glibc build may be too small.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-07-09 15:20:55 -07:00
H.J. Lu
5d98a7dae9 Define PTHREAD_STACK_MIN to sysconf(_SC_THREAD_STACK_MIN)
The constant PTHREAD_STACK_MIN may be too small for some processors.
Rename _SC_SIGSTKSZ_SOURCE to _DYNAMIC_STACK_SIZE_SOURCE.  When
_DYNAMIC_STACK_SIZE_SOURCE or _GNU_SOURCE are defined, define
PTHREAD_STACK_MIN to sysconf(_SC_THREAD_STACK_MIN) which is changed
to MIN (PTHREAD_STACK_MIN, sysconf(_SC_MINSIGSTKSZ)).

Consolidate <bits/local_lim.h> with <bits/pthread_stack_min.h> to
provide a constant target specific PTHREAD_STACK_MIN value.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-07-09 15:10:35 -07:00
Adhemerval Zanella
ae8c243d24 support: Add support_stack_alloc
The code to allocate a stack from xsigstack is refactored so it can
be more generic.  The new support_stack_alloc() also set PROT_EXEC
if DEFAULT_STACK_PERMS has PF_X.  This is required on some
 architectures (hppa for instance) and trying to access the rtld
global from testsuite will require more intrusive refactoring
in the ldsodefs.h header.

Checked on x86_64-linux-gnu and i686-linux-gnu.  I also ran
tst-xsigstack on both hppa and ia64.
2021-07-08 13:48:06 -03:00
Florian Weimer
97ed4749be support: Fix xclone build failures on ia64 and hppa 2021-06-25 09:36:28 +02:00
Adhemerval Zanella
de8995a2a0 support: Add xclone
It is a wrapper for Linux clone syscall, to simplify the call to the
use only the most common arguments and remove architecture specific
handling (such as ia64 different name and signature).
2021-06-24 10:00:52 -03:00
Adhemerval Zanella
92f7b46510 support: Add support_create_timer
It is a simple wrapper over timer_create, timer_settime, and
sigaction.  It will be used to check for large timeout to trigger an
EINTR and to avoid use a large timeout (as for alarm()).

Reviewed-by: Lukasz Majewski <lukma@denx.de>
2021-06-22 12:09:52 -03:00
Adhemerval Zanella
372d2ef1f9 libsupport: Add 64-bit time_t support for stat functions
The patch adds redirections for xstat, xlstat, and xfstat when
_TIME_BITS=64 is defined.

Reviewed-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-06-15 10:42:11 -03:00
Adhemerval Zanella
e9bc2b3b38 libsupport: Add 64-bit time_t support for time functions
The patch adds redirections for xclock_gettime, xclock_settime,
timespec_add, timespec_sub, test_timespec_before_impl,
test_timespec_equal_or_after_impl, support_timespec_ns,
support_timespec_normalize, and support_timespec_check_in_range when
_TIME_BITS=64 is defined.

Co-authored-by: Lukasz Majewski <lukma@denx.de>
Tested-by: Carlos O'Donell <carlos@redhat.com>
2021-06-15 10:42:11 -03:00
Florian Weimer
acc85ea1eb io: Fix sporadic test failures in io/tst-stat
support_stat_nanoseconds cannot restore the ctime time, and
this may lead to sporadic test failures.  Therefore, probe for
nanoseconds support before the initial statx call.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-06-10 13:48:26 +02:00
Adhemerval Zanella
271ec55d0a support: Do not build xpthread_attr_setaffinity_np for hurd
It does not provide pthread_attr_setaffinity_np extension.
2021-05-28 16:00:19 -03:00
Adhemerval Zanella
d85ad0e58a support: Add xpthread_attr_setaffinity_np wrapper 2021-05-27 13:12:07 -03:00
Siddhesh Poyarekar
c7d200400c support: Free gdb_script_name
Identified by static analysis.
2021-05-13 08:07:23 +05:30
Siddhesh Poyarekar
75fe6d1a16 support: Close fds in copy_func
copy_func may leave file descriptors open on error, so close them on
function exit.
2021-05-13 08:07:20 +05:30
Adhemerval Zanella
49a40ba18e libsupport: Add support_select_normalizes_timeout
It will be used on a select() test.
2021-04-12 18:38:37 -03:00
Adhemerval Zanella
5628f103f5 libsupport: Add support_select_modifies_timeout
It will be used on a select() test.
2021-04-12 18:38:37 -03:00
Siddhesh Poyarekar
716a3bdc41 support: Add capability to fork an sgid child
Add a new function support_capture_subprogram_self_sgid that spawns an
sgid child of the running program with its own image and returns the
exit code of the child process.  This functionality is used by at
least three tests in the testsuite at the moment, so it makes sense to
consolidate.

There is also a new function support_subprogram_wait which should
provide simple system() like functionality that does not set up file
actions.  This is useful in cases where only the return code of the
spawned subprocess is interesting.

This patch also ports tst-secure-getenv to this new function.  A
subsequent patch will port other tests.  This also brings an important
change to tst-secure-getenv behaviour.  Now instead of succeeding, the
test fails as UNSUPPORTED if it is unable to spawn a setgid child,
which is how it should have been in the first place.
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2021-04-12 19:03:19 +05:30
Adhemerval Zanella
4d8cf564a2 support: Fix hurd build after bfddda2570 2021-04-01 13:55:46 -03:00
Adhemerval Zanella
bfddda2570 io: Check at runtime if timestamp supports nanoseconds
Now that non-LFS stat function is implemented on to on LFS, it will
use statx when available.  It allows to check for nanosecond timestamp
if the kernel supports __NR_statx.

Checked on s390-linux-gnu with 4.12.14 kernel.
2021-03-31 17:20:14 -03:00
Adhemerval Zanella
6fbc0540de support: Add support_path_support_time64_value
It allows to check for support on arbitrary timestamp values.
2021-03-29 10:22:13 -03:00
Stefan Liebler
1966f47a1e S390: Don't test nanoseconds in io/tst-stat.c
Both new tests io/tst-stat and io/tst-stat-lfs (_FILE_OFFSET_BITS=64)
are comparing the nanosecond fields with the statx result.  Unfortunately
on s390(31bit) those fields are always zero if old KABI with non-LFS
support is used.  With _FILE_OFFSET_BITS=64 stat is using statx internally.

As suggested by Adhemerval this patch disables the nanosecond check for
s390(31bit).
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-03-26 10:21:13 +01:00
Adhemerval Zanella
48593b505b support: Use syscall function instead of INLINE_SYSCALL_CALL
It fixes the build on ARM in thumb mode that requires an out of the
line helper (__libc_do_syscall) to issue the syscall.
2021-03-18 17:52:09 -03:00
Siddhesh Poyarekar
e958490f8c support: Pass environ to child process
Pass environ to posix_spawn so that the child process can inherit
environment of the test.
2021-03-16 19:06:36 +05:30
Siddhesh Poyarekar
95c68080a3 support: Typo and formatting fixes
- Add a newline to the end of error messages in transfer().
- Fixed the name of support_subprocess_init().
2021-03-15 20:16:27 +05:30
Adhemerval Zanella
0280b390fb support: Add xpthread_kill
Checked on x86_64-linux-gnu.
2021-03-12 10:20:18 -03:00
Adhemerval Zanella
b2970919ba io: Return UNSUPPORTED if filesystem do not support 64 bit timestamps
Some Linux filesystems might not fully support 64 bit timestamps [1],
which make some Linux specific tests to fail when they check for the
functionality.

This patch adds a new libsupport function, support_path_support_time64,
that returns whether the target file supports or not 64 bit timestamps.
The support is checked by issuing a utimensat and verifying both the
last access and last modification time against a statx call.

The tests that might fail are also adjusted to check the file support
as well:

  $ dd if=/dev/zero of=loopbackfile.img bs=100M count=1
  1+0 records in
  1+0 records out
  104857600 bytes (105 MB, 100 MiB) copied, 0,0589568 s, 1,8 GB/s
  $ sudo losetup -fP loopbackfile.img
  $ mkfs.xfs loopbackfile.img
  meta-data=loopbackfile.img       isize=512    agcount=4, agsize=6400 blks
           =                       sectsz=512   attr=2, projid32bit=1
           =                       crc=1        finobt=1, sparse=1, rmapbt=0
           =                       reflink=1
  data     =                       bsize=4096   blocks=25600, imaxpct=25
           =                       sunit=0      swidth=0 blks
  naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
  log      =internal log           bsize=4096   blocks=1368, version=2
           =                       sectsz=512   sunit=0 blks, lazy-count=1
  realtime =none                   extsz=4096   blocks=0, rtextents=0
  $ mkdir loopfs
  $ sudo mount -o loop /dev/loop0 loopfs/
  $ sudo chown -R azanella:azanella loopfs
  $ TMPDIR=loopfs/ ./testrun.sh misc/tst-utimes
  error: ../sysdeps/unix/sysv/linux/tst-utimes.c:55: File loopfs//utimesfECsK1 does not support 64-bit timestamps

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1795576
2021-03-12 10:17:31 -03:00
DJ Delorie
20bee71348 test-container: Always copy test-specific support files [BZ #27537]
There's a small chance that a fresh checkout will result in some of
the test-specific container files will have the same timestamp and
size, which breaks the rsync logic in test-container, resulting in
tests running with the wrong support files.

This patch changes the rsync logic to always copy the test-specific
files, which normally would always be copied anyway.  The rsync logic
for the testroot itself is unchanged.
2021-03-11 17:04:12 -05:00
Lukasz Majewski
a156555007 support: Provide xclock_settime test helper function
The xclock_settime is a wrapper function on the clock_settime syscall
to be used in the test code.

It checks if the GLIBC_TEST_ALLOW_TIME_SETTING env variable is defined
in the environment in which test is executed. If it is not - the test
ends as unsupported. Otherwise, the clock-settime is executed and return
value is assessed.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2021-03-08 22:41:28 +01:00
Adhemerval Zanella
a50a080f6b elf: Fix tests that rely on ld.so.cache for cross-compiling
For configurations with cross-compiling equal to 'maybe' or 'no',
ldconfig will not run and thus the ld.so.cache will not be created
on the container testroot.pristine.

This lead to failures on both tst-glibc-hwcaps-prepend-cache and
tst-ldconfig-ld_so_conf-update on environments where the same
compiler can be used to build different ABIs (powerpc and x86 for
instance).

This patch addas a new test-container hook, ldconfig.run, that
triggers a ldconfig execution prior the test execution.

Checked on x86_64-linux-gnu and i686-linux-gnu.
2021-01-29 14:08:18 -03:00
Adhemerval Zanella
42dda89dcb posix: Fix return value of system if shell can not be executed [BZ #27053]
POSIX states that system returned code for failure to execute the shell
shall be as if the shell had terminated using _exit(127).  This
behaviour was removed with 5fb7fc9635.

Checked on x86_64-linux-gnu.
2021-01-11 12:26:58 -03:00
Adhemerval Zanella
7b9c3260bc support: Add xchmod wrapper
Checked on x86_64-linux-gnu.
2021-01-11 12:26:58 -03:00
Alexandra Hájková
7a72265436 Add xfchmod to libsupport 2021-01-10 18:55:47 +01:00
Alexandra Hájková
a7e9dbb774 Add xchdir to libsupport. 2021-01-09 17:47:50 +01:00
Adhemerval Zanella
ecdb06cdf2 support: Add support_small_thread_stack_size
It returns the minimum stack size large enough to cover most internal
glibc stack usage.
2021-01-05 11:33:16 -03:00
Paul Eggert
2b778ceb40 Update copyright dates with scripts/update-copyrights
I used these shell commands:

../glibc/scripts/update-copyrights $PWD/../gnulib/build-aux/update-copyright
(cd ../glibc && git commit -am"[this commit message]")

and then ignored the output, which consisted lines saying "FOO: warning:
copyright statement not found" for each of 6694 files FOO.
I then removed trailing white space from benchtests/bench-pthread-locks.c
and iconvdata/tst-iconv-big5-hkscs-to-2ucs4.c, to work around this
diagnostic from Savannah:
remote: *** pre-commit check failed ...
remote: *** error: lines with trailing whitespace found
remote: error: hook declined to update refs/heads/master
2021-01-02 12:17:34 -08:00
Samuel Thibault
f9c3cf2864 support: Make support_process_state_wait wait less
Tests such as posix/tst-waitid.c make heavy use of
support_process_state_wait, and thus on non-Linux where it falls back
to sleeping, a 2s sleep makes such test time out, while 1s remains
fine enough.
2020-12-28 23:17:56 +01:00
Florian Weimer
cb81264fd9 support: Add support_slibdir_prefix variable
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
2020-12-11 18:30:57 +01:00
Florian Weimer
603ae243f6 support: Add support_copy_file
Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
2020-11-26 18:19:46 +01:00