1// { dg-require-sharedlib "" }
2// { dg-options "-g -O2 -pthread -ldl -x c -fvtable-verify=none" { target *-*-linux* *-*-gnu* } }
3
4// Copyright (C) 2005-2015 Free Software Foundation, Inc.
5//
6// This file is part of the GNU ISO C++ Library.  This library is free
7// software; you can redistribute it and/or modify it under the
8// terms of the GNU General Public License as published by the
9// Free Software Foundation; either version 3, or (at your option)
10// any later version.
11//
12// This library is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this library; see the file COPYING3.  If not see
19// <http://www.gnu.org/licenses/>.
20
21#include <pthread.h>
22#include <dlfcn.h>
23#include <errno.h>
24#include <stdio.h>
25#include <string.h>
26
27// NB: This must be compiled and linked as a "C" executable.
28static void* run(void* arg)
29{
30  typedef void (*function_type) (void);
31  void* lib;
32  void (*cb)();
33
34  lib = dlopen("./testsuite_shared.so", RTLD_NOW);
35  if (!lib)
36    {
37      printf("dlopen failed: %s\n", strerror(errno));
38      return 0;
39    }
40  cb = (function_type) dlsym(lib, "try_throw_exception");
41  if (!cb)
42    {
43      printf("dlsym failed: %s\n", strerror(errno));
44      return 0;
45    }
46  cb();
47  dlclose(lib);
48  return 0;
49}
50
51// libstdc++/23591
52int main(void)
53{
54  pthread_t pt;
55
56  if (pthread_create(&pt, 0, &run, 0) != 0)
57    return 1;
58  if (pthread_join(pt, 0) != 0)
59    return 1;
60
61  return 0;
62}
63