|
Packit |
6c4009 |
/* Test that loading libpthread does not break ld.so exceptions (bug 16628).
|
|
Packit |
6c4009 |
Copyright (C) 2016-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <dlfcn.h>
|
|
Packit |
6c4009 |
#include <signal.h>
|
|
Packit |
6c4009 |
#include <stdio.h>
|
|
Packit |
6c4009 |
#include <string.h>
|
|
Packit |
6c4009 |
#include <sys/wait.h>
|
|
Packit |
6c4009 |
#include <unistd.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
static int
|
|
Packit |
6c4009 |
do_test (void)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
void *handle = dlopen ("tst-latepthreadmod.so", RTLD_LOCAL | RTLD_LAZY);
|
|
Packit |
6c4009 |
if (handle == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: dlopen failed: %s\n", dlerror ());
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
void *ptr = dlsym (handle, "trigger_dynlink_failure");
|
|
Packit |
6c4009 |
if (ptr == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: dlsym failed: %s\n", dlerror ());
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
int (*func) (void) = ptr;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Run the actual test in a subprocess, to capture the error. */
|
|
Packit |
6c4009 |
int fds[2];
|
|
Packit |
6c4009 |
if (pipe (fds) < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: pipe: %m\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
pid_t pid = fork ();
|
|
Packit |
6c4009 |
if (pid < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: fork: %m\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
else if (pid == 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
if (dup2 (fds[1], STDERR_FILENO) < 0)
|
|
Packit |
6c4009 |
_exit (2);
|
|
Packit |
6c4009 |
/* Trigger an abort. */
|
|
Packit |
6c4009 |
func ();
|
|
Packit |
6c4009 |
_exit (3);
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
/* NB: This assumes that the abort message is so short that the pipe
|
|
Packit |
6c4009 |
does not block. */
|
|
Packit |
6c4009 |
int status;
|
|
Packit |
6c4009 |
if (waitpid (pid, &status, 0) < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: waitpid: %m\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Check the printed error message. */
|
|
Packit |
6c4009 |
if (close (fds[1]) < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: close: %m\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
char buf[512];
|
|
Packit |
6c4009 |
/* Leave room for the NUL terminator. */
|
|
Packit |
6c4009 |
ssize_t ret = read (fds[0], buf, sizeof (buf) - 1);
|
|
Packit |
6c4009 |
if (ret < 0)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: read: %m\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (ret > 0 && buf[ret - 1] == '\n')
|
|
Packit |
6c4009 |
--ret;
|
|
Packit |
6c4009 |
buf[ret] = '\0';
|
|
Packit |
6c4009 |
printf ("info: exit status: %d, message: %s\n", status, buf);
|
|
Packit |
6c4009 |
if (strstr (buf, "undefined symbol: this_function_is_not_defined") == NULL)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: message does not contain expected string\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
if (!WIFEXITED (status) || WEXITSTATUS (status) != 127)
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
printf ("error: unexpected process exit status\n");
|
|
Packit |
6c4009 |
return 1;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
return 0;
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <support/test-driver.c>
|